Salome HOME
Issue #653 - Double and triple click edges -- Fix Debian dynamic_pointer_cast problem...
[modules/shaper.git] / src / ModuleBase / ModuleBase_ParamSpinBox.cpp
index 5b88af890e58418d2afeb1658165f071d781170f..8b09ac9fece6ec394cf21314cd0a580084d3e274 100644 (file)
@@ -8,8 +8,9 @@
 
 #include <QKeyEvent>
 #include <QLineEdit>
-#include <QToolTip>
+#include <QLocale>
 #include <QRegExp>
+#include <QToolTip>
 
 #include <string>
 #include <iostream>
@@ -52,7 +53,7 @@ ModuleBase_ParamSpinBox::~ModuleBase_ParamSpinBox()
  */
 void ModuleBase_ParamSpinBox::stepBy(int steps)
 {
-  if (hasVariable())
+  if ((!myTextValue.isEmpty()) && hasVariable())
     return;
 
   ModuleBase_DoubleSpinBox::stepBy(steps);
@@ -72,6 +73,7 @@ void ModuleBase_ParamSpinBox::connectSignalsAndSlots()
  */
 void ModuleBase_ParamSpinBox::onTextChanged(const QString& text)
 {
+  ModuleBase_DoubleSpinBox::onTextChanged(text);
   myTextValue = text;
 }
 
@@ -92,7 +94,7 @@ double ModuleBase_ParamSpinBox::valueFromText(const QString& theText) const
 
 QString ModuleBase_ParamSpinBox::textFromValue (double theValue) const
 {
-  if (hasVariable(myTextValue)){
+  if ((!myTextValue.isEmpty()) && hasVariable(myTextValue)){
     return myTextValue;
   }
   return ModuleBase_DoubleSpinBox::textFromValue(theValue);
@@ -123,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);
 }
 
 /*!
@@ -134,6 +135,7 @@ void ModuleBase_ParamSpinBox::setValue(const double value)
  */
 void ModuleBase_ParamSpinBox::setText(const QString& value)
 {
+  myTextValue = value;
   lineEdit()->setText(value);
 }
 
@@ -164,8 +166,22 @@ 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 aHasDigit = false;
+  theText.toDouble(&aHasDigit);
+  return !aHasDigit;
+
 }
 
 /*!
@@ -212,14 +228,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 +243,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);
   }
 }