DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
apps
SchemaEditor
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
8
#include "
dbe/SchemaAttributeEditor.hpp
"
9
#include "
dbe/SchemaKernelWrapper.hpp
"
11
#include "ui_SchemaAttributeEditor.h"
12
13
using namespace
dunedaq::oks
;
14
15
dbse::SchemaAttributeEditor::SchemaAttributeEditor
(
OksClass
* ClassInfo,
OksAttribute
* AttributeData, QWidget* parent)
16
: QWidget(parent)
17
,
ui
(new
Ui
::
SchemaAttributeEditor
)
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
);
25
InitialSettings
();
26
SetController
();
27
}
28
29
dbse::SchemaAttributeEditor::SchemaAttributeEditor
(
OksClass
* ClassInfo, QWidget* parent)
30
: QWidget(parent)
31
,
ui
(new
Ui
::
SchemaAttributeEditor
)
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
);
39
InitialSettings
();
40
SetController
();
41
}
42
43
dbse::SchemaAttributeEditor::~SchemaAttributeEditor
() =
default
;
44
45
void
46
dbse::SchemaAttributeEditor::FillInfo
()
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
94
void
95
dbse::SchemaAttributeEditor::keyPressEvent
(QKeyEvent* event)
96
{
97
if
(event->key() == Qt::Key_Escape) {
98
close();
99
}
100
QWidget::keyPressEvent(event);
101
}
102
103
void
104
dbse::SchemaAttributeEditor::InitialSettings
()
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
128
void
129
dbse::SchemaAttributeEditor::SetController
()
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
137
void
138
dbse::SchemaAttributeEditor::ClassUpdated
(QString ClassName)
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
149
void
150
dbse::SchemaAttributeEditor::ParseToSave
()
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()) {
221
KernelWrapper::GetInstance
().
PushSetAttributeNameCommand
(
SchemaClass
,
SchemaAttribute
, AttributeName);
222
Changed =
true
;
223
}
224
225
if
(AttributeType !=
SchemaAttribute
->get_type()) {
226
KernelWrapper::GetInstance
().
PushSetAttributeTypeCommand
(
SchemaClass
,
SchemaAttribute
, AttributeType);
227
Changed =
true
;
228
}
229
230
if
(AttributeFormat !=
SchemaAttribute
->get_format()) {
231
KernelWrapper::GetInstance
().
PushSetAttributeFormatCommand
(
SchemaClass
,
SchemaAttribute
, AttributeFormat);
232
Changed =
true
;
233
}
234
235
if
(IsMultivariable !=
SchemaAttribute
->get_is_multi_values()) {
236
KernelWrapper::GetInstance
().
PushSetAttributeMultiCommand
(
SchemaClass
,
SchemaAttribute
, IsMultivariable);
237
Changed =
true
;
238
}
239
240
if
(IsNotNull !=
SchemaAttribute
->get_is_no_null()) {
241
KernelWrapper::GetInstance
().
PushSetAttributeIsNullCommand
(
SchemaClass
,
SchemaAttribute
, IsNotNull);
242
Changed =
true
;
243
}
244
245
if
(AttributeDescription !=
SchemaAttribute
->get_description()) {
246
KernelWrapper::GetInstance
().
PushSetAttributeDescriptionCommand
(
SchemaClass
,
SchemaAttribute
, AttributeDescription);
247
Changed =
true
;
248
}
249
250
if
(AttributeRange !=
SchemaAttribute
->get_range()) {
251
KernelWrapper::GetInstance
().
PushSetAttributeRangeCommand
(
SchemaClass
,
SchemaAttribute
, AttributeRange);
252
Changed =
true
;
253
}
254
255
if
(AttributeInitial !=
SchemaAttribute
->get_init_value()) {
256
KernelWrapper::GetInstance
().
PushSetAttributeInitialValuesCommand
(
SchemaClass
,
SchemaAttribute
, AttributeInitial);
257
Changed =
true
;
258
}
259
260
if
(Changed) {
261
emit
RebuildModel
();
262
}
263
264
close();
265
}
266
267
void
268
dbse::SchemaAttributeEditor::ParseToCreate
()
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
338
KernelWrapper::GetInstance
().
PushAddAttributeCommand
(
SchemaClass
,
339
AttributeName,
340
AttributeType,
341
IsMultivariable,
342
AttributeRange,
343
AttributeInitial,
344
AttributeDescription,
345
IsNotNull,
346
AttributeFormat);
347
emit
RebuildModel
();
348
close();
349
}
350
351
void
352
dbse::SchemaAttributeEditor::ProxySlot
()
353
{
354
if
(
UsedNew
) {
355
ParseToCreate
();
356
}
else
{
357
ParseToSave
();
358
}
359
}
360
361
void
362
dbse::SchemaAttributeEditor::ToggleFormat
(
int
)
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
}
SchemaAttributeEditor.hpp
SchemaKernelWrapper.hpp
dbse::KernelWrapper
Definition
SchemaKernelWrapper.hpp:26
dbse::KernelWrapper::PushSetAttributeDescriptionCommand
void PushSetAttributeDescriptionCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewDescription)
Definition
SchemaKernelWrapper.cpp:638
dbse::KernelWrapper::PushSetAttributeIsNullCommand
void PushSetAttributeIsNullCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, bool NewIsNull)
Definition
SchemaKernelWrapper.cpp:692
dbse::KernelWrapper::GetInstance
static KernelWrapper & GetInstance()
Definition
SchemaKernelWrapper.cpp:19
dbse::KernelWrapper::PushSetAttributeRangeCommand
void PushSetAttributeRangeCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewRange)
Definition
SchemaKernelWrapper.cpp:660
dbse::KernelWrapper::PushSetAttributeFormatCommand
void PushSetAttributeFormatCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, dunedaq::oks::OksAttribute::Format NewFormat)
Definition
SchemaKernelWrapper.cpp:670
dbse::KernelWrapper::PushSetAttributeMultiCommand
void PushSetAttributeMultiCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, bool NewIsMulti)
Definition
SchemaKernelWrapper.cpp:682
dbse::KernelWrapper::PushSetAttributeInitialValuesCommand
void PushSetAttributeInitialValuesCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewValues)
Definition
SchemaKernelWrapper.cpp:702
dbse::KernelWrapper::PushSetAttributeTypeCommand
void PushSetAttributeTypeCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewType)
Definition
SchemaKernelWrapper.cpp:650
dbse::KernelWrapper::PushAddAttributeCommand
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)
Definition
SchemaKernelWrapper.cpp:714
dbse::KernelWrapper::PushSetAttributeNameCommand
void PushSetAttributeNameCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewName)
Attribute commands.
Definition
SchemaKernelWrapper.cpp:628
dbse::SchemaAttributeEditor::ui
std::unique_ptr< dbse::Ui::SchemaAttributeEditor > ui
Definition
SchemaAttributeEditor.hpp:41
dbse::SchemaAttributeEditor::SetController
void SetController()
Definition
SchemaAttributeEditor.cpp:129
dbse::SchemaAttributeEditor::InitialSettings
void InitialSettings()
Definition
SchemaAttributeEditor.cpp:104
dbse::SchemaAttributeEditor::SchemaAttribute
dunedaq::oks::OksAttribute * SchemaAttribute
Definition
SchemaAttributeEditor.hpp:43
dbse::SchemaAttributeEditor::~SchemaAttributeEditor
~SchemaAttributeEditor()
dbse::SchemaAttributeEditor::FillInfo
void FillInfo()
Definition
SchemaAttributeEditor.cpp:46
dbse::SchemaAttributeEditor::SchemaAttributeEditor
SchemaAttributeEditor(dunedaq::oks::OksClass *ClassInfo, dunedaq::oks::OksAttribute *AttributeData, QWidget *parent=nullptr)
Definition
SchemaAttributeEditor.cpp:15
dbse::SchemaAttributeEditor::ClassUpdated
void ClassUpdated(QString ClassName)
Definition
SchemaAttributeEditor.cpp:138
dbse::SchemaAttributeEditor::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Definition
SchemaAttributeEditor.cpp:95
dbse::SchemaAttributeEditor::RebuildModel
void RebuildModel()
dbse::SchemaAttributeEditor::ProxySlot
void ProxySlot()
Definition
SchemaAttributeEditor.cpp:352
dbse::SchemaAttributeEditor::ParseToCreate
void ParseToCreate()
Definition
SchemaAttributeEditor.cpp:268
dbse::SchemaAttributeEditor::ToggleFormat
void ToggleFormat(int)
Definition
SchemaAttributeEditor.cpp:362
dbse::SchemaAttributeEditor::m_writable
bool m_writable
Definition
SchemaAttributeEditor.hpp:45
dbse::SchemaAttributeEditor::UsedNew
bool UsedNew
Definition
SchemaAttributeEditor.hpp:44
dbse::SchemaAttributeEditor::SchemaClass
dunedaq::oks::OksClass * SchemaClass
Definition
SchemaAttributeEditor.hpp:42
dbse::SchemaAttributeEditor::ParseToSave
void ParseToSave()
Definition
SchemaAttributeEditor.cpp:150
dunedaq::oks::OksAttribute
OKS attribute class.
Definition
attribute.hpp:94
dunedaq::oks::OksAttribute::Format
Format
Definition
attribute.hpp:105
dunedaq::oks::OksAttribute::Oct
@ Oct
Definition
attribute.hpp:106
dunedaq::oks::OksAttribute::Hex
@ Hex
Definition
attribute.hpp:108
dunedaq::oks::OksAttribute::Dec
@ Dec
Definition
attribute.hpp:107
dunedaq::oks::OksClass
The OKS class.
Definition
class.hpp:223
Ui
Definition
SchemaSettings.hpp:9
dunedaq::oks
Definition
SchemaCommand.hpp:17
Generated on
for DUNE-DAQ by
1.18.0