• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 13280109945

12 Feb 2025 07:19AM UTC coverage: 12.129% (+0.03%) from 12.099%
13280109945

Pull #3751

github

10110111
Regenerate the SC .pot file
Pull Request #3751: Switch skycultures to the new format

14613 of 120480 relevant lines covered (12.13%)

18988.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/gui/ObsListDialog.hpp
1
/*
2
 * Stellarium
3
 * Copyright (C) 2020 Jocelyn GIROD
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License along
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
 */
19

20
#ifndef OBSLISTDIALOG_H
21
#define OBSLISTDIALOG_H
22

23
#include <QObject>
24
#include <QStandardItemModel>
25

26
#include "StelDialog.hpp"
27
#include "StelCore.hpp"
28
#include "StelObjectType.hpp"
29

30
//! @class ObsListDialog
31
//! Since V0.21.2, this class manages the ObservingLists, successor of the Bookmarks feature available since 0.15.
32
//! @note The old Bookmarks.json format should now be seen as deprecated.
33
//! Updated in Version 1.0: ObservingLists Version 2.0
34
//! Updated in Version 23.1: ObservingLists Version 2.1
35
//!
36
//! This tool manages Observing Lists based on a unique list identifier, the OLUD = Observing List Unique Designation
37
//! Old bookmarks.json files are auto-imported at first run. The old file is then not touched any further and could still be used in older versions of Stellarium.
38
//! This first bookmarks list is then the first stored ObservingList.
39
//! You can create new lists, edit them, delete them, import/export them and exchange with other users etc.
40
//! You can also highlight all bookmarked objects of the active list
41
//!
42
//! When creating an entry for a selected object, you can optionally store current time, location, landscapeID and field of view.
43
//! This helps to retrieve the possible same view if location and/or time matter, e.g. for a list of Solar eclipses with their locations and landscapes.
44
//! Obviously, a list of favourite DSOs would not need those data (but maybe FoV is still meaningful).
45
//! On retrieval, the same optional elements can again be selected, so you can retrieve an object without stored time or location, if that is meaningful.
46
//! If location or landscape IDs cannot be found, they are not changed.
47
//!
48
//! An observingList.json looks like this:
49
//! {
50
//! "defaultListOlud": "{6d297068-a644-4d1b-9d2d-9c2dd64eef53}",
51
//! "observingLists": {
52
//!     "{84744f7b-c353-45b0-8394-69af2a1e0917}": { // List OLUD. This is a unique ID
53
//!         "creation date": "2022-09-29 20:05:07",
54
//!        "last edit": "2022-11-29 22:15:38",
55
//!         "description": "Bookmarks of previous Stellarium version.",
56
//!         "name": "bookmarks list",
57
//!         "objects": [                                // List is stored alphabetized, but given here in contextualized order for clarity.
58
//!             {
59
//!                 "designation": "HIP 57632",         // Catalog name. Object should be found by one of StelObjectModuleSubclasses->getStelObjectType(designation, type)
60
//!                 "type": "Star"                      // Object type code (actually its class name in Stellarium) given by StelObjectModuleSubclasses->getStelObjectType() or StelObject->getType()
61
//!             "objtype" : "binary, pulsating variable" // More extensive description, localized. This will be re-read on program start to ensure current language.
62
//!                 "name": "Denebola",                 // Primary English name of the object. This will be re-read on program start to ensure current language.
63
//!                 "nameI18n": "Denebola",             // Translated name at time of addition to the list. Added for reference when using the exported list elsewhere. The name is retranslated in Stellarium after loading because user language may have changed.
64
//!                 "ra": "11h49m05.0s",                // Optional. Right Ascension in J2000.0 frame. Good if moving object is stored. If empty, current coordinates will be added on loading.
65
//!                 "dec": "+14°34'15\"",               // Optional. Declination     in J2000.0 frame. Good if moving object is stored. If empty, current coordinates will be added on loading.
66
//!                 "constellation": "Leo",             // Optional. Good if moving object is stored.
67
//!                 "magnitude": "2.10",                // Optional. Good if moving object is stored.
68
//!                 "fov": 0,                           // Optional. Good if event is stored.
69
//!                 "jd": 0,                            // Optional. Good if event is stored.
70
//!                 "landscapeID": "",                  // Optional. Good if event is stored.
71
//!                 "location": "",                     // Optional. Good if event is stored.
72
//!                 "isVisibleMarker": false,           // UNKNOWN PURPOSE or NO PROPER IMPLEMENTATION OF WHATEVER THIS SHOULD DO
73
//!             },
74
//!         ... <other objects>
75
//!         ],
76
//!         "sorting": ""
77
//!     },                                            // end of list 84744f7b-...
78
//!     "{bd40274c-a321-40c1-a6f3-bc8f11026326}": {   // List OLUD of next list.
79
//!         "creation date": "2022-12-21 11:12:39",
80
//!        "last edit": "2023-07-29 22:23:38",
81
//!         "description": "test of unification",
82
//!         "name": "mine_edited",
83
//!         "objects": [
84
//!             {
85
//!                 "constellation": "Cyg",
86
//!                 "dec": "+45°16'59\"",
87
//!                 "designation": "HIP 102098",
88
//!                 "fov": 0,
89
//!                 "isVisibleMarker": true,
90
//!                 "jd": 0,
91
//!                 "landscapeID": "",
92
//!                 "location": "",
93
//!                 "magnitude": "1.25",
94
//!                 "name": "Deneb",                     // Used to be nameI18n, but this is a bad idea for list exchange!
95
//!                 "ra": "20h41m24.4s",
96
//!                 "type": "Star"
97
//!                 "objType": "double star, pulsating variable star"
98
//!             },
99
//!         ...  <other objects>
100
//!         ],
101
//!         "sorting": ""
102
//!     },
103
//!     ... <other observingLists>
104
//! },
105
//! "shortName": "Observing list for Stellarium",
106
//! "version": "2.0"
107
//! }
108
//!
109
//!
110
//! Updated for 23.1: Integrated functions of extra edit dialog, deep refactoring.
111
//! You cannot delete the default list. Choose another list as default before deleting the displayed one.
112
//! You cannot delete the last list.
113
//! Importing a JSON file with observingLists will import all lists and unconditionally overwrite existing lists with the same OLUD.
114
//! Exporting writes an observingList file with only the currently displayed list.
115
//!
116
//! Fix a confusion introduced in the 1.* series:
117
//! The ObsList has entries
118
//! - "designation": The catalog number (DSO), HIP number (star), or canonical name (planet).
119
//! - "nameI18n": translated name for display. Actually this is bad design in case of list exchange.
120
//! - "type": As given by ObjectP->getType() or getObjectType()? This was inconsistent.
121
//! FIXES:
122
//! - "designation" used in combination with type as real unique object ID. For DSO, getDSODesignationWIC() must be used.
123
//! - "type": Stellarium class name. Used to unambiguously identify an object even if equal-named objects exist in different classes.
124
//! - "name" (new entry) English name of object. Will be written for external use, but never read.
125
//! - "nameI18n" translated name. Will be written for external use, but never read.
126

127

128
class Ui_obsListDialogForm;
129

130
class ObsListDialog : public StelDialog
131
{
132
        Q_OBJECT
133
        // Configure optionally stored/retrieved items
134
        Q_PROPERTY(bool flagUseJD        READ getFlagUseJD        WRITE setFlagUseJD        NOTIFY flagUseJDChanged)
135
        Q_PROPERTY(bool flagUseLandscape READ getFlagUseLandscape WRITE setFlagUseLandscape NOTIFY flagUseLandscapeChanged)
136
        Q_PROPERTY(bool flagUseLocation  READ getFlagUseLocation  WRITE setFlagUseLocation  NOTIFY flagUseLocationChanged)
137
        Q_PROPERTY(bool flagUseFov       READ getFlagUseFov       WRITE setFlagUseFov       NOTIFY flagUseFovChanged)
138

139
public:
140
        explicit ObsListDialog(QObject *parent);
141

142
        ~ObsListDialog() override;
143

144
        struct observingListItem
145
        {
146
        public:
147
                QString designation;   //!< Relates to designation in the JSON file
148
                QString name;          //!< Relates to name in the JSON file. This is the object's englishName
149
                QString nameI18n;      //!< Relates to nameI18n in the JSON file. This is recreated from the actual object and current language during loading of the list. In the JSON file, it has purely add-on value.
150
                QString objClass;      //!< Object kind ID oriented on Stellarium's object class: Star, Planet (also for sun, moons, Comets, MinorPlanets!), Nebula, ...
151
                QString objTypeI18n;   //!< More physical type description: star (also Sun!), planet, moon, open cluster, galaxy, region in the sky, ...
152
                QString ra;            //!< Optional, eq. J2000.0 position at date jd; useful for moving objects
153
                QString dec;           //!< Optional, eq. J2000.0 position at date jd; useful for moving objects
154
                QString magnitude;     //!< NOT a redundant bit of information! In case of moving objects, it spares computing details on loading.
155
                QString constellation; //!< NOT a redundant bit of information! In case of moving objects, it spares computing positions on loading.
156
                double jd;             //!< optional: stores date of observation
157
                QString location;      //!< optional: should be a full location encoded with StelLocation::serializeToLine()
158
                QString landscapeID;   //!< optional: landscapeID of landscape at moment of item creation.
159
                double fov;            //!< optional: Field of view [degrees]
160
                bool isVisibleMarker;  //!< Something around user-markers or SIMBAD-retrieved objects. Test and document!
161

162
                //! constructor
163
                observingListItem():
×
164
                designation(""),
×
165
                name(""),
×
166
                nameI18n(""),
×
167
                objClass(""),
×
168
                objTypeI18n(""),
×
169
                ra(""),
×
170
                dec(""),
×
171
                magnitude(""),
×
172
                constellation(""),
×
173
                jd(0.0),
×
174
                location(""),
×
175
                landscapeID(""),
×
176
                fov(0.0),
×
177
                isVisibleMarker(false)
×
178
                {}
×
179
                //! Convert to QVariantMap
180
                QVariantMap toVariantMap(){
×
181
                        return {
182
                                {QString(KEY_DESIGNATION)      , designation},
×
183
                                {QString(KEY_NAME)             , name},
×
184
                                {QString(KEY_NAME_I18N)        , nameI18n},
×
185
                                {QString(KEY_TYPE)             , objClass},
×
186
                                {QString(KEY_OBJECTS_TYPE)     , objTypeI18n},
×
187
                                {QString(KEY_RA)               , ra},
×
188
                                {QString(KEY_DEC)              , dec},
×
189
                                {QString(KEY_MAGNITUDE)        , magnitude},
×
190
                                {QString(KEY_CONSTELLATION)    , constellation},
×
191
                                {QString(KEY_JD)               , jd},
×
192
                                {QString(KEY_LOCATION)         , location},
×
193
                                {QString(KEY_LANDSCAPE_ID)     , landscapeID},
×
194
                                {QString(KEY_FOV)              , fov>1.e-6 ? fov : 0},
×
195
                                {QString(KEY_IS_VISIBLE_MARKER), isVisibleMarker}};
×
196
                }
×
197
        };
198

199
        enum ObsListColumns {
200
                ColumnUUID,          //! UUID of object
201
                ColumnDesignation,   //! English name or catalog designation of object
202
                ColumnNameI18n,      //! Localized name/nickname of object
203
                ColumnType,          //! Localized detailed Type of the object
204
                ColumnRa,            //! Right ascension of the object
205
                ColumnDec,           //! Declination of the object
206
                ColumnMagnitude,     //! Magnitude of the object
207
                ColumnConstellation, //! Constellation in which the object is located
208
                ColumnDate,          //! Date
209
                ColumnLocation,      //! Location where the object is observed
210
                ColumnLandscapeID,   //! LandscapeID linked to object observation
211
                ColumnCount          //! Total number of columns
212
        };
213
        Q_ENUM(ObsListColumns)
214

215
protected:
216
        Ui_obsListDialogForm *ui;
217

218
        //! Initialize the dialog widgets and connect the signals/slots.
219
        void createDialogContent() override;
220

221
private:
222
        class StelCore *core;
223
        class StelObjectMgr *objectMgr;
224
        class LandscapeMgr *landscapeMgr;
225
        class LabelMgr *labelMgr;
226

227
        QStandardItemModel *itemModel;       //!< Data for the table display.
228
        const QString observingListJsonPath; //!< Path to observingList.json file, set once in constructor.
229
        const QString bookmarksJsonPath;     //!< Path to bookmarks.json, set once in constructor.
230

231
        //! This QVariantMap represents the contents of the observingList.json file. Read ONCE at start. Contains 4 key/value pairs:
232
        //! - defaultListOlud: The OLUD of the currently configured default list. If empty or invalid, the first list is used as default.
233
        //! - observingLists:  QVariantMap of OLUD/ObsList pairs
234
        //! - shortName: "Observing list for Stellarium"
235
        //! - version: "2.1"
236
        //! The other methods can load, add, delete, or edit lists from the observingLists list.
237
        QVariantMap jsonMap;
238
        QVariantMap observingLists; //!< Contains the observingLists map from the JSON file
239

240
        QString defaultOlud;  //!< OLUD (UUID) of default list
241
        QString selectedOlud; //!< OLUD has to be set before calling loadSelectedObservingList. Could be called currentOlud
242

243
        //! filled when loading a selected observing list. This is needed for the interaction with the table/itemModel in GUI
244
        QHash<QString, observingListItem> currentItemCollection;
245

246
        QList<int> highlightLabelIDs; //!< int label IDs for addressing labels by the HighlightMgr
247

248
        QList<QString> listNames; //!< List names, used for the ComboBox
249
        QString currentListName;  //!< Name of list with selectedOlud
250
        QString sorting;          //!< Sorting of the list ex: right ascension
251

252
        bool flagUseJD;         //!< Property. Store/retrieve date
253
        bool flagUseLandscape;  //!< Property. Store/retrieve landscape
254
        bool flagUseLocation;   //!< Property. Store/retrieve location
255
        bool flagUseFov;        //!< Property. Store/retrieve field of view
256

257
        bool tainted;           //!< List has changed. Needs write on exit.
258
        bool isEditMode;        //!< true if in Edit/Create New mode.
259
        bool isCreationMode;    //!< if true we are in creation mode otherwise in edit mode. We ONLY need this to decide what to do in case of a CANCEL during EDIT.
260

261
        //! Set header names for observing list table
262
        void setObservingListHeaderNames();
263

264
        //! Append row in the obsListListModel (the table to display/select list entries)
265
        //! @param olud id of the record
266
        //! @param designation name or the designation of the object
267
        //! @param nameI18n localized name of the object
268
        //! @param typeI18n Localized detailed type (e.g. moon, cubewano, galaxy, binary star) of the object
269
        //! @param ra right assencion of the object
270
        //! @param dec declination of the object
271
        //! @param magnitude magnitude of the object
272
        //! @param constellation constellation in which the object is located
273
        //! @param date human-redable event date (optional)
274
        //! @param location name of location (optional)
275
        //! @param landscapeID of observation (optional)
276
        void addModelRow(const QString &olud, const QString &designation, const QString &nameI18n, const QString &typeI18n,
277
                         const QString &ra, const QString &dec, const QString &magnitude, const QString &constellation,
278
                         const QString &date, const QString &location, const QString &landscapeID);
279

280
        //! Load the lists names from jsonMap,
281
        //! Populate the list names into combo box and extract defaultOlud
282
        //! Note that list names may not be unique, but the OLUDs must be.
283
        void loadListNames(const QString &listID = "");
284

285
        //! Load the selected observing list (selectedOlud) from the jsonMap.
286
        void loadSelectedList();
287

288
        //! Load the default list. If no default has been defined, current or first list (from comboBox) is loaded and are made default.
289
        void loadDefaultList();
290

291
        //! Load the bookmarks of a file (usually bookmarks.json) into a temporary structure
292
        QHash<QString, observingListItem> loadBookmarksFile(QFile &file);
293

294
        //! Prepare the currently displayed/edited list for storage
295
        //! Returns QVariantList with keys={creation date, description, name, objects, sorting}
296
        QVariantMap prepareCurrentList(QHash<QString, observingListItem> &itemHash);
297

298
        //! Put the bookmarks in bookmarksHash into observingLists under the listname "bookmarks list". Does not write JSON!
299
        //! @return OLUD of the imported bookmarks list.
300
        QString saveBookmarksHashInObservingLists(const QHash<QString, observingListItem> &bookmarksHash);
301

302
        //! Sort the obsListTreeView by the column name given in parameter
303
        void sortObsListTreeViewByColumnName(const QString &columnName);
304

305
        //! Check if bookmarks list already exists in observing list file,
306
        //! i.e., if the old bookmarks file has already be loaded.
307
        bool checkIfBookmarksListExists();
308

309
        //! NEW: Switch between regular and edit modes.
310
        //! @param newList activate creation mode. This is only relevant to aborts
311
        void switchEditMode(bool enableEditMode, bool newList);
312

313
        //! Save the object information into json file
314
        void saveObservedObjectsInJsonFile();
315

316
        //! Get the magnitude from selected object (or a dash if unavailable)
317
        static QString getMagnitude(const QList<StelObjectP> &selectedObject, StelCore *core);
318

319
signals:
320
        void flagUseJDChanged(bool b);
321
        void flagUseLandscapeChanged(bool b);
322
        void flagUseLocationChanged(bool b);
323
        void flagUseFovChanged(bool b);
324

325
public slots:
326
        void retranslate() override;
327
        bool getFlagUseJD() {return flagUseJD;}
×
328
        bool getFlagUseLandscape() {return flagUseLandscape;}
×
329
        bool getFlagUseLocation() {return flagUseLocation;}
×
330
        bool getFlagUseFov() {return flagUseFov;}
×
331
        void setFlagUseJD(bool b);
332
        void setFlagUseLandscape(bool b);
333
        void setFlagUseLocation(bool b);
334
        void setFlagUseFov(bool b);
335

336
private slots:
337
        //! Label all bookmarked objects of the current list with a label
338
        void highlightAll();
339
        //! Clear highlights (remove screen labels)
340
        void clearHighlights();
341

342
        //! Method called when a list name is selected in the combobox
343
        //! @param selectedIndex the index of the list name in the combo box
344
        void loadSelectedObservingList(int selectedIndex);
345

346
        //! Select and go to object
347
        //! @param index the QModelIndex of the list
348
        void selectAndGoToObject(QModelIndex index);
349

350
        //! Create a new empty list (new OLUD), make it the active list and enable editing
351
        void newListButtonPressed();
352

353
        //! Initiate edit mode: Enable/disable GUI elements and initiate editing
354
        void editListButtonPressed();
355

356
        void deleteListButtonPressed();
357

358
        void addObjectButtonPressed();
359

360
        void removeObjectButtonPressed();
361

362
        void exportListButtonPressed();
363

364
        void importListButtonPressed();
365

366
        void saveButtonPressed();
367

368
        void cancelButtonPressed();
369

370
        void headerClicked(int index);
371

372
        //! Connected to the defaultList checkbox
373
        void defaultClicked(bool b);
374

375
        //! open a file dialog to browse for a directory to save observing lists to or retrieve them from.
376
        //! If a directory is selected (i.e. dialog not cancelled), current
377
        //! value will be changed and saved to config file.
378
        void browseForObsListDir();
379
        void selectObsListDir();
380

381
private:
382
        static const QString JSON_FILE_NAME;
383
        static const QString JSON_FILE_BASENAME;
384
        static const QString FILE_VERSION;
385

386
        static const QString JSON_BOOKMARKS_FILE_NAME;
387
        static const QString BOOKMARKS_LIST_NAME;
388
        static const QString BOOKMARKS_LIST_DESCRIPTION;
389
        static const QString SHORT_NAME_VALUE;
390

391
        static const QString KEY_DEFAULT_LIST_OLUD;
392
        static const QString KEY_OBSERVING_LISTS;
393
        static const QString KEY_CREATION_DATE;
394
        static const QString KEY_LAST_EDIT;
395
        static const QString KEY_BOOKMARKS;
396
        static const QString KEY_NAME;
397
        static const QString KEY_NAME_I18N;
398
        static const QString KEY_JD;
399
        static const QString KEY_RA;
400
        static const QString KEY_DEC;
401
        static const QString KEY_FOV;
402
        static const QString KEY_DESCRIPTION;
403
        static const QString KEY_LANDSCAPE_ID;
404
        static const QString KEY_OBJECTS;
405
        static const QString KEY_OBJECTS_TYPE;
406
        static const QString KEY_TYPE;
407
        static const QString KEY_DESIGNATION;
408
        static const QString KEY_SORTING;
409
        static const QString KEY_LOCATION;
410
        static const QString KEY_MAGNITUDE;
411
        static const QString KEY_CONSTELLATION;
412
        static const QString KEY_VERSION;
413
        static const QString KEY_SHORT_NAME;
414
        static const QString KEY_IS_VISIBLE_MARKER;
415

416
        static const QString SORTING_BY_NAME;
417
        static const QString SORTING_BY_NAMEI18N;
418
        static const QString SORTING_BY_TYPE;
419
        static const QString SORTING_BY_RA;
420
        static const QString SORTING_BY_DEC;
421
        static const QString SORTING_BY_MAGNITUDE;
422
        static const QString SORTING_BY_CONSTELLATION;
423
        static const QString SORTING_BY_DATE;
424
        static const QString SORTING_BY_LOCATION;
425
        static const QString SORTING_BY_LANDSCAPE_ID;
426

427
        static const QString CUSTOM_OBJECT;
428

429
        static const QString DASH;
430
};
431

432
#endif // OBSLISTDIALOG_H
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc