Kstars

collimationoverlayoptions.h
1/*
2 SPDX-FileCopyrightText: 2023 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "ui_collimationOptions.h"
10#include "collimationoverlaytypes.h"
11
12#include <QDialog>
13#include <QSqlDatabase>
14#include <QQueue>
15#include <QPointer>
16#include <QMetaEnum>
17
18class QSqlTableModel;
19
20class CollimationOverlayOptions: public QDialog, public Ui::collimationOptions
21{
23 Q_PROPERTY(QList <QString> elementNames READ getElementNames)
24
25 public:
26
27 static CollimationOverlayOptions *Instance(QWidget *parent);
28 static void release();
29
30 void checkElements();
31
32 bool exists(uint8_t id) const;
33 const QVariantMap getCollimationOverlayElement(uint8_t id) const;
34 const QVariantMap getCollimationOverlayElement(const QString &name) const;
35 const QList<QVariantMap> &getCollimationOverlayElements() const
36 {
37 return m_CollimationOverlayElements;
38 }
39 const QList <QString> &getElementNames() const
40 {
41 return m_ElementNames;
42 }
43
44 /**
45 * @brief Select a collimation overlay element and fill the field values in the element editor
46 * with the appropriate values of the selected collimation overlay element.
47 * @param item collimation overlay element list item
48 * @return true if collimation overlay element found
49 */
50 bool selectCollimationOverlayElement(QListWidgetItem *item);
51
52 /**
53 * @brief Select a collimation overlay element and fill the field values in the element editor
54 * with the appropriate values of the selected collimation overlay element.
55 * @param name collimation overlay element name
56 * @return true if collimation overlay element found
57 */
58 bool selectCollimationOverlayElement(const QString &name);
59
60 /**
61 * @brief Show the dialog and select a collimation overlay element for editing.
62 * @param name collimation overlay element name
63 */
64 void openEditor();
65
66 /**
67 * @brief setCollimationOverlayElementValue Set specific field of collimation overlay element
68 * @param name Name of collimation overlay element
69 * @param field Name of element field
70 * @param value Value of element field
71 * @return True if set is successful, false otherwise.
72 */
73 bool setCollimationOverlayElementValue(const QString &name, const QString &field, const QVariant &value);
74
75 /**
76 * @brief Change the name of the currently selected collimation overlay element to a new value
77 * @param name new element name
78 */
79 void renameCollimationOverlayElement(const QString &name);
80
81 /**
82 * @brief setCollimationOverlayElement Replaces collimation overlay element matching the name of the passed element.
83 * @param train element information, including name and database id
84 * @return True if element is successfully updated in the database.
85 */
86 bool setCollimationOverlayElement(const QJsonObject &element);
87
88 /**
89 * @brief removeCollimationOverlayElement Remove collimation overlay element from database and all associated settings
90 * @param name name of the element to remove
91 * @return True if successful, false if id is not found.
92 */
93 bool removeCollimationOverlayElement(const QString &name);
94
95 void refreshModel();
96 void refreshElements();
97
98 /**
99 * @brief syncValues Sync delegates and then update model accordingly.
100 */
101 void syncValues();
102
103 /**
104 * @brief id Get database ID for a given element
105 * @param name Name of element
106 * @return ID if exists, or -1 if not found.
107 */
108 int id(const QString &name) const;
109
110 /**
111 * @brief name Get database name for a given id
112 * @param id database ID for the element to get
113 * @return Element name, or empty string if not found.
114 */
115 QString name(int id) const;
116
117 signals:
118 void updated();
119
120 protected:
121 void initModel();
122
123 private slots:
124 /**
125 * @brief Update a value in the currently selected element
126 * @param cb combo box holding the new value
127 * @param element value name
128 */
129 void updateValue(QComboBox *cb, const QString &valueName);
130 /**
131 * @brief Update a value in the currently selected element
132 * @param value the new value
133 * @param element element name
134 */
135 void updateValue(double value, const QString &valueName);
136 void updateValue(int value, const QString &valueName);
137 void updateValue(QColor value, const QString &valueName);
138 void updateValue(QString value, const QString &valueName);
139
140 private:
141
142 CollimationOverlayOptions(QWidget *parent);
143 static CollimationOverlayOptions *m_Instance;
144
145 /**
146 * @brief generateOpticalTrains Automatically generate optical trains based on the current profile information.
147 * This happens when users use the tool for the first time.
148 */
149 void generateElement();
150
151 /**
152 * @brief Add a new collimation overlay element with the given name
153 * @param name element name
154 * @return unique element name
155 */
156 QString addElement(const QString &name);
157
158 /**
159 * @brief Create a unique element name
160 * @param name original element name
161 * @param type element type
162 * @return name, eventually added (i) to make the element name unique
163 */
164 QString uniqueElementName(QString name, QString type);
165
166 QList<QVariantMap> m_CollimationOverlayElements;
167 QVariantMap *m_CurrentElement = nullptr;
168
169 bool editing = false;
170
171 // Table model
172 QSqlTableModel *m_CollimationOverlayElementsModel = { nullptr };
173
174 QList <QString> m_ElementNames;
175};
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:49:22 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.