From 8c5b4c18154b15e61a8cb19d9eef25832b330b4b Mon Sep 17 00:00:00 2001 From: Gordon Crone Date: Fri, 16 Jan 2026 13:57:10 +0000 Subject: [PATCH 1/7] Don't deactivate widget table for readonly objects, just disable them being updated --- include/dbe/BuildingBlockEditors.hpp | 23 ++- include/dbe/ObjectEditor.hpp | 1 + src/widgets/BuildingBlockEditors.cpp | 261 ++++++++++++++------------- src/widgets/ObjectEditor.cpp | 29 +-- 4 files changed, 176 insertions(+), 138 deletions(-) diff --git a/include/dbe/BuildingBlockEditors.hpp b/include/dbe/BuildingBlockEditors.hpp index 12cdc98..dbfd0b4 100644 --- a/include/dbe/BuildingBlockEditors.hpp +++ b/include/dbe/BuildingBlockEditors.hpp @@ -130,6 +130,8 @@ class base: public QWidget virtual QStringList getdata(); + const QString c_input_placeholder{"Add a new value"}; + const QString c_no_object_placeholder{"No Object currently set"}; protected: base ( std::shared_ptr editordata, QWidget * parent = nullptr, bool owned = false ); @@ -171,7 +173,8 @@ class relation: public base, private dbe::Ui::RelationshipForm typedef dunedaq::conffwk::relationship_t t_virtue; typedef editor_data t_build_block_editor; - relation ( t_virtue const & relation, QWidget * parent = nullptr, bool owned = false ); + relation ( t_virtue const & relation, QWidget * parent = nullptr, + bool owned = false, bool readonly=false ); bool GetIsMultiValue() const; @@ -191,6 +194,7 @@ class relation: public base, private dbe::Ui::RelationshipForm std::shared_ptr p_base_data_editor; bool IsMultiValue; + bool m_readonly; QStatusBar * StatusBar; QStringList CurrentDataList; @@ -240,7 +244,8 @@ class stringattr: public base, private Ui::StringAttributeWidgetForm typedef dunedaq::conffwk::attribute_t t_virtue; typedef editor_data t_build_block_editor; - stringattr ( t_virtue const & attr, QWidget * parent = nullptr, bool owned = false ); + stringattr ( t_virtue const & attr, QWidget * parent = nullptr, + bool owned = false, bool readonly=false ); ~stringattr(); void SetEditor() override; @@ -265,6 +270,7 @@ class stringattr: public base, private Ui::StringAttributeWidgetForm std::shared_ptr m_base_data_editor; + bool m_readonly; QString DefaultValue; QPushButton * PopUpButton; QDialog * Dialog; @@ -294,7 +300,8 @@ class numericattr: public base, private Ui::NumericAttributeWidgetForm typedef dunedaq::conffwk::attribute_t t_virtue; typedef editor_data t_build_block_editor; - numericattr ( t_virtue const & attr, QWidget * parent = nullptr, bool owned = false ); + numericattr ( t_virtue const & attr, QWidget * parent = nullptr, + bool owned = false, bool readonly=false ); void SetEditor() override; @@ -313,6 +320,7 @@ class numericattr: public base, private Ui::NumericAttributeWidgetForm std::shared_ptr this_base_data_editor; + bool m_readonly; int this_base; int this_native_base; @@ -341,7 +349,8 @@ class combo: public base, public Ui::EditCombo typedef dunedaq::conffwk::attribute_t t_virtue; typedef editor_data t_build_block_editor; - combo ( t_virtue const & attr, QWidget * parent = nullptr, bool owned = false ); + combo ( t_virtue const & attr, QWidget * parent = nullptr, + bool owned = false, bool readonly=false ); void SetEditor() override; @@ -359,7 +368,7 @@ class combo: public base, public Ui::EditCombo void SetController(); std::shared_ptr m_base_data_editor; - + bool m_readonly; private slots: void TryValidate ( QString ); void ChangeDetected ( QString const & ); @@ -379,7 +388,8 @@ class multiattr: public base typedef dunedaq::conffwk::attribute_t t_virtue; typedef editor_data t_build_block_editor; - multiattr ( t_virtue const & attr, QWidget * parent = nullptr, bool owned = false ); + multiattr ( t_virtue const & attr, QWidget * parent = nullptr, + bool owned = false, bool readonly=false ); void SetEditor() override; @@ -391,6 +401,7 @@ class multiattr: public base std::shared_ptr m_base_data_editor; + bool m_readonly; QStatusBar * StatusBar; QPushButton * OkButton; QPushButton * RemoveButton; diff --git a/include/dbe/ObjectEditor.hpp b/include/dbe/ObjectEditor.hpp index 7454b3e..4bc5a69 100644 --- a/include/dbe/ObjectEditor.hpp +++ b/include/dbe/ObjectEditor.hpp @@ -72,6 +72,7 @@ class ObjectEditor: std::string classname; std::unique_ptr m_object_to_edit; + bool m_readonly{false}; tref Object() { diff --git a/src/widgets/BuildingBlockEditors.cpp b/src/widgets/BuildingBlockEditors.cpp index ca106e2..6d8ef11 100644 --- a/src/widgets/BuildingBlockEditors.cpp +++ b/src/widgets/BuildingBlockEditors.cpp @@ -101,12 +101,13 @@ void base::closeEvent ( QCloseEvent * Event ) //------------------------------------------------------------------------------------------------ relation::relation ( t_virtue const & relation, QWidget * parent, - bool owned ) + bool owned, bool readonly ) : base ( std::make_shared ( relation ), parent, owned ), p_base_data_editor ( std::static_pointer_cast ( p_data_editor ) ), IsMultiValue ( false ), + m_readonly(readonly), StatusBar ( nullptr ), ContextMenu ( nullptr ), RemoveAction ( nullptr ), @@ -190,12 +191,12 @@ bool relation::eventFilter ( QObject * Target, QEvent * Event ) }; if(Event->type() == QEvent::DragEnter) { - QDragEnterEvent *tDropEvent = static_cast(Event); + QDragEnterEvent *tDragEvent = static_cast(Event); - const QMimeData * const data = tDropEvent->mimeData(); + const QMimeData * const data = tDragEvent->mimeData(); const auto& decodedData = decode(data); if((decodedData.first == true) && (decodedData.second.size() > 0)) { - tDropEvent->acceptProposedAction(); + tDragEvent->acceptProposedAction(); } return true; @@ -203,11 +204,12 @@ bool relation::eventFilter ( QObject * Target, QEvent * Event ) if(Event->type() == QEvent::Drop) { QDropEvent *tDropEvent = static_cast(Event); - - const QMimeData * const data = tDropEvent->mimeData(); - for(const QString& o : decode(data).second) { - // TODO: this is not very efficient for large lists - AddToDataList(o); + if (!m_readonly) { + const QMimeData * const data = tDropEvent->mimeData(); + for(const QString& o : decode(data).second) { + // TODO: this is not very efficient for large lists + AddToDataList(o); + } } tDropEvent->acceptProposedAction(); @@ -237,50 +239,17 @@ bool relation::eventFilter ( QObject * Target, QEvent * Event ) return true; } - if(FirstItem == nullptr) { - if(IsMultiValue) { - FirstItem = new QListWidgetItem("Type here"); - } else { - if(this_data.isEmpty()) { - FirstItem = new QListWidgetItem("No Object"); - } else { - FirstItem = new QListWidgetItem(this_data.at(0)); - } - } - - ListWidget->addItem(FirstItem); - - if(IsMultiValue) { - FirstItem->setBackground(Qt::GlobalColor::lightGray); - FirstItem->setForeground(QColor(0, 0, 0, 127)); - } - - FirstItem->setSizeHint(FirstItem->sizeHint() + QSize(0, 25)); - } else if(FirstItem->listWidget() == ListWidget && ListWidget->itemWidget(FirstItem) != 0) { + if(FirstItem != nullptr && + FirstItem->listWidget() == ListWidget && + ListWidget->itemWidget(FirstItem) != 0) { ListWidget->takeItem(ListWidget->row(FirstItem)); ListWidget->setItemWidget(FirstItem, nullptr); delete FirstItem; - - if(IsMultiValue) { - FirstItem = new QListWidgetItem("Type here"); - } else { - if(this_data.isEmpty()) { - FirstItem = new QListWidgetItem("No Object"); - } else { - FirstItem = new QListWidgetItem(this_data.at(0)); - } - } - - ListWidget->addItem(FirstItem); - - if(IsMultiValue) { - FirstItem->setBackground(Qt::GlobalColor::lightGray); - FirstItem->setForeground(QColor(0, 0, 0, 127)); - } - - FirstItem->setSizeHint(FirstItem->sizeHint() + QSize(0, 25)); + SetFirstItem(); + } + else { + std::cout << "Do we ever get here? FirstItem is not null but other conditions not met!\n"; } - return false; } } else if(QLineEdit* le = dynamic_cast(Target)) { @@ -288,7 +257,7 @@ bool relation::eventFilter ( QObject * Target, QEvent * Event ) const QString& value = le->text(); // This string checking is very very bad... - if((value.isEmpty() == false) && (value != "Type here") && (value != "No Object")) { + if((value.isEmpty() == false) && (value != c_input_placeholder) && (value != c_no_object_placeholder)) { CreateObjectEditor(le->text().toStdString()); return false; } @@ -309,8 +278,10 @@ void relation::SetEditor() // Enable drops only for multi-value // This allows to drop several objects in a relationship (e.g., several computers in a rack) // Not really needed for single-value relationship (the item can be selected from the list) - ListWidget->setAcceptDrops ( true ); - ListWidget->installEventFilter ( this ); + if (!m_readonly) { + ListWidget->setAcceptDrops ( true ); + ListWidget->installEventFilter ( this ); + } } SetFirstItem(); @@ -353,8 +324,9 @@ bool relation::GetIsMultiValue() const void relation::DataWasFetched ( QStringList ListOfObjects ) { ComboBox->clear(); - ComboBox->addItems ( ListOfObjects ); - + if (!m_readonly) { + ComboBox->addItems ( ListOfObjects ); + } emit signal_internal_value_change(); if ( this_initial_load ) @@ -389,28 +361,35 @@ void relation::SetFirstItem() { if ( IsMultiValue ) { - FirstItem = new QListWidgetItem ( "Type here" ); + if (m_readonly) { + if ( this_data.isEmpty() ) { + FirstItem = new QListWidgetItem ( c_no_object_placeholder ); + ListWidget->addItem ( FirstItem ); + } + else { + FirstItem = new QListWidgetItem ( this_data.at ( 0 ) ); + } + } + else { + FirstItem = new QListWidgetItem ( c_input_placeholder ); + FirstItem->setBackground ( Qt::GlobalColor::lightGray ); + FirstItem->setForeground ( QColor ( 0, 0, 0, 127 ) ); + ListWidget->addItem ( FirstItem ); + } } else { if ( this_data.isEmpty() ) { - FirstItem = new QListWidgetItem ( "No Object" ); + FirstItem = new QListWidgetItem ( c_no_object_placeholder ); } - else { FirstItem = new QListWidgetItem ( this_data.at ( 0 ) ); } + ListWidget->addItem ( FirstItem ); } - ListWidget->addItem ( FirstItem ); - - if ( IsMultiValue ) - { - FirstItem->setBackground ( Qt::GlobalColor::lightGray ); - FirstItem->setForeground ( QColor ( 0, 0, 0, 127 ) ); - } FirstItem->setSizeHint ( FirstItem->sizeHint() + QSize ( 0, 25 ) ); } @@ -500,7 +479,7 @@ void relation::CustomContextMenuRequested ( const QPoint & pos ) ContextMenu->addAction ( RemoveAction ); } - if ( ( CurrentItem = ListWidget->itemAt ( pos ) ) ) + if ( !m_readonly && ( CurrentItem = ListWidget->itemAt ( pos ) ) ) { if ( CurrentItem != FirstItem ) { @@ -718,7 +697,7 @@ void relation::EditItemEntered ( QListWidgetItem * Item ) void relation::EndSignal() { - if ( IsMultiValue and ListWidget->item ( 0 )->text() == "Type here" + if ( IsMultiValue and ListWidget->item ( 0 )->text() == c_input_placeholder and not this_value_changed ) { return; @@ -734,7 +713,7 @@ void relation::EndSignal() QListWidgetItem * Item = ListWidget->item ( i ); QString const & val = Item->text(); - if ( val != "Type here" and val != "No Object" ) + if ( val != c_input_placeholder and val != c_no_object_placeholder ) { this_data.append ( val ); } @@ -775,7 +754,7 @@ void relation::AddToDataList ( const QString & DataValue ) if ( IsMultiValue ) { - FirstItem = new QListWidgetItem ( "Type here" ); + FirstItem = new QListWidgetItem ( c_input_placeholder ); } else { @@ -819,7 +798,7 @@ void relation::RemoveFromDataList() { QString text = item->text(); - if ( text != "Type here" ) + if ( text != c_input_placeholder ) { if ( IsMultiValue ) { @@ -837,7 +816,7 @@ void relation::RemoveFromDataList() { editbox->lineEdit()->clear(); editbox->lineEdit()->clearFocus(); - FirstItem->setText ( "No Object" ); + FirstItem->setText ( c_no_object_placeholder ); } } @@ -857,7 +836,7 @@ void relation::UpdateActions() { QString const & value = ListWidget->item ( i )->text(); - if ( value != "No Object" and value != "Type here" ) + if ( value != c_no_object_placeholder and value != c_input_placeholder ) { values.append ( value ); } @@ -902,10 +881,11 @@ void relation::closeEvent ( QCloseEvent * Event ) //------------------------------------------------------------------------------------------------ stringattr::stringattr ( t_virtue const & attr, QWidget * parent, - bool owned ) + bool owned, bool readonly ) : base ( std::make_shared ( attr ), parent, owned ), m_base_data_editor ( std::static_pointer_cast ( p_data_editor ) ), + m_readonly(readonly), DefaultValue ( "" ), PopUpButton ( nullptr ), Dialog ( nullptr ), @@ -915,8 +895,13 @@ stringattr::stringattr ( t_virtue const & attr, QWidget * parent, setupUi ( this ); t_virtue const & virtue = m_base_data_editor->get(); - StringLineEdit->installEventFilter(this); - StringLineEdit->setTabChangesFocus(true); + if (m_readonly) { + StringLineEdit->setReadOnly(true); + } + else { + StringLineEdit->installEventFilter(this); + } + StringLineEdit->setTabChangesFocus(true); setWindowTitle ( QString ( "Edit Attr : %1" ).arg ( virtue.p_name.c_str() ) ); AttributeNameLabel->setText ( QString ( virtue.p_name.c_str() ) + " : " ); @@ -1068,9 +1053,11 @@ void stringattr::closeEvent ( QCloseEvent * Event ) void stringattr::SetController() { - connect ( StringLineEdit, SIGNAL ( textChanged ( ) ), this, SLOT ( UpdateActions ( ) ), Qt::UniqueConnection ); - connect ( this, SIGNAL ( signal_data_input_complete() ), this, SLOT ( AddToDataList() ) ); - connect ( OkButton, SIGNAL ( clicked() ), this, SLOT ( AddToDataList() ), Qt::UniqueConnection ); + if (!m_readonly) { + connect ( StringLineEdit, SIGNAL ( textChanged ( ) ), this, SLOT ( UpdateActions ( ) ), Qt::UniqueConnection ); + connect ( this, SIGNAL ( signal_data_input_complete() ), this, SLOT ( AddToDataList() ) ); + connect ( OkButton, SIGNAL ( clicked() ), this, SLOT ( AddToDataList() ), Qt::UniqueConnection ); + } } void stringattr::setdefaults ( const QString & ValueDefault ) @@ -1197,18 +1184,23 @@ void stringattr::ToogleTextEditOkButton() //------------------------------------------------------------------------------------------------ numericattr::numericattr ( t_virtue const & attr, QWidget * parent, - bool owned ) + bool owned, bool readonly ) : base ( std::make_shared ( attr ), parent, owned ), this_base_data_editor ( std::static_pointer_cast ( p_data_editor ) ), + m_readonly(readonly), this_native_base ( -1 ) { setupUi ( this ); t_virtue const & Virtue = this_base_data_editor->get(); setWindowTitle ( QString ( "Edit Attribute: %1" ).arg ( Virtue.p_name.c_str() ) ); - LineEdit->SetPopupMenu(); - + if (m_readonly) { + LineEdit->setReadOnly(true); + } + else { + LineEdit->SetPopupMenu(); + } if ( Virtue.p_is_not_null ) { this_base_data_editor->set_valid ( false ); @@ -1879,27 +1871,33 @@ void numericattr::ChangeFormatOct() //------------------------------------------------------------------------------------------------ combo::combo ( t_virtue const & attr, QWidget * parent, - bool owned ) + bool owned, bool readonly ) : base ( std::make_shared ( attr ), parent, owned ), - m_base_data_editor ( std::static_pointer_cast ( p_data_editor ) ) + m_base_data_editor ( std::static_pointer_cast ( p_data_editor ) ), + m_readonly(readonly) { setupUi ( this ); SetController(); /// Configuration of combo box Combo->setFocusPolicy ( Qt::ClickFocus ); - Combo->installEventFilter ( this ); - - if ( Combo->lineEdit() != nullptr ) - { - Combo->lineEdit()->installEventFilter ( this ); + if (m_readonly) { + Combo->setEditable (false); + if ( Combo->lineEdit() != nullptr ) { + Combo->lineEdit()->setReadOnly(true); + Combo->lineEdit()->hide(); + } } + else { + Combo->installEventFilter ( this ); + if ( Combo->lineEdit() != nullptr ) { + Combo->lineEdit()->installEventFilter ( this ); + } - t_virtue const & Virtue = m_base_data_editor->get(); - - if ( Virtue.p_type == dunedaq::conffwk::class_type ) - { - Combo->setEditable ( true ); + t_virtue const & Virtue = m_base_data_editor->get(); + if ( Virtue.p_type == dunedaq::conffwk::class_type ) { + Combo->setEditable ( true ); + } } } @@ -1924,13 +1922,13 @@ void combo::SetValidatorData ( QStringList const & Data, bool AcceptNoMatch ) Combo->clear(); Combo->addItems ( Data ); - QCompleter * Completer = new QCompleter ( Combo->model(), Combo ); - Completer->setCaseSensitivity ( Qt::CaseInsensitive ); - Completer->setCompletionMode ( QCompleter::PopupCompletion ); - Completer->setFilterMode(Qt::MatchContains); - - Combo->setCompleter ( Completer ); - + if (Combo->isEditable()) { + QCompleter * Completer = new QCompleter ( Combo->model(), Combo ); + Completer->setCaseSensitivity ( Qt::CaseInsensitive ); + Completer->setCompletionMode ( QCompleter::PopupCompletion ); + Completer->setFilterMode(Qt::MatchContains); + Combo->setCompleter ( Completer ); + } m_base_data_editor->set_obligatory ( false ); QVariant VarFromList ( Data ); @@ -1940,7 +1938,6 @@ void combo::SetValidatorData ( QStringList const & Data, bool AcceptNoMatch ) ValidatorAcceptNoMatch * TmpValidator = new ValidatorAcceptNoMatch ( VarFromList, this ); Combo->setValidator ( TmpValidator ); } - else { ValidatorAcceptMatch * TmpValidator = new ValidatorAcceptMatch ( VarFromList, this ); @@ -1977,6 +1974,7 @@ void combo::SetEditor() QStringList classes ( dbe::config::api::info::onclass::allnames() ); classes.sort(); SetValidatorData ( classes ); + Combo->lineEdit()->setText(c_input_placeholder); } SetData ( this_data ); @@ -1989,13 +1987,32 @@ void combo::setdata ( QStringList const & v ) bool combo::eventFilter ( QObject * Target, QEvent * Event ) { - if ( Target == Combo->lineEdit() && Event->type() == QEvent::MouseButtonRelease ) - { - if ( !Combo->lineEdit()->hasSelectedText() ) - { - Combo->lineEdit()->selectAll(); + if (dynamic_cast(Target) != nullptr) { + std::cout << "cast to QLineEdit\n"; + } + if ( Target == Combo && Combo->lineEdit() != nullptr) { + if (Event->type() < 100) { + } + if (Event->type() == QEvent::FocusOut) { + if (Combo->lineEdit()->text().isEmpty()) { + Combo->lineEdit()->setText(c_input_placeholder); + } + return true; + } + if (Event->type() == QEvent::FocusIn) { + if (!Combo->lineEdit()->hasSelectedText() ) { + Combo->lineEdit()->selectAll(); + } return true; } + if(Event->type() == QEvent::KeyPress) { + QKeyEvent * KeyEvent = dynamic_cast(Event); + if(KeyEvent->key() == Qt::Key_Up || KeyEvent->key() == Qt::Key_Down) { + return true; + } else { + return false; + } + } } if ( Event->type() == QEvent::Wheel ) @@ -2018,16 +2035,16 @@ void combo::SetController() SLOT ( TryValidate ( const QString & ) ), Qt::UniqueConnection ); connect ( Combo, SIGNAL ( activated ( const QString & ) ), this, SLOT ( ChangeDetected ( const QString & ) ), Qt::UniqueConnection ); - connect ( Combo, SIGNAL ( currentIndexChanged ( int ) ), this, - SLOT ( CheckDefaults ( int ) ), - Qt::UniqueConnection ); } void combo::TryValidate ( QString tmp ) { + if (tmp == c_input_placeholder) { + Combo->lineEdit()->setPalette ( QApplication::palette ( this ) ); + return; + } int index = 0; - - if ( Combo->validator() != nullptr ) + if (Combo->validator() != nullptr ) { if ( Combo->validator()->validate ( tmp, index ) == QValidator::Acceptable ) { @@ -2035,19 +2052,19 @@ void combo::TryValidate ( QString tmp ) if ( CompareDefaults() ) { - Combo->setPalette ( StyleUtility::LoadedDefault ); + Combo->lineEdit()->setPalette ( StyleUtility::LoadedDefault ); } else { - Combo->setPalette ( QApplication::palette ( this ) ); + Combo->lineEdit()->setPalette ( QApplication::palette ( this ) ); } } else if ( Combo->validator()->validate ( tmp, index ) == QValidator::Intermediate ) { m_base_data_editor->set_not_null ( false ); - Combo->setPalette ( StyleUtility::WarningStatusBarPallete ); + Combo->lineEdit()->setPalette ( StyleUtility::WarningStatusBarPallete ); } } @@ -2103,10 +2120,11 @@ void combo::buildtooltip() //------------------------------------------------------------------------------------------------ multiattr::multiattr ( t_virtue const & attr, QWidget * parent, - bool owned ) + bool owned, bool readonly ) : base ( std::make_shared ( attr ), parent, owned ), m_base_data_editor ( std::static_pointer_cast ( p_data_editor ) ), + m_readonly(readonly), StatusBar ( nullptr ), OkButton ( nullptr ), RemoveButton ( nullptr ), @@ -2124,6 +2142,7 @@ multiattr::multiattr ( t_virtue const & attr, QWidget * parent, QHBoxLayout * ButtonLayout = new QHBoxLayout(); ListWidget = new QListWidget ( this ); ListWidget->setContextMenuPolicy ( Qt::CustomContextMenu ); + MainLayout->addWidget ( ListWidget ); switch ( Virtue.p_type ) { @@ -2138,7 +2157,8 @@ multiattr::multiattr ( t_virtue const & attr, QWidget * parent, connect ( Combo->Combo, SIGNAL ( activated ( const QString & ) ), this, SLOT ( AddToDataList ( const QString & ) ), Qt::UniqueConnection ); BaseWidget = Combo; - + Combo->setStyleSheet ( "QLineEdit { background: #c0c0c0;} " + "QLineEdit:focus {background: white;}" ); break; } @@ -2164,7 +2184,8 @@ multiattr::multiattr ( t_virtue const & attr, QWidget * parent, BaseWidget = Numeric; /// Frame Numeric->GetLineEdit()->setFrame ( false ); - Numeric->GetLineEdit()->setPlaceholderText ( "Type Here" ); + Numeric->GetLineEdit()->setReadOnly(m_readonly); + Numeric->GetLineEdit()->setPlaceholderText (c_input_placeholder); Numeric->setStyleSheet ( "QLineEdit { background: #c0c0c0;} QLineEdit:focus {background: white;}" ); Numeric->GetLineEdit()->setFixedHeight ( 24 ); @@ -2173,7 +2194,6 @@ multiattr::multiattr ( t_virtue const & attr, QWidget * parent, } // Types below are all treated as string types - case dunedaq::conffwk::date_type: case dunedaq::conffwk::time_type: case dunedaq::conffwk::string_type: @@ -2185,10 +2205,11 @@ multiattr::multiattr ( t_virtue const & attr, QWidget * parent, Qt::UniqueConnection ); BaseWidget = String; /// Frame + String->GetLineEdit()->setReadOnly(m_readonly); String->GetLineEdit()->setFrameStyle(QFrame::NoFrame); -// String->GetLineEdit()->setPlaceholderText ( "Type here" ); + String->GetLineEdit()->setPlaceholderText ( c_input_placeholder ); String->setStyleSheet ( "QLineEdit { background: #c0c0c0;} " - "QLineEdit:focus {background: white;}" ); + "QLineEdit:focus {background: white;}" ); // String->GetLineEdit()->setFixedHeight ( 24 ); ListWidget->setFrameStyle ( QFrame::NoFrame ); @@ -2209,7 +2230,6 @@ multiattr::multiattr ( t_virtue const & attr, QWidget * parent, connect ( ListWidget, SIGNAL ( customContextMenuRequested ( QPoint ) ), this, SLOT ( CustomContextMenuRequested ( QPoint ) ) ); - MainLayout->addWidget ( ListWidget ); MainLayout->addLayout ( ButtonLayout ); SetStatusBar(); MainLayout->addWidget ( StatusBar ); @@ -2259,7 +2279,6 @@ void multiattr::SetEditor() widget->setFlags ( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled ); - } connect ( ListWidget, SIGNAL ( itemChanged ( QListWidgetItem * ) ), this, diff --git a/src/widgets/ObjectEditor.cpp b/src/widgets/ObjectEditor.cpp index afe9124..3f44385 100644 --- a/src/widgets/ObjectEditor.cpp +++ b/src/widgets/ObjectEditor.cpp @@ -40,7 +40,8 @@ dbe::ObjectEditor::ObjectEditor(QWidget * parent) this_editor_values_changed ( false ), CurrentRow ( 0 ), MainLayout ( new QHBoxLayout() ), - WidgetTable ( new NoScrollingTable() ), + // WidgetTable ( new NoScrollingTable() ), + WidgetTable ( new QTableWidget() ), RenameWidget ( nullptr ), LineEdit ( nullptr ), GoButton ( nullptr ), @@ -98,6 +99,12 @@ dbe::ObjectEditor::ObjectEditor ( tref const & object, QWidget * parent, bool is //------------------------------------------------------------------------------------------ void dbe::ObjectEditor::init() { + + if (m_object_to_edit and not Object().is_null()) { + m_readonly = !confaccessor::check_file_rw ( + QString::fromStdString ( Object().contained_in() )); + } + dunedaq::conffwk::class_t const & Class = dbe::config::api::info::onclass::definition ( classname, false ); int NumberOfRows = Class.p_attributes.size() + Class.p_relationships.size(); @@ -126,12 +133,11 @@ void dbe::ObjectEditor::init() { ui->MoveButton->setDisabled ( true ); } else { - bool rw = confaccessor::check_file_rw ( - QString::fromStdString ( Object().contained_in() )); - if (!rw) { - WidgetTable->setDisabled(true); + if (m_readonly) { + // WidgetTable->setDisabled(true); ui->RenameButton->setDisabled(true); ui->MoveButton->setDisabled(true); + ui->ApplyButton->hide(); } } ui->TableLayout->addWidget ( WidgetTable ); @@ -400,7 +406,7 @@ void dbe::ObjectEditor::BuildWidgets() if ( attr.p_is_multi_value ) { widgets::editors::multiattr * widget = new widgets::editors::multiattr ( attr, this, - true ); + true, m_readonly ); set_attribute_widget ( attr, widget ); set_tooltip ( attr, widget ); @@ -452,8 +458,8 @@ void dbe::ObjectEditor::BuildWidgets() case dunedaq::conffwk::u64_type: { - widgets::editors::numericattr * Widget = new widgets::editors::numericattr ( attr, this, - true ); + widgets::editors::numericattr * Widget = + new widgets::editors::numericattr ( attr, this, true, m_readonly ); set_attribute_widget ( attr, Widget ); set_tooltip ( attr, Widget ); register_attribute_widget ( name, Widget ); @@ -471,8 +477,8 @@ void dbe::ObjectEditor::BuildWidgets() case dunedaq::conffwk::time_type: { - widgets::editors::stringattr * Widget = new widgets::editors::stringattr ( attr, this, - true ); + widgets::editors::stringattr * Widget = + new widgets::editors::stringattr ( attr, this, true, m_readonly ); set_attribute_widget ( attr, Widget ); set_tooltip ( attr, Widget ); register_attribute_widget ( name, Widget ); @@ -505,7 +511,7 @@ void dbe::ObjectEditor::BuildWidgets() relations ) // Build widgets for relations ( relationships ) { widgets::editors::relation * widget = new widgets::editors::relation ( arelation, this, - true ); + true, m_readonly ); QString name = QString::fromStdString ( arelation.p_name ); QStringList Data; @@ -541,6 +547,7 @@ void dbe::ObjectEditor::BuildWidgets() widget->setdata ( Data ); widget->SetEditor(); + set_tooltip ( arelation, widget ); register_relation_widget ( name, widget ); connect ( widget, SIGNAL ( signal_value_change() ), this, SLOT ( UpdateActions() ), From 77b2a0ed0d287eed6f741ea2a5c2b2c7ce4c71be Mon Sep 17 00:00:00 2001 From: Gordon Crone Date: Fri, 16 Jan 2026 14:44:18 +0000 Subject: [PATCH 2/7] Include class name in relationships in ObjectEditor --- src/widgets/BuildingBlockEditors.cpp | 2 +- src/widgets/ObjectEditor.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/widgets/BuildingBlockEditors.cpp b/src/widgets/BuildingBlockEditors.cpp index 6d8ef11..c69bf7c 100644 --- a/src/widgets/BuildingBlockEditors.cpp +++ b/src/widgets/BuildingBlockEditors.cpp @@ -310,7 +310,7 @@ void relation::FetchData() for ( tref const & o : related ) { - result.append ( QString::fromStdString ( o.UID() ) ); + result.append ( QString::fromStdString ( o.full_name() ) ); } emit FetchDataDone ( result ); diff --git a/src/widgets/ObjectEditor.cpp b/src/widgets/ObjectEditor.cpp index 3f44385..ae73378 100644 --- a/src/widgets/ObjectEditor.cpp +++ b/src/widgets/ObjectEditor.cpp @@ -353,7 +353,7 @@ void dbe::ObjectEditor::UpdateObjectEditor ( QString const & src, dref updated_o std::transform ( connected.begin(), connected.end(), std::back_inserter ( relvalues ), [] ( decltype ( connected ) ::value_type const & x ) { - return QString::fromStdString ( x.UID() ); + return QString::fromStdString ( x.full_name() ); } ); @@ -540,7 +540,7 @@ void dbe::ObjectEditor::BuildWidgets() { if ( not i.is_null() ) { - Data.push_back ( QString::fromStdString ( i.UID() ) ); + Data.push_back ( QString::fromStdString ( i.full_name() ) ); } } } From 4a8cf1b195bd45e6f8a03c633e7b347fedc64089 Mon Sep 17 00:00:00 2001 From: Gordon Crone Date: Tue, 20 Jan 2026 10:44:55 +0000 Subject: [PATCH 3/7] Simplify CreateDatabaseWidget and use static methods from FileInfo for default paths --- include/dbe/CreateDatabaseWidget.hpp | 2 +- include/dbe/FileInfo.hpp | 4 ++ src/internal/Command.cpp | 2 +- src/widgets/CreateDatabaseWidget.cpp | 85 ++++++++++------------------ ui/CreateDatabaseWidget.ui | 8 ++- 5 files changed, 41 insertions(+), 60 deletions(-) diff --git a/include/dbe/CreateDatabaseWidget.hpp b/include/dbe/CreateDatabaseWidget.hpp index dd86df5..b4a85fd 100644 --- a/include/dbe/CreateDatabaseWidget.hpp +++ b/include/dbe/CreateDatabaseWidget.hpp @@ -28,12 +28,12 @@ class CreateDatabaseWidget: public QWidget, private dbe::Ui::CreateDatabaseWidge void CanIncludeDatabase ( const QString & DatabasePath ); private: - QStatusBar * StatusBar; QFileInfo DatabaseFile; QFileInfo SchemaFile; QString DirToCreate; bool CreateToInclude; std::list get_includes(); + bool create_database_file(std::string extra_text); private slots: void DefineSchema(); void DefineDatabaseFile(); diff --git a/include/dbe/FileInfo.hpp b/include/dbe/FileInfo.hpp index 56bf380..a50bbb4 100644 --- a/include/dbe/FileInfo.hpp +++ b/include/dbe/FileInfo.hpp @@ -35,6 +35,10 @@ namespace dbe static QString prune_path(QString file); static void parse_all_objects(); static QString check_file_includes(const QString& file); + static QString get_schema_path() {return s_schema_path;} + static QString get_data_path() {return s_data_path;} + static void set_schema_path(const QString& path) {s_schema_path=path;} + static void set_data_path(const QString& path) {s_data_path=path;} private slots: void accept(); diff --git a/src/internal/Command.cpp b/src/internal/Command.cpp index 9cb6613..cb3198a 100644 --- a/src/internal/Command.cpp +++ b/src/internal/Command.cpp @@ -169,7 +169,7 @@ dbe::actions::file::remove::remove ( std::string & db_file, std::string & includ m_include_file ( include_file ) { setText ( - QObject::tr ( "Remove Include File %1 to %2" ).arg ( + QObject::tr ( "Remove Include File %1 from %2" ).arg ( QFileInfo ( QString ( m_include_file.c_str() ) ).fileName() ).arg ( QFileInfo ( QString ( m_db_file.c_str() ) ).fileName() ) ); } diff --git a/src/widgets/CreateDatabaseWidget.cpp b/src/widgets/CreateDatabaseWidget.cpp index 646a71a..63b4d3c 100644 --- a/src/widgets/CreateDatabaseWidget.cpp +++ b/src/widgets/CreateDatabaseWidget.cpp @@ -17,7 +17,6 @@ using namespace dunedaq::conffwk; dbe::CreateDatabaseWidget::CreateDatabaseWidget ( QWidget * parent, bool Include, const QString & CreateDir ) : QWidget ( parent ), - StatusBar ( nullptr ), DirToCreate ( CreateDir ), CreateToInclude ( Include ) { @@ -44,13 +43,8 @@ dbe::CreateDatabaseWidget::CreateDatabaseWidget ( QWidget * parent, bool Include CreateNoLoadDatabaseButton->hide(); } - StatusBar = new QStatusBar ( StatusFrame ); - StatusBar->setSizeGripEnabled ( false ); - StatusFrame->setFrameStyle ( QFrame::NoFrame ); - StatusLayout->addWidget ( StatusBar ); - StatusBar->setAutoFillBackground ( true ); - StatusBar->showMessage ( "Select schema files and define new database file!" ); + m_instructions->setText ( "Select schema files and define new database file. Database must contain at least one schema file, other includes may be added later via a File info window." ); CreateDatabaseButton->setDisabled ( true ); CreateNoLoadDatabaseButton->setDisabled ( true ); @@ -60,7 +54,7 @@ dbe::CreateDatabaseWidget::CreateDatabaseWidget ( QWidget * parent, bool Include void dbe::CreateDatabaseWidget::DefineSchema() { auto fd = new QFileDialog ( this, tr ( "Select Schema File" ), - DirToCreate.append("./"), + FileInfo::get_schema_path(), tr ( "XML schema files (*.schema.xml)" ) ); fd->setFileMode ( QFileDialog::ExistingFile ); fd->setViewMode ( QFileDialog::Detail ); @@ -69,21 +63,23 @@ void dbe::CreateDatabaseWidget::DefineSchema() if (!(fd->exec() == QDialog::Accepted)) { return; } + FileInfo::set_schema_path(fd->directory().path()); + auto files = fd->selectedFiles(); for (auto file: files) { QFileInfo SchemaFile = QFileInfo (file); if ( !SchemaFile.isFile() ) { - StatusBar->setPalette ( StyleUtility::AlertStatusBarPallete ); - StatusBar->showMessage ( QString ( "The file is not accessible. Check before usage" ) ); + m_instructions->setPalette ( StyleUtility::AlertStatusBarPallete ); + m_instructions->setText ( QString ( "The file is not accessible. Check before usage" )); } else { if (SchemaFile.fileName().contains("schema")) { schema_list->addItem(FileInfo::prune_path(file)); } else { - StatusBar->setPalette ( StyleUtility::AlertStatusBarPallete ); - StatusBar->showMessage ( - QString ( "The file %1 is not a schema file" ).arg ( SchemaFile.absoluteFilePath() ) ); + m_instructions->setPalette ( StyleUtility::AlertStatusBarPallete ); + m_instructions->setText ( + QString ( "The file %1 is not a schema file" ).arg ( SchemaFile.absoluteFilePath() )); } } } @@ -98,17 +94,10 @@ void dbe::CreateDatabaseWidget::DefineDatabaseFile() { QString Dir; - if ( DirToCreate.isEmpty() ) - { - Dir = QString ( "./NewDatabaseFile.data.xml" ); - } - else - { - Dir = DirToCreate.append ( "/NewDatabaseFile.data.xml" ); - } + QString path = FileInfo::get_data_path().append ( "/NewDatabaseFile.data.xml" ); auto fd = new QFileDialog ( this, tr("Select new DB File"), - Dir, + path, tr("XML data files (*.data.xml)")); fd->setFileMode ( QFileDialog::AnyFile ); fd->setViewMode ( QFileDialog::Detail ); @@ -117,6 +106,7 @@ void dbe::CreateDatabaseWidget::DefineDatabaseFile() if (!(fd->exec() == QDialog::Accepted)) { return; } + FileInfo::set_data_path(fd->directory().path()); auto files = fd->selectedFiles(); DatabaseFile = QFileInfo (files.at(0)); @@ -140,60 +130,43 @@ std::list dbe::CreateDatabaseWidget::get_includes() { } -void dbe::CreateDatabaseWidget::CreateDatabaseFileLoad() -{ +bool dbe::CreateDatabaseWidget::create_database_file(std::string extra_text) { Configuration db ( "oksconflibs" ); try { const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString(); - db.create ( DatabaseName, get_includes()); + db.create (DatabaseName, get_includes()); db.commit(); - - QMessageBox::information ( - 0, tr ( "DBE" ), - QString ( "Database was created.\nNow the DB will be loaded into the Editor!\n" ), - QMessageBox::Ok ); - emit CanLoadDatabase ( DatabaseFile.absoluteFilePath() ); - close(); } catch ( dunedaq::conffwk::Exception const & ex ) { FAIL ( "Database creation failure", dbe::config::errors::parse ( ex ).c_str() ); + return false; + } + + QMessageBox::information (0, tr ( "DBE" ), + QString::fromStdString ("The Database was created.\n"+extra_text), + QMessageBox::Ok ); + return true; +} +void dbe::CreateDatabaseWidget::CreateDatabaseFileLoad() +{ + if (create_database_file("Now the DB will be loaded into the Editor!\n")) { + emit CanLoadDatabase ( DatabaseFile.absoluteFilePath() ); + close(); } } void dbe::CreateDatabaseWidget::CreateDatabaseFileNoLoad() { - Configuration db ( "oksconflibs" ); - try { - const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString(); - db.create (DatabaseName, get_includes()); - db.commit(); - - QMessageBox::information ( 0, tr ( "DBE" ), QString ( "The Database was created.\n" ), - QMessageBox::Ok ); + if (create_database_file("")) { close(); } - catch ( dunedaq::conffwk::Exception const & ex ) - { - FAIL ( "Database creation failure", dbe::config::errors::parse ( ex ).c_str() ); - } } void dbe::CreateDatabaseWidget::CreateDatabaseFileInclude() { - Configuration db ( "oksconflibs" ); - try { - const std::string DatabaseName = DatabaseFile.absoluteFilePath().toStdString(); - db.create (DatabaseName, get_includes()); - db.commit(); - - QMessageBox::information ( 0, tr ( "DBE" ), QString ( "The Database was created.\n" ), - QMessageBox::Ok ); + if (create_database_file("")) { emit CanIncludeDatabase ( DatabaseFile.absoluteFilePath() ); close(); } - catch ( dunedaq::conffwk::Exception const & ex ) - { - FAIL ( "Database creation error", dbe::config::errors::parse ( ex ).c_str() ); - } } diff --git a/ui/CreateDatabaseWidget.ui b/ui/CreateDatabaseWidget.ui index c2614a8..2998955 100644 --- a/ui/CreateDatabaseWidget.ui +++ b/ui/CreateDatabaseWidget.ui @@ -11,7 +11,7 @@ - Form + Creat new database file @@ -216,7 +216,11 @@ p, li { white-space: pre-wrap; } - + + + TextLabel + + From 05eedac51ea0873cdab933d12e4495c63b29f443 Mon Sep 17 00:00:00 2001 From: Gordon Crone Date: Wed, 21 Jan 2026 09:31:24 +0000 Subject: [PATCH 4/7] Add base directory of database file and current working directory to FileInfo paths if not already included --- src/structure/FileInfo.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/structure/FileInfo.cpp b/src/structure/FileInfo.cpp index 38c848b..b062be1 100644 --- a/src/structure/FileInfo.cpp +++ b/src/structure/FileInfo.cpp @@ -42,6 +42,18 @@ void FileInfo::setup_paths() { s_path_list.append(path); } } + auto dbpath = confaccessor::dbfullname(); + dbpath.truncate(dbpath.lastIndexOf("/")+1); + if (!s_path_list.contains(dbpath)) { + s_path_urls.append(QUrl::fromLocalFile(dbpath)); + s_path_list.append(dbpath); + } + char* rpath_cd = realpath(".", NULL); + auto path_cd = QString(rpath_cd); + free(rpath_cd); + if (!s_path_list.contains(path_cd)) { + s_path_urls.append(QUrl::fromLocalFile(path_cd)); + } } QString FileInfo::prune_path(QString file) { From 98f4208d1b5cdbdcd3c88639755c6f73c98de837 Mon Sep 17 00:00:00 2001 From: Gordon Crone Date: Wed, 21 Jan 2026 09:55:00 +0000 Subject: [PATCH 5/7] Try to make messages more readable and reduce duplicated code --- include/dbe/MainWindow.hpp | 7 +-- src/internal/MainWindow.cpp | 121 +++++------------------------------- src/internal/config_api.cpp | 10 +-- 3 files changed, 18 insertions(+), 120 deletions(-) diff --git a/include/dbe/MainWindow.hpp b/include/dbe/MainWindow.hpp index 1133df1..5574bec 100644 --- a/include/dbe/MainWindow.hpp +++ b/include/dbe/MainWindow.hpp @@ -108,7 +108,8 @@ class MainWindow: void edit_object_at ( const QModelIndex & Index ); void update_total_objects(); - + void display_message_box(const QString& title, const QString& msg, + const QMessageBox::Icon& icon); private slots: void slot_create_newdb(); void slot_open_database_from_file(); @@ -164,12 +165,10 @@ private slots: public slots: void slot_batch_change_start(); void slot_batch_change_stop(const QList>&); - void slot_debuginfo_message ( QString const, QString const ); + void slot_information_message ( QString const, QString const ); - void slot_notice_message ( QString const, QString const ); void slot_warning_message ( QString const, QString const ); void slot_error_message ( QString const, QString const ); - void slot_failure_message ( QString const, QString const ); signals: //void signal_rdb_found (const QString& p, const RDBMap& rdbs); diff --git a/src/internal/MainWindow.cpp b/src/internal/MainWindow.cpp index 0e0066e..266ed58 100644 --- a/src/internal/MainWindow.cpp +++ b/src/internal/MainWindow.cpp @@ -269,7 +269,7 @@ void dbe::MainWindow::attach() connect ( &dbe::interface::messenger_proxy::ref(), SIGNAL ( signal_debug ( QString const, QString const ) ), this, - SLOT ( slot_debuginfo_message ( QString , QString ) ), Qt::QueuedConnection ); + SLOT ( slot_information_message ( QString , QString ) ), Qt::QueuedConnection ); connect ( &dbe::interface::messenger_proxy::ref(), SIGNAL ( signal_info ( QString const, QString const ) ), this, @@ -277,7 +277,7 @@ void dbe::MainWindow::attach() connect ( &dbe::interface::messenger_proxy::ref(), SIGNAL ( signal_note ( QString const, QString const ) ), this, - SLOT ( slot_notice_message ( QString , QString ) ), Qt::QueuedConnection ); + SLOT ( slot_information_message ( QString , QString ) ), Qt::QueuedConnection ); connect ( &dbe::interface::messenger_proxy::ref(), SIGNAL ( signal_warn ( QString const, QString const ) ), this, @@ -289,7 +289,7 @@ void dbe::MainWindow::attach() connect ( &dbe::interface::messenger_proxy::ref(), SIGNAL ( signal_fail ( QString const, QString const ) ), this, - SLOT ( slot_failure_message ( QString , QString ) ), Qt::QueuedConnection ); + SLOT ( slot_error_message ( QString, QString ) ), Qt::QueuedConnection ); // connect ( this, SIGNAL ( signal_rdb_found(const QString&, const RDBMap& ) ), // this, SLOT ( slot_rdb_found(const QString&, const RDBMap&) ), Qt::AutoConnection ); @@ -1688,17 +1688,17 @@ namespace { const int MAX_MESSAGE_LENGTH = 500; } -void dbe::MainWindow::slot_failure_message ( QString const title, QString const msg ) -{ +void dbe::MainWindow::display_message_box(const QString& title, const QString& msg, + const QMessageBox::Icon& icon) { QMessageBox mb(this); - mb.setIcon(QMessageBox::Icon::Critical); + mb.setIcon(icon); mb.setWindowTitle(title); mb.setStandardButtons(QMessageBox::Ok); if(msg.length() > MAX_MESSAGE_LENGTH) { - QString&& m = msg.left(MAX_MESSAGE_LENGTH); - m.append("..."); - mb.setText("The message has been truncated because too long, look at the details for the full message"); - mb.setInformativeText(m); + QString&& truncated_msg = msg.left(MAX_MESSAGE_LENGTH); + truncated_msg.append("..."); + mb.setText("The message has been truncated because it is too long, look at the details for the full message"); + mb.setInformativeText(truncated_msg); mb.setDetailedText(msg); } else { mb.setText(msg); @@ -1707,31 +1707,6 @@ void dbe::MainWindow::slot_failure_message ( QString const title, QString const mb.exec(); } -/** - * This method permits to propagate and display messages from the messaging subsytem. - * - * It is important that the arguments are pass-by-copy because references will become invalid, - * even if they are bound to consted temporaries, once the deleter from the other thread is called. - * - */ -void dbe::MainWindow::slot_information_message ( QString const title, QString const msg ) -{ - QMessageBox mb(this); - mb.setIcon(QMessageBox::Icon::Information); - mb.setWindowTitle(title); - mb.setStandardButtons(QMessageBox::Ok); - if(msg.length() > MAX_MESSAGE_LENGTH) { - QString&& m = msg.left(MAX_MESSAGE_LENGTH); - m.append("..."); - mb.setText("The message has been truncated because too long, look at the details for the full message"); - mb.setInformativeText(m); - mb.setDetailedText(msg); - } else { - mb.setText(msg); - } - - mb.exec(); -} /** * This method permits to propagate and display messages from the messaging subsytem. @@ -1740,49 +1715,9 @@ void dbe::MainWindow::slot_information_message ( QString const title, QString co * even if they are bound to consted temporaries, once the deleter from the other thread is called. * */ -void dbe::MainWindow::slot_debuginfo_message ( QString const title, QString const msg ) -{ - QMessageBox mb(this); - mb.setIcon(QMessageBox::Icon::Information); - mb.setWindowTitle(title); - mb.setStandardButtons(QMessageBox::Ok); - if(msg.length() > MAX_MESSAGE_LENGTH) { - QString&& m = msg.left(MAX_MESSAGE_LENGTH); - m.append("..."); - mb.setText("The message has been truncated because too long, look at the details for the full message"); - mb.setInformativeText(m); - mb.setDetailedText(msg); - } else { - mb.setText(msg); - } - - mb.exec(); -} - -/** - * This method permits to propagate and display messages from the messaging subsytem. - * - * It is important that the arguments are pass-by-copy because references will become invalid, - * even if they are bound to consted temporaries, once the deleter from the other thread is called. - * - */ -void dbe::MainWindow::slot_notice_message ( QString const title, QString const msg ) +void dbe::MainWindow::slot_information_message ( QString const title, QString const msg ) { - QMessageBox mb(this); - mb.setIcon(QMessageBox::Icon::Information); - mb.setWindowTitle(title); - mb.setStandardButtons(QMessageBox::Ok); - if(msg.length() > MAX_MESSAGE_LENGTH) { - QString&& m = msg.left(MAX_MESSAGE_LENGTH); - m.append("..."); - mb.setText("The message has been truncated because too long, look at the details for the full message"); - mb.setInformativeText(m); - mb.setDetailedText(msg); - } else { - mb.setText(msg); - } - - mb.exec(); + display_message_box(title, msg, QMessageBox::Icon::Information); } /** @@ -1794,21 +1729,7 @@ void dbe::MainWindow::slot_notice_message ( QString const title, QString const m */ void dbe::MainWindow::slot_error_message ( QString const title, QString const msg ) { - QMessageBox mb(this); - mb.setIcon(QMessageBox::Icon::Critical); - mb.setWindowTitle(title); - mb.setStandardButtons(QMessageBox::Ok); - if(msg.length() > MAX_MESSAGE_LENGTH) { - QString&& m = msg.left(MAX_MESSAGE_LENGTH); - m.append("..."); - mb.setText("The message has been truncated because too long, look at the details for the full message"); - mb.setInformativeText(m); - mb.setDetailedText(msg); - } else { - mb.setText(msg); - } - - mb.exec(); + display_message_box(title, msg, QMessageBox::Icon::Critical); } /** @@ -1820,21 +1741,7 @@ void dbe::MainWindow::slot_error_message ( QString const title, QString const ms */ void dbe::MainWindow::slot_warning_message ( QString const title, QString const msg ) { - QMessageBox mb(this); - mb.setIcon(QMessageBox::Icon::Warning); - mb.setWindowTitle(title); - mb.setStandardButtons(QMessageBox::Ok); - if(msg.length() > MAX_MESSAGE_LENGTH) { - QString&& m = msg.left(MAX_MESSAGE_LENGTH); - m.append("..."); - mb.setText("The message has been truncated because too long, look at the details for the full message"); - mb.setInformativeText(m); - mb.setDetailedText(msg); - } else { - mb.setText(msg); - } - - mb.exec(); + display_message_box(title, msg, QMessageBox::Icon::Warning); } //----------------------------------------------------------------------------------------------------------------------------- diff --git a/src/internal/config_api.cpp b/src/internal/config_api.cpp index a754157..68a0bcc 100644 --- a/src/internal/config_api.cpp +++ b/src/internal/config_api.cpp @@ -27,14 +27,6 @@ namespace config namespace errors { -namespace -{ -inline std::string const trendl ( std::string s ) -{ - s.erase ( std::remove ( s.begin(), s.end(), '\n' ), s.end() ); - return s; -} -} /** * Unwind all causes linked to this exception @@ -51,7 +43,7 @@ std::string const unwind ( ers::Issue const & exception ) while ( cause != nullptr ) { - s << trendl ( cause->what() ) << "\n"; + s << cause->what() << "\n"; cause = cause->cause(); } From 5f67929277062ad00efc60d6855baa187b834e2d Mon Sep 17 00:00:00 2001 From: Gordon Crone Date: Fri, 30 Jan 2026 15:58:37 +0000 Subject: [PATCH 6/7] Add preferences dialog and set/save colours --- CMakeLists.txt | 3 + include/dbe/MainWindow.hpp | 7 ++- include/dbe/Preferences.hpp | 33 +++++++++++ include/dbe/StyleUtility.hpp | 6 +- src/internal/MainWindow.cpp | 100 +++++++++++++++++++--------------- src/internal/Preferences.cpp | 73 +++++++++++++++++++++++++ src/internal/StyleUtility.cpp | 58 ++++++++++++++++---- src/structure/table.cpp | 11 ++-- ui/DBE.ui | 13 ++++- ui/Preferences.ui | 74 +++++++++++++++++++++++++ 10 files changed, 313 insertions(+), 65 deletions(-) create mode 100644 include/dbe/Preferences.hpp create mode 100644 src/internal/Preferences.cpp create mode 100644 ui/Preferences.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index c236bf8..1771681 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,6 +161,7 @@ set(dbe_core_ui ui/RelationshipWidgetForm.ui ui/StringAttributeWidgetForm.ui ui/FileInfo.ui + ui/Preferences.ui ) qt5_wrap_ui(dbe_core_ui_header ${dbe_core_ui}) @@ -182,12 +183,14 @@ qt5_wrap_cpp(dbe_core_moc_src include/dbe/ObjectCreator.hpp include/dbe/ObjectEditor.hpp include/dbe/OracleWidget.hpp + include/dbe/Preferences.hpp ) set(dbe_core_src internal/MainWindow.cpp internal/StyleUtility.cpp internal/Validator.cpp + internal/Preferences.cpp object/CustomLineEdit.cpp object/string_attr_text_edit.cpp object/SearchComboBox.cpp diff --git a/include/dbe/MainWindow.hpp b/include/dbe/MainWindow.hpp index 5574bec..d109a20 100644 --- a/include/dbe/MainWindow.hpp +++ b/include/dbe/MainWindow.hpp @@ -4,6 +4,7 @@ /// Including QT Headers #include #include +#include #include #include #include @@ -97,7 +98,7 @@ class MainWindow: public: void build_file_model(); private: - void load_settings ( bool LoadSettings = false ); + void apply_settings (QSettings& setting); void WriteSettings(); void argsparse ( QMap const & ); @@ -110,6 +111,7 @@ class MainWindow: void update_total_objects(); void display_message_box(const QString& title, const QString& msg, const QMessageBox::Icon& icon); + void load_default_settings(); private slots: void slot_create_newdb(); void slot_open_database_from_file(); @@ -134,7 +136,7 @@ private slots: void slot_launch_batchchange(); void slot_launch_batchchange_on_table(); - void LoadDefaultSetting(); + void reload_default_settings(); void slot_filter_query(); void slot_filter_textchange ( const QString & ); @@ -162,6 +164,7 @@ private slots: void slot_loaded_db_file ( QString ); + void slot_launch_preferences(); public slots: void slot_batch_change_start(); void slot_batch_change_stop(const QList>&); diff --git a/include/dbe/Preferences.hpp b/include/dbe/Preferences.hpp new file mode 100644 index 0000000..5031fa3 --- /dev/null +++ b/include/dbe/Preferences.hpp @@ -0,0 +1,33 @@ +#ifndef DBE_PREFERENCES_H +#define DBE_PREFERENCES_H + +#include +#include +#include +#include + +//#include "ui_Preferences.h" + +namespace dbe +{ +namespace Ui +{ + class Preferences; +} // namespace Ui + + class Preferences : public QDialog { + Q_OBJECT + public: + explicit Preferences(QWidget* parent=0); + ~Preferences() = default; + // signals: + // void settings_updated(); + private slots: + void set_color(QListWidgetItem*); + + private: + Ui::Preferences* m_ui; + }; +} //namespace dbe + +#endif // DBE_PREFERENCES_H diff --git a/include/dbe/StyleUtility.hpp b/include/dbe/StyleUtility.hpp index 57c67d5..c0343ad 100644 --- a/include/dbe/StyleUtility.hpp +++ b/include/dbe/StyleUtility.hpp @@ -4,6 +4,7 @@ /// Including DBE #include #include +#include namespace dbe { @@ -15,8 +16,11 @@ class StyleUtility static void InitColorManagement(); static QColor TableColorAttribute; static QColor TableAttributeBackground; - static QColor TableAttributeHighlightBackground; + static QColor TableColorRelationship; + static QColor TableRelationshipBackground; + + static QColor DefaultValueBackground; static QColor FileReadOnlyForeground; static QColor FileReadOnlyBackground; diff --git a/src/internal/MainWindow.cpp b/src/internal/MainWindow.cpp index 266ed58..b41a8c6 100644 --- a/src/internal/MainWindow.cpp +++ b/src/internal/MainWindow.cpp @@ -16,6 +16,7 @@ #include "dbe/treenode.hpp" #include "dbe/version.hpp" #include "dbe/MyApplication.hpp" +#include "dbe/Preferences.hpp" #include "logging/Logging.hpp" @@ -69,7 +70,11 @@ dbe::MainWindow::MainWindow ( QMap const & cmdargs, QWidget * attach(); /// Reading Applications Settings/CommandLine - load_settings ( false ); + QCoreApplication::setOrganizationName("dunedaq"); + QCoreApplication::setApplicationName("dbe_main"); + load_default_settings(); // Start with defaults in case no user setting saved + QSettings settings; // Then try user settings + apply_settings(settings); argsparse ( cmdargs ); if (isArchivedConf == true) { @@ -165,10 +170,6 @@ void dbe::MainWindow::init() // Make Files the current tab InfoWidget->setCurrentIndex (0); - - - /// Color Management - StyleUtility::InitColorManagement(); } void dbe::MainWindow::attach() @@ -176,6 +177,7 @@ void dbe::MainWindow::attach() connect ( OpenDB, SIGNAL ( triggered() ), this, SLOT ( slot_open_database_from_file() ) ); connect ( Commit, SIGNAL ( triggered() ), this, SLOT ( slot_commit_database() ) ); connect ( Exit, SIGNAL ( triggered() ), this, SLOT ( close() ) ); + connect ( actionPreferences, SIGNAL ( triggered() ), this, SLOT ( slot_launch_preferences() ) ); connect ( UndoAction, SIGNAL ( triggered() ), UndoView->stack(), SLOT ( undo() ) ); connect ( RedoAction, SIGNAL ( triggered() ), UndoView->stack(), SLOT ( redo() ) ); connect ( UndoAll, SIGNAL ( triggered() ), this, SLOT ( slot_undo_allchanges() ) ); @@ -201,7 +203,7 @@ void dbe::MainWindow::attach() connect ( LoadDefaultSettings, SIGNAL ( triggered() ), this, - SLOT ( LoadDefaultSetting() ) ); + SLOT ( reload_default_settings() ) ); connect ( CreateDatabase, SIGNAL ( triggered() ), this, SLOT ( slot_create_newdb() ) ); //connect ( OpenOracleDB, SIGNAL ( triggered() ), this, SLOT ( slot_oracle_prepare() ) ); @@ -641,9 +643,17 @@ void dbe::MainWindow::slot_launch_batchchange_on_table() Batch->show(); } -void dbe::MainWindow::LoadDefaultSetting() +void dbe::MainWindow::reload_default_settings() +{ + QSettings settings; + settings.clear(); + load_default_settings(); +} +void dbe::MainWindow::load_default_settings() { - load_settings ( false ); + QSettings defaults(":theme/DBE_Default_User_Settings.conf", + QSettings::NativeFormat); + apply_settings(defaults); } QString dbe::MainWindow::find_db_repository_dir() @@ -818,50 +828,49 @@ void dbe::MainWindow::setinternals() FileView->setModel ( NULL ); } -void dbe::MainWindow::load_settings ( bool LoadSettings ) +void dbe::MainWindow::apply_settings (QSettings& settings) { - /// Load Settings means default settings - QSettings * Settings; - QString userPath = QDir::homePath() + "/.conffwk/ATLAS_TDAQ_DBE"; - QString userFile = "DBE_User_Settings.conf"; + settings.beginGroup ( "MainWindow-layout" ); + if (settings.contains("size")) { + resize ( settings.value ( "size" ).toSize() ); + } + if (settings.contains("pos")) { + move ( settings.value ( "pos" ).toPoint() ); + } + if (settings.contains("TableView")) { + DisplayTableView->setChecked ( settings.value ( "TableView" ).toBool() ); + } + if (settings.contains("ClassView")) { + DisplayClassView->setChecked ( settings.value ( "ClassView" ).toBool() ); + } + if (settings.contains("Messages")) { + DisplayMessages->setChecked ( settings.value ( "Messages" ).toBool() ); + } + if (settings.contains("geometry")) { + restoreGeometry ( settings.value ( "geometry" ).toByteArray() ); + } + if (settings.contains("state")) { + restoreState ( settings.value ( "state" ).toByteArray() ); + } + settings.endGroup(); - if ( !LoadSettings ) - { - if ( QDir ( userPath ).exists ( userFile ) ) - Settings = new QSettings ( "ATLAS_TDAQ_DBE", - "DBE_User_Settings" ); - else - Settings = new QSettings ( ":theme/DBE_Default_User_Settings.conf", - QSettings::NativeFormat ); + settings.beginGroup ( "MainWindow-checkboxes" ); + if (settings.contains("tree-case-sensitive")) { + CaseSensitiveCheckBoxTree->setChecked ( + settings.value ( "tree-case-sensitive" ).toBool() ); } - else - { - Settings = new QSettings ( ":theme/DBE_Default_User_Settings.conf", - QSettings::NativeFormat ); + if (settings.contains("table-case-sensitive")) { + CaseSensitiveCheckBoxTable->setChecked ( + settings.value ( "table-case-sensitive" ).toBool() ); } + settings.endGroup(); - Settings->beginGroup ( "MainWindow-layout" ); - resize ( Settings->value ( "size" ).toSize() ); - move ( Settings->value ( "pos" ).toPoint() ); - DisplayTableView->setChecked ( Settings->value ( "TableView" ).toBool() ); - DisplayClassView->setChecked ( Settings->value ( "ClassView" ).toBool() ); - - DisplayMessages->setChecked ( Settings->value ( "Messages" ).toBool() ); - restoreGeometry ( Settings->value ( "geometry" ).toByteArray() ); - restoreState ( Settings->value ( "state" ).toByteArray() ); - Settings->endGroup(); - - Settings->beginGroup ( "MainWindow-checkboxes" ); - CaseSensitiveCheckBoxTree->setChecked ( - Settings->value ( "tree-case-sensitive" ).toBool() ); - CaseSensitiveCheckBoxTable->setChecked ( - Settings->value ( "table-case-sensitive" ).toBool() ); - Settings->endGroup(); + StyleUtility::InitColorManagement(); } void dbe::MainWindow::WriteSettings() { - QSettings Settings ( "ATLAS_TDAQ_DBE", "DBE_User_Settings" ); + QSettings Settings("dunedaq", "dbe_main"); Settings.beginGroup ( "MainWindow-layout" ); Settings.setValue ( "size", size() ); Settings.setValue ( "pos", pos() ); @@ -1834,3 +1843,8 @@ void dbe::MainWindow::slot_loaded_db_file( QString file ) { allFiles.insert(file); } + +void dbe::MainWindow::slot_launch_preferences() { + auto prefs = new Preferences(); + prefs->show(); +} diff --git a/src/internal/Preferences.cpp b/src/internal/Preferences.cpp new file mode 100644 index 0000000..f5c80bc --- /dev/null +++ b/src/internal/Preferences.cpp @@ -0,0 +1,73 @@ +#include +#include +#include + +#include "dbe/Preferences.hpp" +#include "dbe/StyleUtility.hpp" + +#include "ui_Preferences.h" + +namespace dbe { + +Preferences::Preferences(QWidget* parent) + : QDialog(parent), m_ui(new Ui::Preferences) +{ + m_ui->setupUi(this); + setObjectName("Preferences"); + + QSettings settings; + auto item = new QListWidgetItem("Attribute Foreground"); + item->setToolTip("Foreground colour for attributes"); + item->setForeground(settings.value("attribute/foreground").value()); + m_ui->color_list->addItem(item); + + item = new QListWidgetItem("Attribute Background"); + item->setToolTip("Normal background colour for attributes"); + item->setForeground(settings.value("attribute/background").value()); + m_ui->color_list->addItem(item); + + item = new QListWidgetItem("Attribute Default-Background"); + item->setToolTip("Background colour for attributes set to their default value"); + item->setForeground(settings.value("attribute/default-background").value()); + m_ui->color_list->addItem(item); + + item = new QListWidgetItem("Relationship Foreground"); + item->setToolTip("Foreground colour for relationships"); + item->setForeground(settings.value("relationship/foreground").value()); + m_ui->color_list->addItem(item); + + item = new QListWidgetItem("Relationship Background"); + item->setToolTip("background colour for relationships"); + item->setForeground(settings.value("relationship/background").value()); + m_ui->color_list->addItem(item); + + item = new QListWidgetItem("Readonly Foreground"); + item->setToolTip("Foreground text colour for readonly items"); + item->setForeground(settings.value("readonly/foreground").value()); + m_ui->color_list->addItem(item); + + item = new QListWidgetItem("Readonly Background"); + item->setToolTip("Background text colour for readonly items"); + item->setForeground(settings.value("readonly/background").value()); + m_ui->color_list->addItem(item); + + connect (m_ui->color_list, SIGNAL(itemActivated(QListWidgetItem*)), + this, SLOT(set_color(QListWidgetItem*))); + +} + +void Preferences::set_color(QListWidgetItem* item) { + QSettings settings; + QStringList text = item->text().toLower().split(" "); + settings.beginGroup(text.at(0)); + + auto color = settings.value(text.at(1)).value(); + auto title = QString("Select color for ") + item->text(); + color = QColorDialog::getColor(color, nullptr, title); + + if (color.isValid()) { + settings.setValue(text.at(1), color); + StyleUtility::InitColorManagement(); + } +} +} // namespace dbe diff --git a/src/internal/StyleUtility.cpp b/src/internal/StyleUtility.cpp index 31e32ca..ccbf184 100644 --- a/src/internal/StyleUtility.cpp +++ b/src/internal/StyleUtility.cpp @@ -3,11 +3,15 @@ QColor dbe::StyleUtility::TableColorAttribute; QColor dbe::StyleUtility::TableAttributeBackground; -QColor dbe::StyleUtility::TableAttributeHighlightBackground; + QColor dbe::StyleUtility::FileReadOnlyForeground; QColor dbe::StyleUtility::FileReadOnlyBackground; QColor dbe::StyleUtility::TableColorRelationship; +QColor dbe::StyleUtility::TableRelationshipBackground; + +QColor dbe::StyleUtility::DefaultValueBackground; + QPalette dbe::StyleUtility::AlertStatusBarPallete; QPalette dbe::StyleUtility::AlertStatusBarPalleteWindow; QPalette dbe::StyleUtility::WarningStatusBarPallete; @@ -18,13 +22,46 @@ QPalette dbe::StyleUtility::LoadedDefault; void dbe::StyleUtility::InitColorManagement() { - TableColorAttribute = QColor ( "#1B676B" ); - TableAttributeBackground = QColor ( "#ffffff" ); - TableAttributeHighlightBackground = QColor ( "#f0f0ff" ); - TableColorRelationship = QColor ( "#AD4713" ); + QSettings settings; + + settings.beginGroup("attribute"); + if (!settings.contains("foreground")) { + settings.setValue("foreground", QColor ( "#1B676B" )); + } + if (!settings.contains("background")) { + settings.setValue("background", QColor ( "#ffffff" )); + } + if (!settings.contains("default-background")) { + settings.setValue("default-background", QColor ("#b8f4ff" )); + } - FileReadOnlyForeground = QColor ("#a00000"); - FileReadOnlyBackground = QColor ("#f0f0f0"); + DefaultValueBackground = settings.value("default-background").value(); + TableColorAttribute = settings.value("foreground").value(); + TableAttributeBackground = settings.value("background").value(); + settings.endGroup(); + + settings.beginGroup("relationship"); + if (!settings.contains("foreground")) { + settings.setValue("foreground", QColor ( "#AD4713" )); + } + if (!settings.contains("background")) { + settings.setValue("background", QColor ( Qt::white )); + } + TableColorRelationship = settings.value("foreground").value(); + TableRelationshipBackground = settings.value("background").value(); + settings.endGroup(); + + + settings.beginGroup("readonly"); + if (!settings.contains("background")) { + settings.setValue("background", QColor(Qt::lightGray)); + } + if (!settings.contains("foreground")) { + settings.setValue("foreground", QColor(Qt::darkRed)); + } + FileReadOnlyForeground = settings.value("foreground").value(); + FileReadOnlyBackground = settings.value("background").value(); + settings.endGroup(); AlertStatusBarPallete.setColor ( QPalette::Active, QPalette::Base, QColor ( "red" ) ); @@ -40,10 +77,9 @@ void dbe::StyleUtility::InitColorManagement() QColor ( "yellow" ) ); WarningStatusBarPalleteWindow.setColor ( QPalette::Inactive, QPalette::Window, QColor ( "yellow" ) ); - LoadedDefault.setColor ( QPalette::Active, QPalette::Base, QColor::fromRgb ( 184, 244, - 255 ) ); - LoadedDefault.setColor ( QPalette::Inactive, QPalette::Base, QColor::fromRgb ( 184, 244, - 255 ) ); + LoadedDefault.setColor ( QPalette::Active, QPalette::Base, DefaultValueBackground ); + LoadedDefault.setColor ( QPalette::Inactive, QPalette::Base, DefaultValueBackground ); + PaleGreenPalleteButton.setColor ( QPalette::Active, QPalette::Button, QColor::fromRgb ( 190, 238, 158 ) ); PaleGreenPalleteButton.setColor ( QPalette::Inactive, QPalette::Button, diff --git a/src/structure/table.cpp b/src/structure/table.cpp index 026f653..dae4e42 100644 --- a/src/structure/table.cpp +++ b/src/structure/table.cpp @@ -105,15 +105,16 @@ QVariant dbe::models::table::data ( const QModelIndex & index, int role ) const auto val = attr_node->GetData(); if (val.size() == 1 && val[0].toStdString() == attr_node->GetAttribute().p_default_value) { - return QBrush ( - StyleUtility::TableAttributeHighlightBackground ); + return QBrush (StyleUtility::DefaultValueBackground ); } + return QBrush (StyleUtility::TableAttributeBackground ); + } + else if ( dynamic_cast ( TableItem ) ) { + return QBrush ( + StyleUtility::TableRelationshipBackground ); } - return QBrush ( - StyleUtility::TableAttributeBackground ); } } - return QVariant(); } diff --git a/ui/DBE.ui b/ui/DBE.ui index d70d36b..055d7f9 100644 --- a/ui/DBE.ui +++ b/ui/DBE.ui @@ -6,7 +6,7 @@ 0 0 - 909 + 1249 848 @@ -112,7 +112,7 @@ 0 0 - 909 + 1249 23 @@ -133,6 +133,8 @@ + + @@ -600,7 +602,7 @@ Sensitive true - Messages + Info Tabs @@ -708,6 +710,11 @@ Sensitive About + + + Preferences + + diff --git a/ui/Preferences.ui b/ui/Preferences.ui new file mode 100644 index 0000000..6a69408 --- /dev/null +++ b/ui/Preferences.ui @@ -0,0 +1,74 @@ + + + dbe::Preferences + + + + 0 + 0 + 400 + 300 + + + + DBE Settings + + + + + + Colour settings + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + dbe::Preferences + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + dbe::Preferences + reject() + + + 316 + 260 + + + 286 + 274 + + + + + From 3e7791b90868c51b73831a948e15c95b913f1805 Mon Sep 17 00:00:00 2001 From: Gordon Crone Date: Fri, 30 Jan 2026 17:19:13 +0000 Subject: [PATCH 7/7] Set colours of readonly objects in both tree and table --- include/dbe/StyleUtility.hpp | 3 +++ src/internal/StyleUtility.cpp | 14 ++++++++++++++ src/structure/table.cpp | 13 +++++++++++++ src/structure/tree.cpp | 30 ++++++++++++++++++++++++++++-- 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/include/dbe/StyleUtility.hpp b/include/dbe/StyleUtility.hpp index c0343ad..39e12d3 100644 --- a/include/dbe/StyleUtility.hpp +++ b/include/dbe/StyleUtility.hpp @@ -25,6 +25,9 @@ class StyleUtility static QColor FileReadOnlyForeground; static QColor FileReadOnlyBackground; + static QColor ObjectForeground; + static QColor ObjectBackground; + static QPalette AlertStatusBarPallete; static QPalette AlertStatusBarPalleteWindow; static QPalette WarningStatusBarPallete; diff --git a/src/internal/StyleUtility.cpp b/src/internal/StyleUtility.cpp index ccbf184..d232bd1 100644 --- a/src/internal/StyleUtility.cpp +++ b/src/internal/StyleUtility.cpp @@ -10,6 +10,9 @@ QColor dbe::StyleUtility::FileReadOnlyBackground; QColor dbe::StyleUtility::TableColorRelationship; QColor dbe::StyleUtility::TableRelationshipBackground; +QColor dbe::StyleUtility::ObjectForeground; +QColor dbe::StyleUtility::ObjectBackground; + QColor dbe::StyleUtility::DefaultValueBackground; QPalette dbe::StyleUtility::AlertStatusBarPallete; @@ -63,6 +66,17 @@ void dbe::StyleUtility::InitColorManagement() FileReadOnlyBackground = settings.value("background").value(); settings.endGroup(); + settings.beginGroup("object"); + if (!settings.contains("foreground")) { + settings.setValue("foreground", QColor(Qt::blue)); + } + if (!settings.contains("background")) { + settings.setValue("background", QColor(Qt::white)); + } + ObjectForeground = settings.value("foreground").value(); + ObjectBackground = settings.value("background").value(); + settings.endGroup(); + AlertStatusBarPallete.setColor ( QPalette::Active, QPalette::Base, QColor ( "red" ) ); AlertStatusBarPallete.setColor ( QPalette::Inactive, QPalette::Base, QColor ( "red" ) ); diff --git a/src/structure/table.cpp b/src/structure/table.cpp index dae4e42..ea0c5e9 100644 --- a/src/structure/table.cpp +++ b/src/structure/table.cpp @@ -94,6 +94,11 @@ QVariant dbe::models::table::data ( const QModelIndex & index, int role ) const StyleUtility::TableColorRelationship ); else { + dref obj_desc = this_objects[index.row()]; + tref Object = dbe::inner::dbcontroller::get ( { obj_desc.UID(), obj_desc.class_name() } ); + if ( !confaccessor::check_file_rw ( QString::fromStdString ( Object.contained_in() ) ) ) { + return QBrush ( StyleUtility::FileReadOnlyForeground ); + } return QVariant(); } } @@ -113,6 +118,14 @@ QVariant dbe::models::table::data ( const QModelIndex & index, int role ) const return QBrush ( StyleUtility::TableRelationshipBackground ); } + else + { + dref obj_desc = this_objects[index.row()]; + tref Object = dbe::inner::dbcontroller::get ( { obj_desc.UID(), obj_desc.class_name() } ); + if ( !confaccessor::check_file_rw ( QString::fromStdString ( Object.contained_in() ) ) ) { + return QBrush ( StyleUtility::FileReadOnlyBackground ); + } + } } } return QVariant(); diff --git a/src/structure/tree.cpp b/src/structure/tree.cpp index f13ce0c..05b3817 100644 --- a/src/structure/tree.cpp +++ b/src/structure/tree.cpp @@ -1,3 +1,4 @@ +#include "dbe/StyleUtility.hpp" #include "dbe/config_api.hpp" #include "dbe/confaccessor.hpp" #include "dbe/config_reference.hpp" @@ -128,11 +129,36 @@ QVariant dbe::models::tree::data ( type_index const & index, int role ) const if ( confaccessor::check_file_rw ( QString::fromStdString ( obj.contained_in() ) ) ) { - return QVariant ( QColor ( Qt::blue ) ); + return QVariant ( StyleUtility::ObjectForeground ); } else { - return QVariant ( QColor ( Qt::darkGray ) ); + return QVariant ( StyleUtility::FileReadOnlyForeground ); + } + } + catch ( daq::dbe::config_object_retrieval_result_is_null const & e ) + { + // nothing to do the onode refers to a removed object and has not yet been removed + return QVariant(); + } + } + + break; + + case Qt::BackgroundRole: + if ( ObjectNode * onode = dynamic_cast ( getnode ( index ) ) ) + { + try + { + tref const & obj = onode->GetObject(); + + if ( confaccessor::check_file_rw ( QString::fromStdString ( obj.contained_in() ) ) ) + { + return QVariant ( StyleUtility::ObjectBackground ); + } + else + { + return QVariant ( StyleUtility::FileReadOnlyBackground ); } } catch ( daq::dbe::config_object_retrieval_result_is_null const & e )