LCOV - code coverage report
Current view: top level - dbe/src/widgets - CreateDatabaseWidget.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 101 0
Test Date: 2026-08-30 15:04:40 Functions: 0.0 % 8 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: no.
       5              : 
       6              : /// Including QT Headers
       7              : #include<QFileDialog>
       8              : #include<QMessageBox>
       9              : /// Including DBE
      10              : #include"dbe/CreateDatabaseWidget.hpp"
      11              : #include"dbe/StyleUtility.hpp"
      12              : /// Including config headers
      13              : #include "conffwk/ConfigObject.hpp"
      14              : #include "conffwk/Configuration.hpp"
      15              : #include "conffwk/Schema.hpp"
      16              : #include "dbe/Exceptions.hpp"
      17              : #include "dbe/messenger.hpp"
      18              : #include "dbe/FileInfo.hpp"
      19              : 
      20              : using namespace dunedaq::conffwk;
      21              : 
      22            0 : dbe::CreateDatabaseWidget::CreateDatabaseWidget ( QWidget * parent, bool Include,
      23            0 :                                                   const QString & CreateDir )
      24              :   : QWidget ( parent ),
      25            0 :     DirToCreate ( CreateDir ),
      26            0 :     CreateToInclude ( Include )
      27              : {
      28            0 :   setupUi ( this );
      29              : 
      30            0 :   connect ( SchemaButton, SIGNAL ( clicked() ), this, SLOT ( DefineSchema() ),
      31              :             Qt::UniqueConnection );
      32            0 :   connect ( SelectButton, SIGNAL ( clicked() ), this, SLOT ( DefineDatabaseFile() ),
      33              :             Qt::UniqueConnection );
      34              : 
      35            0 :   if ( !CreateToInclude )
      36              :   {
      37            0 :     connect ( CreateDatabaseButton, SIGNAL ( clicked() ), this,
      38              :               SLOT ( CreateDatabaseFileLoad() ),
      39              :               Qt::UniqueConnection );
      40            0 :     connect ( CreateNoLoadDatabaseButton, SIGNAL ( clicked() ), this,
      41              :               SLOT ( CreateDatabaseFileNoLoad() ), Qt::UniqueConnection );
      42              :   }
      43              :   else
      44              :   {
      45            0 :     connect ( CreateDatabaseButton, SIGNAL ( clicked() ), this,
      46              :               SLOT ( CreateDatabaseFileInclude() ), Qt::UniqueConnection );
      47            0 :     CreateDatabaseButton->setText ( "Create Database File" );
      48            0 :     CreateNoLoadDatabaseButton->hide();
      49              :   }
      50              : 
      51              : 
      52            0 :   m_instructions->setText ( "Select schema files and define new database file. Database must contain at least one schema file, other includes may be added later via a File info window." );
      53            0 :   CreateDatabaseButton->setDisabled ( true );
      54            0 :   CreateNoLoadDatabaseButton->setDisabled ( true );
      55              : 
      56            0 :   DatabaseName->setReadOnly ( true );
      57            0 : }
      58              : 
      59            0 : void dbe::CreateDatabaseWidget::DefineSchema()
      60              : {
      61            0 :   auto fd = new QFileDialog ( this, tr ( "Select Schema File" ),
      62            0 :                               FileInfo::get_schema_path(),
      63            0 :                               tr ( "XML schema files (*.schema.xml)" ) );
      64            0 :   fd->setFileMode ( QFileDialog::ExistingFile );
      65            0 :   fd->setViewMode ( QFileDialog::Detail );
      66            0 :   fd->setAcceptMode ( QFileDialog::AcceptOpen );
      67            0 :   fd->setSidebarUrls(FileInfo::get_path_urls());
      68            0 :   if (!(fd->exec() == QDialog::Accepted)) {
      69            0 :     return;
      70              :   }
      71            0 :   FileInfo::set_schema_path(fd->directory().path());
      72              : 
      73            0 :   auto files = fd->selectedFiles();
      74            0 :   for (auto file: files) {
      75            0 :     QFileInfo SchemaFile = QFileInfo (file);
      76            0 :     if ( !SchemaFile.isFile() ) {
      77            0 :       m_instructions->setPalette ( StyleUtility::AlertStatusBarPallete );
      78            0 :       m_instructions->setText ( QString ( "The file is not accessible. Check before usage" ));
      79              :     }
      80              :     else {
      81            0 :       if (SchemaFile.fileName().contains("schema")) {
      82            0 :         schema_list->addItem(FileInfo::prune_path(file));
      83              :       }
      84              :       else {
      85            0 :         m_instructions->setPalette ( StyleUtility::AlertStatusBarPallete );
      86            0 :         m_instructions->setText (
      87            0 :           QString ( "The file %1 is not a schema file" ).arg ( SchemaFile.absoluteFilePath() ));
      88              :       }
      89              :     }
      90            0 :   }
      91              : 
      92            0 :   if (schema_list->count()>0 && !DatabaseName->text().isEmpty()) {
      93            0 :     CreateDatabaseButton->setEnabled ( true );
      94            0 :     CreateNoLoadDatabaseButton->setEnabled ( true );
      95              :   }
      96            0 : }
      97              : 
      98            0 : void dbe::CreateDatabaseWidget::DefineDatabaseFile()
      99              : {
     100            0 :   QString Dir;
     101              : 
     102            0 :   QString path = FileInfo::get_data_path().append ( "/NewDatabaseFile.data.xml" );
     103              : 
     104            0 :   auto fd = new QFileDialog ( this, tr("Select new DB File"),
     105              :                               path,
     106            0 :                               tr("XML data files (*.data.xml)"));
     107            0 :   fd->setFileMode ( QFileDialog::AnyFile );
     108            0 :   fd->setViewMode ( QFileDialog::Detail );
     109            0 :   fd->setAcceptMode ( QFileDialog::AcceptSave );
     110            0 :   fd->setSidebarUrls(FileInfo::get_path_urls());
     111            0 :   if (!(fd->exec() == QDialog::Accepted)) {
     112            0 :     return;
     113              :   }
     114            0 :   FileInfo::set_data_path(fd->directory().path());
     115            0 :   auto files = fd->selectedFiles();
     116              : 
     117            0 :   DatabaseFile = QFileInfo (files.at(0));
     118              : 
     119            0 :   DatabaseName->setText ( DatabaseFile.absoluteFilePath() );
     120              : 
     121            0 :   if (schema_list->count()>0) {
     122            0 :     CreateDatabaseButton->setEnabled ( true );
     123            0 :     CreateNoLoadDatabaseButton->setEnabled ( true );
     124              :   }
     125            0 : }
     126              : 
     127            0 : std::list<std::string> dbe::CreateDatabaseWidget::get_includes() {
     128            0 :   std::list<std::string> includes;
     129              : 
     130            0 :   for (int row=0; row<schema_list->count(); ++row) {
     131            0 :     auto item = schema_list->item(row)->text();
     132            0 :     includes.push_back(item.toStdString());
     133            0 :   }
     134            0 :   return includes;
     135            0 : }
     136              : 
     137              : 
     138            0 : bool dbe::CreateDatabaseWidget::create_database_file(std::string extra_text) {
     139            0 :   Configuration db ( "oksconflibs" );
     140            0 :   try {
     141            0 :     const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString();
     142            0 :     db.create (DatabaseName, get_includes());
     143            0 :     db.commit();
     144            0 :   }
     145            0 :   catch ( dunedaq::conffwk::Exception const & ex )
     146              :   {
     147            0 :     FAIL ( "Database creation failure", dbe::config::errors::parse ( ex ).c_str() );
     148            0 :     return false;
     149            0 :   }
     150              : 
     151            0 :   QMessageBox::information (0, tr ( "DBE" ),
     152            0 :                             QString::fromStdString ("The Database was created.\n"+extra_text),
     153              :                             QMessageBox::Ok );
     154            0 :   return true;
     155            0 : }
     156            0 : void dbe::CreateDatabaseWidget::CreateDatabaseFileLoad()
     157              : {
     158            0 :   if (create_database_file("Now the DB will be loaded into the Editor!\n")) {
     159            0 :     emit CanLoadDatabase ( DatabaseFile.absoluteFilePath() );
     160            0 :     close();
     161              :   }
     162            0 : }
     163              : 
     164            0 : void dbe::CreateDatabaseWidget::CreateDatabaseFileNoLoad()
     165              : {
     166            0 :   if (create_database_file("")) {
     167            0 :     close();
     168              :   }
     169            0 : }
     170              : 
     171            0 : void dbe::CreateDatabaseWidget::CreateDatabaseFileInclude()
     172              : {
     173            0 :   if (create_database_file("")) {
     174            0 :     emit CanIncludeDatabase ( DatabaseFile.absoluteFilePath() );
     175            0 :     close();
     176              :   }
     177            0 : }
        

Generated by: LCOV version 2.0-1