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{
18 QWidget::setAttribute(Qt::WA_DeleteOnClose);
19 ui->setupUi ( this );
22}
23
25 QWidget * parent )
26 : QWidget ( parent ),
27 ui ( new Ui::SchemaAttributeEditor ),
28 SchemaClass ( ClassInfo ),
29 SchemaAttribute ( nullptr ),
30 UsedNew ( true )
31{
32 QWidget::setAttribute(Qt::WA_DeleteOnClose);
33 ui->setupUi ( this );
36}
37
39
41{
42 setWindowTitle ( QString ( "Attribute Editor : %1" ).arg (
43 SchemaAttribute->get_name().c_str() ) );
44 setObjectName ( QString::fromStdString ( SchemaAttribute->get_name() ) );
45 ui->AttributeNameLineEdit->setText ( QString::fromStdString (
46 SchemaAttribute->get_name() ) );
47 ui->AttributeTypeComboBox->setCurrentIndex (
48 ui->AttributeTypeComboBox->findData ( QString::fromStdString (
49 SchemaAttribute->get_type() ),
50 Qt::DisplayRole ) );
51
52 if ( SchemaAttribute->get_is_multi_values() )
53 ui->AttributeIsMultivariable->setCurrentIndex (
54 0 );
55 else
56 {
57 ui->AttributeIsMultivariable->setCurrentIndex ( 1 );
58 }
59
60 if ( SchemaAttribute->get_is_no_null() )
61 {
62 ui->AttributeIsNotNull->setCurrentIndex ( 0 );
63 }
64 else
65 {
66 ui->AttributeIsNotNull->setCurrentIndex ( 1 );
67 }
68
69 ui->AttributeDescriptionTextBox->setPlainText (
70 QString::fromStdString ( SchemaAttribute->get_description() ) );
71 ui->AttributeRangeLineEdit->setText ( QString::fromStdString (
72 SchemaAttribute->get_range() ) );
73 ui->AttributeInitialValue->setText (
74 QString::fromStdString ( SchemaAttribute->get_init_value() ) );
75
76 int Index = ui->AttributeTypeComboBox->currentIndex();
77
78 if ( Index == 0 || Index >= 9 )
79 {
80 ui->FormatLayout->setEnabled ( false );
81 ui->FormatLabel->hide();
82 ui->AttributeFormatComboBox->hide();
83 }
84 else
85 {
86 ui->FormatLayout->setEnabled ( true );
87 ui->FormatLabel->show();
88 ui->AttributeFormatComboBox->show();
89
90 if ( SchemaAttribute->get_format() == OksAttribute::Dec )
91 ui->AttributeFormatComboBox->setCurrentIndex (
92 0 );
93 else if ( SchemaAttribute->get_format() == OksAttribute::Oct )
94 ui->AttributeFormatComboBox->setCurrentIndex (
95 1 );
96 else
97 {
98 ui->AttributeFormatComboBox->setCurrentIndex ( 2 );
99 }
100 }
101}
102
104{
105 QStringList Items
106 {
107 "bool", "s8", "u8", "s16", "u16", "s32", "u32", "s64", "u64", "float", "double", "date",
108 "time", "string", "enum", "class" };
109 ui->AttributeTypeComboBox->addItems ( Items );
110 setWindowTitle ( QString::fromStdString ( "New Attribute" ) );
111 setObjectName ( "NEW" );
112
113 if ( !UsedNew )
114 {
115 FillInfo();
116 }
117}
118
120{
121 connect ( ui->AttributeTypeComboBox, SIGNAL ( currentIndexChanged ( int ) ), this,
122 SLOT ( ToggleFormat ( int ) ) );
123 connect ( ui->buttonBox, SIGNAL ( accepted() ), this, SLOT ( ProxySlot() ) );
124 connect ( ui->buttonBox, SIGNAL ( rejected() ), this, SLOT ( close() ) );
125 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassUpdated ( QString ) ), this,
126 SLOT ( ClassUpdated ( QString ) ) );
127}
128
130{
131 if(!UsedNew && ClassName.toStdString() == SchemaClass->get_name()) {
132 if(SchemaClass->find_direct_attribute(SchemaAttribute->get_name()) != nullptr) {
133 FillInfo();
134 } else {
135 QWidget::close();
136 }
137 }
138}
139
141{
142 bool Changed = false;
143 std::string AttributeName = ui->AttributeNameLineEdit->text().toStdString();
144 std::string AttributeType = ui->AttributeTypeComboBox->currentText().toStdString();
145 char AttributeFormatChar = ( ui->AttributeFormatComboBox->currentText().toStdString() ) [0];
146
147 OksAttribute::Format AttributeFormat;
148
149 switch ( AttributeFormatChar )
150 {
151 case 'D':
152 AttributeFormat = OksAttribute::Format::Dec;
153 break;
154
155 case 'O':
156 AttributeFormat = OksAttribute::Format::Oct;
157 break;
158
159 case 'H':
160 AttributeFormat = OksAttribute::Format::Hex;
161 break;
162
163 default:
164 AttributeFormat = OksAttribute::Format::Dec;
165 break;
166 }
167
169 int Index = ui->AttributeTypeComboBox->currentIndex();
170
171 if ( Index == 0 || Index >= 9 )
172 {
173 AttributeFormat = OksAttribute::Format::Dec;
174 }
175
176 bool IsMultivariable = false;
177
178 switch ( ui->AttributeIsMultivariable->currentIndex() )
179 {
180 case 0:
181 IsMultivariable = true;
182 break;
183
184 case 1:
185 IsMultivariable = false;
186 break;
187
188 default:
189 IsMultivariable = false;
190 break;
191 }
192
193 bool IsNotNull = false;
194
195 switch ( ui->AttributeIsNotNull->currentIndex() )
196 {
197 case 0:
198 IsNotNull = true;
199 break;
200
201 case 1:
202 IsNotNull = false;
203 break;
204
205 default:
206 IsNotNull = false;
207 break;
208 }
209
210 std::string AttributeDescription =
211 ui->AttributeDescriptionTextBox->toPlainText().toStdString();
212 std::string AttributeRange = ui->AttributeRangeLineEdit->text().toStdString();
213 std::string AttributeInitial = ui->AttributeInitialValue->text().toStdString();
214
215 if ( AttributeName != SchemaAttribute->get_name() )
216 {
217 KernelWrapper::GetInstance().PushSetAttributeNameCommand ( SchemaClass, SchemaAttribute, AttributeName );
218 Changed = true;
219 }
220
221 if ( AttributeType != SchemaAttribute->get_type() )
222 {
223 KernelWrapper::GetInstance().PushSetAttributeTypeCommand ( SchemaClass, SchemaAttribute, AttributeType );
224 Changed = true;
225 }
226
227 if ( AttributeFormat != SchemaAttribute->get_format() )
228 {
230 SchemaAttribute,
231 AttributeFormat );
232 Changed = true;
233 }
234
235 if ( IsMultivariable != SchemaAttribute->get_is_multi_values() )
236 {
238 SchemaAttribute,
239 IsMultivariable );
240 Changed = true;
241 }
242
243 if ( IsNotNull != SchemaAttribute->get_is_no_null() )
244 {
245 KernelWrapper::GetInstance().PushSetAttributeIsNullCommand ( SchemaClass, SchemaAttribute, IsNotNull );
246 Changed = true;
247 }
248
249 if ( AttributeDescription != SchemaAttribute->get_description() )
250 {
252 SchemaAttribute,
253 AttributeDescription );
254 Changed = true;
255 }
256
257 if ( AttributeRange != SchemaAttribute->get_range() )
258 {
260 SchemaAttribute,
261 AttributeRange );
262 Changed = true;
263 }
264
265 if ( AttributeInitial != SchemaAttribute->get_init_value() )
266 {
268 SchemaAttribute,
269 AttributeInitial );
270 Changed = true;
271 }
272
273 if ( Changed )
274 {
275 emit RebuildModel();
276 }
277
278 close();
279}
280
282{
283 std::string AttributeName = ui->AttributeNameLineEdit->text().toStdString();
284 std::string AttributeType = ui->AttributeTypeComboBox->currentText().toStdString();
285 char AttributeFormatChar = ( ui->AttributeFormatComboBox->currentText().toStdString() ) [0];
286
287 OksAttribute::Format AttributeFormat;
288
289 switch ( AttributeFormatChar )
290 {
291 case 'D':
292 AttributeFormat = OksAttribute::Format::Dec;
293 break;
294
295 case 'O':
296 AttributeFormat = OksAttribute::Format::Oct;
297 break;
298
299 case 'H':
300 AttributeFormat = OksAttribute::Format::Hex;
301 break;
302
303 default:
304 AttributeFormat = OksAttribute::Format::Dec;
305 break;
306 }
307
309 int Index = ui->AttributeTypeComboBox->currentIndex();
310
311 if ( Index == 0 || Index >= 9 )
312 {
313 AttributeFormat = OksAttribute::Format::Dec;
314 }
315
316 bool IsMultivariable = false;
317
318 switch ( ui->AttributeIsMultivariable->currentIndex() )
319 {
320 case 0:
321 IsMultivariable = true;
322 break;
323
324 case 1:
325 IsMultivariable = false;
326 break;
327
328 default:
329 IsMultivariable = false;
330 break;
331 }
332
333 bool IsNotNull = false;
334
335 switch ( ui->AttributeIsNotNull->currentIndex() )
336 {
337 case 0:
338 IsNotNull = true;
339 break;
340
341 case 1:
342 IsNotNull = false;
343 break;
344
345 default:
346 IsNotNull = false;
347 break;
348 }
349
350 std::string AttributeDescription =
351 ui->AttributeDescriptionTextBox->toPlainText().toStdString();
352 std::string AttributeRange = ui->AttributeRangeLineEdit->text().toStdString();
353 std::string AttributeInitial = ui->AttributeInitialValue->text().toStdString();
354
356 KernelWrapper::GetInstance().PushAddAttributeCommand ( SchemaClass, AttributeName,
357 AttributeType, IsMultivariable,
358 AttributeRange, AttributeInitial,
359 AttributeDescription, IsNotNull,
360 AttributeFormat );
361 emit RebuildModel();
362 close();
363}
364
366{
367 if ( UsedNew )
368 {
369 ParseToCreate();
370 }
371 else
372 {
373 ParseToSave();
374 }
375}
376
378{
379 int Index = ui->AttributeTypeComboBox->currentIndex();
380
381 if ( Index == 0 || Index >= 9 )
382 {
383 ui->FormatLayout->setEnabled ( false );
384 ui->FormatLabel->hide();
385 ui->AttributeFormatComboBox->hide();
386 }
387 else
388 {
389 ui->FormatLayout->setEnabled ( true );
390 ui->FormatLabel->show();
391 ui->AttributeFormatComboBox->show();
392 }
393}
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)
OKS attribute class.
The OKS class.
Definition class.hpp:200