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