DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SchemaAttributeEditor.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: yes (from src/SchemaEditor/SchemaAttributeEditor.cpp to
5// apps/SchemaEditor/SchemaAttributeEditor.cpp).
6
11#include "ui_SchemaAttributeEditor.h"
12
13using namespace dunedaq::oks;
14
16 : QWidget(parent)
18 , SchemaClass(ClassInfo)
19 , SchemaAttribute(AttributeData)
20 , UsedNew(false)
21 , m_writable(KernelWrapper::GetInstance().IsFileWritable(SchemaClass->get_file()->get_full_file_name()))
22{
23 QWidget::setAttribute(Qt::WA_DeleteOnClose);
24 ui->setupUi(this);
27}
28
30 : QWidget(parent)
32 , SchemaClass(ClassInfo)
33 , SchemaAttribute(nullptr)
34 , UsedNew(true)
35 , m_writable(KernelWrapper::GetInstance().IsFileWritable(SchemaClass->get_file()->get_full_file_name()))
36{
37 QWidget::setAttribute(Qt::WA_DeleteOnClose);
38 ui->setupUi(this);
41}
42
44
45void
47{
48 auto name = QString::fromStdString(SchemaClass->get_name() + "::" + SchemaAttribute->get_name());
49 setWindowTitle(name);
50 setObjectName(name);
51 ui->AttributeNameLineEdit->setText(QString::fromStdString(SchemaAttribute->get_name()));
52 ui->AttributeTypeComboBox->setCurrentIndex(
53 ui->AttributeTypeComboBox->findData(QString::fromStdString(SchemaAttribute->get_type()), Qt::DisplayRole));
54
55 if (SchemaAttribute->get_is_multi_values())
56 ui->AttributeIsMultivariable->setCurrentIndex(0);
57 else {
58 ui->AttributeIsMultivariable->setCurrentIndex(1);
59 }
60
61 if (SchemaAttribute->get_is_no_null()) {
62 ui->AttributeIsNotNull->setCurrentIndex(0);
63 } else {
64 ui->AttributeIsNotNull->setCurrentIndex(1);
65 }
66
67 ui->AttributeDescriptionTextBox->setPlainText(QString::fromStdString(SchemaAttribute->get_description()));
68 ui->AttributeRangeLineEdit->setText(QString::fromStdString(SchemaAttribute->get_range()));
69 ui->AttributeInitialValue->setText(QString::fromStdString(SchemaAttribute->get_init_value()));
70
71 int Index = ui->AttributeTypeComboBox->currentIndex();
72
73 if (Index == 0 || Index >= 9) {
74 ui->FormatLayout->setEnabled(false);
75 ui->FormatLabel->hide();
76 ui->AttributeFormatComboBox->hide();
77 } else {
78 if (m_writable) {
79 ui->FormatLayout->setEnabled(true);
80 }
81 ui->FormatLabel->show();
82 ui->AttributeFormatComboBox->show();
83
84 if (SchemaAttribute->get_format() == OksAttribute::Dec)
85 ui->AttributeFormatComboBox->setCurrentIndex(0);
86 else if (SchemaAttribute->get_format() == OksAttribute::Oct)
87 ui->AttributeFormatComboBox->setCurrentIndex(1);
88 else {
89 ui->AttributeFormatComboBox->setCurrentIndex(2);
90 }
91 }
92}
93
94void
96{
97 if (event->key() == Qt::Key_Escape) {
98 close();
99 }
100 QWidget::keyPressEvent(event);
101}
102
103void
105{
106 QStringList Items{ "bool", "s8", "u8", "s16", "u16", "s32", "u32", "s64",
107 "u64", "float", "double", "date", "time", "string", "enum", "class" };
108 ui->AttributeTypeComboBox->addItems(Items);
109 auto name = SchemaClass->get_name() + "::";
110 setWindowTitle(QString::fromStdString(name + " New Attribute"));
111 setObjectName(QString::fromStdString(name));
112
113 if (!m_writable) {
114 ui->AttributeTypeComboBox->setEnabled(false);
115 ui->AttributeIsMultivariable->setEnabled(false);
116 ui->AttributeIsNotNull->setEnabled(false);
117 ui->AttributeRangeLineEdit->setEnabled(false);
118 ui->AttributeInitialValue->setEnabled(false);
119
120 ui->AttributeDescriptionTextBox->setReadOnly(true);
121 }
122
123 if (!UsedNew) {
124 FillInfo();
125 }
126}
127
128void
130{
131 connect(ui->AttributeTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(ToggleFormat(int)));
132 connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(ProxySlot()));
133 connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
134 connect(&KernelWrapper::GetInstance(), SIGNAL(ClassUpdated(QString)), this, SLOT(ClassUpdated(QString)));
135}
136
137void
139{
140 if (!UsedNew && ClassName.toStdString() == SchemaClass->get_name()) {
141 if (SchemaClass->find_direct_attribute(SchemaAttribute->get_name()) != nullptr) {
142 FillInfo();
143 } else {
144 QWidget::close();
145 }
146 }
147}
148
149void
151{
152 bool Changed = false;
153 std::string AttributeName = ui->AttributeNameLineEdit->text().toStdString();
154 std::string AttributeType = ui->AttributeTypeComboBox->currentText().toStdString();
155 char AttributeFormatChar = (ui->AttributeFormatComboBox->currentText().toStdString())[0];
156
157 OksAttribute::Format AttributeFormat;
158
159 switch (AttributeFormatChar) {
160 case 'D':
161 AttributeFormat = OksAttribute::Format::Dec;
162 break;
163
164 case 'O':
165 AttributeFormat = OksAttribute::Format::Oct;
166 break;
167
168 case 'H':
169 AttributeFormat = OksAttribute::Format::Hex;
170 break;
171
172 default:
173 AttributeFormat = OksAttribute::Format::Dec;
174 break;
175 }
176
178 int Index = ui->AttributeTypeComboBox->currentIndex();
179
180 if (Index == 0 || Index >= 9) {
181 AttributeFormat = OksAttribute::Format::Dec;
182 }
183
184 bool IsMultivariable = false;
185
186 switch (ui->AttributeIsMultivariable->currentIndex()) {
187 case 0:
188 IsMultivariable = true;
189 break;
190
191 case 1:
192 IsMultivariable = false;
193 break;
194
195 default:
196 IsMultivariable = false;
197 break;
198 }
199
200 bool IsNotNull = false;
201
202 switch (ui->AttributeIsNotNull->currentIndex()) {
203 case 0:
204 IsNotNull = true;
205 break;
206
207 case 1:
208 IsNotNull = false;
209 break;
210
211 default:
212 IsNotNull = false;
213 break;
214 }
215
216 std::string AttributeDescription = ui->AttributeDescriptionTextBox->toPlainText().toStdString();
217 std::string AttributeRange = ui->AttributeRangeLineEdit->text().toStdString();
218 std::string AttributeInitial = ui->AttributeInitialValue->text().toStdString();
219
220 if (AttributeName != SchemaAttribute->get_name()) {
222 Changed = true;
223 }
224
225 if (AttributeType != SchemaAttribute->get_type()) {
227 Changed = true;
228 }
229
230 if (AttributeFormat != SchemaAttribute->get_format()) {
232 Changed = true;
233 }
234
235 if (IsMultivariable != SchemaAttribute->get_is_multi_values()) {
237 Changed = true;
238 }
239
240 if (IsNotNull != SchemaAttribute->get_is_no_null()) {
242 Changed = true;
243 }
244
245 if (AttributeDescription != SchemaAttribute->get_description()) {
247 Changed = true;
248 }
249
250 if (AttributeRange != SchemaAttribute->get_range()) {
252 Changed = true;
253 }
254
255 if (AttributeInitial != SchemaAttribute->get_init_value()) {
257 Changed = true;
258 }
259
260 if (Changed) {
261 emit RebuildModel();
262 }
263
264 close();
265}
266
267void
269{
270 std::string AttributeName = ui->AttributeNameLineEdit->text().toStdString();
271 std::string AttributeType = ui->AttributeTypeComboBox->currentText().toStdString();
272 char AttributeFormatChar = (ui->AttributeFormatComboBox->currentText().toStdString())[0];
273
274 OksAttribute::Format AttributeFormat;
275
276 switch (AttributeFormatChar) {
277 case 'D':
278 AttributeFormat = OksAttribute::Format::Dec;
279 break;
280
281 case 'O':
282 AttributeFormat = OksAttribute::Format::Oct;
283 break;
284
285 case 'H':
286 AttributeFormat = OksAttribute::Format::Hex;
287 break;
288
289 default:
290 AttributeFormat = OksAttribute::Format::Dec;
291 break;
292 }
293
295 int Index = ui->AttributeTypeComboBox->currentIndex();
296
297 if (Index == 0 || Index >= 9) {
298 AttributeFormat = OksAttribute::Format::Dec;
299 }
300
301 bool IsMultivariable = false;
302
303 switch (ui->AttributeIsMultivariable->currentIndex()) {
304 case 0:
305 IsMultivariable = true;
306 break;
307
308 case 1:
309 IsMultivariable = false;
310 break;
311
312 default:
313 IsMultivariable = false;
314 break;
315 }
316
317 bool IsNotNull = false;
318
319 switch (ui->AttributeIsNotNull->currentIndex()) {
320 case 0:
321 IsNotNull = true;
322 break;
323
324 case 1:
325 IsNotNull = false;
326 break;
327
328 default:
329 IsNotNull = false;
330 break;
331 }
332
333 std::string AttributeDescription = ui->AttributeDescriptionTextBox->toPlainText().toStdString();
334 std::string AttributeRange = ui->AttributeRangeLineEdit->text().toStdString();
335 std::string AttributeInitial = ui->AttributeInitialValue->text().toStdString();
336
339 AttributeName,
340 AttributeType,
341 IsMultivariable,
342 AttributeRange,
343 AttributeInitial,
344 AttributeDescription,
345 IsNotNull,
346 AttributeFormat);
347 emit RebuildModel();
348 close();
349}
350
351void
353{
354 if (UsedNew) {
356 } else {
357 ParseToSave();
358 }
359}
360
361void
363{
364 int Index = ui->AttributeTypeComboBox->currentIndex();
365
366 if (Index == 0 || Index >= 9) {
367 ui->FormatLayout->setEnabled(false);
368 ui->FormatLabel->hide();
369 ui->AttributeFormatComboBox->hide();
370 } else {
371 ui->FormatLayout->setEnabled(true);
372 ui->FormatLabel->show();
373 ui->AttributeFormatComboBox->show();
374 }
375}
void PushSetAttributeDescriptionCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewDescription)
void PushSetAttributeIsNullCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, bool NewIsNull)
static KernelWrapper & GetInstance()
void PushSetAttributeRangeCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewRange)
void PushSetAttributeFormatCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, dunedaq::oks::OksAttribute::Format NewFormat)
void PushSetAttributeMultiCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, bool NewIsMulti)
void PushSetAttributeInitialValuesCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewValues)
void PushSetAttributeTypeCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewType)
void PushAddAttributeCommand(dunedaq::oks::OksClass *Class, std::string name, std::string type, bool is_mv, std::string range, std::string init_values, std::string description, bool is_null, dunedaq::oks::OksAttribute::Format format=dunedaq::oks::OksAttribute::Format::Dec)
void PushSetAttributeNameCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewName)
Attribute commands.
std::unique_ptr< dbse::Ui::SchemaAttributeEditor > ui
dunedaq::oks::OksAttribute * SchemaAttribute
SchemaAttributeEditor(dunedaq::oks::OksClass *ClassInfo, dunedaq::oks::OksAttribute *AttributeData, QWidget *parent=nullptr)
void ClassUpdated(QString ClassName)
void keyPressEvent(QKeyEvent *event) override
dunedaq::oks::OksClass * SchemaClass
OKS attribute class.
Definition attribute.hpp:94
The OKS class.
Definition class.hpp:223