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

Generated by: LCOV version 2.0-1