14#include "ui_ObjectEditor.h"
24 class NoScrollingTable :
public QTableWidget {
26 explicit NoScrollingTable(QWidget* parent =
nullptr)
27 : QTableWidget(parent) {}
29 void scrollTo(
const QModelIndex& , ScrollHint )
override {
56 uuid ( QUuid::createUuid() )
73 ui->RenameButton->setDisabled (
true );
74 ui->ClassLabel->setText ( QString (
"New Object" ) );
90 ui->ClassLabel->setText (
91 QString (
"Full object name : %1@%2" ).arg (
Object().UID().c_str() ).arg (
92 Object().class_name().c_str() ) );
94 this->setWindowTitle (
95 QString (
"Edit Object %1 of Class %2" ).arg (
Object().UID().c_str() ).arg (
96 Object().class_name().c_str() ) );
99 QString (
"%1@%2" ).arg (
Object().UID().c_str() ).arg (
Object().class_name().c_str() ) );
109 int NumberOfColumns = 1;
112 setAttribute ( Qt::WA_DeleteOnClose,
true );
119 ui->DetailsGroupBox->setVisible (
false );
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 );
126 WidgetTable->setSelectionMode ( QAbstractItemView::NoSelection );
130 ui->RenameButton->setDisabled (
true );
131 ui->MoveButton->setDisabled (
true );
135 QString::fromStdString (
Object().contained_in() ));
138 ui->RenameButton->setDisabled(
true);
139 ui->MoveButton->setDisabled(
true);
144 ui->ApplyButton->setEnabled (
false );
146 ui->RenameButton->setToolTip (
"Rename object" );
153 if (event->key() == Qt::Key_Escape) {
156 QWidget::keyPressEvent(event);
165 ui->DetailWidget->hide();
166 ui->DetailsGroupBox->hide();
170 ui->DetailWidget->show();
171 ui->DetailsGroupBox->show();
194 ui->ApplyButton->isEnabled() )
197 QMessageBox::question (
199 tr (
"DBE - ObjectEditor" ),
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 );
209 case QMessageBox::Discard:
213 case QMessageBox::Apply:
217 case QMessageBox::Cancel:
236 StatusBar->setAutoFillBackground (
true );
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 );
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()),
270 for(
const auto& p : objs) {
271 if((p.first.toStdString() ==
Object().class_name()) && (p.second.toStdString() ==
Object().UID())) {
280 if(ref.is_null() ==
false) {
306 std::vector<dunedaq::conffwk::attribute_t> class_attributes = classdef.
p_attributes;
307 std::vector<dunedaq::conffwk::relationship_t> class_relations = classdef.
p_relationships;
320 QStringList relvalues;
321 QString relname = QString ( arelation.p_name.c_str() );
326 if ( relwidget->ischanged() )
328 relvalues = relwidget->getdata();
332 std::vector<tref> connected;
338 connected.push_back (
341 catch ( daq::dbe::config_object_retrieval_result_is_null
const & e )
352 std::transform ( connected.begin(), connected.end(), std::back_inserter ( relvalues ),
353 [] ( decltype ( connected ) ::value_type
const & x )
355 return QString::fromStdString ( x.UID() );
362 relwidget->setdata ( relvalues );
363 relwidget->SetEditor();
369 const auto& s = size();
370 resize(s.width() + 1, s.height() +1);
371 resize(s.width(), s.height());
381 std::string
const & fullname = key.
UID() +
"@" + key.
class_name();
384 or ( this->objectName().toStdString() == fullname ) )
397 std::vector<dunedaq::conffwk::attribute_t> attributes = classdef.
p_attributes;
398 std::vector<dunedaq::conffwk::relationship_t> relations = classdef.
p_relationships;
403 QString name = QString::fromStdString ( attr.p_name );
405 if ( attr.p_is_multi_value )
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 );
421 switch ( attr.p_type )
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 );
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 );
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 );
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 );
514 QString name = QString::fromStdString ( arelation.p_name );
519 std::vector<tref> DataList;
528 catch ( daq::dbe::config_object_retrieval_result_is_null
const & e )
538 for (
tref const & i : DataList )
540 if ( not i.is_null() )
542 Data.push_back ( QString::fromStdString ( i.UID() ) );
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 );
556 Qt::UniqueConnection );
557 connect (
this, SIGNAL (
LoadedInitials() ), widget, SLOT ( slot_set_initial_loaded() ),
558 Qt::UniqueConnection );
571 ToolTip.append ( QString (
"Attribute Name: %1 \n" ).arg (
572 Attribute.
p_name.c_str() ) );
574 QString (
" Type: %1 \n" ).arg (
576 ToolTip.append ( QString (
" Range: %1 \n" ).arg (
579 QString (
" Format: %1 \n" ).arg (
581 ToolTip.append ( QString (
" Not Null: %1 \n" ).arg (
586 QString (
" Default Value: %1 \n" ).arg ( Attribute.
p_default_value.c_str() ) );
588 QString (
" Description: %1 \n" ).arg ( Attribute.
p_description.c_str() ) );
589 Widget->setToolTip ( ToolTip );
600 QString (
"Relationship Name: %1 \n" ).arg ( relation.p_name.c_str() ) );
602 QString (
" Type: %1 \n" ).arg ( relation.p_type.c_str() ) );
604 QString (
" Cardinality %1 \n" ).arg (
607 QString (
" Is Aggregation: %1 \n" ).arg ( relation.p_is_aggregation ) );
609 QString (
" Description: %1 \n" ).arg ( relation.p_description.c_str() ) );
610 widget->setToolTip ( ToolTip );
635 QStringList defaults_values
640 Widget->
setdata(defaults_values);
659 QTextEdit* le = sa->GetLineEdit();
660 const auto& textSize = QFontMetrics(le->document()->defaultFont()).size(0, le->toPlainText());
680 if(w->GetIsMultiValue() ==
true) {
698 QString FileName = QString (
Object().contained_in().c_str() );
700 QFileInfo
FileInfo = QFileInfo ( FileName );
702 for ( QStringList File : FileCache )
704 if ( FileName.contains ( File.at ( 1 ) ) )
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 ) );
741 int NotNullCounter = 0;
742 int NotValidCounter = 0;
744 QStringList NotValidList;
748 std::shared_ptr<editor_data_state> Editor = i.second->dataeditor<
editor_data_state>();
750 if ( Editor !=
nullptr )
752 if ( not Editor->is_valid() )
755 NotValidList.append ( i.first );
758 if ( Editor->must_not_be_null() )
765 QLabel * StatusLabel =
new QLabel();
766 StatusLabel->setWordWrap (
true );
767 StatusLabel->setFrameStyle ( QFrame::NoFrame );
769 if ( NotValidCounter == 0 )
771 StatusLabel->setText (
772 QString (
"All minimal necessary attributes and relationships are set" ) );
777 ui->ApplyButton->setEnabled (
true );
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 );
789 ui->ApplyButton->setEnabled (
false );
808 ui->ApplyButton->setEnabled (
true );
815 ui->ApplyButton->setEnabled (
false );
827 ERROR (
"Changes cannot be applied for object",
"Changes are invalid",
"with UID:",
839 QStringList DataList = ceditor->
getdata();
849 else if (
auto releditor =
862 ui->ApplyButton->setDisabled (
true );
868 ERROR (
"Changes cannot be applied",
"File access permission error" );
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" );
884 QHBoxLayout * Layout =
new QHBoxLayout (
RenameWidget );
885 QLabel * Label =
new QLabel ( QString (
"Rename Object:" ),
RenameWidget );
886 GoButton =
new QPushButton (
"Rename !" );
889 LineEdit->setToolTip (
"Type string and press Enter" );
891 Layout->addWidget ( Label );
910 MoveWidget->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
911 MoveWidget->setToolTip (
"Choose file and press Move." );
912 MoveWidget->setWindowTitle (
"Choose new file for object" );
914 QVBoxLayout * Layout =
new QVBoxLayout (
MoveWidget );
915 QLabel * Label =
new QLabel ( QString (
"Choose new file" ),
MoveWidget );
926 FileView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
928 Layout->addWidget ( Label );
933 connect (
FileView, SIGNAL ( stateChanged (
const QString & ) ),
this,
944 if (
ui->ApplyButton->isEnabled() ) {
953 std::string newname =
LineEdit->text().toStdString();
964 if ( src ==
uuid.toString() )
966 ui->ClassLabel->setText (
967 QString (
"Object : %1@%2" ).arg (
Object().UID().c_str() ).arg (
968 Object().class_name().c_str() ) );
970 QString (
"Edit Object %1 of Class %2" ).arg (
Object().UID().c_str() ).arg (
971 Object().class_name().c_str() ) );
973 QString (
"%1@%2" ).arg (
Object().UID().c_str() ).arg (
Object().class_name().c_str() ) );
981 ui->FileLabel->setText ( QString (
"File: %1" ).arg (
Object().contained_in().c_str() ) );
989 if ( File.isEmpty() )
1018 QStringList editordata = editor->
getdata();
1029 for (
auto const & element : editordata )
1031 object_attributes[attribute.p_name].push_back ( element.toStdString() );
1043 for (
auto const & element : editordata )
1045 object_relations[relation.p_name].push_back (
1046 { element.toStdString(), relation.p_type } );
1056 object_attributes, object_relations,
uuid );
1059 catch ( daq::dbe::ObjectChangeWasNotSuccessful
const & e )
1064 catch ( dunedaq::conffwk::Exception
const & e )
1074 ERROR (
"Object cannot be created for",
"Object already exists",
"with name (UID):",
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
std::map< QString, widgets::editors::base * > this_widgets
bool this_is_in_copy_mode
QDialog * MoveWidget
Move widget.
void slot_external_rename_object(QString const &src, dref const &obj)
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)