LCOV - code coverage report
Current view: top level - dbe/apps/SchemaEditor - SchemaFileInfo.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 421 0
Test Date: 2026-02-16 10:18:04 Functions: 0.0 % 30 0

            Line data    Source code
       1              : 
       2              : #include "dbe/SchemaClassEditor.hpp"
       3              : #include "dbe/SchemaFileInfo.hpp"
       4              : #include "dbe/SchemaKernelWrapper.hpp"
       5              : #include "dbe/SchemaStyle.hpp"
       6              : #include "oks/class.hpp"
       7              : #include "oks/kernel.hpp"  // for CanNotSetActiveFile exception
       8              : #include "ui_SchemaFileInfo.h"
       9              : 
      10              : #include <QBrush>
      11              : #include <QColor>
      12              : #include <QFileDialog>
      13              : #include <QMessageBox>
      14              : #include <QPushButton>
      15              : #include <QString>
      16              : #include <QDialogButtonBox>
      17              : 
      18              : namespace dbse {
      19              : 
      20            0 : SchemaFileInfo::SchemaFileInfo(std::string filename, QWidget* /*parent*/)
      21            0 :   : m_ui(new Ui::SchemaFileInfo), m_filename(filename),
      22            0 :     m_include_menu(nullptr), m_class_menu(nullptr) {
      23              : 
      24            0 :   QWidget::setAttribute(Qt::WA_DeleteOnClose);
      25              : 
      26            0 :   m_ui->setupUi(this);
      27              :   // m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok);
      28            0 :   m_ui->missing_button->hide();
      29              :   // m_ui->class_list->setDragEnabled ( true );
      30              :   // m_ui->class_list->setAcceptDrops ( true );
      31            0 :   setObjectName(QString::fromStdString(filename));
      32            0 :   auto sp = filename.find_last_of('/');
      33            0 :   if (sp == std::string::npos) {
      34              :     sp = 0;
      35              :   }
      36              :   else {
      37            0 :     sp++;
      38              :   }
      39            0 :   setWindowTitle(
      40            0 :     QString("Schema File:  %1").arg(QString::fromStdString(filename.substr(sp))));
      41              : 
      42            0 :   m_ui->label->setText(QString::fromStdString(filename));
      43            0 :   if (!KernelWrapper::GetInstance().IsFileWritable ( m_filename )) {
      44            0 :     QPalette pal;
      45            0 :     pal.setColor(QPalette::Active, QPalette::WindowText,SchemaStyle::get_color("foreground", "readonly"));
      46            0 :     m_ui->label->setPalette(pal);
      47              : //    m_ui->label->setStyleSheet("color:rgb(128,0,0);");
      48            0 :   }
      49            0 :   show_status();
      50              : 
      51              : 
      52            0 :   QString DUNEDAQ_DB_PATH = getenv ( "DUNEDAQ_DB_PATH" );
      53            0 :   m_path_list = DUNEDAQ_DB_PATH.split (QLatin1Char(':'), Qt::SkipEmptyParts );
      54            0 :   for ( QString & path : m_path_list ) {
      55            0 :     if ( !path.endsWith ( "/" ) ) {
      56            0 :       path.append ( "/" );
      57              :     }
      58            0 :     m_path_urls.append(QUrl::fromLocalFile(path));
      59              :   }
      60              : 
      61            0 :   get_includes();
      62              : 
      63            0 :   m_ui->textBrowser->hide();
      64              : 
      65            0 :   update_class_list();
      66              : 
      67            0 :   m_ui->include_list->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
      68            0 :   m_ui->class_list->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
      69            0 :   connect (m_ui->include_list, SIGNAL (itemActivated(QListWidgetItem*)),
      70              :            this, SLOT (show_file_info(QListWidgetItem*)) );
      71            0 :   connect (m_ui->include_list, SIGNAL (customContextMenuRequested(QPoint)),
      72              :            this, SLOT (activate_include_context_menu(QPoint)));
      73              : 
      74              : 
      75            0 :   if (KernelWrapper::GetInstance().IsFileWritable ( m_filename )) {
      76            0 :     connect (m_ui->active_button, SIGNAL(pressed()), this, SLOT(set_active()));
      77            0 :     connect (m_ui->add_button, SIGNAL(pressed()), this, SLOT(add_include()));
      78            0 :     connect (m_ui->missing_button, SIGNAL (pressed()), this, SLOT(add_missing_includes()));
      79            0 :     connect (&KernelWrapper::GetInstance(), SIGNAL (ClassUpdated(QString)),
      80              :              this, SLOT(class_updated(QString)));
      81            0 :     connect (m_ui->class_list, SIGNAL (customContextMenuRequested(QPoint)),
      82              :              this, SLOT (activate_class_context_menu(QPoint)));
      83              :   }
      84              :   else {
      85            0 :     m_ui->add_button->setEnabled(false);
      86            0 :     m_ui->active_button->setEnabled(false);
      87            0 :     m_ui->save_button->setEnabled(false);
      88              :   }
      89            0 :   connect (m_ui->save_button, SIGNAL(pressed()), this, SLOT(save_schema()));
      90            0 :   connect (m_ui->close_button, SIGNAL(pressed()), this, SLOT(close()));
      91            0 :   connect (&KernelWrapper::GetInstance(), SIGNAL (active_updated()),
      92              :            this, SLOT(show_status()));
      93              : 
      94            0 :   connect (m_ui->class_list, SIGNAL (itemActivated(QListWidgetItem*)),
      95              :            this, SLOT (launch_class_editor(QListWidgetItem*)));
      96            0 : }
      97              : 
      98            0 : void SchemaFileInfo::get_includes() {
      99            0 :   m_ui->include_list->clear();
     100            0 :   m_all_includes.clear();
     101            0 :   KernelWrapper::GetInstance().get_all_includes(m_filename, m_all_includes);
     102              : 
     103            0 :   std::set<std::string> direct_includes;
     104            0 :   KernelWrapper::GetInstance().get_direct_includes(m_filename, direct_includes);
     105              : 
     106            0 :   for (auto inc: m_all_includes) {
     107            0 :     auto file = prune_path(inc);
     108            0 :     auto item = new QListWidgetItem(QString::fromStdString(file));
     109            0 :     item->setToolTip(QString::fromStdString(inc));
     110            0 :     m_ui->include_list->addItem(item);
     111            0 :     if (!direct_includes.contains(file)) {
     112            0 :       item->setForeground(QBrush(SchemaStyle::get_color("foreground", "inherited")));
     113              :     }
     114            0 :     else if (!KernelWrapper::GetInstance().IsFileWritable (inc)) {
     115            0 :       item->setForeground(QBrush(SchemaStyle::get_color("foreground", "readonly")));
     116            0 :       item->setBackground(QBrush(SchemaStyle::get_color("background", "readonly")));
     117              :     }
     118              :     else {
     119            0 :       item->setForeground(QBrush(SchemaStyle::get_color("foreground", "default")));
     120            0 :       item->setBackground(QBrush(SchemaStyle::get_color("background", "default")));
     121              :     }
     122            0 :   }
     123            0 :   m_ui->include_list->update();
     124            0 : }
     125              : 
     126            0 : bool SchemaFileInfo::check_relationships(dunedaq::oks::OksClass* cls) {
     127            0 :   bool ok = true;
     128            0 :   auto relationships = cls->direct_relationships();
     129            0 :   if (relationships != nullptr) {
     130            0 :     for (auto rel: *relationships) {
     131            0 :       auto rel_class = rel->get_class_type();
     132            0 :       if (rel_class == nullptr) {
     133            0 :         QString warning = "<b>Warning</b> class <i>"
     134            0 :           + QString::fromStdString(cls->get_name())
     135            0 :           + "</i> has relationship "
     136            0 :           + QString::fromStdString(rel->get_name())
     137            0 :           + " referring to class <i>"
     138            0 :           + QString::fromStdString(rel->get_type())
     139            0 :           + "</i> which is not loaded<br>";
     140            0 :         m_ui->textBrowser->insertHtml(warning);
     141            0 :         m_ui->textBrowser->show();
     142            0 :         ok = false;
     143            0 :         continue;
     144            0 :       }
     145            0 :       auto file = rel_class->get_file()->get_full_file_name();
     146            0 :       if (file != m_filename && !m_all_includes.contains(file)) {
     147            0 :         m_missing_includes.insert(file);
     148            0 :         QString warning = "<b>Warning</b> class <i>"
     149            0 :           + QString::fromStdString(cls->get_name())
     150            0 :           + "</i> has relationship "
     151            0 :           + QString::fromStdString(rel->get_name())
     152            0 :           + " referring to class <i>"
     153            0 :           + QString::fromStdString(rel->get_class_type()->get_name())
     154            0 :           + "</i> from " + QString::fromStdString(file)
     155            0 :           + " which is not included<br>";
     156            0 :         m_ui->textBrowser->insertHtml(warning);
     157            0 :         m_ui->textBrowser->show();
     158            0 :         ok = false;
     159            0 :       }
     160            0 :     }
     161              :   }
     162            0 :   return ok;
     163              : }
     164              : 
     165            0 : bool SchemaFileInfo::check_superclasses(dunedaq::oks::OksClass* cls) {
     166            0 :   bool ok = true;
     167            0 :   auto super_classes = cls->direct_super_classes();
     168            0 :   if (super_classes != nullptr) {
     169            0 :     for (auto sc: *super_classes) {
     170            0 :       auto sclass = KernelWrapper::GetInstance().FindClass(*sc);
     171            0 :       if (sclass == nullptr) {
     172            0 :         QString warning = "<b>Warning</b> class <i>"
     173            0 :           + QString::fromStdString(cls->get_name())
     174            0 :           + "</i> refers to super class <i>" + QString::fromStdString(*sc)
     175            0 :           + "</i> which is not known<br>";
     176            0 :         m_ui->textBrowser->insertHtml(warning);
     177            0 :         m_ui->textBrowser->show();
     178            0 :         ok = false;
     179            0 :         continue;
     180            0 :       }
     181            0 :       auto file = sclass->get_file()->get_full_file_name();
     182            0 :       if (file != m_filename && !m_all_includes.contains(file)) {
     183            0 :         m_missing_includes.insert(file);
     184            0 :         QString warning = "<b>Warning</b> class <i>"
     185            0 :           + QString::fromStdString(cls->get_name())
     186            0 :           + "</i> refers to super class <i>" + QString::fromStdString(*sc)
     187            0 :           + "</i> from " + QString::fromStdString(file)
     188            0 :           + " which is not included<br>";
     189            0 :         m_ui->textBrowser->insertHtml(warning);
     190            0 :         m_ui->textBrowser->show();
     191            0 :         ok = false;
     192            0 :       }
     193            0 :     }
     194              :   }
     195            0 :   return ok;
     196              : }
     197              : 
     198            0 : void SchemaFileInfo::remove_include(std::string filename) {
     199            0 :   std::cout << "Removing include file " << filename << "\n";
     200              : 
     201            0 :   auto temp_files = m_all_includes;
     202            0 :   temp_files.erase(filename);
     203            0 :   temp_files.insert(m_filename);
     204              : 
     205            0 :   auto classes = KernelWrapper::GetInstance().get_schema_classes(m_filename);
     206            0 :   for (auto cls: classes) {
     207              :     // Ignore classes in file we're removing
     208            0 :     if (cls->get_file()->get_full_file_name() != filename) {
     209            0 :       auto relationships = cls->direct_relationships();
     210            0 :       if (relationships != nullptr) {
     211            0 :         for (auto rel: *relationships) {
     212            0 :           auto file = rel->get_class_type()->get_file()->get_full_file_name();
     213            0 :           if (!temp_files.contains(file)) {
     214            0 :             auto message = QString(
     215            0 :               "Cannot remove %1 as class %2 has relationship to its %3 class").arg(
     216            0 :                 QString::fromStdString(filename)).arg(
     217            0 :                   QString::fromStdString(cls->get_name())).arg(
     218            0 :                     QString::fromStdString(rel->get_class_type()->get_name()));
     219            0 :             QMessageBox::warning ( 0, "Schema editor", message );
     220            0 :             return;
     221            0 :           }
     222            0 :         }
     223              :       }
     224            0 :       auto super_classes = cls->direct_super_classes();
     225            0 :       if (super_classes != nullptr) {
     226            0 :         for (auto sc: *super_classes) {
     227            0 :           auto sclass = KernelWrapper::GetInstance().FindClass(*sc);
     228            0 :           auto file = sclass->get_file()->get_full_file_name();
     229            0 :           if (!temp_files.contains(file)) {
     230            0 :             auto message = QString(
     231            0 :               "Cannot remove %1 as class %2 has superclass %3 in %1").arg(
     232            0 :                 QString::fromStdString(filename)).arg(
     233            0 :                   QString::fromStdString(cls->get_name())).arg(
     234            0 :                     QString::fromStdString(*sc));
     235            0 :             QMessageBox::warning ( 0, "Schema editor", message );
     236            0 :             return;
     237            0 :           }
     238            0 :         }
     239              :       }
     240              :     }
     241              :   }
     242            0 :   try {
     243            0 :     dbse::KernelWrapper::GetInstance().RemoveInclude(m_filename,
     244            0 :                                                      prune_path(filename));
     245            0 :     m_all_includes.erase(filename);
     246              :   }
     247            0 :   catch (dunedaq::oks::FailedRemoveInclude& exc) {
     248            0 :     QMessageBox::warning (0, "Schema editor", QString::fromStdString(exc.what()));
     249            0 :   }
     250              : 
     251            0 :   get_includes();
     252            0 :   update_class_list();
     253            0 :   show_status();
     254            0 : }
     255              : 
     256            0 : void dbse::SchemaFileInfo::remove_include() {
     257            0 :   auto item = m_ui->include_list->currentItem();
     258            0 :   std::string fn = item->text().toStdString();
     259            0 :   remove_include (fn);
     260            0 : }
     261              : 
     262              : 
     263            0 : void SchemaFileInfo::accept() {
     264            0 :   close();
     265            0 : }
     266              : 
     267            0 : void SchemaFileInfo::reject() {
     268            0 :   close();
     269            0 : }
     270              : 
     271            0 : void dbse::SchemaFileInfo::keyPressEvent(QKeyEvent* event) {
     272            0 :   if (event->key() == Qt::Key_Escape) {
     273            0 :     close();
     274              :   }
     275            0 :   QWidget::keyPressEvent(event);
     276            0 : }
     277              : 
     278            0 : void SchemaFileInfo::launch_class_editor(QListWidgetItem* item) {
     279            0 :   SchemaClassEditor::launch(item->text());
     280            0 : }
     281              : 
     282            0 : void SchemaFileInfo::update_class_list() {
     283            0 :   m_ui->class_list->clear();
     284            0 :   m_ui->textBrowser->clear();
     285            0 :   auto classes = KernelWrapper::GetInstance().get_schema_classes(m_filename);
     286            0 :   for (auto cls: classes) {
     287            0 :     auto item = new QListWidgetItem(QString::fromStdString(cls->get_name()));
     288              : 
     289            0 :     if (!KernelWrapper::GetInstance().IsFileWritable ( m_filename )) {
     290            0 :       item->setForeground(QBrush(SchemaStyle::get_color("foreground", "readonly")));
     291            0 :       item->setBackground(QBrush(SchemaStyle::get_color("background", "readonly")));
     292              :     }
     293            0 :     if (!check_relationships(cls)) {
     294            0 :       item->setForeground(QBrush(SchemaStyle::get_color("foreground", "error")));
     295            0 :       item->setBackground(QBrush(SchemaStyle::get_color("background", "error")));
     296              :     }
     297            0 :     if (!check_superclasses(cls)) {
     298            0 :       item->setForeground(QBrush(SchemaStyle::get_color("foreground", "error")));
     299            0 :       item->setBackground(QBrush(SchemaStyle::get_color("background", "error")));
     300              :     }
     301              : 
     302            0 :     m_ui->class_list->addItem(item);
     303              :   }
     304            0 :   m_ui->class_summary->setText (
     305            0 :     QString("Total of %1 classes").arg(classes.size()));
     306              : 
     307              :   // if (!m_missing_includes.empty() && m_missing_button == nullptr) {
     308              :   //   m_missing_button = m_ui->buttonBox->addButton("Add missing includes", QDialogButtonBox::ApplyRole);
     309              :   //   if (m_missing_button != nullptr) {
     310              :   //     connect ( m_missing_button, SIGNAL (pressed()), this, SLOT(add_missing_includes()));
     311              :   //   }
     312              :   //   else {
     313              :   //     std::cout << "Failed to add button\n";
     314              :   //   }
     315              :   // }
     316            0 :   if (m_missing_includes.empty()) {
     317            0 :     m_ui->missing_button->setEnabled(false);
     318            0 :     m_ui->missing_button->hide();
     319              :   }
     320              :   else {
     321            0 :     m_ui->missing_button->setEnabled(true);
     322            0 :     m_ui->missing_button->show();
     323              :   }
     324            0 : }
     325              : 
     326            0 : void SchemaFileInfo::class_updated(QString /*class_name*/) {
     327              :   // auto cls = KernelWrapper::GetInstance().FindClass(class_name.toStdString());
     328              :   // auto file = cls->get_file()->get_full_file_name();
     329              :   // if (file == m_filename) {
     330            0 :     show_status();
     331            0 :     update_class_list();
     332              :   // }
     333            0 : }
     334              : 
     335            0 : void SchemaFileInfo::save_schema() {
     336            0 :   try {
     337            0 :     KernelWrapper::GetInstance().SaveSchema (m_filename);
     338              :   }
     339            0 :   catch (const dunedaq::oks::exception& exc) {
     340            0 :     QMessageBox::warning(0,
     341              :                          "Save Schema",
     342            0 :                          QString("Failed to save file %1" )
     343            0 :                          .arg (m_filename.c_str())
     344            0 :                          .append(QString(exc.what())),
     345              :                          QMessageBox::Ok);
     346            0 :   }
     347            0 :   show_status();
     348            0 :   emit files_updated();
     349            0 : }
     350              : 
     351            0 : void SchemaFileInfo::show_status() {
     352            0 :   QString status;
     353            0 :   if (KernelWrapper::GetInstance().IsFileWritable ( m_filename )) {
     354            0 :     status.append("Read/Write");
     355              :   }
     356              :   else {
     357            0 :     status.append("Read only");
     358              :   }
     359            0 :   if (KernelWrapper::GetInstance().is_file_modified ( m_filename )) {
     360            0 :     status.append("  Modified");
     361            0 :     if (m_missing_includes.empty()) {
     362            0 :       m_ui->save_button->setEnabled(true);
     363              :     }
     364              :     else {
     365            0 :       m_ui->save_button->setEnabled(false);
     366              :     }
     367              :   }
     368              :   else {
     369            0 :     m_ui->save_button->setEnabled(false);
     370              :   }
     371              : 
     372            0 :   if (m_filename == KernelWrapper::GetInstance().GetActiveSchema()) {
     373            0 :     status.append("  Active");
     374            0 :     m_ui->active_button->setEnabled(false);
     375              :   }
     376            0 :   else if (KernelWrapper::GetInstance().IsFileWritable (m_filename)) {
     377            0 :     m_ui->active_button->setEnabled(true);
     378              :   }
     379            0 :   m_ui->status->setText(status);
     380            0 : }
     381              : 
     382            0 : void SchemaFileInfo::add_include() {
     383            0 :   auto fd = new QFileDialog ( this, tr ( "Open File" ), ".",
     384            0 :                               tr ( "XML schema files (*.schema.xml)" ) );
     385            0 :   fd->setFileMode ( QFileDialog::ExistingFiles );
     386            0 :   fd->setViewMode ( QFileDialog::Detail );
     387            0 :   fd->setAcceptMode ( QFileDialog::AcceptOpen );
     388            0 :   fd->setSidebarUrls(m_path_urls);
     389            0 :   fd->exec();
     390            0 :   auto files = fd->selectedFiles();
     391            0 :   for (auto file: files) {
     392            0 :     add_file(file.toStdString());
     393            0 :   }
     394            0 :   get_includes();
     395            0 :   update_class_list();
     396            0 :   show_status();
     397            0 : }
     398              : 
     399            0 : void SchemaFileInfo::add_missing_includes() {
     400            0 :   std::cout << "\nAdding missing include files:\n";
     401              : 
     402            0 :   for (auto file: m_missing_includes) {
     403            0 :     add_file(file);
     404            0 :   }
     405            0 :   m_missing_includes.clear();
     406              : 
     407            0 :   get_includes();
     408            0 :   m_ui->textBrowser->clear();
     409            0 :   m_ui->textBrowser->hide();
     410              : 
     411            0 :   get_includes();
     412            0 :   update_class_list();
     413            0 :   show_status();
     414            0 : }
     415              : 
     416            0 : std::string SchemaFileInfo::prune_path(std::string file) {
     417            0 :   for ( QString & element : m_path_list ) {
     418            0 :     if (file.starts_with(element.toStdString())) {
     419            0 :       file = file.substr (element.size());
     420            0 :       break;
     421              :     }
     422              :   }
     423            0 :   return file;
     424              : }
     425            0 :   void dbse::SchemaFileInfo::add_file(std::string file) {
     426            0 :   std::cout << "   " << file << "\n";
     427            0 :   try {
     428            0 :     KernelWrapper::GetInstance().AddInclude(m_filename, prune_path(file));
     429            0 :     emit files_updated();
     430              :   }
     431            0 :   catch (std::exception& exc) {
     432            0 :     QString message = QString(
     433            0 :       "Failed to add %1 to included files, %2" ).arg(
     434            0 :         QString::fromStdString(file)).arg(exc.what());
     435            0 :     QMessageBox::warning ( 0, "Schema editor", message );
     436            0 :   }
     437            0 : }
     438              : 
     439            0 : void dbse::SchemaFileInfo::activate_include_context_menu (QPoint pos)
     440              : {
     441            0 :   if (m_include_menu == nullptr) {
     442            0 :     m_include_menu = new QMenu (this);
     443              : 
     444            0 :     if (KernelWrapper::GetInstance().IsFileWritable ( m_filename )) {
     445            0 :       QAction* add = new QAction ( tr ( "Add New Include File" ), this );
     446            0 :       connect (add, SIGNAL ( triggered() ), this, SLOT ( add_include() ) );
     447            0 :       QAction* remove = new QAction ( tr ( "Remove Selected Include File" ), this );
     448            0 :       connect (remove, SIGNAL ( triggered() ), this, SLOT ( remove_include() ) );
     449            0 :       m_include_menu->addAction ( add );
     450            0 :       m_include_menu->addAction ( remove );
     451              :     }
     452            0 :     QAction* info = new QAction ( tr ( "Show file info" ), this );
     453            0 :     connect (info, SIGNAL ( triggered() ), this, SLOT ( show_file_info() ) );
     454              : 
     455            0 :     m_include_menu->addAction ( info );
     456              :   }
     457              : 
     458            0 :   if (m_ui->include_list->currentIndex().isValid()) {
     459            0 :     m_include_menu->exec (m_ui->include_list->mapToGlobal(pos));
     460              :   }
     461            0 : }
     462              : 
     463            0 : void dbse::SchemaFileInfo::activate_class_context_menu (QPoint pos)
     464              : {
     465            0 :   if (m_class_menu == nullptr) {
     466            0 :     m_class_menu = new QMenu (this);
     467              : 
     468            0 :     QAction * add = new QAction (tr("&Add New Class"), this );
     469            0 :     connect (add, SIGNAL (triggered()), this, SLOT (add_new_class()));
     470              : 
     471            0 :     QAction* remove = new QAction(tr("&Remove Selected Class"), this );
     472            0 :     connect (remove, SIGNAL(triggered()), this, SLOT(remove_class()));
     473              : 
     474            0 :     QAction* edit = new QAction(tr( "&Edit Selected Class"), this );
     475            0 :     connect (edit, SIGNAL (triggered()), this, SLOT (edit_class()));
     476              : 
     477            0 :     QAction* move = new QAction(tr( "&Move Selected Class"), this );
     478            0 :     connect (move, SIGNAL (triggered()), this, SLOT (move_class()));
     479              : 
     480            0 :     m_class_menu->addAction (add);
     481            0 :     m_class_menu->addAction (edit);
     482            0 :     m_class_menu->addAction (move);
     483            0 :     m_class_menu->addAction (remove);
     484              :   }
     485              : 
     486            0 :   if (m_ui->class_list->currentIndex().isValid()) {
     487            0 :     m_class_menu->exec (m_ui->class_list->mapToGlobal(pos));
     488              :   }
     489            0 : }
     490              : 
     491            0 : void dbse::SchemaFileInfo::edit_class()
     492              : {
     493            0 :   SchemaClassEditor::launch(m_ui->class_list->currentItem()->text());
     494            0 : }
     495            0 : void dbse::SchemaFileInfo::move_class()
     496              : {
     497            0 :   auto oks_class = KernelWrapper::GetInstance().FindClass(
     498            0 :     m_ui->class_list->currentItem()->text().toStdString());
     499            0 :   SchemaClassEditor::move_class(oks_class, this);
     500            0 : }
     501            0 : void dbse::SchemaFileInfo::remove_class()
     502              : {
     503            0 :   auto item = m_ui->class_list->currentItem();
     504            0 :   QString cn = item->text();
     505            0 :   dunedaq::oks::OksClass* schema_class =
     506            0 :     KernelWrapper::GetInstance().FindClass(cn.toStdString());
     507            0 :   if (schema_class->all_sub_classes()->size() != 0) {
     508            0 :     QMessageBox::warning ( 0, "Schema editor",
     509            0 :                            QString ( "Cannot delete class because it has sub-classes." ) );
     510            0 :     return;
     511              :   }
     512            0 :   else if (KernelWrapper::GetInstance().AnyClassReferenceThis(schema_class)) {
     513            0 :     QMessageBox::warning (0, "Schema editor",
     514            0 :                           QString ( "Cannot delete class because some other classes references it."));
     515            0 :     return;
     516              :   }
     517              : 
     518            0 :   KernelWrapper::GetInstance().PushRemoveClassCommand (schema_class,
     519            0 :                                                        schema_class->get_name(),
     520            0 :                                                        schema_class->get_description(),
     521            0 :                                                        schema_class->get_is_abstract() );
     522            0 :   delete item;
     523            0 :   m_ui->class_list->update();
     524            0 : }
     525              : 
     526            0 : bool dbse::SchemaFileInfo::set_active(std::string filename) {
     527            0 :   try {
     528            0 :     KernelWrapper::GetInstance().SetActiveSchema (filename);
     529              :   }
     530            0 :   catch (dunedaq::oks::CanNotSetActiveFile& exc) {
     531            0 :     auto qfn = QString::fromStdString(m_filename);
     532            0 :     auto text = QString("Could not make schema file %1 active!\n\n").arg(qfn);
     533            0 :     QMessageBox::warning(0,
     534              :                          "Set Active Schema",
     535            0 :                          text.append(QString(exc.what())),
     536              :                          QMessageBox::Ok);
     537            0 :     return false;
     538            0 :   }
     539            0 :   show_status();
     540            0 :   return true;
     541              : }
     542              : 
     543              : 
     544            0 : void dbse::SchemaFileInfo::set_schemafile_active() {
     545            0 :   auto item = m_ui->include_list->currentItem();
     546            0 :   std::string fn = item->text().toStdString();
     547            0 :   set_active (fn);
     548            0 :   show_status();
     549            0 : }
     550              : 
     551            0 : void dbse::SchemaFileInfo::set_active() {
     552            0 :   set_active (m_filename);
     553            0 :   show_status();
     554            0 : }
     555              : 
     556              : 
     557            0 : void dbse::SchemaFileInfo::add_new_class()
     558              : {
     559            0 :   if (set_active (m_filename)) {
     560            0 :     auto nc = SchemaClassEditor::createNewClass();
     561            0 :     if (!nc.isEmpty()) {
     562            0 :       auto item = new QListWidgetItem(nc);
     563            0 :       m_ui->class_list->addItem(item);
     564            0 :       m_ui->class_list->sortItems();
     565            0 :       m_ui->class_list->setCurrentItem(item);
     566            0 :       m_ui->class_list->update();
     567              :     }
     568            0 :   }
     569            0 : }
     570              : 
     571              : 
     572              : 
     573            0 : void dbse::SchemaFileInfo::show_file_info() {
     574            0 :   show_file_info(m_ui->include_list->currentItem());
     575            0 : }
     576            0 : void dbse::SchemaFileInfo::show_file_info(QListWidgetItem* item) {
     577            0 :   show_file_info(item->text());
     578            0 : }
     579            0 : void dbse::SchemaFileInfo::show_file_info(QString fn) {
     580            0 :   bool widget_found = false;
     581            0 :   for ( QWidget * widget : QApplication::allWidgets() ) {
     582            0 :     auto sfi = dynamic_cast<SchemaFileInfo *> ( widget );
     583            0 :     if ( sfi != nullptr ) {
     584            0 :       if ( (sfi->objectName() ).compare ( fn ) == 0 ) {
     585            0 :         sfi->raise();
     586            0 :         sfi->setVisible ( true );
     587            0 :         sfi->activateWindow();
     588              :         widget_found = true;
     589              :         break;
     590              :       }
     591              :     }
     592            0 :   }
     593            0 :   if ( !widget_found ) {
     594            0 :     auto info = new SchemaFileInfo(fn.toStdString());
     595              :     // connect (info, &SchemaFileInfo::files_updated,
     596              :     //          this, &SchemaMainWindow::update_models);
     597            0 :     emit new_window(this);
     598            0 :     info->show();
     599              :   }
     600            0 : }
     601              : } //namespace dbse
        

Generated by: LCOV version 2.0-1