LCOV - code coverage report
Current view: top level - dbe/apps/SchemaEditor - SchemaClassEditor.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 539 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 45 0

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

Generated by: LCOV version 2.0-1