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