Kstars

observinglist.h
1 /*
2  SPDX-FileCopyrightText: 2004 Jeff Woods Jason Harris <[email protected], [email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "ksalmanac.h"
10 #include "kstarsdatetime.h"
11 #include "ui_observinglist.h"
12 #include "catalogsdb.h"
13 
14 #include <QAbstractTableModel>
15 #include <QDialog>
16 #include <QFrame>
17 #include <QList>
18 #include <QPixmap>
19 #include <QTime>
20 
21 #include <functional>
22 #include <memory>
23 
25 class QStandardItem;
26 class QStandardItemModel;
27 class QTimer;
28 
29 class GeoLocation;
30 class KSDssDownloader;
31 class KStars;
32 class KStarsDateTime;
33 class ObsListPopupMenu;
34 class SkyObject;
35 class SkyPoint;
36 
37 class ObservingListUI : public QFrame, public Ui::ObservingList
38 {
39  Q_OBJECT
40 
41  public:
42  explicit ObservingListUI(QWidget *parent);
43 };
44 
45 /** @class ObservingList
46  *Tool window for managing a custom list of objects. The window
47  *displays the Name, RA, Dec, mag, and type of each object in the list.
48  *
49  *By selecting an object in the list, you can perform a number of functions
50  *on that object:
51  *+ Center it in the display
52  *+ Examine its Details Window
53  *+ Point the telescope at it
54  *+ Attach a custom icon or name label (TBD)
55  *+ Attach a trail (solar system only) (TBD)
56  *+ Open the AltVsTime tool
57  *
58  *The user can also save/load their observing lists, and can export
59  *list data (TBD: as HTML table? CSV format? plain text?)
60  *
61  *The observing notes associated with the selected object are displayed
62  *below the list.
63  *
64  *TODO:
65  *+ Implement a "shaded" state, in which the UI is compressed to
66  * make it easier to float on the KStars window. Displays only
67  * object names, and single-letter action buttons, and no user log.
68  *+ Implement an InfoBox version (the ultimate shaded state)
69  *
70  *@short Tool for managing a custom list of objects
71  *@author Jeff Woods, Jason Harris
72  *@version 1.0
73  */
74 
75 class ObservingList : public QDialog
76 {
77  Q_OBJECT
78 
79  public:
80  ObservingList();
81  virtual ~ObservingList() override = default;
82 
83  /** @return reference to the current observing list
84  */
85  QList<QSharedPointer<SkyObject>> &obsList() { return m_WishList; }
86 
87  /** @return reference to the current observing list
88  */
89  QList<QSharedPointer<SkyObject>> &sessionList() { return m_SessionList; }
90 
91  /** @return pointer to the currently-selected object in the observing list
92  *@note if more than one object is selected, this function returns 0.
93  */
94  inline SkyObject *currentObject() const { return m_CurrentObject; }
95 
96  /** @short If the current list has unsaved changes, ask the user about saving it.
97  *@note also clears the list in preparation of opening a new one
98  */
99  void saveCurrentList();
100 
101  /** @short Plot the SkyObject's Altitude vs Time in the AVTPlotWidget.
102  *@p o pointer to the object to be plotted
103  */
104  void plot(SkyObject *o);
105 
106  /** @short Return the altitude of the given SkyObject for the given hour.
107  *@p p pointer to the SkyObject
108  *@p hour time at which altitude has to be found
109  */
110  double findAltitude(SkyPoint *p, double hour = 0);
111 
112  /** @short Sets the image parameters for the current object
113  *@p o The passed object for setting the parameters
114  */
115  void setCurrentImage(const SkyObject *o);
116 
117  /**
118  * @short Returns a path to the current image, or a writable image.
119  */
121 
122  /** @short Save the user log text to a file.
123  *@note the log is attached to the current object in obsList.
124  */
125  void saveCurrentUserLog();
126 
127  /** @short decides on whether to enable the SaveImages button or not
128  */
129  void setSaveImagesButton();
130 
131  /** @short This is the declaration of the event filter function
132  * which is installed on the KImageFilePreview and the TabeView
133  */
134  bool eventFilter(QObject *obj, QEvent *event) override;
135 
136  /** @short saves a thumbnail image for the details dialog
137  * from the downloaded image
138  */
139  void saveThumbImage();
140 
141  QString getTime(const SkyObject *o) const;
142 
143  QTime scheduledTime(SkyObject *o) const;
144 
145  void setTime(const SkyObject *o, QTime t);
146 
147  inline GeoLocation *geoLocation() { return geo; }
148 
149  inline KStarsDateTime dateTime() const { return dt; }
150 
151  /** @short return the object with the name as the passed
152  * QString from the Session List, return null otherwise
153  */
155 
156  /** @short make a selection in the session view
157  */
158  void selectObject(const SkyObject *o);
159 
160  /** @short set the default image in the image preview.
161  */
162  void setDefaultImage();
163 
164  /** @short get object name. If sky object has no name, generate a name based on catalog number.
165  * @param o pointer to the sky object
166  * @param translated set to true if the translated name is required.
167  */
168  QString getObjectName(const SkyObject *o, bool translated = true);
169 
170  /**
171  * @return true if the selected list contains the given object
172  */
173  inline bool contains(const SkyObject *o, bool session = false) { return bool(findObject(o, session)); }
174 
175  QSharedPointer<SkyObject> findObject(const SkyObject *o, bool session = false);
176 
177  public slots:
178  /** @short add a new object to list
179  *@p o pointer to the object to add to the list
180  *@p session flag toggle adding the object to the session list
181  *@p update flag to toggle the call of slotSaveList
182  */
183  void slotAddObject(const SkyObject *o = nullptr, bool session = false, bool update = false);
184 
185  /** @short Remove skyobjects which are highlighted in the
186  *observing list tool from the observing list.
187  */
189 
190  /** @short Remove skyobject from the observing list.
191  *@p o pointer to the SkyObject to be removed.
192  *@p session flag to tell it whether to remove the object
193  *from the sessionlist or from the wishlist
194  *@p update flag to toggle the call of slotSaveList
195  *Use SkyMap::clickedObject() if o is nullptr (default)
196  */
197  void slotRemoveObject(const SkyObject *o = nullptr, bool session = false, bool update = false);
198 
199  /** @short center the selected object in the display
200  */
201  void slotCenterObject();
202 
203  /** @short slew the telescope to the selected object
204  */
205  void slotSlewToObject();
206 
207  /**
208  * @brief slotAddToEkosScheduler Add object to Ekos scheduler
209  */
210  void slotAddToEkosScheduler();
211 
212  /** @short Show the details window for the selected object
213  */
214  void slotDetails();
215 
216  /** @short Show the Altitude vs Time for selecteld objects
217  */
218  void slotAVT();
219 
220  /** @short Open the WUT dialog
221  */
222  void slotWUT();
223 
224  /** @short Add the object to the Session List
225  */
226  void slotAddToSession();
227 
228  /** @short Open the Find Dialog
229  */
230  void slotFind();
231 
232  /** @short Batch add from a list of objects */
233  void slotBatchAdd();
234 
235  /** @short Tasks needed when changing the selected object
236  *Save the user log of the previous selected object,
237  *find the new selected object in the obsList, and
238  *show the notes associated with the new selected object
239  */
240  void slotNewSelection();
241 
242  /** @short load an observing list from disk.
243  */
244  void slotOpenList();
245 
246  /** @short save the current observing list to disk.
247  */
248  void slotSaveList();
249 
250  /** @short Load the Wish list from disk.
251  */
252  void slotLoadWishList();
253 
254  /** @short save the current observing session plan to disk, specify filename.
255  */
256  void slotSaveSessionAs(bool nativeSave = true);
257 
258  /** @short save the current session
259  */
260  void slotSaveSession(bool nativeSave = true);
261 
262  /** @short construct a new observing list using the wizard.
263  */
264  void slotWizard();
265 
266  /** @short toggle the setEnabled flags according to current view
267  *set the m_currentItem to nullptr and clear selections
268  *@p index captures the integer value sent by the signal
269  *which is the currentIndex of the table
270  */
271  void slotChangeTab(int index);
272 
273  /** @short Opens the Location dialog to set the GeoLocation
274  *for the sessionlist.
275  */
276  void slotLocation();
277 
278  /** @short Updates the tableviews for the new geolocation and date
279  */
280  void slotUpdate();
281 
282  /** @short Takes the time from the QTimeEdit box and sets it as the
283  *time parameter in the tableview of the SessionList.
284  */
285  void slotSetTime();
286 
287  /** @short Downloads the corresponding DSS or SDSS image from the web and
288  *displays it
289  */
290  void slotGetImage(bool _dss = false, const SkyObject *o = nullptr);
291 
292  void slotSearchImage();
293 
294  /** @short Downloads the images of all the objects in the session list
295  *Note: This downloads the SDSS image, checks if the size is > default image
296  *and gets the DSS image if that's the case
297  */
298  void slotSaveAllImages();
299 
300  /** @short saves the image synchronously from a given URL into a given file
301  *@p url the url from which the image has to be downloaded
302  *@p filename the file onto which the url has to be copied to
303  *NOTE: This is not a generic image saver, it is specific to the current object
304  */
305  void saveImage(QUrl url, QString filename, const SkyObject *o = nullptr);
306 
307  /** @short Shows the image in a ImageViewer window.
308  */
309  void slotImageViewer();
310 
311  /** @short Remove the current image
312  */
313  void slotDeleteCurrentImage();
314 
315  /** @short Removes all the save DSS/SDSS images from the disk.
316  */
317  void slotDeleteAllImages();
318 
319  /** @short download the DSS image and show it
320  */
321  void slotDSS() { slotGetImage(true); }
322 
323  /**
324  *@short Present the user with options to get the right DSS image for the job
325  */
326  void slotCustomDSS();
327 
328  /** @short Export a target list to the oal compliant format
329  */
330  void slotOALExport();
331 
332  void slotAddVisibleObj();
333 
334  /**
335  * @short Show the eyepiece field view
336  */
337  void slotEyepieceView();
338 
339  /**
340  * @short Recalculate and update the values of the altitude in the wishlist for the current time
341  */
342  void slotUpdateAltitudes();
343 
344  /**
345  * @brief slotClearList Remove all objects from current list
346  */
347  void slotClearList();
348 
349  protected slots:
350  void slotClose();
351  void downloadReady(bool success);
352 
353  protected:
354  void showEvent(QShowEvent *) override;
355 
356  private:
357  /**
358  * @short Return the active list
359  * @return The session list or the wish list depending on which tab is currently being viewed.
360  */
361  inline QList<QSharedPointer<SkyObject>> &getActiveList() { return ((sessionView) ? m_SessionList : m_WishList); }
362 
363  /**
364  * @short Return the active itemmodel
365  * @return the session model or the wishlist model depending on which tab is currently being viewed.
366  */
367  inline QStandardItemModel *getActiveModel() const { return (sessionView ? m_SessionModel.get() : m_WishListModel.get()); }
368 
369  /**
370  * @short Return the active sort model
371  * @return the session sort model or the wishlist sort model depending on which tab is currently being viewed.
372  */
373  inline QSortFilterProxyModel *getActiveSortModel() const
374  {
375  return (sessionView ? m_SessionSortModel.get() : m_WishListSortModel.get());
376  }
377 
378  /**
379  * @short Return the active view
380  * @return the active view in the UI -- session view or wishlist view depending on which one is active.
381  */
382  inline QTableView *getActiveView() const { return ((sessionView) ? (ui->SessionView) : (ui->WishListView)); }
383 
384  /**
385  * @short Get the currently selected item indexes
386  * @return a QModelIndexList containing the selected rows in the active QTableView
387  */
388  inline QModelIndexList getSelectedItems() const { return getActiveView()->selectionModel()->selectedRows(); }
389 
390  std::unique_ptr<KSAlmanac> ksal;
391  ObservingListUI *ui { nullptr };
392  QList<QSharedPointer<SkyObject>> m_WishList, m_SessionList;
393  SkyObject *LogObject { nullptr };
394  SkyObject *m_CurrentObject { nullptr };
395  bool isModified { false };
396  bool sessionView { false };
397  bool dss { false };
398  bool singleSelection { false };
399  bool showScope { false };
400  bool noSelection { false };
401  QString m_listFileName, m_currentImageFileName, m_currentThumbImageFileName;
402  KStarsDateTime dt;
403  GeoLocation *geo { nullptr };
404  std::unique_ptr<QStandardItemModel> m_WishListModel;
405  std::unique_ptr<QStandardItemModel> m_SessionModel;
406  std::unique_ptr<QSortFilterProxyModel> m_WishListSortModel;
407  std::unique_ptr<QSortFilterProxyModel> m_SessionSortModel;
408  QHash<QString, QTime> TimeHash;
409  std::unique_ptr<ObsListPopupMenu> pmenu;
410  KSDssDownloader *m_dl { nullptr };
411  QHash<SkyObject *, QPixmap> ImagePreviewHash;
412  QPixmap m_NoImagePixmap;
413  QTimer *m_altitudeUpdater { nullptr };
414  std::function<QStandardItem *(const SkyPoint &)> m_altCostHelper;
415  bool m_initialWishlistLoad { false };
416  CatalogsDB::DBManager m_manager;
417 };
Q_OBJECTQ_OBJECT
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
virtual bool eventFilter(QObject *o, QEvent *e) override
void slotClearList()
slotClearList Remove all objects from current list
void slotSaveAllImages()
Downloads the images of all the objects in the session list Note: This downloads the SDSS image,...
void selectObject(const SkyObject *o)
make a selection in the session view
void slotAddToSession()
Add the object to the Session List.
void slotWUT()
Open the WUT dialog.
void slotGetImage(bool _dss=false, const SkyObject *o=nullptr)
Downloads the corresponding DSS or SDSS image from the web and displays it.
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
void slotRemoveObject(const SkyObject *o=nullptr, bool session=false, bool update=false)
Remove skyobject from the observing list.
Helps download a DSS image.
void update()
virtual bool event(QEvent *event) override
QItemSelectionModel * selectionModel() const const
QString getObjectName(const SkyObject *o, bool translated=true)
get object name.
void saveCurrentUserLog()
Save the user log text to a file.
Manages the catalog database and provides an interface to provide an interface to query and modify th...
Definition: catalogsdb.h:181
double findAltitude(SkyPoint *p, double hour=0)
Return the altitude of the given SkyObject for the given hour.
void slotWizard()
construct a new observing list using the wizard.
void slotSaveSessionAs(bool nativeSave=true)
save the current observing session plan to disk, specify filename.
void slotCenterObject()
center the selected object in the display
QList< QSharedPointer< SkyObject > > & obsList()
Definition: observinglist.h:85
void slotSlewToObject()
slew the telescope to the selected object
void slotCustomDSS()
Present the user with options to get the right DSS image for the job.
void slotSaveSession(bool nativeSave=true)
save the current session
void slotRemoveSelectedObjects()
Remove skyobjects which are highlighted in the observing list tool from the observing list.
void slotAddObject(const SkyObject *o=nullptr, bool session=false, bool update=false)
add a new object to list o pointer to the object to add to the list session flag toggle adding the ob...
void slotLoadWishList()
Load the Wish list from disk.
void slotAVT()
Show the Altitude vs Time for selecteld objects.
bool contains(const SkyObject *o, bool session=false)
void saveThumbImage()
saves a thumbnail image for the details dialog from the downloaded image
virtual void showEvent(QShowEvent *event) override
void saveImage(QUrl url, QString filename, const SkyObject *o=nullptr)
saves the image synchronously from a given URL into a given file url the url from which the image has...
QString getCurrentImagePath()
Returns a path to the current image, or a writable image.
void slotDeleteAllImages()
Removes all the save DSS/SDSS images from the disk.
This is the main window for KStars. In addition to the GUI elements, the class contains the program c...
Definition: kstars.h:92
void slotFind()
Open the Find Dialog.
void setCurrentImage(const SkyObject *o)
Sets the image parameters for the current object o The passed object for setting the parameters.
void plot(SkyObject *o)
Plot the SkyObject's Altitude vs Time in the AVTPlotWidget.
void slotDetails()
Show the details window for the selected object.
void slotDeleteCurrentImage()
Remove the current image.
SkyObject * findObjectByName(QString name)
return the object with the name as the passed QString from the Session List, return null otherwise
void slotImageViewer()
Shows the image in a ImageViewer window.
void slotSetTime()
Takes the time from the QTimeEdit box and sets it as the time parameter in the tableview of the Sessi...
void slotUpdateAltitudes()
Recalculate and update the values of the altitude in the wishlist for the current time.
QModelIndexList selectedRows(int column) const const
void slotSaveList()
save the current observing list to disk.
void setDefaultImage()
set the default image in the image preview.
void saveCurrentList()
If the current list has unsaved changes, ask the user about saving it.
void slotBatchAdd()
Batch add from a list of objects.
void slotOALExport()
Export a target list to the oal compliant format.
void slotDSS()
download the DSS image and show it
void slotLocation()
Opens the Location dialog to set the GeoLocation for the sessionlist.
void slotEyepieceView()
Show the eyepiece field view.
void slotAddToEkosScheduler()
slotAddToEkosScheduler Add object to Ekos scheduler
void slotChangeTab(int index)
toggle the setEnabled flags according to current view set the m_currentItem to nullptr and clear sele...
Information about an object in the sky.
Definition: skyobject.h:41
SkyObject * currentObject() const
Definition: observinglist.h:94
void slotNewSelection()
Tasks needed when changing the selected object Save the user log of the previous selected object,...
void setSaveImagesButton()
decides on whether to enable the SaveImages button or not
void slotOpenList()
load an observing list from disk.
QList< QSharedPointer< SkyObject > > & sessionList()
Definition: observinglist.h:89
Relevant data about an observing location on Earth.
Definition: geolocation.h:27
void slotUpdate()
Updates the tableviews for the new geolocation and date.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:56 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.