X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_ParamSpinBox.cpp;h=bfd0823866a868242e6e83567dd7933792166e2d;hb=40f3b736db0100d3793d72f22aecf23fb21cbe1b;hp=bcd0d28e1a149c4a01a0789c0858d7487bb1c384;hpb=8162d26a6ab18c8ba3e21ab1a50db6c75d587b81;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp index bcd0d28e1..bfd082386 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp @@ -8,25 +8,15 @@ #include #include -#include +#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) @@ -52,7 +42,7 @@ ModuleBase_ParamSpinBox::~ModuleBase_ParamSpinBox() */ void ModuleBase_ParamSpinBox::stepBy(int steps) { - if (hasVariable()) + if ((!myTextValue.isEmpty()) && hasVariable()) return; ModuleBase_DoubleSpinBox::stepBy(steps); @@ -67,32 +57,23 @@ 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 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); @@ -123,9 +104,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); } /*! @@ -134,6 +114,7 @@ void ModuleBase_ParamSpinBox::setValue(const double value) */ void ModuleBase_ParamSpinBox::setText(const QString& value) { + myTextValue = value; lineEdit()->setText(value); } @@ -164,8 +145,31 @@ bool ModuleBase_ParamSpinBox::hasVariable() const bool ModuleBase_ParamSpinBox::hasVariable(const QString& theText) const { - QRegExp varNameMask("[-+]?[0-9]*[.]?[0-9]+([eE][-+]?[0-9]+)?"); - return !varNameMask.exactMatch(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); + //} + 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; } /*! @@ -212,14 +216,14 @@ bool ModuleBase_ParamSpinBox::findVariable(const QString& theName, /*! \brief This function is called when the spinbox recieves key press event. */ -void ModuleBase_ParamSpinBox::keyPressEvent(QKeyEvent* e) -{ - if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { - QWidget::keyPressEvent(e); - } else { - ModuleBase_DoubleSpinBox::keyPressEvent(e); - } -} +//void ModuleBase_ParamSpinBox::keyPressEvent(QKeyEvent* e) +//{ +// if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { +// QWidget::keyPressEvent(e); +// } else { +// ModuleBase_DoubleSpinBox::keyPressEvent(e); +// } +//} /*! \brief This function is called when the spinbox recieves show event. @@ -227,7 +231,7 @@ void ModuleBase_ParamSpinBox::keyPressEvent(QKeyEvent* e) void ModuleBase_ParamSpinBox::showEvent(QShowEvent* theEvent) { ModuleBase_DoubleSpinBox::showEvent(theEvent); - if (hasVariable(myTextValue)) { + if ((!myTextValue.isEmpty()) && hasVariable(myTextValue)) { setText(myTextValue); } }