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

Generated by: LCOV version 2.0-1