DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ObjectCreator.cpp
Go to the documentation of this file.
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#include "dbe/messenger.hpp"
9#include "dbe/Validator.hpp"
10#include "dbe/StyleUtility.hpp"
11#include "ui_ObjectCreator.h"
15#include "dbe/config_api.hpp"
16
17#include "logging/Logging.hpp"
18
19#include <boost/scope_exit.hpp>
20
21#include <QCompleter>
22#include <QMenu>
23#include <QFileDialog>
24#include <QFileInfo>
25#include <QCloseEvent>
26#include <QMessageBox>
27
36
37//------------------------------------------------------------------------------------------
39//------------------------------------------------------------------------------------------
40
41//------------------------------------------------------------------------------------------
42/*
43 * Create an object in a class
44 */
46 :
47 QWidget ( parent ),
48 ui ( new Ui::ObjectCreator ),
49 this_object_class ( cinfo ),
50 this_target_object ( nullptr ),
51 this_relation ( dunedaq::conffwk::relationship_t() ),
52 this_files ( nullptr ),
53 this_status_bar ( nullptr ),
54 this_state ( 0 ),
55 UidSet ( false ),
56 this_associated_editor ( nullptr ),
57 ContextMenu ( nullptr ),
58 this_is_temporary ( false ),
59 this_object_changed ( false ),
60 this_create_copy ( false ),
61 uuid ( QUuid::createUuid() )
62{
63 ui->setupUi ( this );
64 this_status_bar = new QStatusBar ( ui->StatusFrame );
65
66 QString cname = QString::fromStdString ( this_object_class.p_name );
67 setWindowTitle ( QString ( "Create New Object of Class %1" ).arg ( cname ) );
68
70 ui->LineEditUID->setToolTip ( QString ( "Type Object unique ID and press ENTER" ) );
71
72 ui->ComboBoxForbiddenUid->hide();
73 ui->SetFileButton->hide();
74
79
80 int index = ui->ComboBoxClass->findText ( cname );
81 ui->ComboBoxClass->setCurrentIndex ( 1 ); // If index is 0 somehow this doesnt work
82 ui->ComboBoxClass->setCurrentIndex ( index ); // Now set it to the right value posssibly 0
84 ui->ComboBoxClass->setEditText ( cname );
85
86 ui->SetUidButton->setVisible ( false );
88
89 QSize SplitterSize = ui->splitter->size();
90 int Width = SplitterSize.width() / 2;
91
92 QList<int> List;
93 List.push_back ( Width );
94 List.push_back ( Width );
95
96 ui->splitter->setSizes ( List );
97}
98
99//------------------------------------------------------------------------------------------
100
101//------------------------------------------------------------------------------------------
102/*
103 * Clone an object in a class , uid will be required to be set explicitly
104 */
106 dunedaq::conffwk::relationship_t const & the_relation,
107 QWidget * parent )
108 :
110 config::api::info::onclass::definition ( clonefrom.class_name(), false ), parent )
111{
112 this_target_object.reset ( new tref ( clonefrom ) );
113 this_relation = the_relation;
114}
115
116//------------------------------------------------------------------------------------------
117
118//------------------------------------------------------------------------------------------
119dbe::ObjectCreator::ObjectCreator ( tref const & clonefrom, QWidget * parent )
120 :
121 QWidget ( parent ),
122 ui ( new Ui::ObjectCreator ),
124 config::api::info::onclass::definition ( clonefrom.class_name(), false ) ),
125 this_src_object ( new tref ( clonefrom ) ),
126 this_files ( nullptr ),
127 this_status_bar ( nullptr ),
128 UidSet ( false ),
129 this_associated_editor ( nullptr ),
130 ContextMenu ( nullptr ),
131 this_is_temporary ( false ),
132 this_object_changed ( false ),
133 this_create_copy ( true ),
134 uuid ( QUuid::createUuid() )
135{
136 ui->setupUi ( this );
137 this_status_bar = new QStatusBar ( ui->StatusFrame );
138
139 setWindowTitle (
140 QString ( "Create New Object of Class %1" ).arg (
141 QString::fromStdString ( this_object_class.p_name ) ) );
142
144 ui->LineEditUID->setToolTip ( QString ( "Type Object unique ID and press ENTER" ) );
145
146 ui->ComboBoxForbiddenUid->hide();
147 ui->SetFileButton->hide();
148
151 SetStatusBar();
153
154 int index = ui->ComboBoxClass->findText ( QString::fromStdString (
155 clonefrom.class_name() ) );
156
157 ui->ComboBoxClass->setCurrentIndex ( index );
159
161 QString const & fn = QString::fromStdString ( this_src_object->contained_in() );
162 QFileInfo fileinfo ( fn );
163 QModelIndexList ListOfMatch = this_files->match (
164 this_files->index ( 0, 0 ),
165 Qt::DisplayRole, fileinfo.fileName(), 1000,
166 Qt::MatchContains | Qt::MatchWrap | Qt::MatchRecursive );
167
168 ui->FileView->selectRow ( ListOfMatch.at ( 0 ).row() );
169
170 ActiveFileChanged ( fn );
171
172 // Set uid to the that of the object being copied
173 ui->LineEditUID->setText ( QString::fromStdString ( clonefrom.UID() ) );
174 ui->ComboBoxClass->setEditText ( QString::fromStdString ( clonefrom.class_name() ) );
175
176 ui->SetUidButton->setVisible ( false );
178
179 QSize spliter_size = ui->splitter->size();
180 int w = spliter_size.width() / 2;
181 ui->splitter->setSizes ( QList<int>
182 { w, w } );
183}
184
185//------------------------------------------------------------------------------------------
186
187//------------------------------------------------------------------------------------------
189{
190 QStringList ListOfClasses ( dbe::config::api::info::onclass::allnames<QStringList>() );
191 ui->ComboBoxClass->addItems ( ListOfClasses );
192
193 QCompleter * completer = new QCompleter ( ui->ComboBoxClass->model(), ui->ComboBoxClass );
194 completer->setCaseSensitivity ( Qt::CaseInsensitive );
195 completer->setFilterMode(Qt::MatchContains);
196 ui->ComboBoxClass->setCompleter ( completer );
197 ui->ComboBoxClass->setEditable ( true );
198
199 QVariant VarFromList ( ListOfClasses );
200 ValidatorAcceptMatch * Validator = new ValidatorAcceptMatch ( VarFromList, this );
201 ui->ComboBoxClass->setValidator ( Validator );
202}
203
204
206{
207 connect ( ui->FileView, SIGNAL ( stateChanged ( const QString & ) ),
208 this, SLOT ( ActiveFileChanged ( const QString & ) ),
209 Qt::UniqueConnection );
210
211 connect ( ui->CreateObjectButton, SIGNAL ( clicked() ), this, SLOT ( CreateObject() ),
212 Qt::UniqueConnection );
213
214 connect ( ui->CreateOpenObjectButton, SIGNAL ( clicked() ), this, SLOT ( CreateOpenObject() ),
215 Qt::UniqueConnection );
216
217 connect ( ui->ExitButton, SIGNAL ( clicked() ), this, SLOT ( close() ),
218 Qt::UniqueConnection );
219
220 connect ( ui->LineEditUID, SIGNAL ( textChanged ( QString ) ), this,
221 SLOT ( UpdateActions ( QString ) ),
222 Qt::UniqueConnection );
223
224 connect ( ui->LineEditUID, SIGNAL ( textEdited ( const QString & ) ),
225 this, SLOT ( MustPressReturn ( const QString & ) ),
226 Qt::UniqueConnection );
227
228 connect ( this, SIGNAL ( stateChanged() ), this, SLOT ( UpdateActions() ),
229 Qt::UniqueConnection );
230
231 connect ( this, SIGNAL ( stateChanged() ), this, SLOT ( SetObjectChanged() ),
232 Qt::UniqueConnection );
233}
234
236{
237 if ( not confaccessor::db_implementation_name().contains ( "roksconflibs" ) )
238 {
239 if ( this_files != nullptr )
240 {
241 delete this_files;
242 this_files = nullptr;
243 }
244
245 this_files = new FileModel ( confaccessor::ref().GetIncludedFileCache() );
246
247 this_sort.setSourceModel ( this_files );
248 ui->FileView->setModel ( &this_sort );
249 ui->FileView->sortByColumn ( 2, Qt::DescendingOrder );
250
251 // ui->FileView->HideReadOnlyFilesSlot(true);
252 ui->FileView->setColumnHidden(2, true);
253 ui->FileView->setColumnHidden(3, true);
254 ui->FileView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
255 }
256}
257
259{
260 this_status_bar->setSizeGripEnabled ( false );
261 this_status_bar->setAutoFillBackground ( true );
262 this_status_bar->showMessage (
263 QString ( "Select class, set new object UID, select file where to create object!" ) );
264 ui->StatusFrame->setFrameStyle ( QFrame::NoFrame );
265 ui->StatusLayout->addWidget ( this_status_bar );
266}
267
269{
270 bool ReleaseEditor = true;
272
273 if ( !ui->LineEditUID->IsValid() || ui->LineEditUID->text().isEmpty() )
274 {
276 ReleaseEditor = false;
277 this_newuid = QString();
278 }
279 else
280 {
282 this_newuid = ui->LineEditUID->text();
283 }
284
285 if ( this_file_for_new_object.isEmpty() )
286 {
288 ReleaseEditor = false;
289 }
290 else
291 {
293 }
294
295 if ( ReleaseEditor )
296 {
297 this_associated_editor->setEnabled ( true );
298 }
299
300 if ( this_associated_editor != nullptr )
301 {
302 if ( !this_associated_editor->IsEditorValid() )
303 {
305 }
306 else
307 {
309 }
310 }
311
312 if ( this_state == editorOk )
313 {
314 ui->CreateObjectButton->setEnabled ( true );
315 ui->CreateObjectButton->setPalette ( StyleUtility::PaleGreenPalleteButton );
316
317 ui->CreateOpenObjectButton->setEnabled ( true );
318 ui->CreateOpenObjectButton->setPalette ( StyleUtility::PaleGreenPalleteButton );
319
320 this_status_bar->setPalette ( QApplication::palette ( this ) );
321 this_status_bar->showMessage ( GetMessage() );
322 }
323 else
324 {
325 ui->CreateObjectButton->setEnabled ( false );
326 ui->CreateOpenObjectButton->setEnabled ( false );
327 QPalette buttonAlert;
328 buttonAlert.setColor ( QPalette::Disabled, QPalette::Button, QColor ( "grey" ) );
329 ui->CreateObjectButton->setPalette ( buttonAlert );
330 ui->CreateOpenObjectButton->setPalette ( buttonAlert );
332 this_status_bar->showMessage ( GetMessage() );
333 }
334}
335
337{
338 Q_UNUSED ( Dummy )
340}
341
343{
344 if ( this_state == editorOk )
345 return QString (
346 "Now you can create object '%1' of class '%2'." ).arg ( this_newuid ).arg (
347 QString ( ( this_object_class.p_name ).c_str() ) );
349 return QString (
350 "Select class, set unique ID, select file where to create object and set obligatory attributes and relationships!" );
351 else if ( GetState ( classNotSelected ) )
352 {
353 return QString ( "First select class!" );
354 }
355 else if ( GetState ( fileNotSet ) )
356 return QString (
357 "Set active file where to create new object" );
358 else if ( GetState ( uidNotSet ) )
359 {
360 return QString ( "Set the object UID" );
361 }
362 else if ( GetState ( nullNotFilled ) )
363 return QString (
364 "All NOT NULL attributes or relationships must be set!" );
365
366 return QString ( "Problem to process Object Create operation!" );
367}
368
370{
371 return ( ( this_state & Flags ) == Flags );
372}
373
375{
376 ContextMenu = new QMenu ( this );
377 ContextMenu->addAction ( tr ( "&Edit Include Files" ), this, SLOT ( AddInclude() ),
378 QKeySequence ( tr ( "Ctrl+Z" ) ) );
379}
380
383
385{
386 ui->ComboBoxForbiddenUid->clear();
387
388 QStringList listOfUID;
389 QString nameOfClass = QString ( this_object_class.p_name.c_str() );
390
391 std::vector<tref> const & vec = dbe::config::api::info::onclass::objects (
392 nameOfClass.toStdString(),
393 false );
394
395 for ( size_t i = 0; i < vec.size(); ++i )
396 {
397 ui->ComboBoxForbiddenUid->addItem ( QString ( vec.at ( i ).UID().c_str() ) );
398 listOfUID << QString ( vec.at ( i ).UID().c_str() );
399 }
400
401 if ( !listOfUID.isEmpty() )
402 {
403 ui->ComboBoxForbiddenUid->setToolTip (
404 QString ( "Already used object unique ID of class %1 " ).arg ( nameOfClass ) );
405 ui->ComboBoxForbiddenUid->show();
406 }
407
408 QVariant varFromList ( listOfUID );
409 ValidatorAcceptNoMatch * myval = new ValidatorAcceptNoMatch ( varFromList, this );
410 ui->LineEditUID->SetValidator ( myval );
411}
412
416
418{
419 setCursor ( Qt::WaitCursor );
420
421 BOOST_SCOPE_EXIT(this_)
422 {
423 this_->unsetCursor();
424 }
425 BOOST_SCOPE_EXIT_END
426
427 if ( this_file_for_new_object.isEmpty() )
428 {
429 ERROR ( "Object creation not feasible", "Object file must be selected" )
430 }
431 else if ( this_newuid.isEmpty() )
432 {
433 ERROR ( "Object creation not feasible", "Object name (uid) cannot be an empty string" );
434 }
435 else if ( this_associated_editor )
436 {
437 this_associated_editor->SetUsedForCopy ( true );
438
439 bool done = this_associated_editor->ParseToCreate ( this_newuid.toStdString(),
440 this_file_for_new_object.toStdString() );
441 this_associated_editor->SetUsedForCopy ( false );
442 this_associated_editor->ResetObjectChanged();
443 this_object_changed = false;
444
445 if ( done )
446 {
447 close();
448
449 if ( openEditor == true ) {
450 ( new ObjectEditor ( dbe::inner::dbcontroller::get({this_newuid.toStdString(), this_object_class.p_name}) ) )->show();
451 }
452 }
453 }
454}
455
460
461void dbe::ObjectCreator::ActiveFileChanged ( const QString & fname )
462{
463 if ( fname.isEmpty() or not confaccessor::check_file_rw ( fname ) )
464 {
465 this_file_for_new_object = QString();
466 emit stateChanged();
467 return;
468 }
469
471 ui->FileView->setToolTip (
472 QString ( "Activate file which will store the new object: " ).append (
474 QString setFilesWithPath = QString ( "Selected File: %1" ).arg ( this_file_for_new_object );
475 QString setOnlyFiles = QString ( "Selected File: %1" ).arg (
476 QFileInfo ( this_file_for_new_object ).fileName() );
477 ui->FileLabel->setText ( setOnlyFiles );
478 ui->FileLabel->setToolTip ( setFilesWithPath );
479 ui->FileView->setStyleSheet ( "selection-background-color : rgb(190,238,158)" );
480 emit stateChanged();
481}
482
484{
485 if ( ui->ComboBoxClass->IsValid() )
486 {
487
488 this_newuid = QString();
489 QString cname = QString::fromStdString ( this_object_class.p_name );
490
491 // Create the editor for the new object to be able to modify attributes before creation
492 this_associated_editor = new ObjectEditor ( cname.toStdString(), this );
493 this_associated_editor->setWindowModality ( Qt::NonModal );
494 this_associated_editor->HideDetailWidget ( true );
495 this_associated_editor->setDisabled ( true );
496 ui->EditorLayout->addWidget ( this_associated_editor );
497
498 {
499 // Set appropriately the stretch factor such that contents are resized
500 // favoring the object editor side
501 QSizePolicy pol = ui->splitter->widget ( 1 )->sizePolicy();
502 pol.setHorizontalStretch ( 2 );
503// pol.setHorizontalPolicy(QSizePolicy::Maximum);
504 ui->splitter->widget ( 1 )->setSizePolicy ( pol );
505 }
506
507 {
508 // Set horizontal size of the editor pane to the first widget size
509 this_associated_editor->resize ( this_associated_editor->sizeHint() );
510 QList<QTableWidget *> const & editor_widgets
511 {
512 this_associated_editor->findChildren<QTableWidget *>()
513 };
514
515 this_associated_editor->setMinimumWidth ( editor_widgets[0]->width() / 2 );
516
517 QRect this_widget_geometry = this->geometry();
518 this_widget_geometry.setWidth ( editor_widgets[0]->width() +
519 ui->ObjectCreatorWidget->width() );
520 this->setGeometry ( this_widget_geometry );
521
522 }
523
524 // Set the labels to the class name
525 ui->ClassLabel->setText ( QString ( "Selected Class: %1" ).arg ( cname ) );
526 setWindowTitle ( QString ( "Create New Object of class %1" ).arg ( cname ) );
527
528 connect ( this_associated_editor, SIGNAL ( WidgetUpdated() ), this,
529 SLOT ( UpdateActions() ),
530 Qt::UniqueConnection );
531
533 ui->ComboBoxForbiddenUid->hide();
534
535 QString const & linetext = ui->LineEditUID->text();
536
537 if ( !linetext.isEmpty() )
538 {
539 ui->LineEditUID->clear();
540 ui->LineEditUID->setText ( linetext );
541 SetUID();
542 }
543
544 emit stateChanged();
545 this_object_changed = false;
546 }
547}
548
550{
551 if ( ui->ComboBoxClass->IsValid() )
552 {
553 QString cname = QString::fromStdString ( this_object_class.p_name );
554
555 ui->ClassLabel->setText ( QString ( "Selected Class: %1" ).arg ( cname ) );
556 setWindowTitle ( QString ( "Create New Object of Class %1" ).arg ( cname ) );
557
559 this_associated_editor->setWindowModality ( Qt::NonModal );
560 this_associated_editor->SetUsedForCopy ( true );
561 this_associated_editor->HideDetailWidget ( true );
562 this_associated_editor->setDisabled ( true );
563
564 ui->EditorLayout->addWidget ( this_associated_editor );
565 connect ( this_associated_editor, SIGNAL ( WidgetUpdated() ), this,
566 SLOT ( UpdateActions() ),
567 Qt::UniqueConnection );
568
570 ui->ComboBoxForbiddenUid->hide();
571
572 QString tmpSt = ui->LineEditUID->text();
573
574 if ( !tmpSt.isEmpty() )
575 {
576 ui->LineEditUID->clear();
577 ui->LineEditUID->setText ( tmpSt );
578 SetUID();
579 }
580
581 emit stateChanged();
582 this_object_changed = false;
583 }
584}
585
587{
588 if ( this_file_for_new_object.isEmpty() )
589 {
590 ERROR ( "Object creation is not feasible", "Database file not selected" );
591 return;
592 }
593
594 if ( ui->LineEditUID->IsValid() )
595 {
596 this_newuid = ui->LineEditUID->text();
597
598 QString textForUser = QString ( "New Object ID: %1" ).arg ( this_newuid );
599 ui->UidLabel->setText ( textForUser );
600 }
601 else
602 {
603 WARN ( "Object creation is not feasible", "Invalid UID provided" );
604 return;
605 }
606
607 if ( !this_file_for_new_object.isEmpty() )
608 {
609 UidSet = true;
610 this_associated_editor->setDisabled ( false );
611 emit stateChanged();
612 }
613 else
614 {
615 TLOG_DEBUG(0) << "active file empty!! check!!" ;
616 }
617}
618
620{
621 QPalette yellow;
622 yellow.setColor ( QPalette::Active, QPalette::Window, QColor ( "yellow" ) );
623
624 this_status_bar->setPalette ( yellow );
625 this_status_bar->showMessage ( QString ( "Press ENTER to set new UID!" ) );
626}
627
629{
630
631 if ( ( this_object_changed and ui->CreateObjectButton->isEnabled() ) or
632 ( this_associated_editor and this_associated_editor->WasObjectChanged() ) )
633 {
634 int ret =
635 QMessageBox::question (
636 0,
637 tr ( "DBE - ObjectCreate" ),
638 QString ( "There are pending actions for this dialogue" ),
639 QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel );
640
641 if ( ret == QMessageBox::Discard )
642 {
643 this_object_changed = false;
644 this_associated_editor->ResetObjectChanged();
645
646 try
647 {
649 inner::dbcontroller::get ( { this_newuid.toStdString(), this_object_class.p_name } ),
650 uuid );
651 }
652 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
653 {
654 // nothing specific handle needed in this , it is possible that there is no resul
655 }
656
657 return true;
658 }
659 else if ( ret == QMessageBox::Cancel )
660 {
661 return false;
662 }
663
664 return true;
665 }
666 else
667 {
668 return true;
669 }
670}
671
672void dbe::ObjectCreator::closeEvent ( QCloseEvent * event )
673{
674 if ( CanClose() )
675 {
677 {
678 this_associated_editor->close();
679 this_associated_editor = nullptr;
680 }
681
682 event->accept();
683 }
684 else
685 {
686 event->ignore();
687 }
688}
EditStates
@ editorOk
@ nullNotFilled
@ classNotSelected
@ uidNotSet
@ fileNotSet
ObjectEditor * this_associated_editor
void MustPressReturn(QString const &)
dunedaq::conffwk::relationship_t this_relation
void ActiveFileChanged(QString const &)
ObjectCreator(dunedaq::conffwk::class_t const &classinfo, QWidget *parent=0)
void closeEvent(QCloseEvent *event)
std::unique_ptr< dbe::Ui::ObjectCreator > ui
dunedaq::conffwk::class_t this_object_class
std::unique_ptr< tref > this_src_object
void CreateObject(bool openEditor=false)
QSortFilterProxyModel this_sort
std::unique_ptr< tref > this_target_object
QStatusBar * this_status_bar
bool GetState(int Flags)
static QPalette PaleGreenPalleteButton
static QPalette WarningStatusBarPalleteWindow
static bool check_file_rw(const QString &FileName)
static confaccessor & ref()
static QString db_implementation_name()
static std::vector< dbe::inner::configobject::tref > objects(std::string const &cname, bool const keep_inherited=true)
static configobject::tref get(dbe::cokey const &desc)
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
#define ERROR(...)
Definition messenger.hpp:93
#define WARN(...)
Definition messenger.hpp:85
bool delobj(inner::configobject::tref obj, QUuid const &src)
inner::configobject::tref tref
Definition tref.hpp:35
Including Qt Headers.
Definition module.cpp:16