Kstars

starhopperdialog.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Utkarsh Simha <utkarshsimha@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "starhopperdialog.h"
8
9#include "kstars.h"
10#include "ksutils.h"
11#include "skymap.h"
12#include "ksnotification.h"
13#include "skymapcomposite.h"
14#include "starhopper.h"
15#include "targetlistcomponent.h"
16#include "dialogs/detaildialog.h"
17
18StarHopperDialog::StarHopperDialog(QWidget *parent) : QDialog(parent), ui(new Ui::StarHopperDialog)
19{
20 ui->setupUi(this);
21 m_lw = ui->listWidget;
22 m_Metadata = new QStringList();
23 ui->directionsLabel->setWordWrap(true);
24 m_sh.reset(new StarHopper());
25 connect(ui->NextButton, SIGNAL(clicked()), this, SLOT(slotNext()));
26 connect(ui->GotoButton, SIGNAL(clicked()), this, SLOT(slotGoto()));
27 connect(ui->DetailsButton, SIGNAL(clicked()), this, SLOT(slotDetails()));
28 connect(m_lw, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotGoto()));
29 connect(m_lw, SIGNAL(itemSelectionChanged()), this, SLOT(slotRefreshMetadata()));
30 connect(this, SIGNAL(finished(int)), this, SLOT(deleteLater()));
31}
32
33StarHopperDialog::~StarHopperDialog()
34{
35 TargetListComponent *t = getTargetListComponent();
36
37 if (t->list)
38 t->list->clear();
39 SkyMap::Instance()->forceUpdate(true);
40 delete ui;
41}
42
43void StarHopperDialog::starHop(const SkyPoint &startHop, const SkyPoint &stopHop, float fov, float maglim)
44{
45 QList<StarObject *> *starList = m_sh->computePath(startHop, stopHop, fov, maglim, m_Metadata);
46
47 if (!starList->empty())
48 {
49 foreach (StarObject *so, *starList)
50 {
51 setData(so);
52 }
53 slotRefreshMetadata();
54 m_skyObjList = KSUtils::castStarObjListToSkyObjList(starList);
55 starList->clear();
56 delete starList;
57 TargetListComponent *t = getTargetListComponent();
58 t->list.reset(m_skyObjList);
59 SkyMap::Instance()->forceUpdate(true);
60 }
61 else
62 {
63 delete starList;
64 KSNotification::error(i18n("Star-hopper algorithm failed. If you're trying a large star hop, try using a "
65 "smaller FOV or changing the source point"));
67 }
68}
69
70void StarHopperDialog::setData(StarObject *sobj)
71{
72 QListWidgetItem *item = new QListWidgetItem();
73 QString starName;
74
75 if (sobj->name() != "star")
76 {
77 starName = sobj->translatedLongName();
78 }
79 else if (sobj->getHDIndex())
80 {
81 starName = QString("HD%1").arg(QString::number(sobj->getHDIndex()));
82 }
83 else
84 {
85 starName = "";
86 starName += sobj->spchar();
87 starName += QString(" Star of mag %2").arg(QString::number(sobj->mag()));
88 }
89 item->setText(starName);
90 QVariant qv;
91
92 qv.setValue(sobj);
93 item->setData(Qt::UserRole, qv);
94 m_lw->addItem(item);
95}
96
97void StarHopperDialog::slotNext()
98{
99 m_lw->setCurrentRow(m_lw->currentRow() + 1);
100 slotGoto();
101}
102
103void StarHopperDialog::slotGoto()
104{
105 slotRefreshMetadata();
106 SkyObject *skyobj = getStarData(m_lw->currentItem());
107
108 if (skyobj != nullptr)
109 {
110 KStars *ks = KStars::Instance();
111 ks->map()->setClickedObject(skyobj);
112 ks->map()->setClickedPoint(skyobj);
113 ks->map()->slotCenter();
114 }
115}
116
117void StarHopperDialog::slotDetails()
118{
119 SkyObject *skyobj = getStarData(m_lw->currentItem());
120
121 if (skyobj != nullptr)
122 {
123 DetailDialog *detailDialog =
124 new DetailDialog(skyobj, KStarsData::Instance()->ut(), KStarsData::Instance()->geo(), KStars::Instance());
125 detailDialog->exec();
126 delete detailDialog;
127 }
128}
129
130SkyObject *StarHopperDialog::getStarData(QListWidgetItem *item)
131{
132 if (!item)
133 return nullptr;
134 else
135 {
136 QVariant v = item->data(Qt::UserRole);
137 StarObject *starobj = v.value<StarObject *>();
138 return starobj;
139 }
140}
141
142inline TargetListComponent *StarHopperDialog::getTargetListComponent()
143{
144 return KStarsData::Instance()->skyComposite()->getStarHopRouteList();
145}
146
147void StarHopperDialog::slotRefreshMetadata()
148{
149 int row = m_lw->currentRow();
150
151 qDebug() << Q_FUNC_INFO << "Slot RefreshMetadata";
152 if (row >= 0)
153 {
154 ui->directionsLabel->setText(m_Metadata->at(row));
155 }
156 else
157 {
158 ui->directionsLabel->setText(m_Metadata->at(0));
159 }
160 qDebug() << Q_FUNC_INFO << "Slot RefreshMetadata";
161}
DetailDialog is a window showing detailed information for a selected object.
SkyMapComposite * skyComposite()
Definition kstarsdata.h:168
This is the main window for KStars.
Definition kstars.h:89
SkyMap * map() const
Definition kstars.h:139
static KStars * Instance()
Definition kstars.h:121
void setClickedPoint(const SkyPoint *f)
Set the ClickedPoint to the skypoint given as an argument.
Definition skymap.cpp:1008
void setClickedObject(SkyObject *o)
Set the ClickedObject pointer to the argument.
Definition skymap.cpp:366
void forceUpdate(bool now=false)
Recalculates the positions of objects in the sky, and then repaints the sky map.
Definition skymap.cpp:1173
void slotCenter()
Center the display at the point ClickedPoint.
Definition skymap.cpp:380
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
QString translatedLongName() const
Definition skyobject.h:170
float mag() const
Definition skyobject.h:207
The sky coordinates of a point in the sky.
Definition skypoint.h:45
Helps planning star hopping.
Definition starhopper.h:25
This is a subclass of SkyObject.
Definition starobject.h:33
QString name(void) const override
If star is unnamed return "star" otherwise return the name.
Definition starobject.h:130
char spchar() const
Returns just the first character of the spectral type string.
int getHDIndex() const
Definition starobject.h:254
Highlights objects present in certain lists by drawing "target" symbols around them.
std::unique_ptr< SkyObjectList > list
Pointer to list of objects to draw.
QString i18n(const char *text, const TYPE &arg...)
GeoCoordinates geo(const QVariant &location)
virtual void done(int r)
virtual int exec()
const_reference at(qsizetype i) const const
void clear()
bool empty() const const
void addItem(QListWidgetItem *item)
QListWidgetItem * currentItem() const const
void setCurrentRow(int row)
virtual QVariant data(int role) const const
virtual void setData(int role, const QVariant &value)
void setText(const QString &text)
QString arg(Args &&... args) const const
QString number(double n, char format, int precision)
UserRole
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setValue(QVariant &&value)
T value() const const
void setupUi(QWidget *widget)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.