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

KDE's Doxygen guidelines are available online.