LCOV - code coverage report
Current view: top level - dbe/apps/SchemaEditor - SchemaAttributeEditor.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 197 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 12 0

            Line data    Source code
       1              : /// Including schema
       2              : #include "dbe/SchemaAttributeEditor.hpp"
       3              : #include "dbe/SchemaKernelWrapper.hpp"
       4              : /// Including auto-generated ui
       5              : #include "ui_SchemaAttributeEditor.h"
       6              : 
       7              : using namespace dunedaq::oks;
       8              : 
       9            0 : dbse::SchemaAttributeEditor::SchemaAttributeEditor ( OksClass * ClassInfo,
      10              :                                                      OksAttribute * AttributeData,
      11            0 :                                                      QWidget * parent )
      12              :   : QWidget ( parent ),
      13            0 :     ui ( new Ui::SchemaAttributeEditor ),
      14            0 :     SchemaClass ( ClassInfo ),
      15            0 :     SchemaAttribute ( AttributeData ),
      16            0 :     UsedNew ( false ),
      17            0 :     m_writable(KernelWrapper::GetInstance().IsFileWritable(
      18            0 :                  SchemaClass->get_file()->get_full_file_name()))
      19              : {
      20            0 :   QWidget::setAttribute(Qt::WA_DeleteOnClose);
      21            0 :   ui->setupUi ( this );
      22            0 :   InitialSettings();
      23            0 :   SetController();
      24            0 : }
      25              : 
      26            0 : dbse::SchemaAttributeEditor::SchemaAttributeEditor ( OksClass * ClassInfo,
      27            0 :                                                      QWidget * parent )
      28              :   : QWidget ( parent ),
      29            0 :     ui ( new Ui::SchemaAttributeEditor ),
      30            0 :     SchemaClass ( ClassInfo ),
      31            0 :     SchemaAttribute ( nullptr ),
      32            0 :     UsedNew ( true ),
      33            0 :     m_writable(KernelWrapper::GetInstance().IsFileWritable(
      34            0 :                  SchemaClass->get_file()->get_full_file_name()))
      35              : {
      36            0 :   QWidget::setAttribute(Qt::WA_DeleteOnClose);
      37            0 :   ui->setupUi ( this );
      38            0 :   InitialSettings();
      39            0 :   SetController();
      40            0 : }
      41              : 
      42            0 : dbse::SchemaAttributeEditor::~SchemaAttributeEditor() = default;
      43              : 
      44            0 : void dbse::SchemaAttributeEditor::FillInfo()
      45              : {
      46            0 :   auto name = QString::fromStdString(SchemaClass->get_name() + "::" +
      47            0 :                                      SchemaAttribute->get_name());
      48            0 :     setWindowTitle (name);
      49            0 :     setObjectName (name);
      50            0 :     ui->AttributeNameLineEdit->setText ( QString::fromStdString (
      51            0 :                                            SchemaAttribute->get_name() ) );
      52            0 :     ui->AttributeTypeComboBox->setCurrentIndex (
      53            0 :       ui->AttributeTypeComboBox->findData ( QString::fromStdString (
      54            0 :                                               SchemaAttribute->get_type() ),
      55              :                                             Qt::DisplayRole ) );
      56              : 
      57            0 :     if ( SchemaAttribute->get_is_multi_values() )
      58            0 :       ui->AttributeIsMultivariable->setCurrentIndex (
      59              :         0 );
      60              :     else
      61              :     {
      62            0 :       ui->AttributeIsMultivariable->setCurrentIndex ( 1 );
      63              :     }
      64              : 
      65            0 :     if ( SchemaAttribute->get_is_no_null() )
      66              :     {
      67            0 :       ui->AttributeIsNotNull->setCurrentIndex ( 0 );
      68              :     }
      69              :     else
      70              :     {
      71            0 :       ui->AttributeIsNotNull->setCurrentIndex ( 1 );
      72              :     }
      73              : 
      74            0 :     ui->AttributeDescriptionTextBox->setPlainText (
      75            0 :       QString::fromStdString ( SchemaAttribute->get_description() ) );
      76            0 :     ui->AttributeRangeLineEdit->setText ( QString::fromStdString (
      77            0 :                                             SchemaAttribute->get_range() ) );
      78            0 :     ui->AttributeInitialValue->setText (
      79            0 :       QString::fromStdString ( SchemaAttribute->get_init_value() ) );
      80              : 
      81            0 :     int Index = ui->AttributeTypeComboBox->currentIndex();
      82              : 
      83            0 :     if ( Index == 0 || Index >= 9 )
      84              :     {
      85            0 :       ui->FormatLayout->setEnabled ( false );
      86            0 :       ui->FormatLabel->hide();
      87            0 :       ui->AttributeFormatComboBox->hide();
      88              :     }
      89              :     else
      90              :     {
      91            0 :       if (m_writable) {
      92            0 :         ui->FormatLayout->setEnabled ( true );
      93              :       }
      94            0 :       ui->FormatLabel->show();
      95            0 :       ui->AttributeFormatComboBox->show();
      96              : 
      97            0 :       if ( SchemaAttribute->get_format() == OksAttribute::Dec )
      98            0 :         ui->AttributeFormatComboBox->setCurrentIndex (
      99              :           0 );
     100            0 :       else if ( SchemaAttribute->get_format() == OksAttribute::Oct )
     101            0 :         ui->AttributeFormatComboBox->setCurrentIndex (
     102              :           1 );
     103              :       else
     104              :       {
     105            0 :         ui->AttributeFormatComboBox->setCurrentIndex ( 2 );
     106              :       }
     107              :     }
     108            0 : }
     109              : 
     110            0 : void dbse::SchemaAttributeEditor::keyPressEvent(QKeyEvent* event) {
     111            0 :   if (event->key() == Qt::Key_Escape) {
     112            0 :     close();
     113              :   }
     114            0 :   QWidget::keyPressEvent(event);
     115            0 : }
     116              : 
     117            0 : void dbse::SchemaAttributeEditor::InitialSettings()
     118              : {
     119            0 :   QStringList Items
     120              :   {
     121              :     "bool", "s8", "u8", "s16", "u16", "s32", "u32", "s64", "u64", "float", "double", "date",
     122            0 :     "time", "string", "enum", "class" };
     123            0 :   ui->AttributeTypeComboBox->addItems ( Items );
     124            0 :   auto name = SchemaClass->get_name() + "::";
     125            0 :   setWindowTitle ( QString::fromStdString ( name + " New Attribute" ) );
     126            0 :   setObjectName ( QString::fromStdString(name) );
     127              : 
     128            0 :   if (!m_writable) {
     129            0 :     ui->AttributeTypeComboBox->setEnabled(false);
     130            0 :     ui->AttributeIsMultivariable->setEnabled(false);
     131            0 :     ui->AttributeIsNotNull->setEnabled(false);
     132            0 :     ui->AttributeRangeLineEdit->setEnabled(false);
     133            0 :     ui->AttributeInitialValue->setEnabled(false);
     134              : 
     135            0 :     ui->AttributeDescriptionTextBox->setReadOnly(true);
     136              :   }
     137              : 
     138            0 :   if ( !UsedNew )
     139              :   {
     140            0 :       FillInfo();
     141              :   }
     142            0 : }
     143              : 
     144            0 : void dbse::SchemaAttributeEditor::SetController()
     145              : {
     146            0 :   connect ( ui->AttributeTypeComboBox, SIGNAL ( currentIndexChanged ( int ) ), this,
     147              :             SLOT ( ToggleFormat ( int ) ) );
     148            0 :   connect ( ui->buttonBox, SIGNAL ( accepted() ), this, SLOT ( ProxySlot() ) );
     149            0 :   connect ( ui->buttonBox, SIGNAL ( rejected() ), this, SLOT ( close() ) );
     150            0 :   connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassUpdated ( QString ) ), this,
     151              :             SLOT ( ClassUpdated ( QString ) ) );
     152            0 : }
     153              : 
     154            0 : void dbse::SchemaAttributeEditor::ClassUpdated( QString ClassName)
     155              : {
     156            0 :     if(!UsedNew && ClassName.toStdString() == SchemaClass->get_name()) {
     157            0 :         if(SchemaClass->find_direct_attribute(SchemaAttribute->get_name()) != nullptr) {
     158            0 :             FillInfo();
     159              :         } else {
     160            0 :             QWidget::close();
     161              :         }
     162              :     }
     163            0 : }
     164              : 
     165            0 : void dbse::SchemaAttributeEditor::ParseToSave()
     166              : {
     167            0 :   bool Changed = false;
     168            0 :   std::string AttributeName = ui->AttributeNameLineEdit->text().toStdString();
     169            0 :   std::string AttributeType = ui->AttributeTypeComboBox->currentText().toStdString();
     170            0 :   char AttributeFormatChar = ( ui->AttributeFormatComboBox->currentText().toStdString() ) [0];
     171              : 
     172            0 :   OksAttribute::Format AttributeFormat;
     173              : 
     174            0 :   switch ( AttributeFormatChar )
     175              :   {
     176              :   case 'D':
     177              :     AttributeFormat = OksAttribute::Format::Dec;
     178              :     break;
     179              : 
     180            0 :   case 'O':
     181            0 :     AttributeFormat = OksAttribute::Format::Oct;
     182            0 :     break;
     183              : 
     184            0 :   case 'H':
     185            0 :     AttributeFormat = OksAttribute::Format::Hex;
     186            0 :     break;
     187              : 
     188              :   default:
     189              :     AttributeFormat = OksAttribute::Format::Dec;
     190              :     break;
     191              :   }
     192              : 
     193              :   /// Making sure we dont get anything weird
     194            0 :   int Index = ui->AttributeTypeComboBox->currentIndex();
     195              : 
     196            0 :   if ( Index == 0 || Index >= 9 )
     197              :   {
     198            0 :     AttributeFormat = OksAttribute::Format::Dec;
     199              :   }
     200              : 
     201            0 :   bool IsMultivariable = false;
     202              : 
     203            0 :   switch ( ui->AttributeIsMultivariable->currentIndex() )
     204              :   {
     205              :   case 0:
     206              :     IsMultivariable = true;
     207              :     break;
     208              : 
     209              :   case 1:
     210            0 :     IsMultivariable = false;
     211              :     break;
     212              : 
     213              :   default:
     214            0 :     IsMultivariable = false;
     215              :     break;
     216              :   }
     217              : 
     218            0 :   bool IsNotNull = false;
     219              : 
     220            0 :   switch ( ui->AttributeIsNotNull->currentIndex() )
     221              :   {
     222              :   case 0:
     223              :     IsNotNull = true;
     224              :     break;
     225              : 
     226              :   case 1:
     227            0 :     IsNotNull = false;
     228              :     break;
     229              : 
     230              :   default:
     231            0 :     IsNotNull = false;
     232              :     break;
     233              :   }
     234              : 
     235            0 :   std::string AttributeDescription =
     236            0 :     ui->AttributeDescriptionTextBox->toPlainText().toStdString();
     237            0 :   std::string AttributeRange = ui->AttributeRangeLineEdit->text().toStdString();
     238            0 :   std::string AttributeInitial = ui->AttributeInitialValue->text().toStdString();
     239              : 
     240            0 :   if ( AttributeName != SchemaAttribute->get_name() )
     241              :   {
     242            0 :     KernelWrapper::GetInstance().PushSetAttributeNameCommand ( SchemaClass, SchemaAttribute, AttributeName );
     243            0 :     Changed = true;
     244              :   }
     245              : 
     246            0 :   if ( AttributeType != SchemaAttribute->get_type() )
     247              :   {
     248            0 :     KernelWrapper::GetInstance().PushSetAttributeTypeCommand ( SchemaClass, SchemaAttribute, AttributeType );
     249            0 :     Changed = true;
     250              :   }
     251              : 
     252            0 :   if ( AttributeFormat != SchemaAttribute->get_format() )
     253              :   {
     254            0 :     KernelWrapper::GetInstance().PushSetAttributeFormatCommand ( SchemaClass,
     255              :                                                                  SchemaAttribute,
     256              :                                                                  AttributeFormat );
     257              :     Changed = true;
     258              :   }
     259              : 
     260            0 :   if ( IsMultivariable != SchemaAttribute->get_is_multi_values() )
     261              :   {
     262            0 :     KernelWrapper::GetInstance().PushSetAttributeMultiCommand ( SchemaClass,
     263              :                                                                 SchemaAttribute,
     264              :                                                                 IsMultivariable );
     265              :     Changed = true;
     266              :   }
     267              : 
     268            0 :   if ( IsNotNull != SchemaAttribute->get_is_no_null() )
     269              :   {
     270            0 :     KernelWrapper::GetInstance().PushSetAttributeIsNullCommand ( SchemaClass, SchemaAttribute, IsNotNull );
     271              :     Changed = true;
     272              :   }
     273              : 
     274            0 :   if ( AttributeDescription != SchemaAttribute->get_description() )
     275              :   {
     276            0 :     KernelWrapper::GetInstance().PushSetAttributeDescriptionCommand ( SchemaClass,
     277              :                                                                       SchemaAttribute,
     278              :                                                                       AttributeDescription );
     279            0 :     Changed = true;
     280              :   }
     281              : 
     282            0 :   if ( AttributeRange != SchemaAttribute->get_range() )
     283              :   {
     284            0 :     KernelWrapper::GetInstance().PushSetAttributeRangeCommand ( SchemaClass,
     285              :                                                                 SchemaAttribute,
     286              :                                                                 AttributeRange );
     287            0 :     Changed = true;
     288              :   }
     289              : 
     290            0 :   if ( AttributeInitial != SchemaAttribute->get_init_value() )
     291              :   {
     292            0 :     KernelWrapper::GetInstance().PushSetAttributeInitialValuesCommand ( SchemaClass,
     293              :                                                                         SchemaAttribute,
     294              :                                                                         AttributeInitial );
     295            0 :     Changed = true;
     296              :   }
     297              : 
     298            0 :   if ( Changed )
     299              :   {
     300            0 :     emit RebuildModel();
     301              :   }
     302              : 
     303            0 :   close();
     304            0 : }
     305              : 
     306            0 : void dbse::SchemaAttributeEditor::ParseToCreate()
     307              : {
     308            0 :   std::string AttributeName = ui->AttributeNameLineEdit->text().toStdString();
     309            0 :   std::string AttributeType = ui->AttributeTypeComboBox->currentText().toStdString();
     310            0 :   char AttributeFormatChar = ( ui->AttributeFormatComboBox->currentText().toStdString() ) [0];
     311              : 
     312            0 :   OksAttribute::Format AttributeFormat;
     313              : 
     314            0 :   switch ( AttributeFormatChar )
     315              :   {
     316              :   case 'D':
     317              :     AttributeFormat = OksAttribute::Format::Dec;
     318              :     break;
     319              : 
     320            0 :   case 'O':
     321            0 :     AttributeFormat = OksAttribute::Format::Oct;
     322            0 :     break;
     323              : 
     324            0 :   case 'H':
     325            0 :     AttributeFormat = OksAttribute::Format::Hex;
     326            0 :     break;
     327              : 
     328              :   default:
     329              :     AttributeFormat = OksAttribute::Format::Dec;
     330              :     break;
     331              :   }
     332              : 
     333              :   /// Making sure we dont get anything weird
     334            0 :   int Index = ui->AttributeTypeComboBox->currentIndex();
     335              : 
     336            0 :   if ( Index == 0 || Index >= 9 )
     337              :   {
     338            0 :     AttributeFormat = OksAttribute::Format::Dec;
     339              :   }
     340              : 
     341            0 :   bool IsMultivariable = false;
     342              : 
     343            0 :   switch ( ui->AttributeIsMultivariable->currentIndex() )
     344              :   {
     345              :   case 0:
     346              :     IsMultivariable = true;
     347              :     break;
     348              : 
     349              :   case 1:
     350            0 :     IsMultivariable = false;
     351              :     break;
     352              : 
     353              :   default:
     354            0 :     IsMultivariable = false;
     355              :     break;
     356              :   }
     357              : 
     358            0 :   bool IsNotNull = false;
     359              : 
     360            0 :   switch ( ui->AttributeIsNotNull->currentIndex() )
     361              :   {
     362              :   case 0:
     363              :     IsNotNull = true;
     364              :     break;
     365              : 
     366              :   case 1:
     367            0 :     IsNotNull = false;
     368              :     break;
     369              : 
     370              :   default:
     371            0 :     IsNotNull = false;
     372              :     break;
     373              :   }
     374              : 
     375            0 :   std::string AttributeDescription =
     376            0 :     ui->AttributeDescriptionTextBox->toPlainText().toStdString();
     377            0 :   std::string AttributeRange = ui->AttributeRangeLineEdit->text().toStdString();
     378            0 :   std::string AttributeInitial = ui->AttributeInitialValue->text().toStdString();
     379              : 
     380              :   /// Creating attribute and updating
     381            0 :   KernelWrapper::GetInstance().PushAddAttributeCommand ( SchemaClass, AttributeName,
     382              :                                                          AttributeType, IsMultivariable,
     383              :                                                          AttributeRange, AttributeInitial,
     384              :                                                          AttributeDescription, IsNotNull,
     385              :                                                          AttributeFormat );
     386            0 :   emit RebuildModel();
     387            0 :   close();
     388            0 : }
     389              : 
     390            0 : void dbse::SchemaAttributeEditor::ProxySlot()
     391              : {
     392            0 :   if ( UsedNew )
     393              :   {
     394            0 :     ParseToCreate();
     395              :   }
     396              :   else
     397              :   {
     398            0 :     ParseToSave();
     399              :   }
     400            0 : }
     401              : 
     402            0 : void dbse::SchemaAttributeEditor::ToggleFormat ( int )
     403              : {
     404            0 :   int Index = ui->AttributeTypeComboBox->currentIndex();
     405              : 
     406            0 :   if ( Index == 0 || Index >= 9 )
     407              :   {
     408            0 :     ui->FormatLayout->setEnabled ( false );
     409            0 :     ui->FormatLabel->hide();
     410            0 :     ui->AttributeFormatComboBox->hide();
     411              :   }
     412              :   else
     413              :   {
     414            0 :     ui->FormatLayout->setEnabled ( true );
     415            0 :     ui->FormatLabel->show();
     416            0 :     ui->AttributeFormatComboBox->show();
     417              :   }
     418            0 : }
        

Generated by: LCOV version 2.0-1