Salome HOME
Simplification of the code: it removes focusNextPrevChild processing.
[modules/shaper.git] / src / ModuleBase / ModuleBase_DoubleSpinBox.cpp
index e436875bf5da34f40345db76ed51fc80857548c2..081ca65b3fb12dad6800a131d18cda5e0c95a9c1 100644 (file)
@@ -8,6 +8,7 @@
 #include <QLineEdit>
 #include <QDoubleValidator>
 #include <QVariant>
+#include <QKeyEvent>
 
 #include <limits>
 
@@ -58,7 +59,8 @@ const double PSEUDO_ZERO = 1.e-20;
 ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePrecision)
     : QDoubleSpinBox(theParent),
       myCleared(false),
-      myIsModified(false)
+      myIsModified(false),
+      myIsEmitKeyPressEvent(false)
 {
   // VSR 01/07/2010: Disable thousands separator for spin box
   // (to avoid inconsistency of double-2-string and string-2-double conversion)
@@ -78,7 +80,6 @@ ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePr
           SLOT(onTextChanged( const QString& )));
 
   connect(this, SIGNAL(valueChanged(const QString&)), this, SLOT(onValueChanged(const QString&)));
-  connect(this, SIGNAL(editingFinished()), this, SLOT(onEditingFinished()));
 }
 
 /*!
@@ -200,29 +201,20 @@ QString ModuleBase_DoubleSpinBox::removeTrailingZeroes(const QString& src) const
   return res;
 }
 
-#include <QKeyEvent>
 void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent *theEvent)
 {
-  myProcessedEvent = 0;
-
-  bool anIsModified = myIsModified;
-  QDoubleSpinBox::keyPressEvent(theEvent);
-
   switch (theEvent->key()) {
     case Qt::Key_Enter:
     case Qt::Key_Return: {
-      if (anIsModified)
-        myProcessedEvent = theEvent;
-      /*qDebug("ModuleBase_DoubleSpinBox::keyPressEvent");
-      if (anIsModified) // we should not perform this event outside
-        theEvent->setAccepted(true);
-      else
-        theEvent->setAccepted(false);*/
+      // do not react to the Enter key, the property panel processes it
+      if (!myIsEmitKeyPressEvent)
+        return;
     }
     break;
     default:
       break;
   }
+  QDoubleSpinBox::keyPressEvent(theEvent);
 }
 
 /*!
@@ -343,12 +335,20 @@ void ModuleBase_DoubleSpinBox::onValueChanged(const QString& theValue)
   myIsModified = true;
 }
 
-void ModuleBase_DoubleSpinBox::onEditingFinished()
+bool ModuleBase_DoubleSpinBox::isModified() const
+{
+  return myIsModified;
+}
+
+void ModuleBase_DoubleSpinBox::clearModified()
 {
   myIsModified = false;
 }
 
-bool ModuleBase_DoubleSpinBox::isEventProcessed(QKeyEvent* theEvent)
+bool ModuleBase_DoubleSpinBox::enableKeyPressEvent(const bool& theEnable)
 {
-  return myProcessedEvent && myProcessedEvent == theEvent;
+  bool aPreviousValue = myIsEmitKeyPressEvent;
+  myIsEmitKeyPressEvent = theEnable;
+
+  return aPreviousValue;
 }