Kstars

customproperties.cpp
1/*
2 SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "customproperties.h"
8
9CustomProperties::CustomProperties()
10{
11 setupUi(this);
12
13 addB->setIcon(QIcon::fromTheme("go-next"));
14 addB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
15
16 removeB->setIcon(QIcon::fromTheme("go-previous"));
17 removeB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
18
19 clearB->setIcon(QIcon::fromTheme("edit-clear"));
20 clearB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
21
22 connect(addB, &QPushButton::clicked, this, &CustomProperties::slotAdd);
23 connect(removeB, &QPushButton::clicked, this, &CustomProperties::slotRemove);
24 connect(clearB, &QPushButton::clicked, this, &CustomProperties::slotClear);
25
26 connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotApply()));
27}
28
29void CustomProperties::setCCD(ISD::Camera *ccd)
30{
31 currentCCD = ccd;
32 syncProperties();
33}
34
35void CustomProperties::syncProperties()
36{
37 availablePropertiesList->clear();
38 QStringList props;
39
40 const QStringList skipProperties = QStringList()
41 << "CONNECTION"
42 << "DEBUG"
43 << "SIMULATION"
44 << "CONFIG_PROCESS"
45 << "CCD_TEMPERATURE"
46 << "CCD_FRAME"
47 << "CCD_EXPOSURE"
48 << "CCD_BINNING"
49 << "FRAME_TYPE"
50 << "CCD_EXPOSURE_ABORT"
51 << "GUIDER_FRAME"
52 << "GUIDER_BINNING"
53 << "GUIDER_EXPOSURE"
54 << "GUIDER_EXPOSURE_ABORT"
55 << "GUIDER_FRAME_TYPE"
56 << "FILTER_SLOT"
57 << "CCD_FRAME_RESET"
58 << "WCS_CONTROL"
59 << "UPLOAD_MODE"
60 << "UPLOAD_SETTINGS"
61 << "CCD_FILE_PATH"
62 << "CCD_FAST_COUNT"
63 << "ACTIVE_DEVICES"
64 << "DEBUG_LEVEL"
65 << "LOGGING_LEVEL"
66 << "LOG_OUTPUT"
67 << "FILE_DEBUG"
68 << "EQUATORIAL_EOD_COORD"
69 << "TARGET_EOD_COORD"
70 << "TELESCOPE_TIMED_GUIDE_NS"
71 << "TELESCOPE_TIMED_GUIDE_WE";
72
73
74 for (auto &property : *currentCCD->getProperties())
75 {
76 const QString name = property.getName();
77 // Skip empty properties
78 if (name.isEmpty())
79 continue;
80
81 if (skipProperties.contains(name) ||
82 property.getPermission() == IP_RO ||
83 property.getType() == INDI_BLOB || property.getType() == INDI_LIGHT)
84 continue;
85
86 props << property.getLabel();
87 }
88
89
90 props.removeDuplicates();
91 props.sort();
92 availablePropertiesList->addItems(props);
93}
94
95QMap<QString, QMap<QString, QVariant> > CustomProperties::getCustomProperties() const
96{
97 return customProperties;
98}
99
100void CustomProperties::setCustomProperties(const QMap<QString, QMap<QString, QVariant> > &value)
101{
102 customProperties = value;
103}
104
105void CustomProperties::slotAdd()
106{
107 if (availablePropertiesList->selectedItems().isEmpty() == false)
108 {
109 QString prop = availablePropertiesList->selectedItems().first()->text();
110 if (jobPropertiesList->findItems(prop, Qt::MatchExactly).isEmpty())
111 jobPropertiesList->addItem(prop);
112 }
113}
114
115void CustomProperties::slotRemove()
116{
117 if (jobPropertiesList->selectedItems().isEmpty() == false)
118 {
119 QModelIndex i = jobPropertiesList->selectionModel()->currentIndex();
120 jobPropertiesList->model()->removeRow(i.row());
121 }
122}
123
124void CustomProperties::slotClear()
125{
126 jobPropertiesList->clear();
127}
128
129void CustomProperties::slotApply()
130{
131 if (currentCCD == nullptr)
132 return;
133
134 // Remove any keys in the list from custom properties
135 for (int i = 0; i < jobPropertiesList->count(); i++)
136 customProperties.remove(jobPropertiesList->item(i)->text());
137
138 // Start from existing properties not in the list (external ones set by Ekos e.g. CCD_GAIN)
139 QMap<QString, QMap<QString, QVariant> > newMap = customProperties;
140
141 for (int i = 0; i < jobPropertiesList->count(); i++)
142 {
143 auto label = jobPropertiesList->item(i)->text();
144
145 // Match against existing properties
146 for(auto &oneProperty : *currentCCD->getProperties())
147 {
148 // Search by label
149 if (label != oneProperty.getLabel())
150 continue;
151
152 // Now get all the elements for this property
154
155 switch (oneProperty.getType())
156 {
157 case INDI_SWITCH:
158 for (const auto &oneSwitch : *oneProperty.getSwitch())
159 {
160 elements[oneSwitch.getName()] = oneSwitch.getState();
161 }
162 break;
163 case INDI_TEXT:
164 for (const auto &oneText : *oneProperty.getText())
165 {
166 elements[oneText.getName()] = oneText.getText();
167 }
168 break;
169 case INDI_NUMBER:
170 for (const auto &oneNumber : *oneProperty.getNumber())
171 {
172 elements[oneNumber.getName()] = oneNumber.getValue();
173 }
174 break;
175
176 default:
177 continue;
178 }
179
180 newMap[oneProperty.getName()] = elements;
181
182 break;
183 }
184 }
185
186 customProperties = newMap;
187 close();
188 emit valueChanged();
189}
Camera class controls an INDI Camera device.
Definition indicamera.h:45
QString name(StandardAction id)
QString label(StandardShortcut id)
void clicked(bool checked)
bool removeRow(int row, const QModelIndex &parent)
QIcon fromTheme(const QString &name)
size_type remove(const Key &key)
const QAbstractItemModel * model() const const
int row() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QVariant property(const char *name) const const
QString first(qsizetype n) const const
bool isEmpty() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
qsizetype removeDuplicates()
void sort(Qt::CaseSensitivity cs)
MatchExactly
WA_LayoutUsesWidgetRect
bool close()
void setupUi(QWidget *widget)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.