Kstars

ksuserdb.h
1 /*
2  SPDX-FileCopyrightText: 2012 Rishab Arora <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "auxiliary/profileinfo.h"
10 #ifndef KSTARS_LITE
11 #include "oal/oal.h"
12 #endif
13 #include "skyobjects/skyobject.h"
14 
15 #include <QFile>
16 #include <QSqlDatabase>
17 #include <QSqlError>
18 #include <QStringList>
19 #include <QVariantMap>
20 #include <QXmlStreamReader>
21 
22 #include <memory>
23 
24 class LineList;
25 class ArtificialHorizonEntity;
26 
27 /**
28  * @brief Single class to delegate all User database I/O
29  *
30  * usage: Call QSqlDatabase::removeDatabase("userdb"); after the object
31  * of this class is deallocated
32  * @author Rishab Arora
33  * @author Jasem Mutlaq
34  * @version 1.2
35  **/
36 // cppcheck-suppress noConstructor
37 class KSUserDB
38 {
39  public:
40  ~KSUserDB();
41 
42  /**
43  * Initialize KStarsDB while running splash screen
44  * @return true on success
45  */
46  bool Initialize();
47 
48  QSqlDatabase GetDatabase();
49 
50  /************************************************************************
51  ********************************* Drivers ******************************
52  ************************************************************************/
53 
54  int AddProfile(const QString &name);
55 
56  bool DeleteProfile(ProfileInfo *pi);
57 
58  void SaveProfile(ProfileInfo *pi);
59 
60  /**
61  * @brief GetAllProfiles Return all profiles in a QList
62  * @return QMap with the keys as profile names and values are profile ids.
63  */
64  void GetAllProfiles(QList<std::shared_ptr<ProfileInfo>> &profiles);
65 
66  /************************************************************************
67  ******************************* Dark Library****************************
68  ************************************************************************/
69 
70  void AddDarkFrame(const QVariantMap &oneFrame);
71  void UpdateDarkFrame(const QVariantMap &oneFrame);
72  void DeleteDarkFrame(const QString &filename);
73  void GetAllDarkFrames(QList<QVariantMap> &darkFrames);
74 
75 
76  /************************************************************************
77  ******************************* Effective FOVs *************************
78  ************************************************************************/
79 
80  void AddEffectiveFOV(const QVariantMap &oneFOV);
81  bool DeleteEffectiveFOV(const QString &id);
82  void GetAllEffectiveFOVs(QList<QVariantMap> &effectiveFOVs);
83 
84 
85  /************************************************************************
86  ******************************* Driver Alias *************************
87  ************************************************************************/
88 
89  bool AddCustomDriver(const QVariantMap &oneDriver);
90  bool DeleteCustomDriver(const QString &id);
91  void GetAllCustomDrivers(QList<QVariantMap> &CustomDrivers);
92 
93  /************************************************************************
94  *********************************** HiPS *******************************
95  ************************************************************************/
96 
97  void AddHIPSSource(const QMap<QString, QString> &oneSource);
98  bool DeleteHIPSSource(const QString &ID);
99  void GetAllHIPSSources(QList<QMap<QString, QString>> &HIPSSources);
100 
101  /************************************************************************
102  *********************************** DSLR *******************************
103  ************************************************************************/
104 
105  void AddDSLRInfo(const QMap<QString, QVariant> &oneInfo);
106  bool DeleteDSLRInfo(const QString &model);
107  bool DeleteAllDSLRInfo();
108  void GetAllDSLRInfos(QList<QMap<QString, QVariant>> &DSLRInfos);
109 
110  /************************************************************************
111  ******************************* Observers ******************************
112  ************************************************************************/
113 
114  /** @brief Adds a new observer into the database **/
115  void AddObserver(const QString &name, const QString &surname, const QString &contact);
116 
117  /**
118  * @brief Returns the unique id of the user with given name & surname
119  *
120  * @return true if found, false otherwise
121  **/
122  bool FindObserver(const QString &name, const QString &surname);
123  /**
124  * @brief Removes the user with unique id as given by FindObserver
125  * Returns false if the user is not found
126  *
127  * @return bool
128  **/
129  bool DeleteObserver(const QString &id);
130 
131 #ifndef KSTARS_LITE
132  /**
133  * @brief Updates the passed reference of observer_list with all observers
134  * The original content of the list is cleared.
135  *
136  * @return void
137  **/
138  void GetAllObservers(QList<OAL::Observer *> &observer_list);
139 #endif
140  /************************************************************************
141  ********************************* Horizon ******************************
142  ************************************************************************/
143 
144  // Jasem: Add API doc
145  void DeleteAllHorizons();
146  void AddHorizon(ArtificialHorizonEntity *horizon);
147  QList<ArtificialHorizonEntity *> GetAllHorizons();
148 
149  /************************************************************************
150  ********************************* Flags ********************************
151  ************************************************************************/
152 
153  /**
154  * @brief Erases all the flags from the database
155  *
156  * @return void
157  **/
158  void DeleteAllFlags();
159 
160  /**
161  * @brief Add a new Flag with given parameters
162  *
163  * @param ra Right Ascension
164  * @param dec Declination
165  * @param epoch Epoch
166  * @param image_name Name of the image used
167  * @param label Content of display label on screen
168  * @param labelColor Color of the label (name or hex code) eg #00FF00
169  * @return void
170  **/
171  void AddFlag(const QString &ra, const QString &dec, const QString &epoch, const QString &image_name,
172  const QString &label, const QString &labelColor);
173  /**
174  * @brief Returns a QList populated with all stored flags
175  * Order: const QString &ra, const QString &dec, const QString &epoch,
176  * const QString &imageName, const QString &label, const QString &labelColor
177  * @return QList< QStringList >
178  **/
180 
181  /************************************************************************
182  ******************************* Equipment ******************************
183  ************************************************************************/
184 
185  /**
186  * @brief Erase the equipment with given type and unique id
187  * Valid equipment types: "telescope","lens","filter"
188  *
189  * @param type Equipment type (same as table name)
190  * @param id Unique id (same as row number)
191  * @return void
192  **/
193  void DeleteEquipment(const QString &type, const int &id);
194  /**
195  * @brief Erases the whole equipment table of given type
196  *
197  * @param type Equipment type (same as table name)
198  * @return void
199  **/
200  void DeleteAllEquipment(const QString &type);
201 
202  /************************************************************************
203  ********************************** Scope *******************************
204  ************************************************************************/
205 
206  /**
207  * @brief Appends the scope with given details in the database
208  *
209  * @return void
210  **/
211  void AddScope(const QString &model, const QString &vendor, const QString &driver, const QString &type,
212  const double &focalLength, const double &aperture);
213  /**
214  * @brief Replaces the scope with given ID with provided content
215  *
216  * @return void
217  **/
218  void AddScope(const QString &model, const QString &vendor, const QString &driver, const QString &type,
219  const double &focalLength, const double &aperture, const QString &id);
220 #ifndef KSTARS_LITE
221  /**
222  * @brief updates the scope list with all scopes from database
223  * List is cleared and then filled with content.
224  *
225  * @param m_scopeList Reference to list to be updated
226  * @return void
227  **/
228  void GetAllScopes(QList<OAL::Scope *> &m_scopeList);
229 #endif
230  /************************************************************************
231  ******************************* Eye Piece ******************************
232  ************************************************************************/
233 
234  /**
235  * @brief Add new eyepiece to database
236  *
237  * @return void
238  **/
239  void AddEyepiece(const QString &vendor, const QString &model, const double &focalLength, const double &fov,
240  const QString &fovunit);
241  /**
242  * @brief Replace eyepiece at position (ID) with new content
243  *
244  * @return void
245  **/
246  void AddEyepiece(const QString &vendor, const QString &model, const double &focalLength, const double &fov,
247  const QString &fovunit, const QString &id);
248 #ifndef KSTARS_LITE
249  /**
250  * @brief Populate the reference passed with all eyepieces
251  *
252  * @param m_eyepieceList Reference to list of eyepieces
253  * @return void
254  **/
255  void GetAllEyepieces(QList<OAL::Eyepiece *> &m_eyepieceList);
256 #endif
257  /************************************************************************
258  ********************************** Lens ********************************
259  ************************************************************************/
260 
261  /**
262  * @brief Add a new lens to the database
263  *
264  * @return void
265  **/
266  void AddLens(const QString &vendor, const QString &model, const double &factor);
267  /**
268  * @brief Replace a lens at given ID with new content
269  *
270  * @return void
271  **/
272  void AddLens(const QString &vendor, const QString &model, const double &factor, const QString &id);
273 #ifndef KSTARS_LITE
274  /**
275  * @brief Populate the reference passed with all lenses
276  *
277  * @param m_lensList Reference to list of lenses
278  * @return void
279  **/
280  void GetAllLenses(QList<OAL::Lens *> &m_lensList);
281 #endif
282  /************************************************************************
283  ******************************** Filters *******************************
284  ************************************************************************/
285 
286  /**
287  * @brief Add a new filter to the database
288  *
289  * @return void
290  **/
291  void AddFilter(const QString &vendor, const QString &model, const QString &type, const QString &color,
292  int offset, double exposure, bool useAutoFocus, const QString &lockedFilter, int absFocusPos);
293  /**
294  * @brief Replace a filter at given ID with new content
295  *
296  * @return void
297  **/
298  void AddFilter(const QString &vendor, const QString &model, const QString &type, const QString &color,
299  int offset, double exposure, bool useAutoFocus, const QString &lockedFilter, int absFocusPos, const QString &id);
300 #ifndef KSTARS_LITE
301  /**
302  * @brief Populate the reference passed with all filters
303  *
304  * @param m_filterList Reference to list of filters
305  * @return void
306  **/
307  void GetAllFilters(QList<OAL::Filter *> &m_filterList);
308 #endif
309  private:
310  /**
311  * @brief This function initializes a new database in the user's directory.
312  * To be run only when a new db is needed. Should not be run over existing database file.
313  *
314  * @return bool
315  **/
316  bool RebuildDB();
317  /**
318  * @brief Rebuilds the User DB from scratch using RebuildDB.
319  * Also, loads any previous user data into the DB.
320  *
321  * @return bool
322  **/
323  bool FirstRun();
324 
325 #if 0
326  /**
327  * @brief Imports flags data from previous format
328  *
329  * @return bool
330  **/
331  bool ImportFlags();
332  /**
333  * @brief Imports users from previous format
334  *
335  * @return bool
336  **/
337  bool ImportUsers();
338  /**
339  * @brief Imports equipment from previous format
340  *
341  * @return bool
342  **/
343  bool ImportEquipment();
344 
345 #endif
346  // Helper functions
347  void readScopes();
348  void readScope();
349  void readEyepieces();
350  void readEyepiece();
351  void readLenses();
352  void readLens();
353  void readFilters();
354  void readFilter();
355 
356  void DeleteProfileDrivers(ProfileInfo *pi);
357  void GetProfileDrivers(ProfileInfo *pi);
358  //void GetProfileCustomDrivers(ProfileInfo *pi);
359 
360  /**
361  * @brief Function to return the last error encountered by SQLite
362  *
363  * @return QSqlError
364  **/
365  inline QSqlError LastError();
366 
367  /** Linked to the user database _once_. **/
368  QSqlDatabase m_UserDB;
369  /** XML reader for importing old formats **/
370  QXmlStreamReader *reader_ { nullptr };
371 
372  static const uint16_t SCHEMA_VERSION = 310;
373 };
void 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:541
void AddFilter(const QString &vendor, const QString &model, const QString &type, const QString &color, int offset, double exposure, bool useAutoFocus, const QString &lockedFilter, int absFocusPos)
Add a new filter to the database.
Definition: ksuserdb.cpp:1245
Single class to delegate all User database I/O.
Definition: ksuserdb.h:37
void GetAllFilters(QList< OAL::Filter * > &m_filterList)
Populate the reference passed with all filters.
Definition: ksuserdb.cpp:1317
void 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.
Definition: ksuserdb.cpp:939
void GetAllProfiles(QList< std::shared_ptr< ProfileInfo >> &profiles)
GetAllProfiles Return all profiles in a QList.
Definition: ksuserdb.cpp:2010
void DeleteAllFlags()
Erases all the flags from the database.
Definition: ksuserdb.cpp:924
void DeleteAllEquipment(const QString &type)
Erases the whole equipment table of given type.
Definition: ksuserdb.cpp:1012
Handles adding new drivers to database. This would enable to add arbitrary aliases of existing driver...
Definition: customdrivers.h:25
void DeleteDarkFrame(const QString &filename)
KSUserDB::DeleteDarkFrame Delete from database a dark frame record that matches the filename field.
Definition: ksuserdb.cpp:616
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:518
bool Initialize()
Initialize KStarsDB while running splash screen.
Definition: ksuserdb.cpp:40
void AddObserver(const QString &name, const QString &surname, const QString &contact)
Adds a new observer into the database.
Definition: ksuserdb.cpp:472
QList< QStringList > GetAllFlags()
Returns a QList populated with all stored flags Order: const QString &ra, const QString &dec,...
Definition: ksuserdb.cpp:960
bool FindObserver(const QString &name, const QString &surname)
Returns the unique id of the user with given name & surname.
Definition: ksuserdb.cpp:502
void DeleteEquipment(const QString &type, const int &id)
Erase the equipment with given type and unique id Valid equipment types: "telescope",...
Definition: ksuserdb.cpp:997
void GetAllLenses(QList< OAL::Lens * > &m_lensList)
Populate the reference passed with all lenses.
Definition: ksuserdb.cpp:1218
void UpdateDarkFrame(const QVariantMap &oneFrame)
KSUserDB::UpdateDarkFrame Updates an existing dark frame record in the data, replace all values match...
Definition: ksuserdb.cpp:595
void GetAllScopes(QList< OAL::Scope * > &m_scopeList)
updates the scope list with all scopes from database List is cleared and then filled with content.
Definition: ksuserdb.cpp:1076
void AddScope(const QString &model, const QString &vendor, const QString &driver, const QString &type, const double &focalLength, const double &aperture)
Appends the scope with given details in the database.
Definition: ksuserdb.cpp:1030
void AddDarkFrame(const QVariantMap &oneFrame)
KSUserDB::AddDarkFrame Saves a new dark frame data to the database.
Definition: ksuserdb.cpp:571
void GetAllEyepieces(QList< OAL::Eyepiece * > &m_eyepieceList)
Populate the reference passed with all eyepieces.
Definition: ksuserdb.cpp:1151
void AddEyepiece(const QString &vendor, const QString &model, const double &focalLength, const double &fov, const QString &fovunit)
Add new eyepiece to database.
Definition: ksuserdb.cpp:1107
void AddLens(const QString &vendor, const QString &model, const double &factor)
Add a new lens to the database.
Definition: ksuserdb.cpp:1181
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:55 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.