DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SchemaRelationshipEditor.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/SchemaRelationshipEditor.cpp to apps/SchemaEditor/SchemaRelationshipEditor.cpp).
5
6#include <QMessageBox>
10#include "ui_SchemaRelationshipEditor.h"
11
12using namespace dunedaq::oks;
13
15
17 OksRelationship * Relationship,
18 QWidget * parent )
19 : QWidget ( parent ),
21 SchemaRelationship ( Relationship ),
22 SchemaClass ( Class ),
23 UsedNew ( false ),
24 GraphScene ( false )
25{
26 QWidget::setAttribute(Qt::WA_DeleteOnClose);
27
29
30 ui->setupUi ( this );
31 auto title = SchemaClass->get_name() + "::" + SchemaRelationship->get_name();
32 setWindowTitle (
33 QString ( "Relationship Editor : %1" ).arg ( title.c_str() ) );
36}
37
39 QWidget * parent )
40 : QWidget ( parent ),
42 SchemaRelationship ( nullptr ),
43 SchemaClass ( Class ),
44 UsedNew ( true ),
45 GraphScene ( false )
46{
47 QWidget::setAttribute(Qt::WA_DeleteOnClose);
48 ui->setupUi ( this );
49 m_writable = true;
50 setWindowTitle (QString("Relationship Editor : %1 New Relationship")
51 .arg(SchemaClass->get_name().c_str()));
54}
55
57 QString ClassType,
58 QWidget * parent )
59 : QWidget ( parent ),
61 SchemaRelationship ( nullptr ),
62 SchemaClass ( Class ),
63 UsedNew ( true ),
64 GraphScene ( true )
65{
66 QWidget::setAttribute(Qt::WA_DeleteOnClose);
67 m_writable = true;
68 ui->setupUi ( this );
69 setWindowTitle (QString("Relationship Editor : %1 New Relationship")
70 .arg(SchemaClass->get_name().c_str()));
73 ui->RelationshipTypeComboBox->setCurrentIndex (
74 ui->RelationshipTypeComboBox->findData ( ClassType, Qt::DisplayRole ) );
75}
77{
78 if(!UsedNew && ClassName.toStdString() == SchemaClass->get_name()) {
79 if(SchemaClass->find_direct_relationship(SchemaRelationship->get_name()) == nullptr) {
80 QWidget::close();
81 } else {
82 FillInfo();
83 }
84 }
85}
86
88{
89 auto name = SchemaClass->get_name() + "::" + SchemaRelationship->get_name();
90 setObjectName ( QString::fromStdString ( name ) );
91 ui->RelationshipNameLineEdit->setText (
92 QString::fromStdString ( SchemaRelationship->get_name() ) );
93 ui->RelationshipTypeComboBox->setCurrentIndex (
94 ui->RelationshipTypeComboBox->findData (
95 QString::fromStdString ( SchemaRelationship->get_type() ), Qt::DisplayRole ) );
96 ui->RelationshipDescriptionTextEdit->setPlainText (
97 QString::fromStdString ( SchemaRelationship->get_description() ) );
98
99 if ( SchemaRelationship->get_is_composite() )
100 {
101 ui->IsCompositeCombo->setCurrentIndex ( 0 );
102 }
103 else
104 {
105 ui->IsCompositeCombo->setCurrentIndex ( 1 );
106 }
107
108 if ( SchemaRelationship->get_is_exclusive() )
109 {
110 ui->IsExclusiveCombo->setCurrentIndex ( 0 );
111 }
112 else
113 {
114 ui->IsExclusiveCombo->setCurrentIndex ( 1 );
115 }
116
117 if ( SchemaRelationship->get_is_dependent() )
118 {
119 ui->IsDependentCombo->setCurrentIndex ( 0 );
120 }
121 else
122 {
123 ui->IsDependentCombo->setCurrentIndex ( 1 );
124 }
125
126 if ( SchemaRelationship->get_low_cardinality_constraint() ==
128 ->LowCcCombo->setCurrentIndex ( 0 );
129 else if ( SchemaRelationship->get_low_cardinality_constraint()
131 {
132 ui->LowCcCombo->setCurrentIndex ( 1 );
133 }
134 else
135 {
136 ui->LowCcCombo->setCurrentIndex ( 2 );
137 }
138
139 if ( SchemaRelationship->get_high_cardinality_constraint() ==
141 ->HighCcCombo->setCurrentIndex ( 0 );
142 else if ( SchemaRelationship->get_high_cardinality_constraint()
144 {
145 ui->HighCcCombo->setCurrentIndex ( 1 );
146 }
147 else
148 {
149 ui->HighCcCombo->setCurrentIndex ( 2 );
150 }
151}
152
154 if (event->key() == Qt::Key_Escape) {
155 close();
156 }
157 QWidget::keyPressEvent(event);
158}
159
160
162{
163 QStringList ClassList;
165 ui->RelationshipTypeComboBox->addItems ( ClassList );
166 auto name = SchemaClass->get_name() + "::";
167 setObjectName ( QString::fromStdString(name) );
168
169 if (!m_writable) {
170 ui->RelationshipTypeComboBox->setEnabled(false);
171 ui->IsCompositeCombo->setEnabled(false);
172 ui->IsExclusiveCombo->setEnabled(false);
173 ui->IsDependentCombo->setEnabled(false);
174 ui->LowCcCombo->setEnabled(false);
175 ui->HighCcCombo->setEnabled(false);
176 ui->RelationshipDescriptionTextEdit->setEnabled(false);
177 ui->RelationshipNameLineEdit->setEnabled(false);
178 }
179
180 if ( !UsedNew )
181 {
182 FillInfo();
183 }
184}
185
187{
188 if (m_writable) {
189 connect ( ui->buttonBox, SIGNAL ( accepted() ), this, SLOT ( ProxySlot() ) );
190 }
191 else {
192 connect ( ui->buttonBox, SIGNAL ( accepted() ), this, SLOT ( close() ) );
193 }
194 connect ( ui->buttonBox, SIGNAL ( rejected() ), this, SLOT ( close() ) );
195 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassCreated(QString) ), this,
196 SLOT ( UpdateClassCombo() ) );
197 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassUpdated ( QString ) ), this,
198 SLOT ( ClassUpdated ( QString ) ) );
199}
200
202{
203 bool changed = false;
204 QString RelationshipName = ui->RelationshipNameLineEdit->text();
205 QString RelationshipType = ui->RelationshipTypeComboBox->currentText();
206 QString RelationshipDescription = ui->RelationshipDescriptionTextEdit->toPlainText();
207
208 bool IsComposite;
209
210 if ( ui->IsCompositeCombo->currentIndex() == 0 )
211 {
212 IsComposite = true;
213 }
214 else
215 {
216 IsComposite = false;
217 }
218
219 bool IsExclusive;
220
221 if ( ui->IsExclusiveCombo->currentIndex() == 0 )
222 {
223 IsExclusive = true;
224 }
225 else
226 {
227 IsExclusive = false;
228 }
229
230 bool IsDependent;
231
232 if ( ui->IsDependentCombo->currentIndex() == 0 )
233 {
234 IsDependent = true;
235 }
236 else
237 {
238 IsDependent = false;
239 }
240
241 OksRelationship::CardinalityConstraint RelationshipHighCardinality;
242 OksRelationship::CardinalityConstraint RelationshipLowCardinality;
243
244 if ( ui->HighCcCombo->currentIndex() == 0 ) RelationshipHighCardinality =
246 else if ( ui->HighCcCombo->currentIndex() == 1 ) RelationshipHighCardinality =
248 else
249 {
250 RelationshipHighCardinality = OksRelationship::CardinalityConstraint::Many;
251 }
252
253 if ( ui->LowCcCombo->currentIndex() == 0 ) RelationshipLowCardinality =
255 else if ( ui->LowCcCombo->currentIndex() == 1 ) RelationshipLowCardinality =
257 else
258 {
259 RelationshipLowCardinality = OksRelationship::CardinalityConstraint::Many;
260 }
261
262 if ( RelationshipName != QString::fromStdString ( SchemaRelationship->get_name() ) )
263 {
265 SchemaClass, SchemaRelationship, RelationshipName.toStdString() );
266 changed = true;
267 }
268
269 if ( RelationshipType != QString::fromStdString ( SchemaRelationship->get_type() ) )
270 {
272 SchemaClass, SchemaRelationship, RelationshipType.toStdString() );
273 changed = true;
274 }
275
276 if ( RelationshipDescription != QString::fromStdString (
277 SchemaRelationship->get_description() ) )
278 {
280 SchemaClass, SchemaRelationship, RelationshipDescription.toStdString() );
281 changed = true;
282 }
283
284 if ( SchemaRelationship->get_is_composite() != IsComposite )
285 {
288 IsComposite );
289 changed = true;
290 }
291
292 if ( SchemaRelationship->get_is_exclusive() != IsExclusive )
293 {
296 IsExclusive );
297 changed = true;
298 }
299
300 if ( SchemaRelationship->get_is_dependent() != IsDependent )
301 {
304 IsDependent );
305 changed = true;
306 }
307
308 if ( RelationshipHighCardinality != SchemaRelationship->get_high_cardinality_constraint() )
309 {
311 SchemaClass, SchemaRelationship, RelationshipHighCardinality );
312 changed = true;
313 }
314
315 if ( RelationshipLowCardinality != SchemaRelationship->get_low_cardinality_constraint() )
316 {
318 SchemaClass, SchemaRelationship, RelationshipLowCardinality );
319 changed = true;
320 }
321
322 if ( changed )
323 {
324 emit RebuildModel();
325 }
326
327 close();
328}
329
331{
332 if ( ui->RelationshipNameLineEdit->text().isEmpty() )
333 {
334 QMessageBox::warning ( 0, "Schema editor",
335 QString ( "Please Provide a name for the relationship !" ) );
336 return;
337 }
338
339 QString RelationshipName = ui->RelationshipNameLineEdit->text();
340 QString RelationshipType = ui->RelationshipTypeComboBox->currentText();
341 QString RelationshipDescription = ui->RelationshipDescriptionTextEdit->toPlainText();
342
343 bool IsComposite;
344
345 if ( ui->IsCompositeCombo->currentIndex() == 0 )
346 {
347 IsComposite = true;
348 }
349 else
350 {
351 IsComposite = false;
352 }
353
354 bool IsExclusive;
355
356 if ( ui->IsExclusiveCombo->currentIndex() == 0 )
357 {
358 IsExclusive = true;
359 }
360 else
361 {
362 IsExclusive = false;
363 }
364
365 bool IsDependent;
366
367 if ( ui->IsDependentCombo->currentIndex() == 0 )
368 {
369 IsDependent = true;
370 }
371 else
372 {
373 IsDependent = false;
374 }
375
376 OksRelationship::CardinalityConstraint RelationshipHighCardinality;
377 OksRelationship::CardinalityConstraint RelationshipLowCardinality;
378
379 if ( ui->HighCcCombo->currentIndex() == 0 ) RelationshipHighCardinality =
381 else if ( ui->HighCcCombo->currentIndex() == 1 ) RelationshipHighCardinality =
383 else
384 {
385 RelationshipHighCardinality = OksRelationship::CardinalityConstraint::Many;
386 }
387
388 if ( ui->LowCcCombo->currentIndex() == 0 ) RelationshipLowCardinality =
390 else if ( ui->LowCcCombo->currentIndex() == 1 ) RelationshipLowCardinality =
392 else
393 {
394 RelationshipLowCardinality = OksRelationship::CardinalityConstraint::Many;
395 }
396
398 RelationshipName.toStdString(),
399 RelationshipDescription.toStdString(),
400 RelationshipType.toStdString(),
401 IsComposite, IsExclusive, IsDependent,
402 RelationshipLowCardinality,
403 RelationshipHighCardinality );
404 emit RebuildModel();
405
406 if ( GraphScene ) emit MakeGraphConnection ( QString::fromStdString (
407 SchemaClass->get_name() ),
408 ui->RelationshipTypeComboBox->currentText(),
409 RelationshipName );
410
411 close();
412}
413
415{
416 if ( UsedNew )
417 {
419 }
420 else
421 {
422 ParseToSave();
423 }
424}
425
427{
428 QStringList ClassList;
430 ui->RelationshipTypeComboBox->clear();
431 ui->RelationshipTypeComboBox->addItems ( ClassList );
432 ui->RelationshipTypeComboBox->setCurrentIndex (
433 ui->RelationshipTypeComboBox->findData (
434 QString::fromStdString ( SchemaRelationship->get_type() ), Qt::DisplayRole ) );
435}
void PushSetIsCompositeRelationshipCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, bool Value)
void GetClassListString(QStringList &ClassListString) const
static KernelWrapper & GetInstance()
void PushSetHighCcRelationshipCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, dunedaq::oks::OksRelationship::CardinalityConstraint NewCardinality)
void PushSetIsDependentRelationshipCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, bool Value)
void PushAddRelationship(dunedaq::oks::OksClass *Class, std::string Name, std::string Description, std::string Type, bool Composite, bool Exclusive, bool Dependent, dunedaq::oks::OksRelationship::CardinalityConstraint LowCc, dunedaq::oks::OksRelationship::CardinalityConstraint HighCc)
void PushSetIsExclusiveRelationshipCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, bool Value)
void PushSetClassTypeRelationshipCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, std::string ClassType)
void PushSetLowCcRelationshipCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, dunedaq::oks::OksRelationship::CardinalityConstraint NewCardinality)
bool IsFileWritable(const std::string &FileName) const
void PushSetDescriptionRelationshipCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, std::string Description)
void PushSetNameRelationshipCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, std::string Name)
Relationship commands.
dbse::Ui::SchemaRelationshipEditor * ui
void MakeGraphConnection(QString ClassName1, QString ClassName2, QString RelationshipName)
SchemaRelationshipEditor(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, QWidget *parent=nullptr)
void keyPressEvent(QKeyEvent *event) override
dunedaq::oks::OksRelationship * SchemaRelationship
The OKS class.
Definition class.hpp:205
OksFile * get_file() const noexcept
Definition class.hpp:343
const std::string & get_full_file_name() const
Definition file.hpp:528