X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_ParamSpinBox.cpp;h=febd29badbf419cdbf187edbbcf8533742bf04e6;hb=ec6769ca1253d91c847027b5d36c800d9b5ed793;hp=4569e2b8fe351e47b8e1ece1465cceefe6d62e4e;hpb=17715b8aeca077903884e929d495c81370e655dc;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp index 4569e2b8f..febd29bad 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -53,7 +54,7 @@ ModuleBase_ParamSpinBox::~ModuleBase_ParamSpinBox() */ void ModuleBase_ParamSpinBox::stepBy(int steps) { - if (hasVariable()) + if ((!myTextValue.isEmpty()) && hasVariable()) return; ModuleBase_DoubleSpinBox::stepBy(steps); @@ -84,16 +85,16 @@ void ModuleBase_ParamSpinBox::onTextChanged(const QString& text) */ double ModuleBase_ParamSpinBox::valueFromText(const QString& theText) const { - if (!hasVariable(theText)) { + if (!hasVariable(theText)) return ModuleBase_DoubleSpinBox::valueFromText(theText); - } - // small hack: return length of the string to iniiate valuesChanged signal - return theText.length(); + + // small hack: return length of the string to initiate valuesChanged signal + return qHash(theText); } QString ModuleBase_ParamSpinBox::textFromValue (double theValue) const { - if (hasVariable(myTextValue)){ + if ((!myTextValue.isEmpty()) && hasVariable(myTextValue)){ return myTextValue; } return ModuleBase_DoubleSpinBox::textFromValue(theValue); @@ -124,9 +125,8 @@ QValidator::State ModuleBase_ParamSpinBox::validate(QString& str, int& pos) cons */ void ModuleBase_ParamSpinBox::setValue(const double value) { - ModuleBase_DoubleSpinBox::setValue(value); - myTextValue = ModuleBase_DoubleSpinBox::textFromValue(value); + ModuleBase_DoubleSpinBox::setValue(value); } /*! @@ -135,6 +135,7 @@ void ModuleBase_ParamSpinBox::setValue(const double value) */ void ModuleBase_ParamSpinBox::setText(const QString& value) { + myTextValue = value; lineEdit()->setText(value); } @@ -165,21 +166,31 @@ bool ModuleBase_ParamSpinBox::hasVariable() const bool ModuleBase_ParamSpinBox::hasVariable(const QString& theText) const { - QString aDigitPattern = QString("[-+]?[0-9]*[%1]?[0-9]+([eE][-+]?[0-9]+)?"); - - bool aHasDigit = false; - { - QRegExp varNameMask(aDigitPattern.arg(".")); - aHasDigit = varNameMask.exactMatch(theText); - } - if (!aHasDigit) - { - QRegExp varNameMask(aDigitPattern.arg(",")); - aHasDigit = varNameMask.exactMatch(theText); - } - - return !aHasDigit; - + //const QString aDigitPattern = QString("[-+]?[0-9]*[%1]?[0-9]*([eE][-+]?[0-9]+)?"); + + //bool aHasDigit = false; + //{ + // QRegExp varNameMask(aDigitPattern.arg(".")); + // aHasDigit = varNameMask.exactMatch(theText); + //} + //if (!aHasDigit) + //{ + // QRegExp varNameMask(aDigitPattern.arg(",")); + // aHasDigit = varNameMask.exactMatch(theText); + //} + bool isDouble = false; + QLocale::c().toDouble(theText, &isDouble); + +// theText.toDouble(&isDouble); +// if (isDouble) { +// QLocale aLoc; // create default locale +// QChar aDecPnt = aLoc.decimalPoint(); +// if (aDecPnt == '.') +// isDouble = theText.contains(aDecPnt) || (!theText.contains(',')); +// else if (aDecPnt == ',') +// isDouble = theText.contains(aDecPnt) || (!theText.contains('.')); +// } + return !isDouble; } /*! @@ -241,7 +252,7 @@ bool ModuleBase_ParamSpinBox::findVariable(const QString& theName, void ModuleBase_ParamSpinBox::showEvent(QShowEvent* theEvent) { ModuleBase_DoubleSpinBox::showEvent(theEvent); - if (hasVariable(myTextValue)) { + if ((!myTextValue.isEmpty()) && hasVariable(myTextValue)) { setText(myTextValue); } }