diff --git a/OMEdit/OMEditLIB/Element/ElementProperties.cpp b/OMEdit/OMEditLIB/Element/ElementProperties.cpp index adb9281a005..5591de532e9 100644 --- a/OMEdit/OMEditLIB/Element/ElementProperties.cpp +++ b/OMEdit/OMEditLIB/Element/ElementProperties.cpp @@ -772,7 +772,7 @@ void Parameter::createValueWidget() case Parameter::Normal: default: mpValueTextBox = new QLineEdit; - connect(mpValueTextBox, SIGNAL(textEdited(QString)), SLOT(valueTextBoxEdited(QString))); + mpValueTextBox->installEventFilter(this); break; } } @@ -1049,16 +1049,6 @@ void Parameter::valueCheckBoxChanged(bool toggle) updateValueBinding(FlatModelica::Expression(toggle)); } -/*! - * \brief Parameter::valueTextBoxEdited - * This slot is only called when user manually edits the text.\n - * \param text - */ -void Parameter::valueTextBoxEdited(const QString &text) -{ - enableDisableUnitComboBox(text); -} - void Parameter::showFixedMenu() { // create a menu @@ -1115,6 +1105,22 @@ void Parameter::inheritedFixedClicked() mpFixedCheckBox->setTickState(true, mpFixedCheckBox->getInheritedValue()); } +/*! + * \brief Parameter::eventFilter + * Handles the FocusOut event of value textbox. + * \param pWatched + * \param pEvent + * \return + */ +bool Parameter::eventFilter(QObject *pWatched, QEvent *pEvent) +{ + if (mpValueTextBox == pWatched && pEvent->type() == QEvent::FocusOut) { + enableDisableUnitComboBox(mpValueTextBox->text()); + } + + return QObject::eventFilter(pWatched, pEvent); +} + /*! \class GroupBox \brief Creates a group for parameters. diff --git a/OMEdit/OMEditLIB/Element/ElementProperties.h b/OMEdit/OMEditLIB/Element/ElementProperties.h index 2559b4676d7..52e95db2b88 100644 --- a/OMEdit/OMEditLIB/Element/ElementProperties.h +++ b/OMEdit/OMEditLIB/Element/ElementProperties.h @@ -178,11 +178,13 @@ public slots: void unitComboBoxChanged(int index); void valueComboBoxChanged(int index); void valueCheckBoxChanged(bool toggle); - void valueTextBoxEdited(const QString &text); void showFixedMenu(); void trueFixedClicked(); void falseFixedClicked(); void inheritedFixedClicked(); + // QObject interface +public: + virtual bool eventFilter(QObject *pWatched, QEvent *pEvent) override; }; class GroupBox : public QGroupBox diff --git a/OMEdit/OMEditLIB/Util/Utilities.cpp b/OMEdit/OMEditLIB/Util/Utilities.cpp index 315ce53e6cd..2ed89f56d30 100644 --- a/OMEdit/OMEditLIB/Util/Utilities.cpp +++ b/OMEdit/OMEditLIB/Util/Utilities.cpp @@ -640,23 +640,11 @@ qreal Utilities::convertUnit(qreal value, qreal offset, qreal scaleFactor) bool Utilities::isValueLiteralConstant(QString value) { /* Issue #11795. Allow setting negative values for parameters. - * In future we should use proper regular expressions for this. Maybe when we switch to Qt 6. + * Issue #11840. Allow setting array of values. + * The following regular expression allows decimal values and array of decimal values. The values can be negative. */ - if (value.compare(QStringLiteral("-")) == 0) { - return true; - } - - bool ok = true; - value.toDouble(&ok); - if (ok) { - return true; - } - - QStringList valuesArray = StringHandler::removeFirstLastCurlBrackets(value).split(","); - foreach (QString valueElement, valuesArray) { - valueElement.toDouble(&ok); - } - return ok; + QRegExp rx("\\{?\\s*-?\\d+(\\.\\d+)?(?:\\s*,\\s*-?\\d+(\\.\\d+)?)*\\s*\\}?"); + return rx.exactMatch(value); } /*!