DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SchemaClassEditor.cpp
Go to the documentation of this file.
1
2#include <QMessageBox>
3#include <QLineEdit>
4#include <QListWidget>
5#include <QListWidgetItem>
6#include <QInputDialog>
7#include <QString>
8#include <QStringList>
9
17#include "ui_SchemaClassEditor.h"
18
19#include "oks/file.hpp"
20
21#include <map>
22
23using namespace dunedaq::oks;
24
26 : QWidget ( parent ),
27 ui ( new Ui::SchemaClassEditor ),
28 SchemaClass ( ClassInfo ),
29 MethodModel ( nullptr ),
30 AttributeModel ( nullptr ),
31 RelationshipModel ( nullptr ),
32 SuperClassModel ( nullptr ),
33 SubClassModel ( nullptr ),
34 ContextMenuAttribute ( nullptr ),
35 ContextMenuRelationship ( nullptr ),
36 ContextMenuMethod ( nullptr ),
37 ContextMenuClass ( nullptr )
38{
39 QWidget::setAttribute(Qt::WA_DeleteOnClose);
40
42 ui->setupUi ( this );
43 setWindowTitle (
44 QString ( "Class Editor : %1" ).arg ( QString::fromStdString (
45 SchemaClass->get_name() ) ) );
46 setObjectName ( QString::fromStdString ( SchemaClass->get_name() ) );
52}
53
55
57 if (event->key() == Qt::Key_Escape) {
58 close();
59 }
60 QWidget::keyPressEvent(event);
61}
63{
64 connect ( ui->buttonBox, SIGNAL ( accepted() ), this, SLOT ( ParseToSave() ) );
65 connect ( ui->buttonBox, SIGNAL ( rejected() ), this, SLOT ( close_slot() ) );
66 connect ( ui->moveButton, SIGNAL(clicked()), this, SLOT (move_class()));
67 connect ( ui->AddButtonAttribute, SIGNAL ( clicked() ), this, SLOT ( AddNewAttribute() ) );
68 connect ( ui->AddButtonSuperClass, SIGNAL ( clicked() ), this, SLOT ( AddNewSuperClass() ) );
69 connect ( ui->AddButtonRelationship, SIGNAL ( clicked() ), this,
70 SLOT ( AddNewRelationship() ) );
71 connect ( ui->AddButtonMethod, SIGNAL ( clicked() ), this, SLOT ( AddNewMethod() ) );
72 connect ( ui->RelationshipView, SIGNAL ( activated ( QModelIndex ) ), this,
73 SLOT ( OpenRelationshipEditor ( QModelIndex ) ) );
74 connect ( ui->MethodsView, SIGNAL ( activated ( QModelIndex ) ), this,
75 SLOT ( OpenMethodEditor ( QModelIndex ) ) );
76 connect ( ui->AttributeView, SIGNAL ( activated ( QModelIndex ) ), this,
77 SLOT ( OpenAttributeEditor ( QModelIndex ) ) );
78 connect ( ui->SuperClassView, SIGNAL ( activated ( QModelIndex ) ), this,
79 SLOT ( OpenSuperClass ( QModelIndex ) ) );
80 connect ( ui->SubClassView, SIGNAL ( activated ( QModelIndex ) ), this,
81 SLOT ( OpenSubClass ( QModelIndex ) ) );
82 connect ( ui->AttributeView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
83 SLOT ( CustomMenuAttributeView ( QPoint ) ) );
84 connect ( ui->RelationshipView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
85 SLOT ( CustomMenuRelationshipView ( QPoint ) ) );
86 connect ( ui->MethodsView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
87 SLOT ( CustomMenuMethodView ( QPoint ) ) );
88 connect ( ui->SuperClassView, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
89 SLOT ( CustomMenuClassView ( QPoint ) ) );
90 connect ( ui->ShowDerivedAttributes, &QCheckBox::toggled, this, &SchemaClassEditor::BuildAttributeModelSlot );
91 connect ( ui->ShowDerivedRelationships, &QCheckBox::toggled, this, &SchemaClassEditor::BuildRelationshipModelSlot );
92 connect ( ui->ShowDerivedMethods, &QCheckBox::toggled, this, &SchemaClassEditor::BuildMethodModelSlot );
93 connect ( ui->ShowAllSuperClasses, &QCheckBox::toggled, this, &SchemaClassEditor::BuildSuperClassModelSlot );
94 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassRemoved ( QString ) ), this,
95 SLOT ( ClassRemoved ( QString ) ) );
96 connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassUpdated ( QString ) ), this,
97 SLOT ( ClassUpdated ( QString ) ) );
98}
99
101{
102 if(className == objectName()) {
103 QWidget::close();
104 }
105}
106
108{
109 if(className == objectName()) {
110 BuildModels();
112 }
113}
114
123
125{
126 ui->AttributeView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
127 ui->RelationshipView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
128 ui->MethodsView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
129 ui->SuperClassView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
130 ui->SubClassView->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
131
133 ui->ClassNameLineEdit->setText ( QString::fromStdString ( SchemaClass->get_name() ) );
134 //ui->ClassNameLineEdit->setEnabled ( false );
136 ui->SchemaFileLineEdit->setText ( QString::fromStdString ( SchemaClass->get_file()->get_short_file_name() ) );
137 //ui->SchemaFileLineEdit->setEnabled ( false );
138
139 if (KernelWrapper::GetInstance().IsFileWritable(
140 SchemaClass->get_file()->get_full_file_name())) {
141 ui->AddButtonAttribute->setEnabled (true);
142 ui->AddButtonSuperClass->setEnabled (true);
143 ui->AddButtonRelationship->setEnabled (true);
144 ui->AddButtonMethod->setEnabled (true);
145 ui->moveButton->setEnabled (true);
146 }
147 else {
148 ui->SchemaFileLineEdit->setStyleSheet("color:rgb(128,0,0);");
149 // ui->DescriptionTextEdit->setEnabled(false);
150 ui->DescriptionTextEdit->setReadOnly(true);
151
152 ui->AddButtonAttribute->setEnabled (false);
153 ui->AddButtonSuperClass->setEnabled (false);
154 ui->AddButtonRelationship->setEnabled (false);
155 ui->AddButtonMethod->setEnabled (false);
156 ui->moveButton->setEnabled (false);
157 ui->AbstractComboBox->setEnabled(false);
158 }
159
161 ui->DescriptionTextEdit->setPlainText ( QString::fromStdString ( SchemaClass->get_description() ) );
162 ui->DescriptionTextEdit->setTabChangesFocus (true);
164 if ( SchemaClass->get_is_abstract() )
165 {
166 ui->AbstractComboBox->setCurrentIndex ( 0 );
167 }
168 else
169 {
170 ui->AbstractComboBox->setCurrentIndex ( 1 );
171 }
172}
173
177
178
180 QWidget* pwidget) {
181 std::string current_file = schema_class->get_file()->get_full_file_name();
182 std::vector<OksFile*> files;
184 QStringList writable_files;
185 std::map<QString, OksFile*> file_map;
186 int current_row = -1;
187 for (auto file: files) {
188 auto fn = file->get_full_file_name();
189 if (KernelWrapper::GetInstance().IsFileWritable(fn)) {
190 if (fn == current_file) {
191 current_row = writable_files.size();
192 }
193 writable_files.append(QString::fromStdString(fn));
194 file_map[QString::fromStdString(fn)] = file;
195 }
196 }
197 if (writable_files.empty()) {
198 QMessageBox::warning ( 0, "Schema editor",
199 QString ( "No writable schema files to move class to." ) );
200 return;
201 }
202
203 QWidget* widget = new QWidget();
204 QString text = "Select file to hold class " +
205 QString::fromStdString(schema_class->get_name());
206 QLabel* label = new QLabel(text);
207 QListWidget* qlw = new QListWidget();
208 qlw->addItems(writable_files);
209 if (current_row != -1) {
210 qlw->setCurrentRow(current_row);
211 }
212
213 connect (qlw, &QListWidget::itemActivated,
214 pwidget, [=] () {
215 QListWidgetItem* it = qlw->currentItem();
216 auto fn = it->text();
217 if (fn.toStdString() != current_file) {
218 schema_class->set_file(file_map.at(fn));
219 emit KernelWrapper::GetInstance().ClassUpdated ( QString::fromStdString(schema_class->get_name()) );
220 }
221 delete widget;
222 }
223 );
224
225 auto bb = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
226 connect (bb, &QDialogButtonBox::accepted, pwidget, [=] () {
227 auto it = qlw->currentItem();
228 if (it != nullptr) {
229 auto fn = it->text();
230 if (fn.toStdString() != current_file) {
231 schema_class->set_file(file_map.at(fn));
232 emit KernelWrapper::GetInstance().ClassUpdated ( QString::fromStdString(schema_class->get_name()) );
233 }
234 delete widget;
235 }
236 else {
237 QMessageBox::warning ( 0, "Schema editor",
238 QString ( "No schema file selected to move class to." ) );
239 return;
240 }
241 });
242 connect ( bb, &QDialogButtonBox::rejected, pwidget, [=] () {delete widget;} );
243
244 QVBoxLayout* layout = new QVBoxLayout();
245 layout->addWidget(label);
246 layout->addWidget(qlw);
247 layout->addWidget(bb);
248 widget->setWindowTitle("Select new file for class");
249 widget->setLayout(layout);
250 widget->setParent(pwidget, Qt::Dialog);
251 widget->show();
252}
253
255{
256 QString name = QString::fromStdString(SchemaClass->get_name() + "::") +
257 attrName;
258 for (QWidget* widget : QApplication::allWidgets())
259 {
260 if (dynamic_cast<SchemaAttributeEditor *> (widget) != nullptr)
261 {
262 if ( (widget->objectName()).compare (name) == 0 )
263 {
264 widget->raise();
265 widget->setVisible ( true );
266 widget->activateWindow();
267 return false;
268 }
269 }
270 }
271
272 return true;
273}
274
276{
277 QString name = QString::fromStdString(SchemaClass->get_name() + "::") +
278 relName;
279
280 for ( QWidget* widget : QApplication::allWidgets() )
281 {
282 if (dynamic_cast<SchemaRelationshipEditor *> (widget) != nullptr)
283 {
284 if ( ( widget->objectName() ).compare ( name ) == 0 )
285 {
286 widget->raise();
287 widget->setVisible ( true );
288 widget->activateWindow();
289 return false;
290 }
291 }
292 }
293
294 return true;
295}
296
298{
299 bool WidgetFound = false;
300
301 for ( QWidget * Editor : QApplication::allWidgets() )
302 {
303 SchemaMethodEditor * Widget = dynamic_cast<SchemaMethodEditor *> ( Editor );
304
305 if ( Widget != nullptr )
306 {
307 if ( ( Widget->objectName() ).compare ( Name ) == 0 )
308 {
309 Widget->raise();
310 Widget->setVisible ( true );
311 Widget->activateWindow();
312 WidgetFound = true;
313 }
314 }
315 }
316
317 return !WidgetFound;
318}
319
321{
322 const std::string& attributeName = CurrentRow.at ( 0 ).toStdString();
323 OksAttribute * SchemaAttribute = SchemaClass->find_direct_attribute( attributeName );
324 if(SchemaAttribute != nullptr) {
326 SchemaClass, SchemaAttribute, SchemaAttribute->get_name(), SchemaAttribute->get_type(),
327 SchemaAttribute->get_is_multi_values(), SchemaAttribute->get_range(),
328 SchemaAttribute->get_init_value(), SchemaAttribute->get_description(),
329 SchemaAttribute->get_is_no_null(), SchemaAttribute->get_format() );
330 } else {
331 QMessageBox::warning ( 0, "Schema editor",
332 QString::fromStdString( "Cannot remove attribute \"" + attributeName +
333 "\" because it is not a direct attribute of \"" + SchemaClass->get_name() + "\"") );
334 }
335}
336
338{
339 const std::string& relationshipName = CurrentRow.at ( 0 ).toStdString();
340 OksRelationship * SchemaRelationship = SchemaClass->find_direct_relationship( relationshipName );
341 if(SchemaRelationship != nullptr) {
343 SchemaClass, SchemaRelationship, SchemaRelationship->get_name(),
344 SchemaRelationship->get_description(), SchemaRelationship->get_type(),
345 SchemaRelationship->get_is_composite(), SchemaRelationship->get_is_exclusive(),
346 SchemaRelationship->get_is_dependent(),
347 SchemaRelationship->get_low_cardinality_constraint(),
348 SchemaRelationship->get_high_cardinality_constraint() );
349 } else {
350 QMessageBox::warning ( 0, "Schema editor",
351 QString::fromStdString( "Cannot remove relationship \"" + relationshipName +
352 "\" because it is not a direct relationship of \"" + SchemaClass->get_name() + "\"") );
353 }
354}
355
357{
358 const std::string& methodName = CurrentRow.at ( 0 ).toStdString();
359 OksMethod * SchemaMethod = SchemaClass->find_direct_method ( methodName );
360 if(SchemaMethod != nullptr) {
362 SchemaMethod->get_name(),
363 SchemaMethod->get_description() );
364 } else {
365 QMessageBox::warning ( 0, "Schema editor",
366 QString::fromStdString( "Cannot remove method \"" + methodName +
367 "\" because it is not a direct method of \"" + SchemaClass->get_name() + "\"") );
368 }
369}
370
372{
373 const std::string& superClassName = CurrentRow.at ( 0 ).toStdString();
374 if(SchemaClass->has_direct_super_class(superClassName))
375 {
377 }
378 else
379 {
380 QMessageBox::warning ( 0, "Schema editor",
381 QString::fromStdString( "Cannot remove super-class \"" + superClassName +
382 "\" because it is not a direct super-class of \"" + SchemaClass->get_name() + "\"") );
383 }
384}
385
386
388{
389 std::string NewDescription = ui->DescriptionTextEdit->toPlainText().toStdString();
390
391 bool Abstract = false;
392
393 if ( ui->AbstractComboBox->currentIndex() == 0 )
394 {
395 Abstract = true;
396 }
397 else
398 {
399 Abstract = false;
400 }
401
402 if ( Abstract != SchemaClass->get_is_abstract() )
403 {
405 }
406
407 if ( NewDescription != SchemaClass->get_description() )
408 {
410 }
411
412 close();
413}
414
416{
417 bool widgetFound=false;
418 QString class_name = QString::fromStdString(SchemaClass->get_name());
419
420 QString wname = "add_sc_"+class_name;
421 for ( QWidget* widget : QApplication::allWidgets() ) {
422 if (widget->objectName().compare(wname) == 0 ) {
423 widget->raise();
424 widget->setVisible ( true );
425 widget->activateWindow();
426 widgetFound = true;
427 break;
428 }
429 }
430
431 if (!widgetFound) {
432 QWidget* widget = new QWidget();
433 widget->setObjectName(wname);
434 QLabel* label = new QLabel("Select a super-class to add to " + class_name);
435 label->setWordWrap(true);
436
437 // QLabel* status = new QLabel();
438 // status->setStyleSheet("QLabel { color : green; }");
439
440 auto search = new QLineEdit(widget);
441 search->setPlaceholderText("Search classes");
442 search->setClearButtonEnabled(true);
443
444 QListWidget* qlwidget = new QListWidget();
445 QStringList allClasses;
447 qlwidget->addItems(allClasses);
448
449 connect ( qlwidget, &QListWidget::itemActivated,
450 this, [=] () {
451 const std::string& className = qlwidget->currentItem()->text().toStdString();
453 BuildModels();
454 // status->setText(QString::fromStdString(className + " added as a super-class of " + SchemaClass->get_name()));
455 });
456
457 connect (search, &QLineEdit::textChanged, this, [search, qlwidget] () {
458 auto items = qlwidget->findItems(search->text(), Qt::MatchRegularExpression);
459 if (!items.empty()) {
460 qlwidget->setCurrentItem(items[0]);
461 }
462 });
463
464 auto close_button = new QPushButton("Close");
465 connect (close_button, SIGNAL (clicked()), widget, SLOT(close()));
466 QVBoxLayout* lout = new QVBoxLayout();
467 lout->addWidget(label);
468 lout->addWidget(qlwidget);
469 lout->addWidget(search);
470 lout->addWidget(close_button);
471 // l->addWidget(status);
472
473 widget->setWindowTitle("Select super-class(es) for " + class_name);
474 widget->setLayout(lout);
475 widget->setParent(this, Qt::Dialog);
476 widget->show();
477 }
478}
479
481{
484 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildAttributeModelSlot() ) );
485 Editor->show();
486 }
487}
488
490{
493 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildRelationshipModelSlot() ) );
494 Editor->show();
495 }
496}
497
499{
501 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildMethodModelSlot() ) );
502 Editor->show();
503}
504
506{
507 QStringList Row = AttributeModel->getRowFromIndex ( Index );
508 bool ShouldOpen = ShouldOpenAttributeEditor ( Row.at ( 0 ) );
509
510 if ( !Row.isEmpty() && ShouldOpen )
511 {
513 SchemaClass, SchemaClass->find_attribute ( Row.at ( 0 ).toStdString() ) );
514 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildAttributeModelSlot() ) );
515 Editor->show();
516 }
517}
518
520{
521 QStringList Row = RelationshipModel->getRowFromIndex ( Index );
522 bool ShouldOpen = ShouldOpenRelationshipEditor ( Row.at ( 0 ) );
523
524 if ( !Row.isEmpty() && ShouldOpen )
525 {
527 SchemaClass, SchemaClass->find_relationship ( Row.at ( 0 ).toStdString() ) );
528 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildRelationshipModelSlot() ) );
529 Editor->show();
530 }
531}
532
534{
535 QStringList Row = MethodModel->getRowFromIndex ( Index );
536 auto method = Row.at(0).toStdString();
537 if (SchemaClass->find_direct_method(method) == nullptr) {
538 std::string message{"Method '" + method + "' is not a direct method of " +
539 SchemaClass->get_name() +
540". Please open the method editor from the base class or add a local implementation to overrride it."};
541 QMessageBox::warning (0,
542 "Schema editor",
543 QString::fromStdString(message));
544 return;
545 }
546
547 bool ShouldOpen = ShouldOpenMethodEditor ( Row.at ( 0 ) );
548
549 if ( !Row.isEmpty() && ShouldOpen )
550 {
552 SchemaClass, SchemaClass->find_method ( method ) );
553 connect ( Editor, SIGNAL ( RebuildModel() ), this, SLOT ( BuildMethodModelSlot() ) );
554 Editor->show();
555 }
556}
557
559{
560 QStringList Row = SuperClassModel->getRowFromIndex ( Index );
561
562 if ( !Row.isEmpty() )
563 {
564 QString ClassName = Row.at ( 0 );
565 OpenNewClassEditor(ClassName);
566 }
567}
568
570{
571 QStringList Row = SubClassModel->getRowFromIndex ( Index );
572
573 if ( !Row.isEmpty() )
574 {
575 QString ClassName = Row.at ( 0 );
576 OpenNewClassEditor(ClassName);
577 }
578}
579
580void dbse::SchemaClassEditor::OpenNewClassEditor ( const QString& ClassName )
581{
582 bool WidgetFound = false;
583 OksClass * ClassInfo = KernelWrapper::GetInstance().FindClass ( ClassName.toStdString() );
584
585 for ( QWidget * Editor : QApplication::allWidgets() )
586 {
587 SchemaClassEditor * Widget = dynamic_cast<SchemaClassEditor *> ( Editor );
588
589 if ( Widget != nullptr )
590 {
591 if ( ( Widget->objectName() ).compare ( ClassName ) == 0 )
592 {
593 Widget->raise();
594 Widget->setVisible ( true );
595 Widget->activateWindow();
596 WidgetFound = true;
597 }
598 }
599 }
600
601 if ( !WidgetFound )
602 {
603 SchemaClassEditor * Editor = new SchemaClassEditor ( ClassInfo );
604 Editor->show();
605 }
606}
607
609{
610 QStringList AttributeHeaders
611 { "Name", "Type" };
612
613 if ( AttributeModel != nullptr ) {
614 delete AttributeModel;
615 }
618 AttributeHeaders,
619 ui->ShowDerivedAttributes->isChecked());
620
621 ui->AttributeView->setModel ( AttributeModel );
622 ui->AttributeView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
623 ui->AttributeView->setSelectionBehavior ( QAbstractItemView::SelectRows );
624}
625
627{
628 QStringList RelationshipHeaders
629 { "Name", "Type", "Low cc", "High cc" };
630
632 SchemaClass, RelationshipHeaders, ui->ShowDerivedRelationships->isChecked() );
633 else
634 {
635 delete RelationshipModel;
636 RelationshipModel = new CustomRelationshipModel ( SchemaClass, RelationshipHeaders, ui->ShowDerivedRelationships->isChecked() );
637 }
638
639 ui->RelationshipView->setModel ( RelationshipModel );
640 ui->RelationshipView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
641 ui->RelationshipView->setSelectionBehavior ( QAbstractItemView::SelectRows );
642}
643
645{
646 QStringList MethodHeaders
647 { "Method Name" };
648
649 if ( MethodModel == nullptr )
650 {
651 MethodModel = new CustomMethodModel ( SchemaClass, MethodHeaders, ui->ShowDerivedMethods->isChecked() );
652 }
653 else
654 {
655 delete MethodModel;
656 MethodModel = new CustomMethodModel ( SchemaClass, MethodHeaders, ui->ShowDerivedMethods->isChecked() );
657 }
658
659 ui->MethodsView->setModel ( MethodModel );
660 ui->MethodsView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
661 ui->MethodsView->setSelectionBehavior ( QAbstractItemView::SelectRows );
662}
663
665{
666 QStringList SuperClassHeaders
667 { "Class Name" };
668
669 if ( SuperClassModel == nullptr )
670 {
671 SuperClassModel = new CustomSuperClassModel ( SchemaClass, SuperClassHeaders, ui->ShowAllSuperClasses->isChecked() );
672 }
673 else
674 {
675 delete SuperClassModel;
676 SuperClassModel = new CustomSuperClassModel ( SchemaClass, SuperClassHeaders, ui->ShowAllSuperClasses->isChecked() );
677 }
678
679 ui->SuperClassView->setModel ( SuperClassModel );
680 ui->SuperClassView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
681 ui->SuperClassView->setSelectionBehavior ( QAbstractItemView::SelectRows );
682}
683
685{
686 QStringList SubClassHeaders
687 { "Class Name" };
688
689 if ( SubClassModel == nullptr )
690 {
691 SubClassModel = new CustomSubClassModel ( SchemaClass, SubClassHeaders );
692 }
693 else
694 {
695 delete SubClassModel;
696 SubClassModel = new CustomSubClassModel ( SchemaClass, SubClassHeaders );
697 }
698
699 ui->SubClassView->setModel ( SubClassModel );
700 ui->SubClassView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
701 ui->SubClassView->setSelectionBehavior ( QAbstractItemView::SelectRows );
702}
703
705{
706 if ( ContextMenuClass == nullptr )
707 {
708 ContextMenuClass = new QMenu ( this );
709
710 QAction * Add = new QAction ( tr ( "&Add" ), this );
711 Add->setShortcut ( tr ( "Ctrl+A" ) );
712 Add->setShortcutContext ( Qt::WidgetShortcut );
713 connect ( Add, SIGNAL ( triggered() ), this, SLOT ( AddNewSuperClass() ) );
714
715 QAction * Remove = new QAction ( tr ( "&Remove" ), this );
716 Remove->setShortcut ( tr ( "Ctrl+R" ) );
717 Remove->setShortcutContext ( Qt::WidgetShortcut );
718 connect ( Remove, SIGNAL ( triggered() ), this, SLOT ( RemoveSuperClass() ) );
719
720 ContextMenuClass->addAction ( Add );
721 ContextMenuClass->addAction ( Remove );
722 }
723
724 QModelIndex Index = ui->SuperClassView->currentIndex();
725
726 if ( Index.isValid() )
727 {
728 CurrentRow = SuperClassModel->getRowFromIndex ( Index );
729 ContextMenuClass->exec ( ui->SuperClassView->mapToGlobal ( pos ) );
730 }
731}
732
734{
735 if ( ContextMenuAttribute == nullptr )
736 {
737 ContextMenuAttribute = new QMenu ( this );
738
739 QAction * Add = new QAction ( tr ( "&Add" ), this );
740 Add->setShortcut ( tr ( "Ctrl+A" ) );
741 Add->setShortcutContext ( Qt::WidgetShortcut );
742 connect ( Add, SIGNAL ( triggered() ), this, SLOT ( AddNewAttribute() ) );
743
744 QAction * Remove = new QAction ( tr ( "&Remove" ), this );
745 Remove->setShortcut ( tr ( "Ctrl+R" ) );
746 Remove->setShortcutContext ( Qt::WidgetShortcut );
747 connect ( Remove, SIGNAL ( triggered() ), this, SLOT ( RemoveAttribute() ) );
748
749 ContextMenuAttribute->addAction ( Add );
750 ContextMenuAttribute->addAction ( Remove );
751 }
752
753 QModelIndex Index = ui->AttributeView->currentIndex();
754
755 if ( Index.isValid() )
756 {
757 CurrentRow = AttributeModel->getRowFromIndex ( Index );
758 ContextMenuAttribute->exec ( ui->AttributeView->mapToGlobal ( pos ) );
759 }
760}
761
763{
764 if ( ContextMenuRelationship == nullptr )
765 {
766 ContextMenuRelationship = new QMenu ( this );
767
768 QAction * Add = new QAction ( tr ( "&Add" ), this );
769 Add->setShortcut ( tr ( "Ctrl+A" ) );
770 Add->setShortcutContext ( Qt::WidgetShortcut );
771 connect ( Add, SIGNAL ( triggered() ), this, SLOT ( AddNewRelationship() ) );
772
773 QAction * Remove = new QAction ( tr ( "&Remove" ), this );
774 Remove->setShortcut ( tr ( "Ctrl+R" ) );
775 Remove->setShortcutContext ( Qt::WidgetShortcut );
776 connect ( Remove, SIGNAL ( triggered() ), this, SLOT ( RemoveRelationship() ) );
777
778 ContextMenuRelationship->addAction ( Add );
779 ContextMenuRelationship->addAction ( Remove );
780 }
781
782 QModelIndex Index = ui->RelationshipView->currentIndex();
783
784 if ( Index.isValid() )
785 {
786 CurrentRow = RelationshipModel->getRowFromIndex ( Index );
787 ContextMenuRelationship->exec ( ui->RelationshipView->mapToGlobal ( pos ) );
788 }
789}
790
792{
793 if ( ContextMenuMethod == nullptr )
794 {
795 ContextMenuMethod = new QMenu ( this );
796
797 QAction * Add = new QAction ( tr ( "&Add" ), this );
798 Add->setShortcut ( tr ( "Ctrl+A" ) );
799 Add->setShortcutContext ( Qt::WidgetShortcut );
800 connect ( Add, SIGNAL ( triggered() ), this, SLOT ( AddNewMethod() ) );
801
802 QAction * Remove = new QAction ( tr ( "&Remove" ), this );
803 Remove->setShortcut ( tr ( "Ctrl+R" ) );
804 Remove->setShortcutContext ( Qt::WidgetShortcut );
805 connect ( Remove, SIGNAL ( triggered() ), this, SLOT ( RemoveMethod() ) );
806
807 ContextMenuMethod->addAction ( Add );
808 ContextMenuMethod->addAction ( Remove );
809 }
810
811 QModelIndex Index = ui->MethodsView->currentIndex();
812
813 if ( Index.isValid() )
814 {
815 CurrentRow = MethodModel->getRowFromIndex ( Index );
816 ContextMenuMethod->exec ( ui->MethodsView->mapToGlobal ( pos ) );
817 }
818}
819
821{
822 auto createNewClass = [] (const std::string& className) -> bool {
823 if ( !KernelWrapper::GetInstance().IsActive() )
824 {
825 QMessageBox::warning (
826 0,
827 "Schema editor",
828 QString (
829 "There is no active schema set!\n\nPlease set a schema file as active and continue!" ) );
830
831 return false;
832 }
833
834 if ( !KernelWrapper::GetInstance().FindClass ( className ) )
835 {
837 "", false );
838 return true;
839 }
840 else
841 {
842 QMessageBox::warning ( 0, "Schema editor",
843 QString ( "Can not create class because class already exist !" ) );
844
845 return false;
846 }
847 };
848
849 bool ok;
850 QString text = QInputDialog::getText(nullptr, "Schema editor: create new class",
851 "New class name:", QLineEdit::Normal,
852 "NewOksClass", &ok);
853
854 if(ok && !text.isEmpty()) {
855 if(createNewClass(text.toStdString())) {
856 SchemaClassEditor * Editor = new SchemaClassEditor(KernelWrapper::GetInstance().FindClass(text.toStdString()));
857 Editor->show();
858 }
859 }
860 return text;
861}
862
863void dbse::SchemaClassEditor::launch(QString class_name) {
864 bool widgetFound=false;
865 dunedaq::oks::OksClass* class_info =
866 KernelWrapper::GetInstance().FindClass (class_name.toStdString());
867 for ( QWidget* widget : QApplication::allWidgets() ) {
868 SchemaClassEditor* editor = dynamic_cast<SchemaClassEditor *> (widget);
869 if (editor != nullptr) {
870 if ((editor->objectName()).compare(class_name) == 0 ) {
871 widget->raise();
872 widget->setVisible ( true );
873 widget->activateWindow();
874 widgetFound = true;
875 break;
876 }
877 }
878 }
879
880 if ( !widgetFound ) {
881 SchemaClassEditor* editor = new SchemaClassEditor (class_info);
882 editor->show();
883 }
884}
885
void PushRemoveSuperClassCommand(dunedaq::oks::OksClass *Class, std::string SuperClass)
void GetClassListString(QStringList &ClassListString) const
static KernelWrapper & GetInstance()
void PushSetAbstractClassCommand(dunedaq::oks::OksClass *Class, bool Value)
dunedaq::oks::OksClass * FindClass(std::string ClassName) const
void PushAddSuperClassCommand(dunedaq::oks::OksClass *Class, std::string SuperClass)
void ClassUpdated(QString ClassName)
void PushRemoveAttributeCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksAttribute *Attribute, 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 PushSetDescriptionClassCommand(dunedaq::oks::OksClass *Class, std::string Description)
void PushRemoveRelationship(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, 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 PushRemoveMethodCommand(dunedaq::oks::OksClass *Class, dunedaq::oks::OksMethod *Method, std::string name, std::string description)
void PushCreateClassCommand(std::string ClassName, std::string ClassDescription, bool Abstract)
void GetSchemaFiles(std::vector< std::string > &SchemaFiles)
void CustomMenuMethodView(QPoint pos)
void keyPressEvent(QKeyEvent *event)
void OpenRelationshipEditor(QModelIndex Index)
void ClassUpdated(QString className)
bool ShouldOpenAttributeEditor(QString Name)
Helper functions.
CustomRelationshipModel * RelationshipModel
bool ShouldOpenRelationshipEditor(QString Name)
CustomSuperClassModel * SuperClassModel
bool ShouldOpenMethodEditor(QString Name)
CustomMethodModel * MethodModel
static void move_class(dunedaq::oks::OksClass *schema_class, QWidget *widget)
void RemoveAttribute()
Remove Functions.
void CustomMenuRelationshipView(QPoint pos)
void ClassRemoved(QString className)
void OpenSuperClass(QModelIndex Index)
SchemaClassEditor(dunedaq::oks::OksClass *ClassInfo, QWidget *parent=nullptr)
static void launch(QString class_name)
dunedaq::oks::OksClass * SchemaClass
void CustomMenuClassView(QPoint pos)
void OpenMethodEditor(QModelIndex Index)
CustomAttributeModel * AttributeModel
void OpenSubClass(QModelIndex Index)
std::unique_ptr< dbse::Ui::SchemaClassEditor > ui
void OpenAttributeEditor(QModelIndex Index)
void OpenNewClassEditor(const QString &ClassName)
void CustomMenuAttributeView(QPoint pos)
Context Menu Functions.
CustomSubClassModel * SubClassModel
OKS attribute class.
bool get_is_multi_values() const noexcept
const std::string & get_type() const noexcept
Get attribute string type.
const std::string & get_range() const noexcept
Get attribute range.
const std::string & get_name() const noexcept
out stream operator
const std::string & get_init_value() const noexcept
const std::string & get_description() const noexcept
bool get_is_no_null() const noexcept
Format get_format() const noexcept
Get attribute format.
The OKS class.
Definition class.hpp:200
void set_file(OksFile *f, bool update_owner=true)
Move class to different file.
Definition class.cpp:286
const std::string & get_name() const noexcept
Definition class.hpp:363
OksFile * get_file() const noexcept
Definition class.hpp:338
const std::string & get_full_file_name() const
Definition file.hpp:523
OKS method class.
Definition method.hpp:153
const std::string & get_description() const noexcept
Definition method.hpp:214
const std::string & get_name() const noexcept
Definition method.hpp:196
bool get_is_exclusive() const noexcept
bool get_is_composite() const noexcept
bool get_is_dependent() const noexcept
const std::string & get_name() const noexcept
CardinalityConstraint get_high_cardinality_constraint() const noexcept
Get relationship high cardinality constraint.
const std::string & get_description() const noexcept
CardinalityConstraint get_low_cardinality_constraint() const noexcept
Get relationship low cardinality constraint.
const std::string & get_type() const noexcept