DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbe::IncludeFileWidget Class Reference

#include <IncludeFileWidget.hpp>

Inheritance diagram for dbe::IncludeFileWidget:
[legend]
Collaboration diagram for dbe::IncludeFileWidget:
[legend]

Public Member Functions

 ~IncludeFileWidget ()
 
 IncludeFileWidget (QString FilePath, QWidget *parent=0)
 

Private Slots

void SelectFileToInclude ()
 
void AddFileToInclude ()
 
void AddNewFileToInclude (const QString &File)
 
void RemoveFileFromInclude ()
 
void RemoveFileFromInclude (int)
 
void SetDirectory (const QString &Dir)
 
void CheckInclude ()
 
void CreateFileToInclude ()
 

Private Member Functions

void SetRemoveComboBox ()
 
void SetController ()
 

Private Attributes

std::unique_ptr< dbe::Ui::IncludeFileWidget > ui
 
CreateDatabaseWidgetCreateWidget
 
QString DatabasePath
 
QString Directory
 
bool Removed
 
QStatusBar * StatusBar
 
QFileDialog * SelectFile
 
QStringList FolderPathList
 
QStringList dbPath
 

Detailed Description

Definition at line 18 of file IncludeFileWidget.hpp.

Constructor & Destructor Documentation

◆ ~IncludeFileWidget()

dbe::IncludeFileWidget::~IncludeFileWidget ( )
default

◆ IncludeFileWidget()

dbe::IncludeFileWidget::IncludeFileWidget ( QString FilePath,
QWidget * parent = 0 )
explicit

Visual

Definition at line 19 of file IncludeFileWidget.cpp.

20 : QWidget ( parent ),
21 ui ( new Ui::IncludeFileWidget ),
22 CreateWidget ( nullptr ),
23 DatabasePath ( FilePath ),
24 Removed ( false ),
25 StatusBar ( nullptr ),
26 SelectFile ( nullptr )
27{
28 ui->setupUi ( this );
29
31 ui->AddLabel->setStyleSheet (
32 "QLabel{background-color:#8DAA2E; color:#facd64; font:bold14px; border-style:outset; border-width:2px; border-radius:10px;"
33 "border-color:beige; font:bold14px; min-width:10em; padding: 6px;}" );
34 ui->RemoveLabel->setStyleSheet (
35 "QLabel{background-color:#b5351b; color:#facd64; font:bold14px; border-style:outset;"
36 "border-width:2px; border-radius:10px; border-color:beige; font:bold14px; min-width:10em; padding:6px;}" );
37 setWindowTitle (
38 QString ( "Edit Included Files for Database : %1" ).arg ( QFileInfo (
39 FilePath ).fileName() ) );
40
41 StatusBar = new QStatusBar ( ui->StatusFrame );
42 StatusBar->setSizeGripEnabled ( false );
43 ui->StatusFrame->setFrameStyle ( QFrame::NoFrame );
44 ui->StatusLayout->addWidget ( StatusBar );
45
46 StatusBar->setAutoFillBackground ( true );
47 StatusBar->showMessage ( "Select files to include or to remove from include!" );
48
50
51 SelectFile = new QFileDialog ( this, tr ( "Open File" ), ".", tr ( "XML files (*.xml)" ) );
52 SelectFile->setFileMode ( QFileDialog::ExistingFiles );
53 SelectFile->setViewMode ( QFileDialog::Detail );
54 SelectFile->setAcceptMode ( QFileDialog::AcceptOpen );
55
56 QString TDAQ_DB_REPOSITORY = getenv ( "TDAQ_DB_REPOSITORY" );
57 if(TDAQ_DB_REPOSITORY.isEmpty() == false) {
58 QString TDAQ_DB_USER_REPOSITORY = getenv ( "TDAQ_DB_USER_REPOSITORY" );
59 FolderPathList = TDAQ_DB_USER_REPOSITORY.split ( ":", QString::SkipEmptyParts );
60
61 FolderPathList.append(dbe::MainWindow::findthis()->find_db_repository_dir());
62 } else {
63 QString DUNEDAQ_DB_PATH = getenv ( "DUNEDAQ_DB_PATH" );
64 FolderPathList = DUNEDAQ_DB_PATH.split ( ":", QString::SkipEmptyParts );
65 }
66
67 for ( QString & PathName : FolderPathList )
68 {
69 if ( !PathName.endsWith ( "/" ) )
70 {
71 PathName.append ( "/" );
72 }
73 }
74
75 QList<QUrl> List = SelectFile->sidebarUrls();
76
77 if ( !FolderPathList.isEmpty() )
78 {
80
81 for ( const QString & Dir : dbPath )
82 {
83 ui->DirectoryCombo->addItem ( Dir );
84 QString TDAqDir = QString ( "file://" ).append ( Dir );
85 QUrl URL = QUrl ( TDAqDir );
86 List << URL;
87 }
88 }
89
90 SelectFile->setSidebarUrls ( List );
91 SelectFile->setResolveSymlinks ( false );
92 ui->AddToIncludeButton->setDisabled ( true );
93 ui->RemoveButton->setDisabled ( true );
94
95 ui->AddFileLine->setSelectionMode(QAbstractItemView::NoSelection);
96
98}
CreateDatabaseWidget * CreateWidget
std::unique_ptr< dbe::Ui::IncludeFileWidget > ui
static MainWindow * findthis()

Member Function Documentation

◆ AddFileToInclude

void dbe::IncludeFileWidget::AddFileToInclude ( )
privateslot

Need to strip file....

Definition at line 170 of file IncludeFileWidget.cpp.

171{
172 BOOST_SCOPE_EXIT(void)
173 {
174 QApplication::restoreOverrideCursor();
175 }
176 BOOST_SCOPE_EXIT_END
177
178 QApplication::setOverrideCursor(Qt::WaitCursor);
179
180 for(int i = 0; i < ui->AddFileLine->count(); ++i) {
181 QString File = ui->AddFileLine->item(i)->text();
182
183 if ( !File.isEmpty() )
184 {
186 for ( QString & PathFile : FolderPathList )
187 {
188 if ( File.startsWith ( PathFile ) )
189 {
190 File = File.replace ( 0, PathFile.size(), "" );
191 break;
192 }
193 }
194
196
197 StatusBar->setPalette ( QApplication::palette ( this ) );
198 StatusBar->showMessage (
199 QString ( "The file %1 was added to the included files" ).arg ( File ) );
200 }
201 }
202
204
205 ui->AddFileLine->clear();
206 ui->AddToIncludeButton->setDisabled ( true );
207}
void add(QString const &db, QString const &fn)

◆ AddNewFileToInclude

void dbe::IncludeFileWidget::AddNewFileToInclude ( const QString & File)
privateslot

Definition at line 209 of file IncludeFileWidget.cpp.

210{
211 ui->AddFileLine->clear();
212
213 QString includeFilePath;
214 includeFilePath = File;
215
216 if ( includeFilePath.isEmpty() )
217 {
218 return;
219 }
220
221 QFileInfo includeFile = QFileInfo ( includeFilePath );
222
223 if ( !includeFile.isFile() )
224 {
226 StatusBar->showMessage ( QString ( "The file is NOT accessible. Check before usage" ) );
227 }
228 else
229 {
230 QString fileToInclude;
231
232 if ( Directory.isEmpty() )
233 {
234 fileToInclude = includeFile.absoluteFilePath();
235 }
236 else if ( ( includeFile.absoluteDir().canonicalPath() ).compare (
237 Directory ) == 0 ) fileToInclude =
238 includeFile.absoluteFilePath().remove ( Directory + QString ( '/' ), Qt::CaseSensitive );
239 else
240 {
241 fileToInclude = includeFile.absoluteFilePath();
242 }
243
244 ui->AddFileLine->addItem( fileToInclude );
245 ui->AddToIncludeButton->setDisabled(false);
246 }
247}
static QPalette AlertStatusBarPallete

◆ CheckInclude

void dbe::IncludeFileWidget::CheckInclude ( )
privateslot

Definition at line 302 of file IncludeFileWidget.cpp.

303{
305
306 if ( ui->AddFileLine->count() == 0 )
307 {
309 StatusBar->showMessage ( QString ( "Select existing file!" ) );
310 ui->AddToIncludeButton->setDisabled ( true );
311
312 return;
313 }
314
315 std::vector<int> removedItems;
316 for(int i = 0; i < ui->AddFileLine->count(); ++i) {
317 const QString inc = ui->AddFileLine->item(i)->text();
318
319 if(inc == DatabasePath) {
320 removedItems.push_back(i);
321 } else {
322 for(int j = 0; j < ui->RemoveCombo->count(); ++j) {
323 if(ui->RemoveCombo->itemText(j).compare(inc) == 0) {
324 removedItems.push_back(i);
325 }
326 }
327 }
328 }
329
330 if(removedItems.empty() == false) {
331 QString message = "The following files will not be included because already included:";
332
333 for(int i : removedItems) {
334 QListWidgetItem* item = ui->AddFileLine->takeItem(i);
335 message += "\n- " + item->text();
336 delete item;
337 }
338
339 WARN("File inclusion issue", message.toStdString());
340 }
341
342 ui->AddToIncludeButton->setDisabled((ui->AddFileLine->count() == 0) ? true : false);
343}
#define WARN(...)
Definition messenger.hpp:80

◆ CreateFileToInclude

void dbe::IncludeFileWidget::CreateFileToInclude ( )
privateslot

Definition at line 345 of file IncludeFileWidget.cpp.

346{
347 CreateWidget = new CreateDatabaseWidget ( nullptr, true, Directory );
348 connect ( CreateWidget, SIGNAL ( CanIncludeDatabase ( const QString & ) ), this,
349 SLOT ( AddNewFileToInclude ( const QString & ) ), Qt::UniqueConnection );
350 CreateWidget->show();
351}
void AddNewFileToInclude(const QString &File)

◆ RemoveFileFromInclude [1/2]

void dbe::IncludeFileWidget::RemoveFileFromInclude ( )
privateslot

Definition at line 249 of file IncludeFileWidget.cpp.

250{
251 if ( ui->RemoveCombo->currentIndex() != -1 )
252 {
253 BOOST_SCOPE_EXIT(void)
254 {
255 QApplication::restoreOverrideCursor();
256 }
257 BOOST_SCOPE_EXIT_END
258
259 QApplication::setOverrideCursor(Qt::WaitCursor);
260
261 QString File = ui->RemoveCombo->currentText();
262
264 Removed = true;
265 StatusBar->setPalette ( QApplication::palette ( this ) );
266 StatusBar->showMessage (
267 QString ( "The file %1 was removed from the included files" ).arg ( File ) );
269 }
270 else
271 {
273 StatusBar->showMessage (
274 QString ( "The file is NOT selected. Use combo box to select one." ) );
275 }
276}
void remove(QString const &db, QString const &fn)

◆ RemoveFileFromInclude [2/2]

void dbe::IncludeFileWidget::RemoveFileFromInclude ( int )
privateslot

Definition at line 278 of file IncludeFileWidget.cpp.

279{
280 if ( ui->RemoveCombo->currentIndex() != -1 )
281 {
282 ui->RemoveButton->setEnabled ( true );
283 StatusBar->setPalette ( QApplication::palette ( this ) );
284 StatusBar->showMessage (
285 QString ( "The file %1 will be removed from the included files of %2" ).arg (
286 QFileInfo ( ui->RemoveCombo->currentText() ).fileName() ).arg (
287 QFileInfo ( DatabasePath ).fileName() ) );
288 }
289}

◆ SelectFileToInclude

void dbe::IncludeFileWidget::SelectFileToInclude ( )
privateslot

Definition at line 135 of file IncludeFileWidget.cpp.

136{
137 ui->AddFileLine->clear();
138 QStringList Files;
139
140 if ( !Directory.isEmpty() )
141 {
142 SelectFile->setDirectory ( Directory );
143 }
144
145 if ( SelectFile->exec() )
146 {
147 Files = SelectFile->selectedFiles();
148 }
149
150 if(Files.isEmpty()) {
151 return;
152 }
153
154 for(const QString& FileToInclude : Files) {
155 QFileInfo f(FileToInclude);
156
157 if ( Directory.isEmpty() )
158 {
159 ui->AddFileLine->addItem(f.absoluteFilePath());
160 }
161 else
162 {
163 ui->AddFileLine->addItem(f.absoluteFilePath().remove ( Directory + QString ( '/' ), Qt::CaseSensitive ));
164 }
165 }
166
167 CheckInclude();
168}

◆ SetController()

void dbe::IncludeFileWidget::SetController ( )
private

Definition at line 117 of file IncludeFileWidget.cpp.

118{
119 connect ( ui->SelectFileButton, SIGNAL ( clicked() ), this, SLOT ( SelectFileToInclude() ),
120 Qt::UniqueConnection );
121 connect ( ui->CreateFileButton, SIGNAL ( clicked() ), this, SLOT ( CreateFileToInclude() ),
122 Qt::UniqueConnection );
123 connect ( ui->AddToIncludeButton, SIGNAL ( clicked() ), this, SLOT ( AddFileToInclude() ),
124 Qt::UniqueConnection );
125 connect ( ui->RemoveButton, SIGNAL ( clicked() ), this, SLOT ( RemoveFileFromInclude() ),
126 Qt::UniqueConnection );
127 connect ( ui->RemoveCombo, SIGNAL ( activated ( int ) ), this,
128 SLOT ( RemoveFileFromInclude ( int ) ),
129 Qt::UniqueConnection );
130 connect ( ui->DirectoryCombo, SIGNAL ( activated ( const QString & ) ), this,
131 SLOT ( SetDirectory ( const QString & ) ), Qt::UniqueConnection );
132 connect ( ui->ExitButton, SIGNAL ( clicked() ), this, SLOT ( close() ) );
133}
void SetDirectory(const QString &Dir)

◆ SetDirectory

void dbe::IncludeFileWidget::SetDirectory ( const QString & Dir)
privateslot

Definition at line 291 of file IncludeFileWidget.cpp.

292{
293 if(dbPath.contains(Dir, Qt::CaseSensitivity::CaseSensitive) && QDir(Dir).exists()) {
294 Directory = Dir;
295 SelectFile->setDirectory ( Directory );
296 } else {
297 Directory.clear();
298 SelectFile->setDirectory(QDir("."));
299 }
300}

◆ SetRemoveComboBox()

void dbe::IncludeFileWidget::SetRemoveComboBox ( )
private

Definition at line 100 of file IncludeFileWidget.cpp.

101{
103 DatabasePath ) );
104
105 if ( !IncludeList.isEmpty() )
106 {
107 if ( IncludeList.contains ( DatabasePath ) )
108 {
109 IncludeList.removeOne ( DatabasePath );
110 }
111
112 ui->RemoveCombo->clear();
113 ui->RemoveCombo->addItems ( IncludeList );
114 }
115}
static QStringList inclusions_singlefile(QString const &)

Member Data Documentation

◆ CreateWidget

CreateDatabaseWidget* dbe::IncludeFileWidget::CreateWidget
private

Definition at line 31 of file IncludeFileWidget.hpp.

◆ DatabasePath

QString dbe::IncludeFileWidget::DatabasePath
private

Definition at line 32 of file IncludeFileWidget.hpp.

◆ dbPath

QStringList dbe::IncludeFileWidget::dbPath
private

Definition at line 38 of file IncludeFileWidget.hpp.

◆ Directory

QString dbe::IncludeFileWidget::Directory
private

Definition at line 33 of file IncludeFileWidget.hpp.

◆ FolderPathList

QStringList dbe::IncludeFileWidget::FolderPathList
private

Definition at line 37 of file IncludeFileWidget.hpp.

◆ Removed

bool dbe::IncludeFileWidget::Removed
private

Definition at line 34 of file IncludeFileWidget.hpp.

◆ SelectFile

QFileDialog* dbe::IncludeFileWidget::SelectFile
private

Definition at line 36 of file IncludeFileWidget.hpp.

◆ StatusBar

QStatusBar* dbe::IncludeFileWidget::StatusBar
private

Definition at line 35 of file IncludeFileWidget.hpp.

◆ ui

std::unique_ptr<dbe::Ui::IncludeFileWidget> dbe::IncludeFileWidget::ui
private

Definition at line 29 of file IncludeFileWidget.hpp.


The documentation for this class was generated from the following files: