From 7d7290c94ce47c8e523a12b32d7573555233a07e Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Fri, 2 Jun 2023 15:46:26 +0200 Subject: [PATCH] Fix the handling of inherited fixed value (#10788) Fixes #10139 Do not update the inherited default values --- OMEdit/OMEditLIB/Element/ElementProperties.cpp | 16 ++++++++-------- OMEdit/OMEditLIB/Element/ElementProperties.h | 2 +- OMEdit/OMEditLIB/Util/Utilities.cpp | 17 +++++++++++------ OMEdit/OMEditLIB/Util/Utilities.h | 10 ++++++---- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/OMEdit/OMEditLIB/Element/ElementProperties.cpp b/OMEdit/OMEditLIB/Element/ElementProperties.cpp index 2ce8b53be7a..16d933c17ce 100644 --- a/OMEdit/OMEditLIB/Element/ElementProperties.cpp +++ b/OMEdit/OMEditLIB/Element/ElementProperties.cpp @@ -73,7 +73,7 @@ Parameter::Parameter(Element *pElement, bool showStartAttribute, QString tab, QS mpNameLabel = new Label; mpFixedCheckBox = new FixedCheckBox; connect(mpFixedCheckBox, SIGNAL(clicked()), SLOT(showFixedMenu())); - setFixedState("false", true); + setFixedState("", true); // set the value type based on element type. OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy(); if (mpElement->getElementInfo()->getClassName().compare("Boolean") == 0) { @@ -488,7 +488,7 @@ QString Parameter::getValue() void Parameter::setFixedState(QString fixed, bool defaultValue) { - mOriginalFixedValue = fixed; + mOriginalFixedValue = defaultValue ? "" : fixed; if (fixed.compare(QStringLiteral("true")) == 0) { mpFixedCheckBox->setTickState(defaultValue, true); } else { @@ -496,9 +496,9 @@ void Parameter::setFixedState(QString fixed, bool defaultValue) } } -QString Parameter::getFixedState() +QString Parameter::getFixedState() const { - return mpFixedCheckBox->tickStateString(); + return mpFixedCheckBox->getTickStateString(); } /*! @@ -955,15 +955,15 @@ void Parameter::showFixedMenu() connect(pFalseAction, SIGNAL(triggered()), SLOT(falseFixedClicked())); menu.addAction(pFalseAction); // inherited case action - QString inheritedText = tr("inherited: (%1)").arg(mpFixedCheckBox->tickState() ? trueText : falseText); + QString inheritedText = tr("inherited: (%1)").arg(mpFixedCheckBox->getInheritedValue() ? trueText : falseText); QAction *pInheritedAction = new QAction(inheritedText, pFixedActionGroup); pInheritedAction->setCheckable(true); connect(pInheritedAction, SIGNAL(triggered()), SLOT(inheritedFixedClicked())); menu.addAction(pInheritedAction); // set the menu actions states - if (mpFixedCheckBox->tickStateString().compare("true") == 0) { + if (mpFixedCheckBox->getTickStateString().compare("true") == 0) { pTrueAction->setChecked(true); - } else if (mpFixedCheckBox->tickStateString().compare("false") == 0) { + } else if (mpFixedCheckBox->getTickStateString().compare("false") == 0) { pFalseAction->setChecked(true); } else { pInheritedAction->setChecked(true); @@ -984,7 +984,7 @@ void Parameter::falseFixedClicked() void Parameter::inheritedFixedClicked() { - mpFixedCheckBox->setTickState(true, true); + mpFixedCheckBox->setTickState(true, mpFixedCheckBox->getInheritedValue()); } /*! diff --git a/OMEdit/OMEditLIB/Element/ElementProperties.h b/OMEdit/OMEditLIB/Element/ElementProperties.h index 71930525c05..d1e47eb2d7c 100644 --- a/OMEdit/OMEditLIB/Element/ElementProperties.h +++ b/OMEdit/OMEditLIB/Element/ElementProperties.h @@ -97,7 +97,7 @@ class Parameter : public QObject QComboBox* getUnitComboBox() {return mpUnitComboBox;} Label* getCommentLabel() {return mpCommentLabel;} void setFixedState(QString fixed, bool defaultValue); - QString getFixedState(); + QString getFixedState() const; void setEnabled(bool enable); void update(); private: diff --git a/OMEdit/OMEditLIB/Util/Utilities.cpp b/OMEdit/OMEditLIB/Util/Utilities.cpp index 111709b64e1..ae3c93d3f08 100644 --- a/OMEdit/OMEditLIB/Util/Utilities.cpp +++ b/OMEdit/OMEditLIB/Util/Utilities.cpp @@ -309,20 +309,25 @@ FixedCheckBox::FixedCheckBox(QWidget *parent) { setCheckable(false); mDefaultValue = false; - mTickState = false; + mInheritedValue = false; + mFixedState = false; } -void FixedCheckBox::setTickState(bool defaultValue, bool tickState) +void FixedCheckBox::setTickState(bool defaultValue, bool fixedState) { mDefaultValue = defaultValue; - mTickState = tickState; + if (mDefaultValue) { + mInheritedValue = fixedState; + } else { + mFixedState = fixedState; + } } -QString FixedCheckBox::tickStateString() +QString FixedCheckBox::getTickStateString() const { if (mDefaultValue) { return ""; - } else if (mTickState) { + } else if (mFixedState) { return "true"; } else { return "false"; @@ -346,7 +351,7 @@ void FixedCheckBox::paintEvent(QPaintEvent *event) } p.drawRect(opt.rect.adjusted(0, 0, -1, -1)); // if is checked then draw a tick - if (mTickState) { + if ((!mDefaultValue && mFixedState) || (mDefaultValue && mInheritedValue)) { p.setRenderHint(QPainter::Antialiasing); QPen pen = p.pen(); pen.setWidthF(1.5); diff --git a/OMEdit/OMEditLIB/Util/Utilities.h b/OMEdit/OMEditLIB/Util/Utilities.h index dced65330ba..eadc007cfaf 100644 --- a/OMEdit/OMEditLIB/Util/Utilities.h +++ b/OMEdit/OMEditLIB/Util/Utilities.h @@ -218,12 +218,14 @@ class FixedCheckBox : public QCheckBox Q_OBJECT private: bool mDefaultValue; - bool mTickState; + bool mInheritedValue; + bool mFixedState; public: FixedCheckBox(QWidget *parent = 0); - void setTickState(bool defaultValue, bool tickStateString); - bool tickState() {return mTickState;} - QString tickStateString(); + void setTickState(bool defaultValue, bool fixedState); + bool isDefaultValue() {return mDefaultValue;} + bool getInheritedValue() const {return mInheritedValue;} + QString getTickStateString() const; protected: virtual void paintEvent(QPaintEvent *event) override; };