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

Generated by: LCOV version 2.0-1