15#include "ui_ObjectEditor.h"
24class NoScrollingTable :
public QTableWidget
27 explicit NoScrollingTable(QWidget* parent =
nullptr)
28 : QTableWidget(parent)
32 void scrollTo(
const QModelIndex& , ScrollHint )
override
61 ,
uuid(QUuid::createUuid())
79 ui->RenameButton->setDisabled(
true);
80 ui->ClassLabel->setText(QString(
"New Object"));
97 ui->ClassLabel->setText(
98 QString(
"Full object name : %1@%2").arg(
Object().UID().c_str()).arg(
Object().class_name().c_str()));
100 this->setWindowTitle(
101 QString(
"Edit Object %1 of Class %2").arg(
Object().UID().c_str()).arg(
Object().class_name().c_str()));
103 this->setObjectName(QString(
"%1@%2").arg(
Object().UID().c_str()).arg(
Object().class_name().c_str()));
119 int NumberOfColumns = 1;
122 setAttribute(Qt::WA_DeleteOnClose,
true);
129 ui->DetailsGroupBox->setVisible(
false);
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);
136 WidgetTable->setSelectionMode(QAbstractItemView::NoSelection);
139 ui->RenameButton->setDisabled(
true);
140 ui->MoveButton->setDisabled(
true);
144 ui->RenameButton->setDisabled(
true);
145 ui->MoveButton->setDisabled(
true);
146 ui->ApplyButton->hide();
151 ui->ApplyButton->setEnabled(
false);
153 ui->RenameButton->setToolTip(
"Rename object");
161 if (event->key() == Qt::Key_Escape) {
164 QWidget::keyPressEvent(event);
173 ui->DetailWidget->hide();
174 ui->DetailsGroupBox->hide();
176 ui->DetailWidget->show();
177 ui->DetailsGroupBox->show();
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,
213 case QMessageBox::Discard:
217 case QMessageBox::Apply:
221 case QMessageBox::Cancel:
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);
261 if (mainwin !=
nullptr) {
263 SIGNAL(signal_batch_change_stopped(
const QList<QPair<QString, QString>>&)),
266 Qt::UniqueConnection);
268 mainwin, SIGNAL(signal_externalchanges_processed()),
this, SLOT(
UpdateObjectEditor()), Qt::UniqueConnection);
275 for (
const auto& p : objs) {
276 if ((p.first.toStdString() ==
Object().class_name()) && (p.second.toStdString() ==
Object().UID())) {
287 if (ref.is_null() ==
false) {
312 std::vector<dunedaq::conffwk::attribute_t> class_attributes = classdef.
p_attributes;
313 std::vector<dunedaq::conffwk::relationship_t> class_relations = classdef.
p_relationships;
322 QStringList relvalues;
323 QString relname = QString(arelation.p_name.c_str());
326 if (relwidget->ischanged()) {
327 relvalues = relwidget->getdata();
329 std::vector<tref> connected;
334 }
catch (daq::dbe::config_object_retrieval_result_is_null
const& e) {
341 std::transform(connected.begin(),
343 std::back_inserter(relvalues),
344 [](
decltype(connected)::value_type
const& x) { return QString::fromStdString(x.full_name()); }
349 relwidget->setdata(relvalues);
350 relwidget->SetEditor();
356 const auto& s = size();
357 resize(s.width() + 1, s.height() + 1);
358 resize(s.width(), s.height());
369 std::string
const& fullname = key.
UID() +
"@" + key.
class_name();
383 std::vector<dunedaq::conffwk::attribute_t> attributes = classdef.
p_attributes;
384 std::vector<dunedaq::conffwk::relationship_t> relations = classdef.
p_relationships;
389 QString name = QString::fromStdString(attr.p_name);
391 if (attr.p_is_multi_value) {
397 connect(widget, SIGNAL(signal_value_change()),
this, SLOT(
UpdateActions()), Qt::UniqueConnection);
398 connect(widget, SIGNAL(signal_value_change()),
this, SLOT(
ObjectChanged()), Qt::UniqueConnection);
401 switch (attr.p_type) {
410 connect(Widget->Combo, SIGNAL(activated(QString)),
this, SLOT(
UpdateActions()), Qt::UniqueConnection);
411 connect(Widget, SIGNAL(signal_value_change()),
this, SLOT(
ObjectChanged()), Qt::UniqueConnection);
439 connect(Widget, SIGNAL(signal_value_change()),
this, SLOT(
UpdateActions()), Qt::UniqueConnection);
440 connect(Widget, SIGNAL(signal_value_change()),
this, SLOT(
ObjectChanged()), Qt::UniqueConnection);
454 connect(Widget, SIGNAL(signal_value_change()),
this, SLOT(
UpdateActions()), Qt::UniqueConnection);
455 connect(Widget, SIGNAL(signal_value_change()),
this, SLOT(
ObjectChanged()), Qt::UniqueConnection);
465 connect(Widget->Combo, SIGNAL(activated(QString)),
this, SLOT(
UpdateActions()), Qt::UniqueConnection);
466 connect(Widget, SIGNAL(signal_value_change()),
this, SLOT(
ObjectChanged()), Qt::UniqueConnection);
477 QString name = QString::fromStdString(arelation.p_name);
481 std::vector<tref> DataList;
486 }
catch (daq::dbe::config_object_retrieval_result_is_null
const& e) {
493 for (
tref const& i : DataList) {
494 if (not i.is_null()) {
495 Data.push_back(QString::fromStdString(i.full_name()));
505 connect(widget, SIGNAL(signal_value_change()),
this, SLOT(
UpdateActions()), Qt::UniqueConnection);
506 connect(widget, SIGNAL(signal_value_change()),
this, SLOT(
ObjectChanged()), Qt::UniqueConnection);
508 connect(
this, SIGNAL(
LoadedInitials()), widget, SLOT(slot_set_initial_loaded()), Qt::UniqueConnection);
521 ToolTip.append(QString(
"Attribute Name: %1 \n").arg(Attribute.
p_name.c_str()));
524 ToolTip.append(QString(
" Range: %1 \n").arg(Attribute.
p_range.c_str()));
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);
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")
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);
573 Widget->
setdata(defaults_values);
592 QTextEdit* le = sa->GetLineEdit();
593 const auto& textSize = QFontMetrics(le->document()->defaultFont()).size(0, le->toPlainText());
613 if (w->GetIsMultiValue() ==
true) {
631 QString FileName = QString(
Object().contained_in().c_str());
633 QFileInfo
FileInfo = QFileInfo(FileName);
635 for (QStringList File : FileCache) {
636 if (FileName.contains(File.at(1))) {
642 ui->FileLabel->setText(QString(
"File: %1").arg(
FileInfo.fileName()));
643 ui->DirLabel->setText(QString(
"Dir: %1").arg(
FileInfo.absolutePath()));
673 int NotNullCounter = 0;
674 int NotValidCounter = 0;
676 QStringList NotValidList;
679 std::shared_ptr<editor_data_state> Editor = i.second->dataeditor<
editor_data_state>();
681 if (Editor !=
nullptr) {
682 if (not Editor->is_valid()) {
684 NotValidList.append(i.first);
687 if (Editor->must_not_be_null()) {
693 QLabel* StatusLabel =
new QLabel();
694 StatusLabel->setWordWrap(
true);
695 StatusLabel->setFrameStyle(QFrame::NoFrame);
697 if (NotValidCounter == 0) {
698 StatusLabel->setText(QString(
"All minimal necessary attributes and relationships are set"));
702 ui->ApplyButton->setEnabled(
true);
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);
712 ui->ApplyButton->setEnabled(
false);
731 ui->ApplyButton->setEnabled(
true);
739 ui->ApplyButton->setEnabled(
false);
750 ERROR(
"Changes cannot be applied for object",
751 "Changes are invalid",
764 QStringList DataList = ceditor->
getdata();
783 ui->ApplyButton->setDisabled(
true);
787 ERROR(
"Changes cannot be applied",
"File access permission error");
799 RenameWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
800 RenameWidget->setToolTip(
"Type string to edit line and press Enter.");
804 QLabel* Label =
new QLabel(QString(
"Rename Object:"),
RenameWidget);
805 GoButton =
new QPushButton(
"Rename !");
808 LineEdit->setToolTip(
"Type string and press Enter");
810 Layout->addWidget(Label);
818 SIGNAL(object_renamed(QString,
dref)),
831 MoveWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
832 MoveWidget->setToolTip(
"Choose file and press Move.");
833 MoveWidget->setWindowTitle(
"Choose new file for object");
835 QVBoxLayout* Layout =
new QVBoxLayout(
MoveWidget);
836 QLabel* Label =
new QLabel(QString(
"Choose new file"),
MoveWidget);
846 FileView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
848 Layout->addWidget(Label);
854 SIGNAL(stateChanged(
const QString&)),
857 Qt::UniqueConnection);
869 if (
ui->ApplyButton->isEnabled()) {
879 std::string newname =
LineEdit->text().toStdString();
890 if (src ==
uuid.toString()) {
891 ui->ClassLabel->setText(QString(
"Object : %1@%2").arg(
Object().UID().c_str()).arg(
Object().class_name().c_str()));
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()));
902 ui->FileLabel->setText(QString(
"File: %1").arg(
Object().contained_in().c_str()));
911 if (File.isEmpty()) {
936 QStringList editordata = editor->
getdata();
946 for (
auto const& element : editordata) {
947 object_attributes[attribute.p_name].push_back(element.toStdString());
957 for (
auto const& element : editordata) {
958 object_relations[relation.p_name].push_back({ element.toStdString(), relation.p_type });
968 }
catch (daq::dbe::ObjectChangeWasNotSuccessful
const& e) {
971 }
catch (dunedaq::conffwk::Exception
const& e) {
979 "Object cannot be created for",
"Object already exists",
"with name (UID):", objectname,
" in class ",
classname);
CustomFileView(QWidget *parent=nullptr)
Including QT Headers.
FileModel(QObject *parent=nullptr)
Including QT Headers.
static MainWindow * findthis()
QTableWidget * WidgetTable
void set_attribute_widget(dunedaq::conffwk::attribute_t const &, widgets::editors::base *)
bool this_is_in_creation_mode
bool IsEditorValid() const
bool this_is_in_copy_mode
QDialog * MoveWidget
Move widget.
void slot_external_rename_object(QString const &src, dref const &obj)
std::map< QString, widgets::editors::base * > this_widgets
void UpdateObjectEditor()
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
void ResetObjectChanged()
bool this_editor_is_owned
QPushButton * MoveGoButton
std::unique_ptr< dref > m_object_to_edit
void LaunchRenameObject()
void register_attribute_widget(QString const &name, widgets::editors::base *widget)
CustomFileView * FileView
void HideDetailWidget(bool Hide)
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
bool this_editor_values_changed
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)
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
config_object_description dref
static QStringList value(dunedaq::conffwk::attribute_t const &)
std::map< type_str, type_images > type_relmap
std::map< type_str, type_attributes > type_attrmap
int_format_t p_int_format
std::string p_description
std::string p_default_value
static const char * type2str(type_t type)
static const char * format2str(int_format_t format)
const std::vector< attribute_t > p_attributes
const std::vector< relationship_t > p_relationships
static const char * card2str(cardinality_t cardinality)