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