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-03-29 15:29:34 Functions: 0.0 % 7 0

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

Generated by: LCOV version 2.0-1