7#include "flagmanager.h"
9#include "config-kstars.h"
12#include "ksnotification.h"
14#include "kstars_debug.h"
15#include "kstarsdata.h"
18#include "skycomponents/flagcomponent.h"
19#include "skycomponents/skymapcomposite.h"
22#include <basedevice.h>
23#include "indi/indilistener.h"
24#include "indi/indistd.h"
25#include "indi/indimount.h"
26#include "indi/driverinfo.h"
31#include <QStandardItemModel>
32#include <QSortFilterProxyModel>
49 ui =
new FlagManagerUI(
this);
51 setWindowTitle(
i18nc(
"@title:window",
"Flag Manager"));
55 setLayout(mainLayout);
59 connect(buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
63 ui->hintLabel->setText(
i18n(
"To add custom icons, just add images in %1. File names must begin with flag. "
64 "For example, the file <i>flagSmall_red_cross.png</i> will be shown as <b>Small red "
65 "cross</b> in the combo box.",
69 m_Model->setHorizontalHeaderLabels(
QStringList() <<
i18nc(
"Right Ascension",
"RA") <<
i18nc(
"Declination",
"Dec")
72 m_SortModel->setSourceModel(m_Model);
73 m_SortModel->setDynamicSortFilter(
true);
74 ui->flagList->setModel(m_SortModel);
75 ui->flagList->horizontalHeader()->setStretchLastSection(
true);
79 ui->saveButton->setEnabled(
false);
81 ui->raBox->setUnits(dmsBox::HOURS);
84 imageList = m_Ks->
data()->skyComposite()->flags()->imageList();
85 flagNames = m_Ks->
data()->skyComposite()->flags()->getNames();
90 for (i = 0; i < m_Ks->data()->skyComposite()->flags()->size(); ++i)
95 itemList <<
new QStandardItem(flags->pointList().
at(i)->ra0().toHMSString())
104 for (i = 0; i < imageList.
size(); ++i)
108 if (imageList.
size() >= 2 && ui->flagCombobox->currentIndex() == 0)
109 ui->flagCombobox->setCurrentIndex(1);
112 connect(ui->addButton, SIGNAL(clicked()),
this, SLOT(slotAddFlag()));
113 connect(ui->delButton, SIGNAL(clicked()),
this, SLOT(slotDeleteFlag()));
114 connect(ui->CenterButton, SIGNAL(clicked()),
this, SLOT(slotCenterFlag()));
115 connect(ui->ScopeButton, SIGNAL(clicked()),
this, SLOT(slotCenterTelescope()));
117 connect(ui->flagList, SIGNAL(doubleClicked(
QModelIndex)),
this, SLOT(slotCenterFlag()));
119 connect(ui->saveButton, SIGNAL(clicked()),
this, SLOT(slotSaveChanges()));
122void FlagManager::setRaDec(
const dms &ra,
const dms &dec)
125 ui->decBox->
show(dec);
128void FlagManager::clearFields()
133 ui->epochBox->setText(
"2000.0");
134 ui->flagLabel->clear();
141 ui->flagList->clearSelection();
144void FlagManager::showFlag(
int flagIdx)
146 if (flagIdx < 0 || flagIdx >= m_Model->
rowCount())
158 ui->flagCombobox->setCurrentText(m_Model->
data(m_Model->
index(flagIdx, 3)).
toString());
162 ui->labelColorcombo->setColor(labelColor);
165 ui->flagList->selectRow(flagIdx);
169bool FlagManager::validatePoint()
171 bool raOk(
false), decOk(
false);
172 dms ra(ui->raBox->createDms(&raOk));
173 dms dec(ui->decBox->createDms(&decOk));
180 KSNotification::error(
i18n(
"Invalid coordinates."));
186 message =
i18n(
"The Right Ascension value must be between 0.0 and 24.0.");
187 if (
dec.Degrees() < -90.0 ||
dec.Degrees() > 90.0)
188 message +=
'\n' +
i18n(
"The Declination value must be between -90.0 and 90.0.");
191 KSNotification::sorry(message,
i18n(
"Invalid Coordinate Data"));
199void FlagManager::deleteFlagItem(
int flagIdx)
201 if (flagIdx < m_Model->rowCount())
209 if (validatePoint() ==
false)
212 dms ra(ui->raBox->createDms());
213 dms dec(ui->decBox->createDms());
219 SkyPoint flagPoint(ra, dec);
220 flags->
add(flagPoint, ui->epochBox->text(), ui->flagCombobox->currentText(), ui->flagLabel->text(),
221 ui->labelColorcombo->color());
223 ui->flagList->selectRow(m_Model->
rowCount() - 1);
234 int flag = ui->flagList->currentIndex().row();
254 if (ui->flagList->currentIndex().isValid())
258 m_Ks->
data()->
skyComposite()->flags()->pointList().
at(ui->flagList->currentIndex().row()).get());
267 if (INDIListener::Instance()->
size() == 0)
269 KSNotification::sorry(
i18n(
"No connected mounts found."));
273 for (
auto oneDevice : INDIListener::devices())
275 if (!(oneDevice->getDriverInterface() & INDI::BaseDevice::TELESCOPE_INTERFACE))
278 if (oneDevice->isConnected() ==
false)
280 KSNotification::error(
281 i18n(
"Telescope %1 is offline. Please connect and retry again.", oneDevice->getDeviceName()));
285 auto mount = oneDevice->getMount();
289 mount->Slew(m_Ks->
data()->
skyComposite()->flags()->pointList().
at(ui->flagList->currentIndex().row()).get());
294 KSNotification::sorry(
i18n(
"No connected mounts found."));
299void FlagManager::slotSaveChanges()
301 int row = ui->flagList->currentIndex().row();
303 if (validatePoint() ==
false)
306 insertFlag(
false, row);
310 dms ra(ui->raBox->createDms());
311 dms dec(ui->decBox->createDms());
317 ui->flagCombobox->currentText(), ui->flagLabel->text(),
318 ui->labelColorcombo->color());
323 ui->flagList->selectRow(row);
331void FlagManager::insertFlag(
bool isNew,
int row)
333 dms ra(ui->raBox->createDms());
334 dms dec(ui->decBox->createDms());
349 ui->flagCombobox->currentText())
361 m_Model->
setItem(row, i, itemList.
at(i));
Represents a flag on the sky map.
void saveToFile()
Save flags to flags.dat file.
QColor labelColor(int index)
Get label color.
void remove(int index)
Remove a flag.
QList< QImage > imageList()
Get images.
QString label(int index)
Get label.
void add(const SkyPoint &flagPoint, QString epoch, QString image, QString label, QColor labelColor)
Add a flag.
QString epoch(int index)
Get epoch.
QString imageName(int index)
Get image name.
void updateFlag(int index, const SkyPoint &flagPoint, QString epoch, QString image, QString label, QColor labelColor)
Update a flag.
QImage image(int index)
Get image.
void slotCenterTelescope()
Center the selected flag in the telescope.
void slotCenterFlag()
Center the selected flag in the display.
void slotAddFlag()
Verify coordinates and add a flag.
void slotDeleteFlag()
Delete a flag.
SkyMapComposite * skyComposite()
static KStars * Instance()
KStarsData * data() const
void setClickedPoint(const SkyPoint *f)
Set the ClickedPoint to the skypoint given as an argument.
void setClickedObject(SkyObject *o)
Set the ClickedObject pointer to the argument.
void forceUpdate(bool now=false)
Recalculates the positions of objects in the sky, and then repaints the sky map.
void slotCenter()
Center the display at the point ClickedPoint.
The sky coordinates of a point in the sky.
An angle, stored as degrees, but expressible in many ways.
const double & Degrees() const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
bool removeRow(int row, const QModelIndex &parent)
const QColor & color() const const
const_reference at(qsizetype i) const const
qsizetype size() const const
QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags)
void appendRow(QStandardItem *item)
QBrush foreground() const const
void setForeground(const QBrush &brush)
void appendRow(QStandardItem *item)
virtual int columnCount(const QModelIndex &parent) const const override
virtual QVariant data(const QModelIndex &index, int role) const const override
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
QStandardItem * item(int row, int column) const const
virtual int rowCount(const QModelIndex &parent) const const override
void setItem(int row, QStandardItem *item)
bool isEmpty() const const
QTextStream & dec(QTextStream &stream)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString toString() const const