DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CreateDatabaseWidget.cpp
Go to the documentation of this file.
1
2#include<QFileDialog>
3#include<QMessageBox>
10#include "conffwk/Schema.hpp"
11#include "dbe/Exceptions.hpp"
12#include "dbe/messenger.hpp"
13
14using namespace dunedaq::conffwk;
15
16dbe::CreateDatabaseWidget::CreateDatabaseWidget ( QWidget * parent, bool Include,
17 const QString & CreateDir )
18 : QWidget ( parent ),
19 StatusBar ( nullptr ),
20 DirToCreate ( CreateDir ),
21 CreateToInclude ( Include )
22{
23 setupUi ( this );
24
25 connect ( SchemaButton, SIGNAL ( clicked() ), this, SLOT ( DefineSchema() ),
26 Qt::UniqueConnection );
27 connect ( SelectButton, SIGNAL ( clicked() ), this, SLOT ( DefineDatabaseFile() ),
28 Qt::UniqueConnection );
29
30 if ( !CreateToInclude )
31 {
32 connect ( CreateDatabaseButton, SIGNAL ( clicked() ), this,
33 SLOT ( CreateDatabaseFileLoad() ),
34 Qt::UniqueConnection );
35 connect ( CreateNoLoadDatabaseButton, SIGNAL ( clicked() ), this,
36 SLOT ( CreateDatabaseFileNoLoad() ), Qt::UniqueConnection );
37 }
38 else
39 {
40 connect ( CreateDatabaseButton, SIGNAL ( clicked() ), this,
41 SLOT ( CreateDatabaseFileInclude() ), Qt::UniqueConnection );
42 CreateDatabaseButton->setText ( "Create Database File" );
43 CreateNoLoadDatabaseButton->hide();
44 }
45
46 StatusBar = new QStatusBar ( StatusFrame );
47 StatusBar->setSizeGripEnabled ( false );
48 StatusFrame->setFrameStyle ( QFrame::NoFrame );
49 StatusLayout->addWidget ( StatusBar );
50
51 StatusBar->setAutoFillBackground ( true );
52 StatusBar->showMessage ( "Select schema files and define new database file!" );
53 CreateDatabaseButton->setDisabled ( true );
54 CreateNoLoadDatabaseButton->setDisabled ( true );
55
56 DatabaseName->setReadOnly ( true );
57}
58
60{
61 QString SchemaFilePath = QFileDialog::getOpenFileName ( this, tr ( "Open Schema File" ),
62 DirToCreate.append("./"),
63 tr ( "XML files (*.xml)" ) );
64 QFileInfo SchemaFile = QFileInfo ( SchemaFilePath );
65
66 if ( !SchemaFile.isFile() )
67 {
68 StatusBar->setPalette ( StyleUtility::AlertStatusBarPallete );
69 StatusBar->showMessage ( QString ( "The file is not accessible. Check before usage" ) );
70 }
71 else
72 {
73 if ( SchemaFile.fileName().contains ( "schema" ) ) SchemaCombo->addItem (
74 SchemaFile.absoluteFilePath() );
75 else
76 {
77 StatusBar->setPalette ( StyleUtility::AlertStatusBarPallete );
78 StatusBar->showMessage (
79 QString ( "The file %1 is not a schema file" ).arg ( SchemaFile.absoluteFilePath() ) );
80 }
81 }
82}
83
85{
86 QString Dir;
87
88 if ( DirToCreate.isEmpty() )
89 {
90 Dir = QString ( "./NewDatabaseFile.data.xml" );
91 }
92 else
93 {
94 Dir = DirToCreate.append ( "/NewDatabaseFile.data.xml" );
95 }
96
97 QString DatabaseFilePath = QFileDialog::getSaveFileName ( this,
98 tr ( "Save to Database File" ),
99 Dir,
100 tr ( "XML files (*.xml)" ) );
101 DatabaseFile = QFileInfo ( DatabaseFilePath );
102
103 DatabaseName->setText ( DatabaseFile.absoluteFilePath() );
104 CreateDatabaseButton->setEnabled ( true );
105 CreateNoLoadDatabaseButton->setEnabled ( true );
106}
107
109{
110 Configuration db ( "oksconflibs" );
111
112 try
113 {
114 std::list<std::string> Includes;
115
116 for ( int i = 0; i < SchemaCombo->count(); ++i )
117 {
118 QString Item = SchemaCombo->itemText ( i );
119 Includes.push_back ( Item.toStdString() );
120 }
121
122 const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString();
123 db.create ( DatabaseName, Includes );
124 db.commit();
125
126 QMessageBox::information (
127 0, tr ( "DBE" ),
128 QString ( "Database was created.\nNow the DB will be loaded into the Editor!\n" ),
129 QMessageBox::Ok );
130 emit CanLoadDatabase ( DatabaseFile.absoluteFilePath() );
131 close();
132 }
133 catch ( dunedaq::conffwk::Exception const & ex )
134 {
135 FAIL ( "Database creation failure", dbe::config::errors::parse ( ex ).c_str() );
136 }
137}
138
140{
141 Configuration db ( "oksconflibs" );
142
143 try
144 {
145 std::list<std::string> Includes;
146
147 for ( int i = 0; i < SchemaCombo->count(); ++i )
148 {
149 QString Item = SchemaCombo->itemText ( i );
150 Includes.push_back ( Item.toStdString() );
151 }
152
153 const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString();
154 db.create ( DatabaseName, Includes );
155 db.commit();
156
157 QMessageBox::information ( 0, tr ( "DBE" ), QString ( "The Database was created.\n" ),
158 QMessageBox::Ok );
159 close();
160 }
161 catch ( dunedaq::conffwk::Exception const & ex )
162 {
163 FAIL ( "Database creation failure", dbe::config::errors::parse ( ex ).c_str() );
164 }
165}
166
168{
169 Configuration db ( "oksconflibs" );
170
171 try
172 {
173 std::list<std::string> Includes;
174
175 for ( int i = 0; i < SchemaCombo->count(); ++i )
176 {
177 QString Item = SchemaCombo->itemText ( i );
178 Includes.push_back ( Item.toStdString() );
179 }
180
181 const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString();
182 db.create ( DatabaseName, Includes );
183 db.commit();
184
185 QMessageBox::information ( 0, tr ( "DBE" ), QString ( "The Database was created.\n" ),
186 QMessageBox::Ok );
187 emit CanIncludeDatabase ( DatabaseFile.absoluteFilePath() );
188 close();
189 }
190 catch ( dunedaq::conffwk::Exception const & ex )
191 {
192 FAIL ( "Database creation error", dbe::config::errors::parse ( ex ).c_str() );
193 }
194}
CreateDatabaseWidget(QWidget *parent=nullptr, bool Include=false, const QString &CreateDir=QString())
static QPalette AlertStatusBarPallete
Defines base class for cache of template objects.
void create(const std::string &at, const std::string &class_name, const std::string &id, ConfigObject &object)
Create new object by class name and object id.
void commit(const std::string &log_message="")
Commit database changes.
conffwk entry point
#define FAIL(...)
std::string const parse(ers::Issue const &)