LCOV - code coverage report
Current view: top level - dbe/src/widgets - CreateDatabaseWidget.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 121 0
Test Date: 2026-07-12 15:23:06 Functions: 0.0 % 7 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 :     StatusBar ( nullptr ),
      26            0 :     DirToCreate ( CreateDir ),
      27            0 :     CreateToInclude ( Include )
      28              : {
      29            0 :   setupUi ( this );
      30              : 
      31            0 :   connect ( SchemaButton, SIGNAL ( clicked() ), this, SLOT ( DefineSchema() ),
      32              :             Qt::UniqueConnection );
      33            0 :   connect ( SelectButton, SIGNAL ( clicked() ), this, SLOT ( DefineDatabaseFile() ),
      34              :             Qt::UniqueConnection );
      35              : 
      36            0 :   if ( !CreateToInclude )
      37              :   {
      38            0 :     connect ( CreateDatabaseButton, SIGNAL ( clicked() ), this,
      39              :               SLOT ( CreateDatabaseFileLoad() ),
      40              :               Qt::UniqueConnection );
      41            0 :     connect ( CreateNoLoadDatabaseButton, SIGNAL ( clicked() ), this,
      42              :               SLOT ( CreateDatabaseFileNoLoad() ), Qt::UniqueConnection );
      43              :   }
      44              :   else
      45              :   {
      46            0 :     connect ( CreateDatabaseButton, SIGNAL ( clicked() ), this,
      47              :               SLOT ( CreateDatabaseFileInclude() ), Qt::UniqueConnection );
      48            0 :     CreateDatabaseButton->setText ( "Create Database File" );
      49            0 :     CreateNoLoadDatabaseButton->hide();
      50              :   }
      51              : 
      52            0 :   StatusBar = new QStatusBar ( StatusFrame );
      53            0 :   StatusBar->setSizeGripEnabled ( false );
      54            0 :   StatusFrame->setFrameStyle ( QFrame::NoFrame );
      55            0 :   StatusLayout->addWidget ( StatusBar );
      56              : 
      57            0 :   StatusBar->setAutoFillBackground ( true );
      58            0 :   StatusBar->showMessage ( "Select schema files and define new database file!" );
      59            0 :   CreateDatabaseButton->setDisabled ( true );
      60            0 :   CreateNoLoadDatabaseButton->setDisabled ( true );
      61              : 
      62            0 :   DatabaseName->setReadOnly ( true );
      63            0 : }
      64              : 
      65            0 : void dbe::CreateDatabaseWidget::DefineSchema()
      66              : {
      67            0 :   auto fd = new QFileDialog ( this, tr ( "Select Schema File" ),
      68            0 :                               DirToCreate.append("./"),
      69            0 :                               tr ( "XML schema files (*.schema.xml)" ) );
      70            0 :   fd->setFileMode ( QFileDialog::ExistingFile );
      71            0 :   fd->setViewMode ( QFileDialog::Detail );
      72            0 :   fd->setAcceptMode ( QFileDialog::AcceptOpen );
      73            0 :   fd->setSidebarUrls(FileInfo::get_path_urls());
      74            0 :   if (!(fd->exec() == QDialog::Accepted)) {
      75            0 :     return;
      76              :   }
      77            0 :   auto files = fd->selectedFiles();
      78            0 :   for (auto file: files) {
      79            0 :     QFileInfo SchemaFile = QFileInfo (file);
      80            0 :     if ( !SchemaFile.isFile() ) {
      81            0 :       StatusBar->setPalette ( StyleUtility::AlertStatusBarPallete );
      82            0 :       StatusBar->showMessage ( QString ( "The file is not accessible. Check before usage" ) );
      83              :     }
      84              :     else {
      85            0 :       if (SchemaFile.fileName().contains("schema")) {
      86            0 :         schema_list->addItem(FileInfo::prune_path(file));
      87              :       }
      88              :       else {
      89            0 :         StatusBar->setPalette ( StyleUtility::AlertStatusBarPallete );
      90            0 :         StatusBar->showMessage (
      91            0 :           QString ( "The file %1 is not a schema file" ).arg ( SchemaFile.absoluteFilePath() ) );
      92              :       }
      93              :     }
      94            0 :   }
      95              : 
      96            0 :   if (schema_list->count()>0 && !DatabaseName->text().isEmpty()) {
      97            0 :     CreateDatabaseButton->setEnabled ( true );
      98            0 :     CreateNoLoadDatabaseButton->setEnabled ( true );
      99              :   }
     100            0 : }
     101              : 
     102            0 : void dbe::CreateDatabaseWidget::DefineDatabaseFile()
     103              : {
     104            0 :   QString Dir;
     105              : 
     106            0 :   if ( DirToCreate.isEmpty() )
     107              :   {
     108            0 :     Dir = QString ( "./NewDatabaseFile.data.xml" );
     109              :   }
     110              :   else
     111              :   {
     112            0 :     Dir = DirToCreate.append ( "/NewDatabaseFile.data.xml" );
     113              :   }
     114              : 
     115            0 :   auto fd = new QFileDialog ( this, tr("Select new DB File"),
     116              :                               Dir,
     117            0 :                               tr("XML data files (*.data.xml)"));
     118            0 :   fd->setFileMode ( QFileDialog::AnyFile );
     119            0 :   fd->setViewMode ( QFileDialog::Detail );
     120            0 :   fd->setAcceptMode ( QFileDialog::AcceptSave );
     121            0 :   fd->setSidebarUrls(FileInfo::get_path_urls());
     122            0 :   if (!(fd->exec() == QDialog::Accepted)) {
     123            0 :     return;
     124              :   }
     125            0 :   auto files = fd->selectedFiles();
     126              : 
     127            0 :   DatabaseFile = QFileInfo (files.at(0));
     128              : 
     129            0 :   DatabaseName->setText ( DatabaseFile.absoluteFilePath() );
     130              : 
     131            0 :   if (schema_list->count()>0) {
     132            0 :     CreateDatabaseButton->setEnabled ( true );
     133            0 :     CreateNoLoadDatabaseButton->setEnabled ( true );
     134              :   }
     135            0 : }
     136              : 
     137            0 : std::list<std::string> dbe::CreateDatabaseWidget::get_includes() {
     138            0 :   std::list<std::string> includes;
     139              : 
     140            0 :   for (int row=0; row<schema_list->count(); ++row) {
     141            0 :     auto item = schema_list->item(row)->text();
     142            0 :     includes.push_back(item.toStdString());
     143            0 :   }
     144            0 :   return includes;
     145            0 : }
     146              : 
     147              : 
     148            0 : void dbe::CreateDatabaseWidget::CreateDatabaseFileLoad()
     149              : {
     150            0 :   Configuration db ( "oksconflibs" );
     151            0 :   try {
     152            0 :     const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString();
     153            0 :     db.create ( DatabaseName, get_includes());
     154            0 :     db.commit();
     155              : 
     156            0 :     QMessageBox::information (
     157            0 :       0, tr ( "DBE" ),
     158            0 :       QString ( "Database was created.\nNow the DB will be loaded into the Editor!\n" ),
     159              :       QMessageBox::Ok );
     160            0 :     emit CanLoadDatabase ( DatabaseFile.absoluteFilePath() );
     161            0 :     close();
     162            0 :   }
     163            0 :   catch ( dunedaq::conffwk::Exception const & ex )
     164              :   {
     165            0 :     FAIL ( "Database creation failure", dbe::config::errors::parse ( ex ).c_str() );
     166            0 :   }
     167            0 : }
     168              : 
     169            0 : void dbe::CreateDatabaseWidget::CreateDatabaseFileNoLoad()
     170              : {
     171            0 :   Configuration db ( "oksconflibs" );
     172            0 :   try {
     173            0 :     const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString();
     174            0 :     db.create (DatabaseName, get_includes());
     175            0 :     db.commit();
     176              : 
     177            0 :     QMessageBox::information ( 0, tr ( "DBE" ), QString ( "The Database was created.\n" ),
     178              :                                QMessageBox::Ok );
     179            0 :     close();
     180            0 :   }
     181            0 :   catch ( dunedaq::conffwk::Exception const & ex )
     182              :   {
     183            0 :     FAIL ( "Database creation failure", dbe::config::errors::parse ( ex ).c_str() );
     184            0 :   }
     185            0 : }
     186              : 
     187            0 : void dbe::CreateDatabaseWidget::CreateDatabaseFileInclude()
     188              : {
     189            0 :   Configuration db ( "oksconflibs" );
     190            0 :   try {
     191            0 :     const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString();
     192            0 :     db.create (DatabaseName, get_includes());
     193            0 :     db.commit();
     194              : 
     195            0 :     QMessageBox::information ( 0, tr ( "DBE" ), QString ( "The Database was created.\n" ),
     196              :                                QMessageBox::Ok );
     197            0 :     emit CanIncludeDatabase ( DatabaseFile.absoluteFilePath() );
     198            0 :     close();
     199            0 :   }
     200            0 :   catch ( dunedaq::conffwk::Exception const & ex )
     201              :   {
     202            0 :     FAIL ( "Database creation error", dbe::config::errors::parse ( ex ).c_str() );
     203            0 :   }
     204            0 : }
        

Generated by: LCOV version 2.0-1