DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ObjectEditor.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
8#include "dbe/Sorting.hpp"
13#include "dbe/messenger.hpp"
14#include "ui_ObjectEditor.h"
15#include "dbe/MainWindow.hpp"
16
17#include <QFileInfo>
18#include <QCloseEvent>
19#include <QMessageBox>
20
22
23namespace {
24 class NoScrollingTable : public QTableWidget {
25 public:
26 explicit NoScrollingTable(QWidget* parent = nullptr)
27 : QTableWidget(parent) {}
28
29 void scrollTo(const QModelIndex& /*index*/, ScrollHint /*hint*/) override {
30 // NOTE: for the reason why this is an empty implementation, see ATLASDBE-202
31 }
32 };
33} // namespace
34
35//------------------------------------------------------------------------------------------
37//------------------------------------------------------------------------------------------
38
39//------------------------------------------------------------------------------------------
41 :
42 QWidget(parent),
43 ui ( new Ui::ObjectEditor ),
44 IsValid ( false ),
46 CurrentRow ( 0 ),
47 MainLayout ( new QHBoxLayout() ),
48 // WidgetTable ( new NoScrollingTable() ),
49 WidgetTable ( new QTableWidget() ),
50 RenameWidget ( nullptr ),
51 LineEdit ( nullptr ),
52 GoButton ( nullptr ),
53 MoveWidget ( nullptr ),
54 FileView ( nullptr ),
55 IncludedFileModel ( nullptr ),
56 MoveGoButton ( nullptr ),
57 uuid ( QUuid::createUuid() )
58{
59 ui->setupUi ( this );
60}
61//------------------------------------------------------------------------------------------
62
63//------------------------------------------------------------------------------------------
64
65dbe::ObjectEditor::ObjectEditor ( std::string const & cname, QWidget * parent )
66 : ObjectEditor ( parent ) {
67
68 classname = cname;
69 m_object_to_edit = nullptr;
73
74 ui->RenameButton->setDisabled ( true ); // Cannot rename an object that does not exist
75 ui->ClassLabel->setText ( QString ( "New Object" ) );
76
77 init();
78}
79
80//------------------------------------------------------------------------------------------
81
82dbe::ObjectEditor::ObjectEditor ( tref const & object, QWidget * parent, bool iscopy )
83 : ObjectEditor ( parent ) {
84
85 classname = object.class_name();
86 m_object_to_edit.reset(new dref ( object ));
87 this_is_in_copy_mode = iscopy;
90
91 ui->ClassLabel->setText (
92 QString ( "Full object name : %1@%2" ).arg ( Object().UID().c_str() ).arg (
93 Object().class_name().c_str() ) );
94
95 this->setWindowTitle (
96 QString ( "Edit Object %1 of Class %2" ).arg ( Object().UID().c_str() ).arg (
97 Object().class_name().c_str() ) );
98
99 this->setObjectName (
100 QString ( "%1@%2" ).arg ( Object().UID().c_str() ).arg ( Object().class_name().c_str() ) );
101
102 init();
103}
104
105//------------------------------------------------------------------------------------------
107
108 if (m_object_to_edit and not Object().is_null()) {
110 QString::fromStdString ( Object().contained_in() ));
111 }
112
113 dunedaq::conffwk::class_t const & Class =
115 int NumberOfRows = Class.p_attributes.size() + Class.p_relationships.size();
116 int NumberOfColumns = 1;
117 WidgetTable->setRowCount ( NumberOfRows );
118 WidgetTable->setColumnCount ( NumberOfColumns );
119 setAttribute ( Qt::WA_DeleteOnClose, true );
120
122 BuildWidgets();
125
126 ui->DetailsGroupBox->setVisible ( false );
127
128 WidgetTable->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
129 WidgetTable->horizontalHeader()->setVisible ( false );
130 WidgetTable->horizontalHeader()->setSectionResizeMode ( QHeaderView::ResizeToContents );
131 WidgetTable->horizontalHeader()->setSectionResizeMode ( 0, QHeaderView::Stretch );
132 WidgetTable->setVerticalHeaderLabels ( HorizontalHeaders );
133 WidgetTable->setSelectionMode ( QAbstractItemView::NoSelection );
134
136 {
137 ui->RenameButton->setDisabled ( true );
138 ui->MoveButton->setDisabled ( true );
139 }
140 else {
141 if (m_readonly) {
142 // WidgetTable->setDisabled(true);
143 ui->RenameButton->setDisabled(true);
144 ui->MoveButton->setDisabled(true);
145 ui->ApplyButton->hide();
146 }
147 }
148 ui->TableLayout->addWidget ( WidgetTable );
149
150 ui->ApplyButton->setEnabled ( false );
151
152 ui->RenameButton->setToolTip ( "Rename object" );
153
154
155 this->show();
156}
157
158void dbe::ObjectEditor::keyPressEvent(QKeyEvent* event) {
159 if (event->key() == Qt::Key_Escape) {
160 close();
161 }
162 QWidget::keyPressEvent(event);
163}
164//------------------------------------------------------------------------------------------
165
166//------------------------------------------------------------------------------------------
168{
169 if ( Hide )
170 {
171 ui->DetailWidget->hide();
172 ui->DetailsGroupBox->hide();
173 }
174 else
175 {
176 ui->DetailWidget->show();
177 ui->DetailsGroupBox->show();
178 }
179}
180
181//------------------------------------------------------------------------------------------
182
183//------------------------------------------------------------------------------------------
185{
186 return IsValid;
187}
188
193
194//------------------------------------------------------------------------------------------
195
196//------------------------------------------------------------------------------------------
198{
200 ui->ApplyButton->isEnabled() )
201 {
202 int ret =
203 QMessageBox::question (
204 0,
205 tr ( "DBE - ObjectEditor" ),
206 QString (
207 "There are unsaved changes for object\n'%1.%2'\n\nDo you want to apply changes?\n" )
208 .arg ( QString::fromStdString ( Object().full_name() ) ),
209 QMessageBox::Apply | QMessageBox::Discard | QMessageBox::Cancel,
210 QMessageBox::Apply );
211
212 switch ( ret )
213 {
214
215 case QMessageBox::Discard:
217 break;
218
219 case QMessageBox::Apply:
220 ParseToSave();
221 break;
222
223 case QMessageBox::Cancel:
224 return false;
225 break;
226 }
227
228 return true;
229 }
230 else
231 {
232 return true;
233 }
234}
235
236//------------------------------------------------------------------------------------------
237
238//------------------------------------------------------------------------------------------
240{
241 StatusBar->setSizeGripEnabled ( false );
242 StatusBar->setAutoFillBackground ( true );
243}
244
245//------------------------------------------------------------------------------------------
246
247//------------------------------------------------------------------------------------------
249{
250 connect ( ui->DetailButton, SIGNAL ( toggled ( bool ) ), ui->DetailsGroupBox,
251 SLOT ( setVisible ( bool ) ), Qt::UniqueConnection );
252 connect ( ui->CloseButton, SIGNAL ( clicked ( bool ) ), this, SLOT ( close() ),
253 Qt::UniqueConnection );
254 connect ( ui->ApplyButton, SIGNAL ( clicked() ), this, SLOT ( ParseToSave() ),
255 Qt::UniqueConnection );
256
257 connect ( ui->RenameButton, SIGNAL ( clicked() ), this, SLOT ( LaunchRenameObject() ) );
258 connect ( ui->MoveButton, SIGNAL ( clicked() ), this, SLOT ( LaunchMoveObject() ) );
259
260 connect ( &confaccessor::ref(), SIGNAL ( object_changed ( QString, dref ) ), this,
261 SLOT ( UpdateObjectEditor ( QString, dref ) ) );
262
263 connect ( &confaccessor::ref(), SIGNAL ( object_deleted ( QString, dref ) ), this,
264 SLOT ( ShouldCloseThisWindow ( QString, dref ) ) );
265
266 MainWindow * mainwin = MainWindow::findthis();
267 if(mainwin != nullptr) {
268 connect (mainwin, SIGNAL(signal_batch_change_stopped(const QList<QPair<QString, QString>>&)),
269 this, SLOT(UpdateObjectEditor(const QList<QPair<QString, QString>>&)), Qt::UniqueConnection);
270 connect (mainwin, SIGNAL(signal_externalchanges_processed()),
271 this, SLOT(UpdateObjectEditor()), Qt::UniqueConnection);
272 }
273}
274
275void dbe::ObjectEditor::UpdateObjectEditor(const QList<QPair<QString, QString>>& objs) {
276 for(const auto& p : objs) {
277 if((p.first.toStdString() == Object().class_name()) && (p.second.toStdString() == Object().UID())) {
278 UpdateObjectEditor("", inner::dbcontroller::get({Object().UID(), Object().class_name()}));
279 break;
280 }
281 }
282}
283
285 const auto& ref = inner::dbcontroller::get({Object().UID(), Object().class_name()});
286 if(ref.is_null() == false) {
287 UpdateObjectEditor("", inner::dbcontroller::get({Object().UID(), Object().class_name()}));
288 } else {
289 // The object has been deleted
290 this->close();
291 }
292}
293
294//------------------------------------------------------------------------------------------
295
296//------------------------------------------------------------------------------------------
297void dbe::ObjectEditor::UpdateObjectEditor ( QString const & src, dref updated_object )
298{
299 // src is ignored even in the case of this being the source
300 // changes must always be applied since it is developer responsibility
301 // to emit signals as needed
302 Q_UNUSED ( src );
303
304 if ( not this_editor_is_owned and m_object_to_edit and Object().UID() == updated_object.UID()
305 and Object().class_name() == updated_object.class_name() )
306 {
307
308 m_object_to_edit.reset ( new dref ( updated_object ) );
309
310 dunedaq::conffwk::class_t const & classdef =
312 std::vector<dunedaq::conffwk::attribute_t> class_attributes = classdef.p_attributes;
313 std::vector<dunedaq::conffwk::relationship_t> class_relations = classdef.p_relationships;
314
315 for ( dunedaq::conffwk::attribute_t attr : class_attributes )
316 {
317 if ( widgets::editors::base * attreditor =
318 this_widgets[QString::fromStdString ( attr.p_name )] )
319 {
320 set_attribute_widget ( attr, attreditor );
321 }
322 }
323
324 for ( dunedaq::conffwk::relationship_t arelation : class_relations )
325 {
326 QStringList relvalues;
327 QString relname = QString ( arelation.p_name.c_str() );
328
329 if ( widgets::editors::relation * relwidget =
330 dynamic_cast<widgets::editors::relation *> ( this_widgets[relname] ) )
331 {
332 if ( relwidget->ischanged() )
333 {
334 relvalues = relwidget->getdata();
335 }
336 else
337 {
338 std::vector<tref> connected;
339
340 if ( config::api::info::relation::is_simple ( arelation ) )
341 {
342 try
343 {
344 connected.push_back (
346 }
347 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
348 {
349 // nothing needs be done to handle the case that a relation has no object set
350 }
351 }
352 else
353 {
354 connected =
356 }
357
358 std::transform ( connected.begin(), connected.end(), std::back_inserter ( relvalues ),
359 [] ( decltype ( connected ) ::value_type const & x )
360 {
361 return QString::fromStdString ( x.full_name() );
362 }
363
364 );
365
366 }
367
368 relwidget->setdata ( relvalues );
369 relwidget->SetEditor();
370 }
371 }
372 }
373
374 // Trick to properly refresh the window (repaint and update does not seem to work)
375 const auto& s = size();
376 resize(s.width() + 1, s.height() +1);
377 resize(s.width(), s.height());
378}
379
380//------------------------------------------------------------------------------------------
381
382//------------------------------------------------------------------------------------------
383void dbe::ObjectEditor::ShouldCloseThisWindow ( QString const src, dref const key )
384{
385 Q_UNUSED ( src );
386
387 std::string const & fullname = key.UID() + "@" + key.class_name();
388
389 if ( ( m_object_to_edit and not m_object_to_edit->is_valid() )
390 or ( this->objectName().toStdString() == fullname ) )
391 {
392 this->close();
393 }
394}
395
396//------------------------------------------------------------------------------------------
397
398//------------------------------------------------------------------------------------------
400{
401 dunedaq::conffwk::class_t const & classdef =
403 std::vector<dunedaq::conffwk::attribute_t> attributes = classdef.p_attributes;
404 std::vector<dunedaq::conffwk::relationship_t> relations = classdef.p_relationships;
405
406 for ( dunedaq::conffwk::attribute_t const & attr : attributes ) // Build widgets for attributes
407
408 {
409 QString name = QString::fromStdString ( attr.p_name );
410
411 if ( attr.p_is_multi_value )
412 {
414 true, m_readonly );
415 set_attribute_widget ( attr, widget );
416
417 set_tooltip ( attr, widget );
418 register_attribute_widget ( name, widget );
419 connect ( widget, SIGNAL ( signal_value_change() ), this, SLOT ( UpdateActions() ),
420 Qt::UniqueConnection );
421 connect ( widget, SIGNAL ( signal_value_change() ), this, SLOT ( ObjectChanged() ),
422 Qt::UniqueConnection );
423 emit LoadedInitials();
424 }
425 else
426 {
427 switch ( attr.p_type )
428 {
429
431
433 {
434 widgets::editors::combo * Widget = new widgets::editors::combo ( attr, this, true );
435 set_attribute_widget ( attr, Widget );
436 set_tooltip ( attr, Widget );
437 register_attribute_widget ( name, Widget );
438 connect ( Widget->Combo, SIGNAL ( activated ( QString ) ), this, SLOT ( UpdateActions() ),
439 Qt::UniqueConnection );
440 connect ( Widget, SIGNAL ( signal_value_change() ), this, SLOT ( ObjectChanged() ),
441 Qt::UniqueConnection );
442 emit LoadedInitials();
443 break;
444 }
445
447
449
451
453
455
457
459
461
463
465 {
467 new widgets::editors::numericattr ( attr, this, true, m_readonly );
468 set_attribute_widget ( attr, Widget );
469 set_tooltip ( attr, Widget );
470 register_attribute_widget ( name, Widget );
471 connect ( Widget, SIGNAL ( signal_value_change() ), this, SLOT ( UpdateActions() ),
472 Qt::UniqueConnection );
473 connect ( Widget, SIGNAL ( signal_value_change() ), this, SLOT ( ObjectChanged() ),
474 Qt::UniqueConnection );
475 emit LoadedInitials();
476 break;
477 }
478
480
482
484 {
486 new widgets::editors::stringattr ( attr, this, true, m_readonly );
487 set_attribute_widget ( attr, Widget );
488 set_tooltip ( attr, Widget );
489 register_attribute_widget ( name, Widget );
490 connect ( Widget, SIGNAL ( signal_value_change() ), this, SLOT ( UpdateActions() ),
491 Qt::UniqueConnection );
492 connect ( Widget, SIGNAL ( signal_value_change() ), this, SLOT ( ObjectChanged() ),
493 Qt::UniqueConnection );
494 emit LoadedInitials();
495 break;
496 }
497
499 {
500 widgets::editors::combo * Widget = new widgets::editors::combo ( attr, this, true );
501 set_attribute_widget ( attr, Widget );
502 set_tooltip ( attr, Widget );
503 register_attribute_widget ( name, Widget );
504 connect ( Widget->Combo, SIGNAL ( activated ( QString ) ), this, SLOT ( UpdateActions() ),
505 Qt::UniqueConnection );
506 connect ( Widget, SIGNAL ( signal_value_change() ), this, SLOT ( ObjectChanged() ),
507 Qt::UniqueConnection );
508 emit LoadedInitials();
509 break;
510 }
511 }
512 }
513 }
514
515 for ( dunedaq::conffwk::relationship_t const & arelation :
516 relations ) // Build widgets for relations ( relationships )
517 {
518 widgets::editors::relation * widget = new widgets::editors::relation ( arelation, this,
519 true, m_readonly );
520 QString name = QString::fromStdString ( arelation.p_name );
521 QStringList Data;
522
523 if ( m_object_to_edit and not Object().is_null() )
524 {
525 std::vector<tref> DataList;
526
527 if ( config::api::info::relation::is_simple ( arelation ) )
528 {
529 try
530 {
531 DataList.push_back (
533 }
534 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
535 {
536 // nothing needs be done to handle cases that a relation has not been set
537 }
538 }
539 else
540 {
542 }
543
544 for ( tref const & i : DataList )
545 {
546 if ( not i.is_null() )
547 {
548 Data.push_back ( QString::fromStdString ( i.full_name() ) );
549 }
550 }
551 }
552
553 widget->setdata ( Data );
554 widget->SetEditor();
555
556 set_tooltip ( arelation, widget );
557 register_relation_widget ( name, widget );
558 connect ( widget, SIGNAL ( signal_value_change() ), this, SLOT ( UpdateActions() ),
559 Qt::UniqueConnection );
560 connect ( widget, SIGNAL ( signal_value_change() ), this, SLOT ( ObjectChanged() ),
561 Qt::UniqueConnection );
562 connect ( widget, SIGNAL ( LoadedInitials() ), this, SLOT ( ResetObjectChanged() ),
563 Qt::UniqueConnection );
564 connect ( this, SIGNAL ( LoadedInitials() ), widget, SLOT ( slot_set_initial_loaded() ),
565 Qt::UniqueConnection );
567 emit LoadedInitials();
568 }
569}
570
571//------------------------------------------------------------------------------------------
572
573//------------------------------------------------------------------------------------------
575 widgets::editors::base * Widget )
576{
577 QString ToolTip;
578 ToolTip.append ( QString ( "Attribute Name: %1 \n" ).arg (
579 Attribute.p_name.c_str() ) );
580 ToolTip.append (
581 QString ( " Type: %1 \n" ).arg (
583 ToolTip.append ( QString ( " Range: %1 \n" ).arg (
584 Attribute.p_range.c_str() ) );
585 ToolTip.append (
586 QString ( " Format: %1 \n" ).arg (
588 ToolTip.append ( QString ( " Not Null: %1 \n" ).arg (
589 Attribute.p_is_not_null ) );
590 ToolTip.append (
591 QString ( " Is Multi Value: %1 \n" ).arg ( Attribute.p_is_multi_value ) );
592 ToolTip.append (
593 QString ( " Default Value: %1 \n" ).arg ( Attribute.p_default_value.c_str() ) );
594 ToolTip.append (
595 QString ( " Description: %1 \n" ).arg ( Attribute.p_description.c_str() ) );
596 Widget->setToolTip ( ToolTip );
597}
598
599//------------------------------------------------------------------------------------------
600
601//------------------------------------------------------------------------------------------
603 widgets::editors::base * widget )
604{
605 QString ToolTip;
606 ToolTip.append (
607 QString ( "Relationship Name: %1 \n" ).arg ( relation.p_name.c_str() ) );
608 ToolTip.append (
609 QString ( " Type: %1 \n" ).arg ( relation.p_type.c_str() ) );
610 ToolTip.append (
611 QString ( " Cardinality %1 \n" ).arg (
612 dunedaq::conffwk::relationship_t::card2str ( relation.p_cardinality ) ) );
613 ToolTip.append (
614 QString ( " Is Aggregation: %1 \n" ).arg ( relation.p_is_aggregation ) );
615 ToolTip.append (
616 QString ( " Description: %1 \n" ).arg ( relation.p_description.c_str() ) );
617 widget->setToolTip ( ToolTip );
618}
619
620//------------------------------------------------------------------------------------------
621
622//------------------------------------------------------------------------------------------
624 widgets::editors::base * Widget )
625{
626 {
627 QStringList values;
628
629 if ( not Widget->ischanged() and m_object_to_edit and not Object().is_null() )
630 {
632 }
633 else
634 {
635 values = Widget->getdata();
636 }
637
638 Widget->setdata ( values );
639 }
640
641 {
642 QStringList defaults_values
644 Widget->setdefaults ( defaults_values.at ( 0 ) );
645
647 Widget->setdata(defaults_values);
648 }
649 }
650
651 Widget->SetEditor();
652}
653
654//------------------------------------------------------------------------------------------
655
656//------------------------------------------------------------------------------------------
658 widgets::editors::base * widget )
659{
660 HorizontalHeaders.append(name);
661 WidgetTable->setCellWidget(CurrentRow, 0, widget);
662
663 if(dynamic_cast<widgets::editors::multiattr *>(widget)) {
664 WidgetTable->setRowHeight(CurrentRow, 100);
665 } else if(widgets::editors::stringattr * sa = dynamic_cast<widgets::editors::stringattr *>(widget)) {
666 QTextEdit* le = sa->GetLineEdit();
667 const auto& textSize = QFontMetrics(le->document()->defaultFont()).size(0, le->toPlainText());
668 WidgetTable->setRowHeight(CurrentRow, std::min(150, textSize.height() + 15));
669 } else {
670 WidgetTable->verticalHeader()->setSectionResizeMode(CurrentRow, QHeaderView::Fixed);
671 }
672
673 CurrentRow++;
674 this_widgets[name] = widget;
675}
676
677//------------------------------------------------------------------------------------------
678
679//------------------------------------------------------------------------------------------
681 widgets::editors::base * widget )
682{
683 HorizontalHeaders.append ( name );
684 WidgetTable->setCellWidget ( CurrentRow, 0, widget );
685
686 if(widgets::editors::relation * w = dynamic_cast<widgets::editors::relation *>(widget)) {
687 if(w->GetIsMultiValue() == true) {
688 WidgetTable->setRowHeight(CurrentRow, 100);
689 } else {
690 WidgetTable->verticalHeader()->setSectionResizeMode(CurrentRow, QHeaderView::Fixed);
691 }
692 }
693
694 CurrentRow++;
695 this_widgets[name] = widget;
696}
697
698//------------------------------------------------------------------------------------------
699
700//------------------------------------------------------------------------------------------
702{
703 if ( m_object_to_edit and not Object().is_null() )
704 {
705 QString FileName = QString ( Object().contained_in().c_str() );
706 QList<QStringList> FileCache = confaccessor::ref().GetIncludedFileCache();
707 QFileInfo FileInfo = QFileInfo ( FileName );
708
709 for ( QStringList File : FileCache )
710 {
711 if ( FileName.contains ( File.at ( 1 ) ) )
712 {
713 FilePermission = File.at ( 2 );
714 break;
715 }
716 }
717
718 ui->FileLabel->setText ( QString ( "File: %1" ).arg ( FileInfo.fileName() ) );
719 ui->DirLabel->setText ( QString ( "Dir: %1" ).arg ( FileInfo.absolutePath() ) );
720 ui->WriteLabel->setText ( QString ( "Permission: %1" ).arg ( FilePermission ) );
721 }
722}
723
724//------------------------------------------------------------------------------------------
725
726//------------------------------------------------------------------------------------------
727// void dbe::ObjectEditor::closeEvent ( QCloseEvent * e )
728// {
729// if ( not this_editor_is_owned and CanCloseWindow() )
730// {
731// e->accept();
732// }
733// else if ( this_editor_is_owned )
734// {
735// e->accept();
736// }
737// else
738// {
739// e->ignore();
740// }
741// }
742
743//------------------------------------------------------------------------------------------
744
745//------------------------------------------------------------------------------------------
747{
748 int NotNullCounter = 0;
749 int NotValidCounter = 0;
750
751 QStringList NotValidList;
752
753 for ( auto & i : this_widgets )
754 {
755 std::shared_ptr<editor_data_state> Editor = i.second->dataeditor<editor_data_state>();
756
757 if ( Editor != nullptr )
758 {
759 if ( not Editor->is_valid() )
760 {
761 NotValidCounter++;
762 NotValidList.append ( i.first );
763 }
764
765 if ( Editor->must_not_be_null() )
766 {
767 NotNullCounter++;
768 }
769 }
770 }
771
772 QLabel * StatusLabel = new QLabel();
773 StatusLabel->setWordWrap ( true );
774 StatusLabel->setFrameStyle ( QFrame::NoFrame );
775
776 if ( NotValidCounter == 0 )
777 {
778 StatusLabel->setText (
779 QString ( "All minimal necessary attributes and relationships are set" ) );
780
782 confaccessor::check_file_rw ( QString::fromStdString ( Object().contained_in() ) ) )
783 {
784 ui->ApplyButton->setEnabled ( true );
785 }
786
787 IsValid = true;
788 }
789 else
790 {
791 QString MexHead = QString ( "From %1 NOT NULL attributes/relationships, %2 are not set: " )
792 .arg ( NotNullCounter ).arg ( NotValidCounter );
793 QString Mex = MexHead + NotValidList.join ( "," );
794 StatusLabel->setText ( Mex );
795
796 ui->ApplyButton->setEnabled ( false );
797
798 IsValid = false;
799 }
800
802 emit WidgetUpdated();
803}
804
805//------------------------------------------------------------------------------------------
806
807//------------------------------------------------------------------------------------------
809{
811
813 or confaccessor::check_file_rw ( QString::fromStdString ( Object().contained_in() ) ) ))
814 {
815 ui->ApplyButton->setEnabled ( true );
816 }
817}
818
820{
822 ui->ApplyButton->setEnabled ( false );
823}
824
825//------------------------------------------------------------------------------------------
826
827//------------------------------------------------------------------------------------------
829{
830 if ( FilePermission != "RO" )
831 {
832 if ( not IsValid )
833 {
834 ERROR ( "Changes cannot be applied for object", "Changes are invalid", "with UID:",
835 Object().UID(), "of class:", Object().class_name() );
836 return;
837 }
838
839 for ( auto const & i : this_widgets )
840 {
841 widgets::editors::base * ceditor = i.second;
842 bool Changed = ceditor->ischanged();
843
844 if ( Changed || this_is_in_copy_mode )
845 {
846 QStringList DataList = ceditor->getdata();
847
848 if ( auto attreditor = ceditor->dataeditor<editor_data<dunedaq::conffwk::attribute_t>>() )
849 {
850 dunedaq::conffwk::attribute_t Attribute = attreditor->get();
851
852 dbe::config::api::set::attribute ( Object(), Attribute, DataList );
853 ceditor->setdata ( DataList );
854 ceditor->setchanged ( false );
855 }
856 else if ( auto releditor =
858 {
859 dunedaq::conffwk::relationship_t Relationship = releditor->get();
860 dbe::config::api::set::relation ( Object(), Relationship, DataList );
861 ceditor->setdata ( DataList );
862 ceditor->setchanged ( false );
863 }
864 }
865 }
866
868
869 ui->ApplyButton->setDisabled ( true );
870
872 }
873 else
874 {
875 ERROR ( "Changes cannot be applied", "File access permission error" );
876 }
877}
878
879//------------------------------------------------------------------------------------------
880
881//------------------------------------------------------------------------------------------
883{
884 if ( RenameWidget == nullptr )
885 {
886 RenameWidget = new QDialog ( this );
887 RenameWidget->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
888 RenameWidget->setToolTip ( "Type string to edit line and press Enter." );
889 RenameWidget->setWindowTitle ( "Choose a new object id" );
890
891 QHBoxLayout * Layout = new QHBoxLayout ( RenameWidget );
892 QLabel * Label = new QLabel ( QString ( "Rename Object:" ), RenameWidget );
893 GoButton = new QPushButton ( "Rename !" );
894
895 LineEdit = new QLineEdit ( RenameWidget );
896 LineEdit->setToolTip ( "Type string and press Enter" );
897
898 Layout->addWidget ( Label );
899 Layout->addWidget ( LineEdit );
900 Layout->addWidget ( GoButton );
901 RenameWidget->setLayout ( Layout );
902
903 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( RenameObject() ) );
904 connect ( GoButton, SIGNAL ( clicked() ), this, SLOT ( RenameObject() ) );
905 connect ( &confaccessor::ref(), SIGNAL ( object_renamed ( QString, dref ) ), this,
906 SLOT ( slot_external_rename_object ( QString, dref ) ) );
907 }
908
909 RenameWidget->show();
910}
911
913{
914 if ( MoveWidget == nullptr )
915 {
916 MoveWidget = new QDialog ( this );
917 MoveWidget->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
918 MoveWidget->setToolTip ( "Choose file and press Move." );
919 MoveWidget->setWindowTitle ( "Choose new file for object" );
920
921 QVBoxLayout * Layout = new QVBoxLayout ( MoveWidget );
922 QLabel * Label = new QLabel ( QString ( "Choose new file" ), MoveWidget );
923 MoveGoButton = new QPushButton ( "Move !" );
924
925 if ( IncludedFileModel == nullptr )
926 {
927 QList<QStringList> List = confaccessor::ref().GetIncludedFileCache();
928 IncludedFileModel = new FileModel ( List );
929 }
930
932 FileView->setModel ( IncludedFileModel );
933 FileView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
934
935 Layout->addWidget ( Label );
936 Layout->addWidget ( FileView );
937 Layout->addWidget ( MoveGoButton );
938
939 MoveWidget->setLayout ( Layout );
940 connect ( FileView, SIGNAL ( stateChanged ( const QString & ) ), this,
941 SLOT ( ActiveFileChanged ( const QString & ) ), Qt::UniqueConnection );
942 connect ( MoveGoButton, SIGNAL ( clicked() ), this, SLOT ( MoveObject() ) );
943 }
944
945 MoveWidget->show();
946}
947
948//------------------------------------------------------------------------------------------
949
951 if (ui->ApplyButton->isEnabled() ) {
952 ParseToSave();
953 }
954 close();
955}
956
957//------------------------------------------------------------------------------------------
959{
960 std::string newname = LineEdit->text().toStdString();
962 RenameWidget->close();
963}
964
966 dref const & /* obj */)
967{
968 // Rename can only occur by undoing a command issued from an ObjectEditor therefore
969 // the uuid and src have to be equal. We also check the UID
970
971 if ( src == uuid.toString() )
972 {
973 ui->ClassLabel->setText (
974 QString ( "Object : %1@%2" ).arg ( Object().UID().c_str() ).arg (
975 Object().class_name().c_str() ) );
976 setWindowTitle (
977 QString ( "Edit Object %1 of Class %2" ).arg ( Object().UID().c_str() ).arg (
978 Object().class_name().c_str() ) );
979 setObjectName (
980 QString ( "%1@%2" ).arg ( Object().UID().c_str() ).arg ( Object().class_name().c_str() ) );
981 }
982}
983
985{
987 {
988 ui->FileLabel->setText ( QString ( "File: %1" ).arg ( Object().contained_in().c_str() ) );
989 }
990
991 MoveWidget->close();
992}
993
994void dbe::ObjectEditor::ActiveFileChanged ( const QString & File )
995{
996 if ( File.isEmpty() )
997 {
998 return;
999 }
1000
1001 ActivateFile = File;
1002}
1003
1004//------------------------------------------------------------------------------------------
1005
1006//------------------------------------------------------------------------------------------
1007bool dbe::ObjectEditor::ParseToCreate ( std::string const & objectname,
1008 std::string const & filename )
1009{
1010 if ( not config::api::info::has_obj ( classname, objectname ) )
1011 {
1012 try
1013 {
1016
1017 // Build [attribute , new values ] map and [ relation , new relations ] map
1018 // by looping through all widgets contained in this objects
1019
1020 for ( auto const & awidget : this_widgets )
1021 {
1022 widgets::editors::base * editor = awidget.second;
1023
1024 // Retrieve data held by the editor
1025 QStringList editordata = editor->getdata();
1026
1027 if ( std::shared_ptr<editor_data<dunedaq::conffwk::attribute_t>> accessor =
1029 {
1030 dunedaq::conffwk::attribute_t attribute = accessor->get();
1031
1032 /*
1033 * Convert to the preimage value type
1034 */
1035
1036 for ( auto const & element : editordata )
1037 {
1038 object_attributes[attribute.p_name].push_back ( element.toStdString() );
1039 }
1040 }
1041 else if ( std::shared_ptr<editor_data<dunedaq::conffwk::relationship_t>> accessor =
1043 {
1044 dunedaq::conffwk::relationship_t relation = accessor->get();
1045
1046 /*
1047 * Convert to the preimage value type
1048 */
1049
1050 for ( auto const & element : editordata )
1051 {
1052 object_relations[relation.p_name].push_back (
1053 { element.toStdString(), relation.p_type } );
1054 }
1055 }
1056
1057 // editor->SetValueList(editordata);
1058 editor->setchanged ( false );
1059 }
1060
1062 filename, classname, objectname,
1063 object_attributes, object_relations, uuid );
1064
1065 }
1066 catch ( daq::dbe::ObjectChangeWasNotSuccessful const & e )
1067 {
1068 ERROR ( "Object creation did not complete successfully", dbe::config::errors::parse ( e ) );
1069 return false;
1070 }
1071 catch ( dunedaq::conffwk::Exception const & e )
1072 {
1073 ERROR ( "Object could not be created", dbe::config::errors::parse ( e ) );
1074 return false;
1075 }
1076
1077 return true;
1078 }
1079 else
1080 {
1081 ERROR ( "Object cannot be created for", "Object already exists", "with name (UID):",
1082 objectname, " in class ", classname );
1083 return false;
1084 }
1085}
1086
1088{
1089 this_is_in_copy_mode = Used;
1090}
1091
1092//------------------------------------------------------------------------------------------
void build_file_model()
static MainWindow * findthis()
QTableWidget * WidgetTable
void set_attribute_widget(dunedaq::conffwk::attribute_t const &, widgets::editors::base *)
bool IsEditorValid() const
QPushButton * GoButton
std::map< QString, widgets::editors::base * > this_widgets
QDialog * MoveWidget
Move widget.
void slot_external_rename_object(QString const &src, dref const &obj)
bool WasObjectChanged() const
void SetUsedForCopy(bool Used)
std::unique_ptr< dbe::Ui::ObjectEditor > ui
bool ParseToCreate(std::string const &name, std::string const &filename)
void set_tooltip(dunedaq::conffwk::attribute_t const &, widgets::editors::base *)
void UpdateObjectEditor(QString const &, dref)
QStringList HorizontalHeaders
QPushButton * MoveGoButton
QStatusBar * StatusBar
std::unique_ptr< dref > m_object_to_edit
void register_attribute_widget(QString const &name, widgets::editors::base *widget)
CustomFileView * FileView
void HideDetailWidget(bool Hide)
QHBoxLayout * MainLayout
void register_relation_widget(QString const &name, widgets::editors::base *widget)
ObjectEditor(QWidget *parent=nullptr)
void ActiveFileChanged(const QString &File)
void keyPressEvent(QKeyEvent *event) override
void ShouldCloseThisWindow(QString src, dref key)
FileModel * IncludedFileModel
std::string classname
QDialog * RenameWidget
Rename widget.
QList< QStringList > GetIncludedFileCache() const
static bool check_file_rw(const QString &FileName)
static confaccessor & ref()
static T list(dbe::inner::configobject::tref obj, dunedaq::conffwk::attribute_t const &attr)
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
static configobject::tref get(dbe::cokey const &desc)
virtual void setdata(QStringList const &)
virtual void SetEditor()=0
virtual void setdefaults(QString const &)
#define ERROR(...)
Definition messenger.hpp:93
void newobj(std::string const &fn, std::string const &class_name, std::string const &UID, dbe::t_config_object_preimage::type_attrmap const &attributes, dbe::t_config_object_preimage::type_relmap const &relations, QUuid const &src)
bool renobj(inner::configobject::tref obj, std::string const &newuuid, QUuid const &src)
bool movobj(inner::configobject::tref obj, std::string const &destination, QUuid const &src)
T relation(tref item, dunedaq::conffwk::relationship_t const &relation)
bool is_simple(dunedaq::conffwk::relationship_t const &)
bool has_obj(std::string const &classname, std::string const &object_uid)
void relation(dbe::inner::configobject::tref src, dunedaq::conffwk::relationship_t const &edge, QStringList const &targets)
void attribute(dbe::inner::configobject::tref objectref, dunedaq::conffwk::attribute_t const &attribute_info, QStringList const &attribute_values)
std::string const parse(ers::Issue const &)
inner::configobject::tref tref
Definition tref.hpp:35
config_object_description dref
static QStringList value(dunedaq::conffwk::attribute_t const &)
static const char * type2str(type_t type)
static const char * format2str(int_format_t format)
const std::vector< attribute_t > p_attributes
Definition Schema.hpp:170
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:171
static const char * card2str(cardinality_t cardinality)