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