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