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 {
57 uuid ( QUuid::createUuid() )
74 ui->RenameButton->setDisabled (
true );
75 ui->ClassLabel->setText ( QString (
"New Object" ) );
91 ui->ClassLabel->setText (
92 QString (
"Full object name : %1@%2" ).arg (
Object().UID().c_str() ).arg (
93 Object().class_name().c_str() ) );
95 this->setWindowTitle (
96 QString (
"Edit Object %1 of Class %2" ).arg (
Object().UID().c_str() ).arg (
97 Object().class_name().c_str() ) );
100 QString (
"%1@%2" ).arg (
Object().UID().c_str() ).arg (
Object().class_name().c_str() ) );
110 QString::fromStdString (
Object().contained_in() ));
116 int NumberOfColumns = 1;
119 setAttribute ( Qt::WA_DeleteOnClose,
true );
126 ui->DetailsGroupBox->setVisible (
false );
128 WidgetTable->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
129 WidgetTable->horizontalHeader()->setVisible (
false );
130 WidgetTable->horizontalHeader()->setSectionResizeMode ( QHeaderView::ResizeToContents );
131 WidgetTable->horizontalHeader()->setSectionResizeMode ( 0, QHeaderView::Stretch );
133 WidgetTable->setSelectionMode ( QAbstractItemView::NoSelection );
137 ui->RenameButton->setDisabled (
true );
138 ui->MoveButton->setDisabled (
true );
143 ui->RenameButton->setDisabled(
true);
144 ui->MoveButton->setDisabled(
true);
145 ui->ApplyButton->hide();
150 ui->ApplyButton->setEnabled (
false );
152 ui->RenameButton->setToolTip (
"Rename object" );
159 if (event->key() == Qt::Key_Escape) {
162 QWidget::keyPressEvent(event);
171 ui->DetailWidget->hide();
172 ui->DetailsGroupBox->hide();
176 ui->DetailWidget->show();
177 ui->DetailsGroupBox->show();
200 ui->ApplyButton->isEnabled() )
203 QMessageBox::question (
205 tr (
"DBE - ObjectEditor" ),
207 "There are unsaved changes for object\n'%1.%2'\n\nDo you want to apply changes?\n" )
208 .arg ( QString::fromStdString (
Object().full_name() ) ),
209 QMessageBox::Apply | QMessageBox::Discard | QMessageBox::Cancel,
210 QMessageBox::Apply );
215 case QMessageBox::Discard:
219 case QMessageBox::Apply:
223 case QMessageBox::Cancel:
242 StatusBar->setAutoFillBackground (
true );
250 connect (
ui->DetailButton, SIGNAL ( toggled (
bool ) ),
ui->DetailsGroupBox,
251 SLOT ( setVisible (
bool ) ), Qt::UniqueConnection );
252 connect (
ui->CloseButton, SIGNAL ( clicked (
bool ) ),
this, SLOT ( close() ),
253 Qt::UniqueConnection );
254 connect (
ui->ApplyButton, SIGNAL ( clicked() ),
this, SLOT (
ParseToSave() ),
255 Qt::UniqueConnection );
267 if(mainwin !=
nullptr) {
268 connect (mainwin, SIGNAL(signal_batch_change_stopped(
const QList<QPair<QString, QString>>&)),
269 this, SLOT(
UpdateObjectEditor(
const QList<QPair<QString, QString>>&)), Qt::UniqueConnection);
270 connect (mainwin, SIGNAL(signal_externalchanges_processed()),
276 for(
const auto& p : objs) {
277 if((p.first.toStdString() ==
Object().class_name()) && (p.second.toStdString() ==
Object().UID())) {
286 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;
326 QStringList relvalues;
327 QString relname = QString ( arelation.p_name.c_str() );
332 if ( relwidget->ischanged() )
334 relvalues = relwidget->getdata();
338 std::vector<tref> connected;
344 connected.push_back (
347 catch ( daq::dbe::config_object_retrieval_result_is_null
const & e )
358 std::transform ( connected.begin(), connected.end(), std::back_inserter ( relvalues ),
359 [] ( decltype ( connected ) ::value_type
const & x )
361 return QString::fromStdString ( x.full_name() );
368 relwidget->setdata ( relvalues );
369 relwidget->SetEditor();
375 const auto& s = size();
376 resize(s.width() + 1, s.height() +1);
377 resize(s.width(), s.height());
387 std::string
const & fullname = key.
UID() +
"@" + key.
class_name();
390 or ( this->objectName().toStdString() == fullname ) )
403 std::vector<dunedaq::conffwk::attribute_t> attributes = classdef.
p_attributes;
404 std::vector<dunedaq::conffwk::relationship_t> relations = classdef.
p_relationships;
409 QString name = QString::fromStdString ( attr.p_name );
411 if ( attr.p_is_multi_value )
419 connect ( widget, SIGNAL ( signal_value_change() ),
this, SLOT (
UpdateActions() ),
420 Qt::UniqueConnection );
421 connect ( widget, SIGNAL ( signal_value_change() ),
this, SLOT (
ObjectChanged() ),
422 Qt::UniqueConnection );
427 switch ( attr.p_type )
438 connect ( Widget->Combo, SIGNAL ( activated ( QString ) ),
this, SLOT (
UpdateActions() ),
439 Qt::UniqueConnection );
440 connect ( Widget, SIGNAL ( signal_value_change() ),
this, SLOT (
ObjectChanged() ),
441 Qt::UniqueConnection );
471 connect ( Widget, SIGNAL ( signal_value_change() ),
this, SLOT (
UpdateActions() ),
472 Qt::UniqueConnection );
473 connect ( Widget, SIGNAL ( signal_value_change() ),
this, SLOT (
ObjectChanged() ),
474 Qt::UniqueConnection );
490 connect ( Widget, SIGNAL ( signal_value_change() ),
this, SLOT (
UpdateActions() ),
491 Qt::UniqueConnection );
492 connect ( Widget, SIGNAL ( signal_value_change() ),
this, SLOT (
ObjectChanged() ),
493 Qt::UniqueConnection );
504 connect ( Widget->Combo, SIGNAL ( activated ( QString ) ),
this, SLOT (
UpdateActions() ),
505 Qt::UniqueConnection );
506 connect ( Widget, SIGNAL ( signal_value_change() ),
this, SLOT (
ObjectChanged() ),
507 Qt::UniqueConnection );
520 QString name = QString::fromStdString ( arelation.p_name );
525 std::vector<tref> DataList;
534 catch ( daq::dbe::config_object_retrieval_result_is_null
const & e )
544 for (
tref const & i : DataList )
546 if ( not i.is_null() )
548 Data.push_back ( QString::fromStdString ( i.full_name() ) );
558 connect ( widget, SIGNAL ( signal_value_change() ),
this, SLOT (
UpdateActions() ),
559 Qt::UniqueConnection );
560 connect ( widget, SIGNAL ( signal_value_change() ),
this, SLOT (
ObjectChanged() ),
561 Qt::UniqueConnection );
563 Qt::UniqueConnection );
564 connect (
this, SIGNAL (
LoadedInitials() ), widget, SLOT ( slot_set_initial_loaded() ),
565 Qt::UniqueConnection );
578 ToolTip.append ( QString (
"Attribute Name: %1 \n" ).arg (
579 Attribute.
p_name.c_str() ) );
581 QString (
" Type: %1 \n" ).arg (
583 ToolTip.append ( QString (
" Range: %1 \n" ).arg (
586 QString (
" Format: %1 \n" ).arg (
588 ToolTip.append ( QString (
" Not Null: %1 \n" ).arg (
593 QString (
" Default Value: %1 \n" ).arg ( Attribute.
p_default_value.c_str() ) );
595 QString (
" Description: %1 \n" ).arg ( Attribute.
p_description.c_str() ) );
596 Widget->setToolTip ( ToolTip );
607 QString (
"Relationship Name: %1 \n" ).arg ( relation.p_name.c_str() ) );
609 QString (
" Type: %1 \n" ).arg ( relation.p_type.c_str() ) );
611 QString (
" Cardinality %1 \n" ).arg (
614 QString (
" Is Aggregation: %1 \n" ).arg ( relation.p_is_aggregation ) );
616 QString (
" Description: %1 \n" ).arg ( relation.p_description.c_str() ) );
617 widget->setToolTip ( ToolTip );
642 QStringList defaults_values
647 Widget->
setdata(defaults_values);
666 QTextEdit* le = sa->GetLineEdit();
667 const auto& textSize = QFontMetrics(le->document()->defaultFont()).size(0, le->toPlainText());
687 if(w->GetIsMultiValue() ==
true) {
705 QString FileName = QString (
Object().contained_in().c_str() );
707 QFileInfo
FileInfo = QFileInfo ( FileName );
709 for ( QStringList File : FileCache )
711 if ( FileName.contains ( File.at ( 1 ) ) )
718 ui->FileLabel->setText ( QString (
"File: %1" ).arg (
FileInfo.fileName() ) );
719 ui->DirLabel->setText ( QString (
"Dir: %1" ).arg (
FileInfo.absolutePath() ) );
720 ui->WriteLabel->setText ( QString (
"Permission: %1" ).arg (
FilePermission ) );
748 int NotNullCounter = 0;
749 int NotValidCounter = 0;
751 QStringList NotValidList;
755 std::shared_ptr<editor_data_state> Editor = i.second->dataeditor<
editor_data_state>();
757 if ( Editor !=
nullptr )
759 if ( not Editor->is_valid() )
762 NotValidList.append ( i.first );
765 if ( Editor->must_not_be_null() )
772 QLabel * StatusLabel =
new QLabel();
773 StatusLabel->setWordWrap (
true );
774 StatusLabel->setFrameStyle ( QFrame::NoFrame );
776 if ( NotValidCounter == 0 )
778 StatusLabel->setText (
779 QString (
"All minimal necessary attributes and relationships are set" ) );
784 ui->ApplyButton->setEnabled (
true );
791 QString MexHead = QString (
"From %1 NOT NULL attributes/relationships, %2 are not set: " )
792 .arg ( NotNullCounter ).arg ( NotValidCounter );
793 QString Mex = MexHead + NotValidList.join (
"," );
794 StatusLabel->setText ( Mex );
796 ui->ApplyButton->setEnabled (
false );
815 ui->ApplyButton->setEnabled (
true );
822 ui->ApplyButton->setEnabled (
false );
834 ERROR (
"Changes cannot be applied for object",
"Changes are invalid",
"with UID:",
846 QStringList DataList = ceditor->
getdata();
856 else if (
auto releditor =
869 ui->ApplyButton->setDisabled (
true );
875 ERROR (
"Changes cannot be applied",
"File access permission error" );
887 RenameWidget->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
888 RenameWidget->setToolTip (
"Type string to edit line and press Enter." );
889 RenameWidget->setWindowTitle (
"Choose a new object id" );
891 QHBoxLayout * Layout =
new QHBoxLayout (
RenameWidget );
892 QLabel * Label =
new QLabel ( QString (
"Rename Object:" ),
RenameWidget );
893 GoButton =
new QPushButton (
"Rename !" );
896 LineEdit->setToolTip (
"Type string and press Enter" );
898 Layout->addWidget ( Label );
917 MoveWidget->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
918 MoveWidget->setToolTip (
"Choose file and press Move." );
919 MoveWidget->setWindowTitle (
"Choose new file for object" );
921 QVBoxLayout * Layout =
new QVBoxLayout (
MoveWidget );
922 QLabel * Label =
new QLabel ( QString (
"Choose new file" ),
MoveWidget );
933 FileView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
935 Layout->addWidget ( Label );
940 connect (
FileView, SIGNAL ( stateChanged (
const QString & ) ),
this,
951 if (
ui->ApplyButton->isEnabled() ) {
960 std::string newname =
LineEdit->text().toStdString();
971 if ( src ==
uuid.toString() )
973 ui->ClassLabel->setText (
974 QString (
"Object : %1@%2" ).arg (
Object().UID().c_str() ).arg (
975 Object().class_name().c_str() ) );
977 QString (
"Edit Object %1 of Class %2" ).arg (
Object().UID().c_str() ).arg (
978 Object().class_name().c_str() ) );
980 QString (
"%1@%2" ).arg (
Object().UID().c_str() ).arg (
Object().class_name().c_str() ) );
988 ui->FileLabel->setText ( QString (
"File: %1" ).arg (
Object().contained_in().c_str() ) );
996 if ( File.isEmpty() )
1025 QStringList editordata = editor->
getdata();
1036 for (
auto const & element : editordata )
1038 object_attributes[attribute.p_name].push_back ( element.toStdString() );
1050 for (
auto const & element : editordata )
1052 object_relations[relation.p_name].push_back (
1053 { element.toStdString(), relation.p_type } );
1063 object_attributes, object_relations,
uuid );
1066 catch ( daq::dbe::ObjectChangeWasNotSuccessful
const & e )
1071 catch ( dunedaq::conffwk::Exception
const & e )
1081 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)