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