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: 2025-12-21 13:07:08 Functions: 0.0 % 16 0

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

Generated by: LCOV version 2.0-1