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 apps/SchemaEditor/SchemaAttributeEditor.cpp).
5
10#include "ui_SchemaAttributeEditor.h"
11
12using namespace dunedaq::oks;
13
15 OksAttribute * AttributeData,
16 QWidget * parent )
17 : QWidget ( parent ),
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 );
29}
30
32 QWidget * parent )
33 : QWidget ( parent ),
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 );
45}
46
48
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
116 if (event->key() == Qt::Key_Escape) {
117 close();
118 }
119 QWidget::keyPressEvent(event);
120}
121
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
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
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
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 {
248 Changed = true;
249 }
250
251 if ( AttributeType != SchemaAttribute->get_type() )
252 {
254 Changed = true;
255 }
256
257 if ( AttributeFormat != SchemaAttribute->get_format() )
258 {
261 AttributeFormat );
262 Changed = true;
263 }
264
265 if ( IsMultivariable != SchemaAttribute->get_is_multi_values() )
266 {
269 IsMultivariable );
270 Changed = true;
271 }
272
273 if ( IsNotNull != SchemaAttribute->get_is_no_null() )
274 {
276 Changed = true;
277 }
278
279 if ( AttributeDescription != SchemaAttribute->get_description() )
280 {
283 AttributeDescription );
284 Changed = true;
285 }
286
287 if ( AttributeRange != SchemaAttribute->get_range() )
288 {
291 AttributeRange );
292 Changed = true;
293 }
294
295 if ( AttributeInitial != SchemaAttribute->get_init_value() )
296 {
299 AttributeInitial );
300 Changed = true;
301 }
302
303 if ( Changed )
304 {
305 emit RebuildModel();
306 }
307
308 close();
309}
310
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
387 AttributeType, IsMultivariable,
388 AttributeRange, AttributeInitial,
389 AttributeDescription, IsNotNull,
390 AttributeFormat );
391 emit RebuildModel();
392 close();
393}
394
396{
397 if ( UsedNew )
398 {
400 }
401 else
402 {
403 ParseToSave();
404 }
405}
406
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}
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.
The OKS class.
Definition class.hpp:205