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 apps/SchemaEditor/SchemaAttributeEditor.cpp).
5
7
#include "
dbe/SchemaAttributeEditor.hpp
"
8
#include "
dbe/SchemaKernelWrapper.hpp
"
10
#include "ui_SchemaAttributeEditor.h"
11
12
using namespace
dunedaq::oks
;
13
14
dbse::SchemaAttributeEditor::SchemaAttributeEditor
(
OksClass
* ClassInfo,
15
OksAttribute
* AttributeData,
16
QWidget * parent )
17
: QWidget ( parent ),
18
ui
( new
Ui
::
SchemaAttributeEditor
),
19
SchemaClass
( ClassInfo ),
20
SchemaAttribute
( AttributeData ),
21
UsedNew
( false ),
22
m_writable
(
KernelWrapper
::GetInstance().IsFileWritable(
23
SchemaClass
->get_file()->get_full_file_name()))
24
{
25
QWidget::setAttribute(Qt::WA_DeleteOnClose);
26
ui
->setupUi (
this
);
27
InitialSettings
();
28
SetController
();
29
}
30
31
dbse::SchemaAttributeEditor::SchemaAttributeEditor
(
OksClass
* ClassInfo,
32
QWidget * parent )
33
: QWidget ( parent ),
34
ui
( new
Ui
::
SchemaAttributeEditor
),
35
SchemaClass
( ClassInfo ),
36
SchemaAttribute
( nullptr ),
37
UsedNew
( true ),
38
m_writable
(
KernelWrapper
::GetInstance().IsFileWritable(
39
SchemaClass
->get_file()->get_full_file_name()))
40
{
41
QWidget::setAttribute(Qt::WA_DeleteOnClose);
42
ui
->setupUi (
this
);
43
InitialSettings
();
44
SetController
();
45
}
46
47
dbse::SchemaAttributeEditor::~SchemaAttributeEditor
() =
default
;
48
49
void
dbse::SchemaAttributeEditor::FillInfo
()
50
{
51
auto
name = QString::fromStdString(
SchemaClass
->get_name() +
"::"
+
52
SchemaAttribute
->get_name());
53
setWindowTitle (name);
54
setObjectName (name);
55
ui
->AttributeNameLineEdit->setText ( QString::fromStdString (
56
SchemaAttribute
->get_name() ) );
57
ui
->AttributeTypeComboBox->setCurrentIndex (
58
ui
->AttributeTypeComboBox->findData ( QString::fromStdString (
59
SchemaAttribute
->get_type() ),
60
Qt::DisplayRole ) );
61
62
if
(
SchemaAttribute
->get_is_multi_values() )
63
ui
->AttributeIsMultivariable->setCurrentIndex (
64
0 );
65
else
66
{
67
ui
->AttributeIsMultivariable->setCurrentIndex ( 1 );
68
}
69
70
if
(
SchemaAttribute
->get_is_no_null() )
71
{
72
ui
->AttributeIsNotNull->setCurrentIndex ( 0 );
73
}
74
else
75
{
76
ui
->AttributeIsNotNull->setCurrentIndex ( 1 );
77
}
78
79
ui
->AttributeDescriptionTextBox->setPlainText (
80
QString::fromStdString (
SchemaAttribute
->get_description() ) );
81
ui
->AttributeRangeLineEdit->setText ( QString::fromStdString (
82
SchemaAttribute
->get_range() ) );
83
ui
->AttributeInitialValue->setText (
84
QString::fromStdString (
SchemaAttribute
->get_init_value() ) );
85
86
int
Index =
ui
->AttributeTypeComboBox->currentIndex();
87
88
if
( Index == 0 || Index >= 9 )
89
{
90
ui
->FormatLayout->setEnabled (
false
);
91
ui
->FormatLabel->hide();
92
ui
->AttributeFormatComboBox->hide();
93
}
94
else
95
{
96
if
(
m_writable
) {
97
ui
->FormatLayout->setEnabled (
true
);
98
}
99
ui
->FormatLabel->show();
100
ui
->AttributeFormatComboBox->show();
101
102
if
(
SchemaAttribute
->get_format() ==
OksAttribute::Dec
)
103
ui
->AttributeFormatComboBox->setCurrentIndex (
104
0 );
105
else
if
(
SchemaAttribute
->get_format() ==
OksAttribute::Oct
)
106
ui
->AttributeFormatComboBox->setCurrentIndex (
107
1 );
108
else
109
{
110
ui
->AttributeFormatComboBox->setCurrentIndex ( 2 );
111
}
112
}
113
}
114
115
void
dbse::SchemaAttributeEditor::keyPressEvent
(QKeyEvent* event) {
116
if
(event->key() == Qt::Key_Escape) {
117
close();
118
}
119
QWidget::keyPressEvent(event);
120
}
121
122
void
dbse::SchemaAttributeEditor::InitialSettings
()
123
{
124
QStringList Items
125
{
126
"bool"
,
"s8"
,
"u8"
,
"s16"
,
"u16"
,
"s32"
,
"u32"
,
"s64"
,
"u64"
,
"float"
,
"double"
,
"date"
,
127
"time"
,
"string"
,
"enum"
,
"class"
};
128
ui
->AttributeTypeComboBox->addItems ( Items );
129
auto
name =
SchemaClass
->get_name() +
"::"
;
130
setWindowTitle ( QString::fromStdString ( name +
" New Attribute"
) );
131
setObjectName ( QString::fromStdString(name) );
132
133
if
(!
m_writable
) {
134
ui
->AttributeTypeComboBox->setEnabled(
false
);
135
ui
->AttributeIsMultivariable->setEnabled(
false
);
136
ui
->AttributeIsNotNull->setEnabled(
false
);
137
ui
->AttributeRangeLineEdit->setEnabled(
false
);
138
ui
->AttributeInitialValue->setEnabled(
false
);
139
140
ui
->AttributeDescriptionTextBox->setReadOnly(
true
);
141
}
142
143
if
( !
UsedNew
)
144
{
145
FillInfo
();
146
}
147
}
148
149
void
dbse::SchemaAttributeEditor::SetController
()
150
{
151
connect (
ui
->AttributeTypeComboBox, SIGNAL ( currentIndexChanged (
int
) ),
this
,
152
SLOT (
ToggleFormat
(
int
) ) );
153
connect (
ui
->buttonBox, SIGNAL ( accepted() ),
this
, SLOT (
ProxySlot
() ) );
154
connect (
ui
->buttonBox, SIGNAL ( rejected() ),
this
, SLOT ( close() ) );
155
connect ( &
KernelWrapper::GetInstance
(), SIGNAL (
ClassUpdated
( QString ) ),
this
,
156
SLOT (
ClassUpdated
( QString ) ) );
157
}
158
159
void
dbse::SchemaAttributeEditor::ClassUpdated
( QString ClassName)
160
{
161
if
(!
UsedNew
&& ClassName.toStdString() ==
SchemaClass
->get_name()) {
162
if
(
SchemaClass
->find_direct_attribute(
SchemaAttribute
->get_name()) !=
nullptr
) {
163
FillInfo
();
164
}
else
{
165
QWidget::close();
166
}
167
}
168
}
169
170
void
dbse::SchemaAttributeEditor::ParseToSave
()
171
{
172
bool
Changed =
false
;
173
std::string AttributeName =
ui
->AttributeNameLineEdit->text().toStdString();
174
std::string AttributeType =
ui
->AttributeTypeComboBox->currentText().toStdString();
175
char
AttributeFormatChar = (
ui
->AttributeFormatComboBox->currentText().toStdString() ) [0];
176
177
OksAttribute::Format
AttributeFormat;
178
179
switch
( AttributeFormatChar )
180
{
181
case
'D'
:
182
AttributeFormat =
OksAttribute::Format::Dec
;
183
break
;
184
185
case
'O'
:
186
AttributeFormat =
OksAttribute::Format::Oct
;
187
break
;
188
189
case
'H'
:
190
AttributeFormat =
OksAttribute::Format::Hex
;
191
break
;
192
193
default
:
194
AttributeFormat =
OksAttribute::Format::Dec
;
195
break
;
196
}
197
199
int
Index =
ui
->AttributeTypeComboBox->currentIndex();
200
201
if
( Index == 0 || Index >= 9 )
202
{
203
AttributeFormat =
OksAttribute::Format::Dec
;
204
}
205
206
bool
IsMultivariable =
false
;
207
208
switch
(
ui
->AttributeIsMultivariable->currentIndex() )
209
{
210
case
0:
211
IsMultivariable =
true
;
212
break
;
213
214
case
1:
215
IsMultivariable =
false
;
216
break
;
217
218
default
:
219
IsMultivariable =
false
;
220
break
;
221
}
222
223
bool
IsNotNull =
false
;
224
225
switch
(
ui
->AttributeIsNotNull->currentIndex() )
226
{
227
case
0:
228
IsNotNull =
true
;
229
break
;
230
231
case
1:
232
IsNotNull =
false
;
233
break
;
234
235
default
:
236
IsNotNull =
false
;
237
break
;
238
}
239
240
std::string AttributeDescription =
241
ui
->AttributeDescriptionTextBox->toPlainText().toStdString();
242
std::string AttributeRange =
ui
->AttributeRangeLineEdit->text().toStdString();
243
std::string AttributeInitial =
ui
->AttributeInitialValue->text().toStdString();
244
245
if
( AttributeName !=
SchemaAttribute
->get_name() )
246
{
247
KernelWrapper::GetInstance
().
PushSetAttributeNameCommand
(
SchemaClass
,
SchemaAttribute
, AttributeName );
248
Changed =
true
;
249
}
250
251
if
( AttributeType !=
SchemaAttribute
->get_type() )
252
{
253
KernelWrapper::GetInstance
().
PushSetAttributeTypeCommand
(
SchemaClass
,
SchemaAttribute
, AttributeType );
254
Changed =
true
;
255
}
256
257
if
( AttributeFormat !=
SchemaAttribute
->get_format() )
258
{
259
KernelWrapper::GetInstance
().
PushSetAttributeFormatCommand
(
SchemaClass
,
260
SchemaAttribute
,
261
AttributeFormat );
262
Changed =
true
;
263
}
264
265
if
( IsMultivariable !=
SchemaAttribute
->get_is_multi_values() )
266
{
267
KernelWrapper::GetInstance
().
PushSetAttributeMultiCommand
(
SchemaClass
,
268
SchemaAttribute
,
269
IsMultivariable );
270
Changed =
true
;
271
}
272
273
if
( IsNotNull !=
SchemaAttribute
->get_is_no_null() )
274
{
275
KernelWrapper::GetInstance
().
PushSetAttributeIsNullCommand
(
SchemaClass
,
SchemaAttribute
, IsNotNull );
276
Changed =
true
;
277
}
278
279
if
( AttributeDescription !=
SchemaAttribute
->get_description() )
280
{
281
KernelWrapper::GetInstance
().
PushSetAttributeDescriptionCommand
(
SchemaClass
,
282
SchemaAttribute
,
283
AttributeDescription );
284
Changed =
true
;
285
}
286
287
if
( AttributeRange !=
SchemaAttribute
->get_range() )
288
{
289
KernelWrapper::GetInstance
().
PushSetAttributeRangeCommand
(
SchemaClass
,
290
SchemaAttribute
,
291
AttributeRange );
292
Changed =
true
;
293
}
294
295
if
( AttributeInitial !=
SchemaAttribute
->get_init_value() )
296
{
297
KernelWrapper::GetInstance
().
PushSetAttributeInitialValuesCommand
(
SchemaClass
,
298
SchemaAttribute
,
299
AttributeInitial );
300
Changed =
true
;
301
}
302
303
if
( Changed )
304
{
305
emit
RebuildModel
();
306
}
307
308
close();
309
}
310
311
void
dbse::SchemaAttributeEditor::ParseToCreate
()
312
{
313
std::string AttributeName =
ui
->AttributeNameLineEdit->text().toStdString();
314
std::string AttributeType =
ui
->AttributeTypeComboBox->currentText().toStdString();
315
char
AttributeFormatChar = (
ui
->AttributeFormatComboBox->currentText().toStdString() ) [0];
316
317
OksAttribute::Format
AttributeFormat;
318
319
switch
( AttributeFormatChar )
320
{
321
case
'D'
:
322
AttributeFormat =
OksAttribute::Format::Dec
;
323
break
;
324
325
case
'O'
:
326
AttributeFormat =
OksAttribute::Format::Oct
;
327
break
;
328
329
case
'H'
:
330
AttributeFormat =
OksAttribute::Format::Hex
;
331
break
;
332
333
default
:
334
AttributeFormat =
OksAttribute::Format::Dec
;
335
break
;
336
}
337
339
int
Index =
ui
->AttributeTypeComboBox->currentIndex();
340
341
if
( Index == 0 || Index >= 9 )
342
{
343
AttributeFormat =
OksAttribute::Format::Dec
;
344
}
345
346
bool
IsMultivariable =
false
;
347
348
switch
(
ui
->AttributeIsMultivariable->currentIndex() )
349
{
350
case
0:
351
IsMultivariable =
true
;
352
break
;
353
354
case
1:
355
IsMultivariable =
false
;
356
break
;
357
358
default
:
359
IsMultivariable =
false
;
360
break
;
361
}
362
363
bool
IsNotNull =
false
;
364
365
switch
(
ui
->AttributeIsNotNull->currentIndex() )
366
{
367
case
0:
368
IsNotNull =
true
;
369
break
;
370
371
case
1:
372
IsNotNull =
false
;
373
break
;
374
375
default
:
376
IsNotNull =
false
;
377
break
;
378
}
379
380
std::string AttributeDescription =
381
ui
->AttributeDescriptionTextBox->toPlainText().toStdString();
382
std::string AttributeRange =
ui
->AttributeRangeLineEdit->text().toStdString();
383
std::string AttributeInitial =
ui
->AttributeInitialValue->text().toStdString();
384
386
KernelWrapper::GetInstance
().
PushAddAttributeCommand
(
SchemaClass
, AttributeName,
387
AttributeType, IsMultivariable,
388
AttributeRange, AttributeInitial,
389
AttributeDescription, IsNotNull,
390
AttributeFormat );
391
emit
RebuildModel
();
392
close();
393
}
394
395
void
dbse::SchemaAttributeEditor::ProxySlot
()
396
{
397
if
(
UsedNew
)
398
{
399
ParseToCreate
();
400
}
401
else
402
{
403
ParseToSave
();
404
}
405
}
406
407
void
dbse::SchemaAttributeEditor::ToggleFormat
(
int
)
408
{
409
int
Index =
ui
->AttributeTypeComboBox->currentIndex();
410
411
if
( Index == 0 || Index >= 9 )
412
{
413
ui
->FormatLayout->setEnabled (
false
);
414
ui
->FormatLabel->hide();
415
ui
->AttributeFormatComboBox->hide();
416
}
417
else
418
{
419
ui
->FormatLayout->setEnabled (
true
);
420
ui
->FormatLabel->show();
421
ui
->AttributeFormatComboBox->show();
422
}
423
}
SchemaAttributeEditor.hpp
SchemaKernelWrapper.hpp
dbse::KernelWrapper
Definition
SchemaKernelWrapper.hpp:27
dbse::KernelWrapper::PushSetAttributeDescriptionCommand
void PushSetAttributeDescriptionCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewDescription)
Definition
SchemaKernelWrapper.cpp:725
dbse::KernelWrapper::PushSetAttributeIsNullCommand
void PushSetAttributeIsNullCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, bool NewIsNull)
Definition
SchemaKernelWrapper.cpp:800
dbse::KernelWrapper::GetInstance
static KernelWrapper & GetInstance()
Definition
SchemaKernelWrapper.cpp:18
dbse::KernelWrapper::PushSetAttributeRangeCommand
void PushSetAttributeRangeCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewRange)
Definition
SchemaKernelWrapper.cpp:755
dbse::KernelWrapper::PushSetAttributeFormatCommand
void PushSetAttributeFormatCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, dunedaq::oks::OksAttribute::Format NewFormat)
Definition
SchemaKernelWrapper.cpp:770
dbse::KernelWrapper::PushSetAttributeMultiCommand
void PushSetAttributeMultiCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, bool NewIsMulti)
Definition
SchemaKernelWrapper.cpp:785
dbse::KernelWrapper::PushSetAttributeInitialValuesCommand
void PushSetAttributeInitialValuesCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewValues)
Definition
SchemaKernelWrapper.cpp:815
dbse::KernelWrapper::PushSetAttributeTypeCommand
void PushSetAttributeTypeCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewType)
Definition
SchemaKernelWrapper.cpp:740
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:830
dbse::KernelWrapper::PushSetAttributeNameCommand
void PushSetAttributeNameCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, std::string NewName)
Attribute commands.
Definition
SchemaKernelWrapper.cpp:710
dbse::SchemaAttributeEditor::ui
std::unique_ptr< dbse::Ui::SchemaAttributeEditor > ui
Definition
SchemaAttributeEditor.hpp:40
dbse::SchemaAttributeEditor::SetController
void SetController()
Definition
SchemaAttributeEditor.cpp:149
dbse::SchemaAttributeEditor::InitialSettings
void InitialSettings()
Definition
SchemaAttributeEditor.cpp:122
dbse::SchemaAttributeEditor::SchemaAttribute
dunedaq::oks::OksAttribute * SchemaAttribute
Definition
SchemaAttributeEditor.hpp:42
dbse::SchemaAttributeEditor::~SchemaAttributeEditor
~SchemaAttributeEditor()
dbse::SchemaAttributeEditor::FillInfo
void FillInfo()
Definition
SchemaAttributeEditor.cpp:49
dbse::SchemaAttributeEditor::SchemaAttributeEditor
SchemaAttributeEditor(dunedaq::oks::OksClass *ClassInfo, dunedaq::oks::OksAttribute *AttributeData, QWidget *parent=nullptr)
Definition
SchemaAttributeEditor.cpp:14
dbse::SchemaAttributeEditor::ClassUpdated
void ClassUpdated(QString ClassName)
Definition
SchemaAttributeEditor.cpp:159
dbse::SchemaAttributeEditor::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Definition
SchemaAttributeEditor.cpp:115
dbse::SchemaAttributeEditor::RebuildModel
void RebuildModel()
dbse::SchemaAttributeEditor::ProxySlot
void ProxySlot()
Definition
SchemaAttributeEditor.cpp:395
dbse::SchemaAttributeEditor::ParseToCreate
void ParseToCreate()
Definition
SchemaAttributeEditor.cpp:311
dbse::SchemaAttributeEditor::ToggleFormat
void ToggleFormat(int)
Definition
SchemaAttributeEditor.cpp:407
dbse::SchemaAttributeEditor::m_writable
bool m_writable
Definition
SchemaAttributeEditor.hpp:44
dbse::SchemaAttributeEditor::UsedNew
bool UsedNew
Definition
SchemaAttributeEditor.hpp:43
dbse::SchemaAttributeEditor::SchemaClass
dunedaq::oks::OksClass * SchemaClass
Definition
SchemaAttributeEditor.hpp:41
dbse::SchemaAttributeEditor::ParseToSave
void ParseToSave()
Definition
SchemaAttributeEditor.cpp:170
dunedaq::oks::OksAttribute
OKS attribute class.
Definition
attribute.hpp:107
dunedaq::oks::OksAttribute::Format
Format
Definition
attribute.hpp:118
dunedaq::oks::OksAttribute::Oct
@ Oct
Definition
attribute.hpp:119
dunedaq::oks::OksAttribute::Hex
@ Hex
Definition
attribute.hpp:121
dunedaq::oks::OksAttribute::Dec
@ Dec
Definition
attribute.hpp:120
dunedaq::oks::OksClass
The OKS class.
Definition
class.hpp:205
Ui
Definition
SchemaSettings.hpp:10
dunedaq::oks
Definition
OksConfiguration.hpp:24
Generated on
for DUNE-DAQ by
1.17.0