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