LCOV - code coverage report
Current view: top level - dbe/apps/SchemaEditor - SchemaMethodEditor.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 140 0
Test Date: 2026-07-12 15:23:06 Functions: 0.0 % 16 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/SchemaMethodEditor.cpp to apps/SchemaEditor/SchemaMethodEditor.cpp).
       5              : 
       6              : /// Including Qt
       7              : #include <QMessageBox>
       8              : /// Including Schema
       9              : #include "dbe/SchemaMethodEditor.hpp"
      10              : #include "dbe/SchemaMethodImplementationEditor.hpp"
      11              : #include "dbe/SchemaKernelWrapper.hpp"
      12              : /// Including auto-generated ui
      13              : #include "ui_SchemaMethodEditor.h"
      14              : 
      15              : using namespace dunedaq::oks;
      16              : 
      17            0 : dbse::SchemaMethodEditor::~SchemaMethodEditor() = default;
      18              : 
      19            0 : dbse::SchemaMethodEditor::SchemaMethodEditor ( OksClass * ClassInfo, OksMethod * Method,
      20            0 :                                                QWidget * parent )
      21              :   : QWidget ( parent ),
      22            0 :     ui ( new Ui::SchemaMethodEditor ),
      23            0 :     m_class ( ClassInfo ),
      24            0 :     m_method ( Method ),
      25            0 :     ImplementationModel ( nullptr ),
      26            0 :     UsedNew ( false )
      27              : {
      28            0 :   QWidget::setAttribute(Qt::WA_DeleteOnClose);
      29            0 :   m_writable = KernelWrapper::GetInstance().IsFileWritable(m_class->get_file()->get_full_file_name());
      30            0 :   ui->setupUi ( this );
      31            0 :   InitialSettings();
      32            0 :   BuildModels();
      33            0 :   SetController();
      34            0 : }
      35              : 
      36            0 : dbse::SchemaMethodEditor::SchemaMethodEditor ( OksClass * ClassInfo, QWidget * parent )
      37              :   : QWidget ( parent ),
      38            0 :     ui ( new Ui::SchemaMethodEditor ),
      39            0 :     m_class ( ClassInfo ),
      40            0 :     m_method ( nullptr ),
      41            0 :     ImplementationModel ( nullptr ),
      42            0 :     UsedNew ( true )
      43              : {
      44            0 :   QWidget::setAttribute(Qt::WA_DeleteOnClose);
      45            0 :   m_writable = KernelWrapper::GetInstance().IsFileWritable(m_class->get_file()->get_full_file_name());
      46            0 :   ui->setupUi ( this );
      47            0 :   InitialSettings();
      48            0 :   SetController();
      49            0 : }
      50              : 
      51            0 : void dbse::SchemaMethodEditor::SetController()
      52              : {
      53            0 :   connect ( ui->buttonBox, SIGNAL ( accepted() ), this, SLOT ( ProxySlot() ) );
      54            0 :   connect ( ui->buttonBox, SIGNAL ( rejected() ), this, SLOT ( close() ) );
      55            0 :   connect ( ui->AddButton, SIGNAL ( clicked() ), this,
      56              :             SLOT ( AddNewMethodImplementation() ) );
      57            0 :   connect ( ui->ImplementationsView, SIGNAL ( doubleClicked ( QModelIndex ) ), this,
      58              :             SLOT ( OpenMethodImplementationEditor ( QModelIndex ) ) );
      59            0 :   connect ( &KernelWrapper::GetInstance(), SIGNAL ( ClassUpdated ( QString ) ), this,
      60              :             SLOT ( ClassUpdated ( QString ) ) );
      61            0 : }
      62              : 
      63            0 : void dbse::SchemaMethodEditor::ClassUpdated( QString ClassName)
      64              : {
      65            0 :     if(!UsedNew && ClassName.toStdString() == m_class->get_name()) {
      66            0 :         if(m_class->find_direct_method(m_method->get_name()) != nullptr) {
      67            0 :             FillInfo();
      68            0 :             BuildModels();
      69              :         } else {
      70            0 :             QWidget::close();
      71              :         }
      72              :     }
      73            0 : }
      74              : 
      75            0 : void dbse::SchemaMethodEditor::FillInfo()
      76              : {
      77            0 :   auto name = QString::fromStdString (
      78            0 :     m_class->get_name() + "::" + m_method->get_name() );
      79            0 :   setObjectName ( name );
      80            0 :   setWindowTitle ( QString ( "Method Editor : %1" ).arg ( name ) );
      81            0 :   ui->MethodName->setText ( QString::fromStdString ( m_method->get_name() ) );
      82            0 :   ui->DescriptionTextBox->setPlainText (
      83            0 :     QString::fromStdString ( m_method->get_description() ) );
      84            0 : }
      85              : 
      86            0 : void dbse::SchemaMethodEditor::InitialSettings()
      87              : {
      88            0 :   if ( UsedNew )
      89              :   {
      90            0 :     setWindowTitle ( "New Method" );
      91            0 :     setObjectName ( "NEW" );
      92            0 :     ui->AddButton->setEnabled ( true );
      93              :   }
      94              :   else
      95              :   {
      96            0 :     if (!m_writable) {
      97            0 :       ui->MethodName->setEnabled (false);
      98            0 :       ui->DescriptionTextBox->setEnabled (false);
      99            0 :       ui->AddButton->setEnabled (false);
     100            0 :       ui->ImplementationsView->setEnabled (false);
     101              :     }
     102            0 :     FillInfo();
     103              :   }
     104            0 : }
     105              : 
     106            0 : void dbse::SchemaMethodEditor::ParseToSave()
     107              : {
     108            0 :   bool changed = false;
     109            0 :   std::string method_name = ui->MethodName->text().toStdString();
     110            0 :   std::string method_description = ui->DescriptionTextBox->toPlainText().toStdString();
     111              : 
     112            0 :   if ( method_name != m_method->get_name() )
     113              :   {
     114            0 :     KernelWrapper::GetInstance().PushSetNameMethodCommand ( m_class, m_method, method_name );
     115            0 :     changed = true;
     116              :   }
     117              : 
     118            0 :   if ( method_description != m_method->get_description() )
     119              :   {
     120            0 :     KernelWrapper::GetInstance().PushSetDescriptionMethodCommand ( m_class,
     121              :                                                                    m_method,
     122              :                                                                    method_description );
     123            0 :     changed = true;
     124              :   }
     125              : 
     126            0 :   if ( changed )
     127              :   {
     128            0 :     emit RebuildModel();
     129              :   }
     130              : 
     131            0 :   close();
     132            0 : }
     133              : 
     134            0 : bool dbse::SchemaMethodEditor::create() {
     135            0 :   std::string method_name = ui->MethodName->text().toStdString();
     136            0 :   if (method_name.empty()) {
     137              :     return false;
     138              :   }
     139            0 :   std::string method_description = ui->DescriptionTextBox->toPlainText().toStdString();
     140            0 :   KernelWrapper::GetInstance().PushAddMethodCommand ( m_class, method_name,
     141              :                                                       method_description );
     142            0 :   emit RebuildModel();
     143            0 :   UsedNew = false;
     144            0 :   return true;
     145            0 : }
     146            0 : void dbse::SchemaMethodEditor::ParseToCreate()
     147              : {
     148            0 :   create();
     149            0 :   close();
     150            0 : }
     151              : 
     152            0 : void dbse::SchemaMethodEditor::BuildModels()
     153              : {
     154            0 :   QStringList MethodHeaders { "Language", "Prototype" };
     155              : 
     156            0 :   if ( ImplementationModel != nullptr ) {
     157            0 :     delete ImplementationModel;
     158              :   }
     159            0 :   ImplementationModel = new CustomMethodImplementationModel ( m_method, MethodHeaders );
     160              : 
     161            0 :   ui->ImplementationsView->setModel ( ImplementationModel );
     162            0 :   ui->ImplementationsView->horizontalHeader()->setSectionResizeMode ( QHeaderView::ResizeToContents );
     163            0 : }
     164              : 
     165            0 : bool dbse::SchemaMethodEditor::ShouldOpenMethodImplementationEditor ( QString Name )
     166              : {
     167            0 :   bool WidgetFound = false;
     168              : 
     169            0 :   for ( QWidget * Editor : QApplication::allWidgets() )
     170              :   {
     171            0 :     SchemaMethodImplementationEditor * Widget =
     172            0 :       dynamic_cast<SchemaMethodImplementationEditor *> ( Editor );
     173              : 
     174            0 :     if ( Widget != nullptr )
     175              :     {
     176            0 :       if ( ( Widget->objectName() ).compare ( Name ) == 0 )
     177              :       {
     178            0 :         Widget->raise();
     179            0 :         Widget->setVisible ( true );
     180            0 :         Widget->activateWindow();
     181              :         WidgetFound = true;
     182              :       }
     183              :     }
     184            0 :   }
     185              : 
     186            0 :   return !WidgetFound;
     187              : }
     188              : 
     189            0 : void dbse::SchemaMethodEditor::ProxySlot()
     190              : {
     191            0 :   if ( UsedNew )
     192              :   {
     193            0 :     ParseToCreate();
     194              :   }
     195              :   else
     196              :   {
     197            0 :     ParseToSave();
     198              :   }
     199            0 : }
     200              : 
     201            0 : void dbse::SchemaMethodEditor::AddNewMethodImplementation()
     202              : {
     203            0 :   if (UsedNew) {
     204            0 :     if (create()) {
     205            0 :       m_method = m_class->find_method(ui->MethodName->text().toStdString());
     206              :     }
     207              :     else {
     208            0 :       QMessageBox::question (
     209            0 :         0, tr ( "SchemaEditor" ),
     210            0 :         tr ( "You must set the method name before you can set an implementation" ),
     211              :              QMessageBox::Ok );
     212            0 :       return;
     213              :     }
     214              :   }
     215            0 :   SchemaMethodImplementationEditor * Editor = new SchemaMethodImplementationEditor (
     216            0 :     m_class, m_method );
     217            0 :   connect ( Editor, SIGNAL ( RebuildModel() ), this,
     218              :             SLOT ( BuildModelImplementationSlot() ) );
     219            0 :   Editor->show();
     220              : }
     221              : 
     222            0 : void dbse::SchemaMethodEditor::OpenMethodImplementationEditor ( QModelIndex Index )
     223              : {
     224            0 :   QStringList Row = ImplementationModel->getRowFromIndex ( Index );
     225            0 :   if ( !Row.isEmpty() ) {
     226            0 :     QString name = QString::fromStdString(
     227            0 :       m_class->get_name()+m_method->get_name()).append(Row.at ( 0 ));
     228            0 :     if (ShouldOpenMethodImplementationEditor ( name )) {
     229            0 :       SchemaMethodImplementationEditor * Editor = new SchemaMethodImplementationEditor (
     230            0 :         m_class, m_method, m_method->find_implementation ( Row.at ( 0 ).toStdString() ) );
     231            0 :       Editor->show();
     232              :     }
     233            0 :   }
     234            0 : }
     235              : 
     236            0 : void dbse::SchemaMethodEditor::BuildModelImplementationSlot()
     237              : {
     238            0 :     BuildModels();
     239            0 : }
        

Generated by: LCOV version 2.0-1