Skip to content

Commit

Permalink
Fix the handling of inherited fixed value (#10788)
Browse files Browse the repository at this point in the history
Fixes #10139
Do not update the inherited default values
  • Loading branch information
adeas31 committed Jun 2, 2023
1 parent 25214f3 commit 7d7290c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
16 changes: 8 additions & 8 deletions OMEdit/OMEditLIB/Element/ElementProperties.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -488,17 +488,17 @@ 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 {
mpFixedCheckBox->setTickState(defaultValue, false);
}
}

QString Parameter::getFixedState()
QString Parameter::getFixedState() const
{
return mpFixedCheckBox->tickStateString();
return mpFixedCheckBox->getTickStateString();
}

/*!
Expand Down Expand Up @@ -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);
Expand All @@ -984,7 +984,7 @@ void Parameter::falseFixedClicked()

void Parameter::inheritedFixedClicked()
{
mpFixedCheckBox->setTickState(true, true);
mpFixedCheckBox->setTickState(true, mpFixedCheckBox->getInheritedValue());
}

/*!
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Element/ElementProperties.h
Expand Up @@ -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:
Expand Down
17 changes: 11 additions & 6 deletions OMEdit/OMEditLIB/Util/Utilities.cpp
Expand Up @@ -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";
Expand All @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions OMEdit/OMEditLIB/Util/Utilities.h
Expand Up @@ -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;
};
Expand Down

0 comments on commit 7d7290c

Please sign in to comment.