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