9#include "ui_ObjectEditor.h"
19 class NoScrollingTable :
public QTableWidget {
21 explicit NoScrollingTable(QWidget* parent =
nullptr)
22 : QTableWidget(parent) {}
24 void scrollTo(
const QModelIndex& , ScrollHint )
override {
51 uuid ( QUuid::createUuid() )
68 ui->RenameButton->setDisabled (
true );
69 ui->ClassLabel->setText ( QString (
"New Object" ) );
85 ui->ClassLabel->setText (
86 QString (
"Full object name : %1@%2" ).arg (
Object().UID().c_str() ).arg (
87 Object().class_name().c_str() ) );
89 this->setWindowTitle (
90 QString (
"Edit Object %1 of Class %2" ).arg (
Object().UID().c_str() ).arg (
91 Object().class_name().c_str() ) );
94 QString (
"%1@%2" ).arg (
Object().UID().c_str() ).arg (
Object().class_name().c_str() ) );
104 int NumberOfColumns = 1;
107 setAttribute ( Qt::WA_DeleteOnClose,
true );
114 ui->DetailsGroupBox->setVisible (
false );
116 WidgetTable->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
117 WidgetTable->horizontalHeader()->setVisible (
false );
118 WidgetTable->horizontalHeader()->setSectionResizeMode ( QHeaderView::ResizeToContents );
119 WidgetTable->horizontalHeader()->setSectionResizeMode ( 0, QHeaderView::Stretch );
121 WidgetTable->setSelectionMode ( QAbstractItemView::NoSelection );
125 ui->RenameButton->setDisabled (
true );
126 ui->MoveButton->setDisabled (
true );
130 QString::fromStdString (
Object().contained_in() ));
133 ui->RenameButton->setDisabled(
true);
134 ui->MoveButton->setDisabled(
true);
139 ui->ApplyButton->setEnabled (
false );
141 ui->RenameButton->setToolTip (
"Rename object" );
148 if (event->key() == Qt::Key_Escape) {
151 QWidget::keyPressEvent(event);
160 ui->DetailWidget->hide();
161 ui->DetailsGroupBox->hide();
165 ui->DetailWidget->show();
166 ui->DetailsGroupBox->show();
189 ui->ApplyButton->isEnabled() )
192 QMessageBox::question (
194 tr (
"DBE - ObjectEditor" ),
196 "There are unsaved changes for object\n'%1.%2'\n\nDo you want to apply changes?\n" )
197 .arg ( QString::fromStdString (
Object().full_name() ) ),
198 QMessageBox::Apply | QMessageBox::Discard | QMessageBox::Cancel,
199 QMessageBox::Apply );
204 case QMessageBox::Discard:
208 case QMessageBox::Apply:
212 case QMessageBox::Cancel:
231 StatusBar->setAutoFillBackground (
true );
239 connect (
ui->DetailButton, SIGNAL ( toggled (
bool ) ),
ui->DetailsGroupBox,
240 SLOT ( setVisible (
bool ) ), Qt::UniqueConnection );
241 connect (
ui->CloseButton, SIGNAL ( clicked (
bool ) ),
this, SLOT ( close() ),
242 Qt::UniqueConnection );
243 connect (
ui->ApplyButton, SIGNAL ( clicked() ),
this, SLOT (
ParseToSave() ),
244 Qt::UniqueConnection );
256 if(mainwin !=
nullptr) {
257 connect (mainwin, SIGNAL(signal_batch_change_stopped(
const QList<QPair<QString, QString>>&)),
258 this, SLOT(
UpdateObjectEditor(
const QList<QPair<QString, QString>>&)), Qt::UniqueConnection);
259 connect (mainwin, SIGNAL(signal_externalchanges_processed()),
265 for(
const auto& p : objs) {
266 if((p.first.toStdString() ==
Object().class_name()) && (p.second.toStdString() ==
Object().UID())) {
275 if(ref.is_null() ==
false) {
301 std::vector<dunedaq::conffwk::attribute_t> class_attributes = classdef.
p_attributes;
302 std::vector<dunedaq::conffwk::relationship_t> class_relations = classdef.
p_relationships;
315 QStringList relvalues;
316 QString relname = QString ( arelation.p_name.c_str() );
321 if ( relwidget->ischanged() )
323 relvalues = relwidget->getdata();
327 std::vector<tref> connected;
333 connected.push_back (
336 catch ( daq::dbe::config_object_retrieval_result_is_null
const & e )
347 std::transform ( connected.begin(), connected.end(), std::back_inserter ( relvalues ),
348 [] ( decltype ( connected ) ::value_type
const & x )
350 return QString::fromStdString ( x.UID() );
357 relwidget->setdata ( relvalues );
358 relwidget->SetEditor();
364 const auto& s = size();
365 resize(s.width() + 1, s.height() +1);
366 resize(s.width(), s.height());
376 std::string
const & fullname = key.
UID() +
"@" + key.
class_name();
379 or ( this->objectName().toStdString() == fullname ) )
392 std::vector<dunedaq::conffwk::attribute_t> attributes = classdef.
p_attributes;
393 std::vector<dunedaq::conffwk::relationship_t> relations = classdef.
p_relationships;
398 QString name = QString::fromStdString ( attr.p_name );
400 if ( attr.p_is_multi_value )
408 connect ( widget, SIGNAL ( signal_value_change() ),
this, SLOT (
UpdateActions() ),
409 Qt::UniqueConnection );
410 connect ( widget, SIGNAL ( signal_value_change() ),
this, SLOT (
ObjectChanged() ),
411 Qt::UniqueConnection );
416 switch ( attr.p_type )
427 connect ( Widget->Combo, SIGNAL ( activated ( QString ) ),
this, SLOT (
UpdateActions() ),
428 Qt::UniqueConnection );
429 connect ( Widget, SIGNAL ( signal_value_change() ),
this, SLOT (
ObjectChanged() ),
430 Qt::UniqueConnection );
460 connect ( Widget, SIGNAL ( signal_value_change() ),
this, SLOT (
UpdateActions() ),
461 Qt::UniqueConnection );
462 connect ( Widget, SIGNAL ( signal_value_change() ),
this, SLOT (
ObjectChanged() ),
463 Qt::UniqueConnection );
479 connect ( Widget, SIGNAL ( signal_value_change() ),
this, SLOT (
UpdateActions() ),
480 Qt::UniqueConnection );
481 connect ( Widget, SIGNAL ( signal_value_change() ),
this, SLOT (
ObjectChanged() ),
482 Qt::UniqueConnection );
493 connect ( Widget->Combo, SIGNAL ( activated ( QString ) ),
this, SLOT (
UpdateActions() ),
494 Qt::UniqueConnection );
495 connect ( Widget, SIGNAL ( signal_value_change() ),
this, SLOT (
ObjectChanged() ),
496 Qt::UniqueConnection );
509 QString name = QString::fromStdString ( arelation.p_name );
514 std::vector<tref> DataList;
523 catch ( daq::dbe::config_object_retrieval_result_is_null
const & e )
533 for (
tref const & i : DataList )
535 if ( not i.is_null() )
537 Data.push_back ( QString::fromStdString ( i.UID() ) );
546 connect ( widget, SIGNAL ( signal_value_change() ),
this, SLOT (
UpdateActions() ),
547 Qt::UniqueConnection );
548 connect ( widget, SIGNAL ( signal_value_change() ),
this, SLOT (
ObjectChanged() ),
549 Qt::UniqueConnection );
551 Qt::UniqueConnection );
552 connect (
this, SIGNAL (
LoadedInitials() ), widget, SLOT ( slot_set_initial_loaded() ),
553 Qt::UniqueConnection );
566 ToolTip.append ( QString (
"Attribute Name: %1 \n" ).arg (
567 Attribute.
p_name.c_str() ) );
569 QString (
" Type: %1 \n" ).arg (
571 ToolTip.append ( QString (
" Range: %1 \n" ).arg (
574 QString (
" Format: %1 \n" ).arg (
576 ToolTip.append ( QString (
" Not Null: %1 \n" ).arg (
581 QString (
" Default Value: %1 \n" ).arg ( Attribute.
p_default_value.c_str() ) );
583 QString (
" Description: %1 \n" ).arg ( Attribute.
p_description.c_str() ) );
584 Widget->setToolTip ( ToolTip );
595 QString (
"Relationship Name: %1 \n" ).arg ( relation.p_name.c_str() ) );
597 QString (
" Type: %1 \n" ).arg ( relation.p_type.c_str() ) );
599 QString (
" Cardinality %1 \n" ).arg (
602 QString (
" Is Aggregation: %1 \n" ).arg ( relation.p_is_aggregation ) );
604 QString (
" Description: %1 \n" ).arg ( relation.p_description.c_str() ) );
605 widget->setToolTip ( ToolTip );
630 QStringList defaults_values
635 Widget->
setdata(defaults_values);
654 QTextEdit* le = sa->GetLineEdit();
655 const auto& textSize = QFontMetrics(le->document()->defaultFont()).size(0, le->toPlainText());
675 if(w->GetIsMultiValue() ==
true) {
693 QString FileName = QString (
Object().contained_in().c_str() );
695 QFileInfo
FileInfo = QFileInfo ( FileName );
697 for ( QStringList File : FileCache )
699 if ( FileName.contains ( File.at ( 1 ) ) )
706 ui->FileLabel->setText ( QString (
"File: %1" ).arg (
FileInfo.fileName() ) );
707 ui->DirLabel->setText ( QString (
"Dir: %1" ).arg (
FileInfo.absolutePath() ) );
708 ui->WriteLabel->setText ( QString (
"Permission: %1" ).arg (
FilePermission ) );
736 int NotNullCounter = 0;
737 int NotValidCounter = 0;
739 QStringList NotValidList;
743 std::shared_ptr<editor_data_state> Editor = i.second->dataeditor<
editor_data_state>();
745 if ( Editor !=
nullptr )
747 if ( not Editor->is_valid() )
750 NotValidList.append ( i.first );
753 if ( Editor->must_not_be_null() )
760 QLabel * StatusLabel =
new QLabel();
761 StatusLabel->setWordWrap (
true );
762 StatusLabel->setFrameStyle ( QFrame::NoFrame );
764 if ( NotValidCounter == 0 )
766 StatusLabel->setText (
767 QString (
"All minimal necessary attributes and relationships are set" ) );
772 ui->ApplyButton->setEnabled (
true );
779 QString MexHead = QString (
"From %1 NOT NULL attributes/relationships, %2 are not set: " )
780 .arg ( NotNullCounter ).arg ( NotValidCounter );
781 QString Mex = MexHead + NotValidList.join (
"," );
782 StatusLabel->setText ( Mex );
784 ui->ApplyButton->setEnabled (
false );
803 ui->ApplyButton->setEnabled (
true );
810 ui->ApplyButton->setEnabled (
false );
822 ERROR (
"Changes cannot be applied for object",
"Changes are invalid",
"with UID:",
834 QStringList DataList = ceditor->
getdata();
844 else if (
auto releditor =
857 ui->ApplyButton->setDisabled (
true );
863 ERROR (
"Changes cannot be applied",
"File access permission error" );
875 RenameWidget->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
876 RenameWidget->setToolTip (
"Type string to edit line and press Enter." );
877 RenameWidget->setWindowTitle (
"Choose a new object id" );
879 QHBoxLayout * Layout =
new QHBoxLayout (
RenameWidget );
880 QLabel * Label =
new QLabel ( QString (
"Rename Object:" ),
RenameWidget );
881 GoButton =
new QPushButton (
"Rename !" );
884 LineEdit->setToolTip (
"Type string and press Enter" );
886 Layout->addWidget ( Label );
905 MoveWidget->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
906 MoveWidget->setToolTip (
"Choose file and press Move." );
907 MoveWidget->setWindowTitle (
"Choose new file for object" );
909 QVBoxLayout * Layout =
new QVBoxLayout (
MoveWidget );
910 QLabel * Label =
new QLabel ( QString (
"Choose new file" ),
MoveWidget );
921 FileView->horizontalHeader()->setSectionResizeMode ( QHeaderView::Stretch );
923 Layout->addWidget ( Label );
928 connect (
FileView, SIGNAL ( stateChanged (
const QString & ) ),
this,
939 if (
ui->ApplyButton->isEnabled() ) {
948 std::string newname =
LineEdit->text().toStdString();
959 if ( src ==
uuid.toString() )
961 ui->ClassLabel->setText (
962 QString (
"Object : %1@%2" ).arg (
Object().UID().c_str() ).arg (
963 Object().class_name().c_str() ) );
965 QString (
"Edit Object %1 of Class %2" ).arg (
Object().UID().c_str() ).arg (
966 Object().class_name().c_str() ) );
968 QString (
"%1@%2" ).arg (
Object().UID().c_str() ).arg (
Object().class_name().c_str() ) );
976 ui->FileLabel->setText ( QString (
"File: %1" ).arg (
Object().contained_in().c_str() ) );
984 if ( File.isEmpty() )
1013 QStringList editordata = editor->
getdata();
1024 for (
auto const & element : editordata )
1026 object_attributes[attribute.p_name].push_back ( element.toStdString() );
1038 for (
auto const & element : editordata )
1040 object_relations[relation.p_name].push_back (
1041 { element.toStdString(), relation.p_type } );
1051 object_attributes, object_relations,
uuid );
1054 catch ( daq::dbe::ObjectChangeWasNotSuccessful
const & e )
1059 catch ( dunedaq::conffwk::Exception
const & e )
1069 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)