Kstars

ksuserdb.h
1/*
2 SPDX-FileCopyrightText: 2012 Rishab Arora <ra.rishab@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "auxiliary/profileinfo.h"
10#include "skymapview.h"
11#ifndef KSTARS_LITE
12#include "oal/oal.h"
13#endif
14#include <oal/filter.h>
15
16#include <QFile>
17#include <QSqlDatabase>
18#include <QSqlError>
19#include <QStringList>
20#include <QVariantMap>
21#include <QXmlStreamReader>
22
23#include <memory>
24
25class LineList;
26class ArtificialHorizonEntity;
27class ImageOverlay;
28class ImagingPlannerDBEntry;
29
30
31/**
32 * @brief Single class to delegate all User database I/O
33 *
34 * usage: Call QSqlDatabase::removeDatabase("userdb"); after the object
35 * of this class is deallocated
36 * @author Rishab Arora
37 * @author Jasem Mutlaq
38 * @version 1.2
39 **/
40// cppcheck-suppress noConstructor
42{
43 public:
44 ~KSUserDB();
45
46 /**
47 * Initialize KStarsDB while running splash screen
48 * @return true on success
49 */
50 bool Initialize();
51
52 const QString &connectionName() const
53 {
54 return m_ConnectionName;
55 }
56
57 /************************************************************************
58 ********************************* Drivers ******************************
59 ************************************************************************/
60
61 int AddProfile(const QString &name);
62
63 bool DeleteProfile(const QSharedPointer<ProfileInfo> &pi);
64
65 // Delete profile and all related settings.
66 bool PurgeProfile(const QSharedPointer<ProfileInfo> &pi);
67
68 bool SaveProfile(const QSharedPointer<ProfileInfo> &pi);
69
70 /**
71 * @brief GetAllProfiles Return all profiles in a QList
72 * @return QMap with the keys as profile names and values are profile ids.
73 */
75
76 /************************************************************************
77 ******************************* Dark Library****************************
78 ************************************************************************/
79
80 bool AddDarkFrame(const QVariantMap &oneFrame);
81 bool UpdateDarkFrame(const QVariantMap &oneFrame);
82 bool DeleteDarkFrame(const QString &filename);
83 bool GetAllDarkFrames(QList<QVariantMap> &darkFrames);
84
85 /************************************************************************
86 ******************************* Effective FOVs *************************
87 ************************************************************************/
88
89 bool AddEffectiveFOV(const QVariantMap &oneFOV);
90 bool DeleteEffectiveFOV(const QString &id);
91 bool GetAllEffectiveFOVs(QList<QVariantMap> &effectiveFOVs);
92
93 /************************************************************************
94 ******************************* Driver Alias *************************
95 ************************************************************************/
96
97 bool AddCustomDriver(const QVariantMap &oneDriver);
98 bool DeleteCustomDriver(const QString &id);
99 bool GetAllCustomDrivers(QList<QVariantMap> &CustomDrivers);
100
101 /************************************************************************
102 *********************************** HiPS *******************************
103 ************************************************************************/
104
105 bool AddHIPSSource(const QMap<QString, QString> &oneSource);
106 bool DeleteHIPSSource(const QString &ID);
107 bool GetAllHIPSSources(QList<QMap<QString, QString>> &HIPSSources);
108
109 /************************************************************************
110 *********************************** DSLR *******************************
111 ************************************************************************/
112
113 bool AddDSLRInfo(const QMap<QString, QVariant> &oneInfo);
114 bool DeleteDSLRInfo(const QString &model);
115 bool DeleteAllDSLRInfo();
116 bool GetAllDSLRInfos(QList<QMap<QString, QVariant>> &DSLRInfos);
117
118 /************************************************************************
119 ******************************* Observers ******************************
120 ************************************************************************/
121
122 /** @brief Adds a new observer into the database **/
123 bool AddObserver(const QString &name, const QString &surname, const QString &contact);
124
125 /**
126 * @brief Returns the unique id of the user with given name & surname
127 *
128 * @return true if found, false otherwise
129 **/
130 bool FindObserver(const QString &name, const QString &surname);
131 /**
132 * @brief Removes the user with unique id as given by FindObserver
133 * Returns false if the user is not found
134 *
135 * @return bool
136 **/
137 bool DeleteObserver(const QString &id);
138
139#ifndef KSTARS_LITE
140 /**
141 * @brief Updates the passed reference of observer_list with all observers
142 * The original content of the list is cleared.
143 *
144 * @return true if database read was successfull, false otherwise.
145 **/
146 bool GetAllObservers(QList<OAL::Observer *> &observer_list);
147#endif
148 /************************************************************************
149 ********************************* Horizon ******************************
150 ************************************************************************/
151
152 /** @brief Deletes all artificial horizon rows from the database **/
153 bool DeleteAllHorizons();
154
155 /** @brief Adds a new artificial horizon row into the database **/
156 bool AddHorizon(ArtificialHorizonEntity *horizon);
157
158 /** @brief Gets all the artificial horizon rows from the database **/
160
161 /************************************************************************
162 ****************************** ImageOverlay ****************************
163 ************************************************************************/
164
165 /** @brief Deletes all image overlay rows from the database **/
167
168 /** @brief Adds a new image overlay row into the database **/
169 bool AddImageOverlay(const ImageOverlay &overlay);
170
171 /** @brief Gets all the image overlay rows from the database **/
172 bool GetAllImageOverlays(QList<ImageOverlay> *imageOverlayList);
173
174 /************************************************************************
175 **************************** Imaging Planner ***************************
176 ************************************************************************/
177
178 /** @brief Deletes all Imaging Planner rows from the database **/
180
181 /** @brief Adds a new Imaging Planner row into the database **/
182 bool AddImagingPlannerEntry(const ImagingPlannerDBEntry &entry);
183
184 /** @brief Gets all the Imaging Planner rows from the database **/
186
187 /************************************************************************
188 ****************************** Sky Map Views ***************************
189 ************************************************************************/
190
191 /** @brief Deletes all the sky map views stored in the database */
193
194 /** @brief Adds a new sky map view row in the database */
195 bool AddSkyMapView(const SkyMapView &view);
196
197 /** @brief Gets all the sky map view rows from the database */
198 bool GetAllSkyMapViews(QList<SkyMapView> &skyMapViewList);
199
200 /************************************************************************
201 ********************************* Flags ********************************
202 ************************************************************************/
203
204 /**
205 * @brief Erases all the flags from the database
206 *
207 * @return void
208 **/
209 bool DeleteAllFlags();
210
211 /**
212 * @brief Add a new Flag with given parameters
213 *
214 * @param ra Right Ascension
215 * @param dec Declination
216 * @param epoch Epoch
217 * @param image_name Name of the image used
218 * @param label Content of display label on screen
219 * @param labelColor Color of the label (name or hex code) eg #00FF00
220 * @return True if database transaction is successful, false otherwise
221 **/
222 bool AddFlag(const QString &ra, const QString &dec, const QString &epoch, const QString &image_name,
223 const QString &label, const QString &labelColor);
224 /**
225 * @brief Returns a QList populated with all stored flags
226 * Order: const QString &ra, const QString &dec, const QString &epoch,
227 * const QString &imageName, const QString &label, const QString &labelColor
228 * @return
229 **/
230 bool GetAllFlags(QList<QStringList> &flagList);
231
232 /************************************************************************
233 ******************************* Equipment ******************************
234 ************************************************************************/
235
236 /**
237 * @brief Erase the equipment with given type and unique id
238 * Valid equipment types: "telescope","lens","filter"
239 *
240 * @param type Equipment type (same as table name)
241 * @param id Unique id (same as row number)
242 * @return void
243 **/
244 bool DeleteEquipment(const QString &type, const QString &id);
245 /**
246 * @brief Erases the whole equipment table of given type
247 *
248 * @param type Equipment type (same as table name)
249 * @return void
250 **/
251 bool DeleteAllEquipment(const QString &type);
252
253 /************************************************************************
254 ********************************** Scope *******************************
255 ************************************************************************/
256
257 /**
258 * @brief Appends the scope with given details in the database
259 *
260 * @return void
261 **/
262 bool AddScope(const QString &model, const QString &vendor, const QString &type,
263 const double &aperture, const double &focalLength);
264 /**
265 * @brief Replaces the scope with given ID with provided content
266 *
267 * @return void
268 **/
269 bool AddScope(const QString &model, const QString &vendor, const QString &type, const double &aperture,
270 const double &focalLength, const QString &id);
271#ifndef KSTARS_LITE
272 /**
273 * @brief updates the scope list with all scopes from database
274 * List is cleared and then filled with content.
275 *
276 * @param m_scopeList Reference to list to be updated
277 * @return void
278 **/
279 bool GetAllScopes(QList<OAL::Scope *> &m_scopeList);
280#endif
281
282 /************************************************************************
283 ******************************* Optical Elements ***********************
284 ************************************************************************/
285 bool getOpticalElementByID(int id, QJsonObject &element);
286 bool getOpticalElementByName(const QString &name, QJsonObject &element);
287 /**
288 * @brief getLastOpticalElement Return last inserted scope or lens
289 * @param element JSON object to fill with scope or lens metadata
290 * @return True if found, false if none found.
291 */
292 bool getLastOpticalElement(QJsonObject &element);
293 QStringList getOpticalElementNames();
294
295 /************************************************************************
296 ******************************* Eye Piece ******************************
297 ************************************************************************/
298
299 /**
300 * @brief Add new eyepiece to database
301 *
302 * @return void
303 **/
304 bool AddEyepiece(const QString &vendor, const QString &model, const double &focalLength, const double &fov,
305 const QString &fovunit);
306 /**
307 * @brief Replace eyepiece at position (ID) with new content
308 *
309 * @return void
310 **/
311 bool AddEyepiece(const QString &vendor, const QString &model, const double &focalLength, const double &fov,
312 const QString &fovunit, const QString &id);
313#ifndef KSTARS_LITE
314 /**
315 * @brief Populate the reference passed with all eyepieces
316 *
317 * @param m_eyepieceList Reference to list of eyepieces
318 * @return void
319 **/
320 bool GetAllEyepieces(QList<OAL::Eyepiece *> &m_eyepieceList);
321#endif
322 /************************************************************************
323 ********************************** Lens ********************************
324 ************************************************************************/
325
326 /**
327 * @brief Add a new lens to the database
328 *
329 * @return void
330 **/
331 bool AddLens(const QString &vendor, const QString &model, const double &factor);
332 /**
333 * @brief Replace a lens at given ID with new content
334 *
335 * @return void
336 **/
337 bool AddLens(const QString &vendor, const QString &model, const double &factor, const QString &id);
338#ifndef KSTARS_LITE
339 /**
340 * @brief Populate the reference passed with all lenses
341 *
342 * @param m_lensList Reference to list of lenses
343 * @return void
344 **/
345 bool GetAllLenses(QList<OAL::Lens *> &m_lensList);
346#endif
347
348 /************************************************************************
349 ********************************** DSLR Lens ***************************
350 ************************************************************************/
351
352 /**
353 * @brief Appends the DSLR lens with given details in the database
354 *
355 * @return void
356 **/
357 bool AddDSLRLens(const QString &model, const QString &vendor, const double focalLength, const double focalRatio);
358 /**
359 * @brief Replaces the scope with given ID with provided content
360 *
361 * @return void
362 **/
363 bool AddDSLRLens(const QString &model, const QString &vendor, const double focalLength, const double focalRatio,
364 const QString &id);
365#ifndef KSTARS_LITE
366 /**
367 * @brief updates the dslr list with all DSLR lenses from database
368 * List is cleared and then filled with content.
369 *
370 * @param dslrlens_list Reference to list to be updated
371 * @return void
372 **/
373 bool GetAllDSLRLenses(QList<OAL::DSLRLens *> &dslrlens_list);
374#endif
375
376 /************************************************************************
377 ******************************** Filters *******************************
378 ************************************************************************/
379
380 /**
381 * @brief Add a new filter to the database
382 *
383 * @return void
384 **/
385 bool AddFilter(const filterProperties *fp);
386 /**
387 * @brief Replace a filter at given ID with new content
388 *
389 * @return void
390 **/
391 bool AddFilter(const filterProperties *fp, const QString &id);
392 /**
393 * @brief Populate the reference passed with all filters
394 *
395 * @param m_filterList Reference to list of filters
396 * @return void
397 **/
398 bool GetAllFilters(QList<OAL::Filter *> &m_filterList);
399
400 /************************************************************************
401 ******************************** Optical Trains ************************
402 ************************************************************************/
403
404 /**
405 * @brief Add a new optical train to the database
406 * @param oneTrain optical train data
407 **/
408 bool AddOpticalTrain(const QVariantMap &oneTrain);
409
410 /**
411 * @brief Update an existing optical train
412 * @param oneTrain optical train data
413 * @param id ID of train to replace in database
414 **/
415 bool UpdateOpticalTrain(const QVariantMap &oneTrain, int id);
416
417 bool DeleteOpticalTrain(int id);
418 /**
419 * @brief Populate the reference passed with all optical trains
420 * @param opticalTrains Reference to all trains list
421 **/
422 bool GetOpticalTrains(uint32_t profileID, QList<QVariantMap> &opticalTrains);
423
424 /************************************************************************
425 ******************************** Profile Settings **********************
426 ************************************************************************/
427
428 /**
429 * @brief Add new profile settings to the database
430 * @param settings JSON settings
431 **/
432 void AddProfileSettings(uint32_t profile, const QByteArray &settings);
433
434 void UpdateProfileSettings(uint32_t profileID, const QByteArray &settings);
435
436 void DeleteProfileSettings(uint32_t profile);
437 /**
438 * @brief Populate the reference passed with settings for one paritcular profile
439 * @param profile id of profile
440 * @param settings populate settings with parsed profile settings.
441 **/
442 bool GetProfileSettings(uint32_t profile, QVariantMap &settings);
443
444 /************************************************************************
445 ******************************** Train Settings **********************
446 ************************************************************************/
447
448 /**
449 * @brief Add new Train settings to the database
450 * @param settings JSON settings
451 **/
452 bool AddOpticalTrainSettings(uint32_t train, const QByteArray &settings);
453
454 bool UpdateOpticalTrainSettings(uint32_t train, const QByteArray &settings);
455
456 bool DeleteOpticalTrainSettings(uint32_t train);
457 /**
458 * @brief Populate the reference passed with settings for one paritcular Train
459 * @param TrainID id of Train
460 * @param settings populate settings with parsed Train settings.
461 **/
462 bool GetOpticalTrainSettings(uint32_t train, QVariantMap &settings);
463
464 /************************************************************************
465 *********************** Collimation Overlay Elements *******************
466 ************************************************************************/
467
468 /**
469 * @brief Add a new collimation overlay element to the database
470 * @param oneElement collimation overlay element data
471 **/
472 bool AddCollimationOverlayElement(const QVariantMap &oneElement);
473
474 /**
475 * @brief Update an existing collimation overlay element
476 * @param oneElement collimation overlay element data
477 * @param id ID of element to replace in database
478 **/
479 bool UpdateCollimationOverlayElement(const QVariantMap &oneElement, int id);
480
481 bool DeleteCollimationOverlayElement(int id);
482
483 /**
484 * @brief Populate the reference passed with all collimation overlay elements
485 * @param collimationOverlayElements Reference to all elements list
486 **/
487 bool GetCollimationOverlayElements(QList<QVariantMap> &collimationOverlayElements);
488
489 private:
490 /**
491 * @brief This function initializes a new database in the user's directory.
492 * To be run only when a new db is needed. Should not be run over existing database file.
493 *
494 * @return bool
495 **/
496 bool RebuildDB();
497 /**
498 * @brief Rebuilds the User DB from scratch using RebuildDB.
499 * Also, loads any previous user data into the DB.
500 *
501 * @return bool
502 **/
503 bool FirstRun();
504
505 /** @brief creates the image overlay table if it doesn't already exist **/
506 void CreateImageOverlayTableIfNecessary();
507
508 /** @brief creates the imaging planner table if it doesn't already exist **/
509 void CreateImagingPlannerTableIfNecessary();
510
511 /** @brief creates the image overlay table if it doesn't already exist **/
512 void CreateSkyMapViewTableIfNecessary();
513
514#if 0
515 /**
516 * @brief Imports flags data from previous format
517 *
518 * @return bool
519 **/
520 bool ImportFlags();
521 /**
522 * @brief Imports users from previous format
523 *
524 * @return bool
525 **/
526 bool ImportUsers();
527 /**
528 * @brief Imports equipment from previous format
529 *
530 * @return bool
531 **/
532 bool ImportEquipment();
533
534#endif
535 // Helper functions
536 void readScopes();
537 void readScope();
538 void readEyepieces();
539 void readEyepiece();
540 void readLenses();
541 void readLens();
542 void readFilters();
543 void readFilter();
544
545 bool DeleteProfileDrivers(const QSharedPointer<ProfileInfo> &pi);
546 bool GetProfileDrivers(const QSharedPointer<ProfileInfo> &pi);
547 //void GetProfileCustomDrivers(ProfileInfo *pi);
548
549 /** XML reader for importing old formats **/
550 QXmlStreamReader *reader_ { nullptr };
551
552 QString m_ConnectionName;
553
554 static const uint16_t SCHEMA_VERSION = 314;
555};
Handles adding new drivers to database.
Single class to delegate all User database I/O.
Definition ksuserdb.h:42
bool GetAllImageOverlays(QList< ImageOverlay > *imageOverlayList)
Gets all the image overlay rows from the database.
bool UpdateCollimationOverlayElement(const QVariantMap &oneElement, int id)
Update an existing collimation overlay element.
bool AddOpticalTrain(const QVariantMap &oneTrain)
Add a new optical train to the database.
Definition ksuserdb.cpp:950
bool AddFilter(const filterProperties *fp)
Add a new filter to the database.
bool AddSkyMapView(const SkyMapView &view)
Adds a new sky map view row in the database.
bool DeleteAllFlags()
Erases all the flags from the database.
bool AddCollimationOverlayElement(const QVariantMap &oneElement)
Add a new collimation overlay element to the database.
bool AddObserver(const QString &name, const QString &surname, const QString &contact)
Adds a new observer into the database.
Definition ksuserdb.cpp:624
bool AddLens(const QString &vendor, const QString &model, const double &factor)
Add a new lens to the database.
bool GetAllScopes(QList< OAL::Scope * > &m_scopeList)
updates the scope list with all scopes from database List is cleared and then filled with content.
bool GetAllHorizons(QList< ArtificialHorizonEntity * > &horizonList)
Gets all the artificial horizon rows from the database.
bool AddDSLRLens(const QString &model, const QString &vendor, const double focalLength, const double focalRatio)
Appends the DSLR lens with given details in the database.
bool getLastOpticalElement(QJsonObject &element)
getLastOpticalElement Return last inserted scope or lens
void AddProfileSettings(uint32_t profile, const QByteArray &settings)
Add new profile settings to the database.
bool AddImagingPlannerEntry(const ImagingPlannerDBEntry &entry)
Adds a new Imaging Planner row into the database.
bool GetAllObservers(QList< OAL::Observer * > &observer_list)
Updates the passed reference of observer_list with all observers The original content of the list is ...
Definition ksuserdb.cpp:713
bool AddFlag(const QString &ra, const QString &dec, const QString &epoch, const QString &image_name, const QString &label, const QString &labelColor)
Add a new Flag with given parameters.
bool GetAllFlags(QList< QStringList > &flagList)
Returns a QList populated with all stored flags Order: const QString &ra, const QString &dec,...
bool GetAllSkyMapViews(QList< SkyMapView > &skyMapViewList)
Gets all the sky map view rows from the database.
bool AddHorizon(ArtificialHorizonEntity *horizon)
Adds a new artificial horizon row into the database.
bool DeleteDarkFrame(const QString &filename)
KSUserDB::DeleteDarkFrame Delete from database a dark frame record that matches the filename field.
Definition ksuserdb.cpp:806
bool GetAllLenses(QList< OAL::Lens * > &m_lensList)
Populate the reference passed with all lenses.
bool DeleteAllSkyMapViews()
Deletes all the sky map views stored in the database.
bool GetAllFilters(QList< OAL::Filter * > &m_filterList)
Populate the reference passed with all filters.
bool AddDarkFrame(const QVariantMap &oneFrame)
KSUserDB::AddDarkFrame Saves a new dark frame data to the database.
Definition ksuserdb.cpp:749
bool AddImageOverlay(const ImageOverlay &overlay)
Adds a new image overlay row into the database.
bool GetProfileSettings(uint32_t profile, QVariantMap &settings)
Populate the reference passed with settings for one paritcular profile.
bool DeleteObserver(const QString &id)
Removes the user with unique id as given by FindObserver Returns false if the user is not found.
Definition ksuserdb.cpp:686
bool Initialize()
Initialize KStarsDB while running splash screen.
Definition ksuserdb.cpp:46
bool GetCollimationOverlayElements(QList< QVariantMap > &collimationOverlayElements)
Populate the reference passed with all collimation overlay elements.
bool AddScope(const QString &model, const QString &vendor, const QString &type, const double &aperture, const double &focalLength)
Appends the scope with given details in the database.
bool DeleteEquipment(const QString &type, const QString &id)
Erase the equipment with given type and unique id Valid equipment types: "telescope",...
bool DeleteAllEquipment(const QString &type)
Erases the whole equipment table of given type.
bool UpdateDarkFrame(const QVariantMap &oneFrame)
KSUserDB::UpdateDarkFrame Updates an existing dark frame record in the data, replace all values match...
Definition ksuserdb.cpp:778
bool GetOpticalTrains(uint32_t profileID, QList< QVariantMap > &opticalTrains)
Populate the reference passed with all optical trains.
bool UpdateOpticalTrain(const QVariantMap &oneTrain, int id)
Update an existing optical train.
Definition ksuserdb.cpp:985
bool FindObserver(const QString &name, const QString &surname)
Returns the unique id of the user with given name & surname.
Definition ksuserdb.cpp:663
bool GetAllDSLRLenses(QList< OAL::DSLRLens * > &dslrlens_list)
updates the dslr list with all DSLR lenses from database List is cleared and then filled with content...
bool GetOpticalTrainSettings(uint32_t train, QVariantMap &settings)
Populate the reference passed with settings for one paritcular Train.
bool AddEyepiece(const QString &vendor, const QString &model, const double &focalLength, const double &fov, const QString &fovunit)
Add new eyepiece to database.
bool DeleteAllImagingPlannerEntries()
Deletes all Imaging Planner rows from the database.
bool DeleteAllImageOverlays()
Deletes all image overlay rows from the database.
bool GetAllProfiles(QList< QSharedPointer< ProfileInfo > > &profiles)
GetAllProfiles Return all profiles in a QList.
bool GetAllEyepieces(QList< OAL::Eyepiece * > &m_eyepieceList)
Populate the reference passed with all eyepieces.
bool AddOpticalTrainSettings(uint32_t train, const QByteArray &settings)
Add new Train settings to the database.
bool DeleteAllHorizons()
Deletes all artificial horizon rows from the database.
bool GetAllImagingPlannerEntries(QList< ImagingPlannerDBEntry > *entryList)
Gets all the Imaging Planner rows from the database.
A simple data container used by LineListIndex.
Definition linelist.h:25
Carries parameters of a sky map view.
Definition skymapview.h:19
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.