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