X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_ParamSpinBox.cpp;h=40b50fb1757ff1dca0a7f0dbbe0a3b3f88689685;hb=752c9e02e6aa8ced24e9b53097cb42540d5e6a08;hp=2b35449170618048bb43d1c9db729e0a3f8c275a;hpb=52357bda85e0997b9fc446f312c8eb58f8e60a65;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp index 2b3544917..40b50fb17 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp @@ -11,23 +11,12 @@ #include #include #include +#include #include #include -/*! - \class ModuleBase_ParamSpinBox - */ - -/*! - \brief Constructor. - - Constructs a spin box with 0.0 as minimum value and 99.99 as maximum value, - a step value of 1.0 and a precision of 2 decimal places. - The value is initially set to 0.00. - \param parent parent object - */ ModuleBase_ParamSpinBox::ModuleBase_ParamSpinBox(QWidget* theParent, int thePrecision) : ModuleBase_DoubleSpinBox(theParent, thePrecision), myAcceptVariables(true) @@ -68,26 +57,17 @@ void ModuleBase_ParamSpinBox::connectSignalsAndSlots() this, SLOT(onTextChanged(const QString&))); } -/*! - \brief This function is called when value is changed. - */ void ModuleBase_ParamSpinBox::onTextChanged(const QString& text) { myTextValue = text; } -/*! - \brief Interpret text entered by the user as a value. - \param text text entered by the user - \return mapped value - \sa textFromValue() - */ 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 initiate valuesChanged signal + + // small hack: return hash of the string to initiate valuesChanged signal return qHash(theText); } @@ -121,9 +101,14 @@ QValidator::State ModuleBase_ParamSpinBox::validate(QString& str, int& pos) cons /*! \brief This function is used to set a current value for this spinbox. \param value current value + + The new value is ignored if the spinbox has a variable. */ void ModuleBase_ParamSpinBox::setValue(const double value) { + if (hasVariable()) + return; + myTextValue = ModuleBase_DoubleSpinBox::textFromValue(value); ModuleBase_DoubleSpinBox::setValue(value); } @@ -177,10 +162,19 @@ bool ModuleBase_ParamSpinBox::hasVariable(const QString& theText) const // QRegExp varNameMask(aDigitPattern.arg(",")); // aHasDigit = varNameMask.exactMatch(theText); //} - bool aHasDigit = false; - theText.toDouble(&aHasDigit); - return !aHasDigit; - + 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; } /*! @@ -225,7 +219,7 @@ bool ModuleBase_ParamSpinBox::findVariable(const QString& theName, } /*! - \brief This function is called when the spinbox recieves key press event. + \brief This function is called when the spinbox receives key press event. */ //void ModuleBase_ParamSpinBox::keyPressEvent(QKeyEvent* e) //{ @@ -237,7 +231,7 @@ bool ModuleBase_ParamSpinBox::findVariable(const QString& theName, //} /*! - \brief This function is called when the spinbox recieves show event. + \brief This function is called when the spinbox receives show event. */ void ModuleBase_ParamSpinBox::showEvent(QShowEvent* theEvent) {