Salome HOME
Within Issue #143 highlight active inputs
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetDoubleValue.cpp
index 97782bf745f66a89bcdf735736456c33948d1c9f..d6d6d65664c8ab14edb97d487d63a621780fdf68 100644 (file)
@@ -3,6 +3,8 @@
 // Author:      Vitaly Smetannikov
 
 #include <ModuleBase_WidgetDoubleValue.h>
+#include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_Tools.h>
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
 #include <QWidget>
 #include <QLayout>
 #include <QLabel>
-#include <QDoubleSpinBox>
 #include <QEvent>
 #include <QKeyEvent>
+#include <QTimer>
+
+#include <math.h>
 
 #ifndef DBL_MAX
 #define DBL_MAX 1.7976931348623158e+308 
 #endif
+#ifdef _DEBUG
+#include <iostream>
+#endif
 
-
-ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, 
-  const Config_WidgetAPI* theData, 
-  const std::string& theParentId)
-  : ModuleBase_ModelWidget(theParent, theData, theParentId)
+ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
+                                                           const Config_WidgetAPI* theData,
+                                                           const std::string& theParentId)
+    : ModuleBase_ModelWidget(theParent, theData, theParentId)
 {
   myContainer = new QWidget(theParent);
   QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
-  aControlLay->setContentsMargins(0, 0, 0, 0);
+  ModuleBase_Tools::adjustMargins(aControlLay);
 
   QString aLabelText = QString::fromStdString(theData->widgetLabel());
   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
@@ -41,7 +47,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
     myLabel->setPixmap(QPixmap(aLabelIcon));
   aControlLay->addWidget(myLabel);
 
-  mySpinBox = new QDoubleSpinBox(myContainer);
+  mySpinBox = new ModuleBase_DoubleSpinBox(myContainer);
   QString anObjName = QString::fromStdString(attributeID());
   mySpinBox->setObjectName(anObjName);
 
@@ -65,14 +71,19 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
   aProp = theData->getProperty(DOUBLE_WDG_STEP);
   double aStepVal = QString::fromStdString(aProp).toDouble(&isOk);
   if (isOk) {
+    double aMinStep = pow(10, -1. * (double) mySpinBox->decimals());
+    if(aStepVal < aMinStep){
+      aStepVal = aMinStep;
+    }
     mySpinBox->setSingleStep(aStepVal);
   }
 
-  aProp = theData->getProperty(DOUBLE_WDG_DFLT);
+  aProp = theData->getProperty(ANY_WDG_DEFAULT);
   double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
-  myHasDefaultValue = isOk;
   if (isOk) {
     mySpinBox->setValue(aDefVal);
+  } else if (aProp == DOUBLE_WDG_DEFAULT_COMPUTED){
+    myIsComputedDefault = true;
   }
 
   QString aTTip = QString::fromStdString(theData->widgetTooltip());
@@ -82,28 +93,24 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
   aControlLay->setStretch(1, 1);
 
   connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
-
-  mySpinBox->installEventFilter(this);
 }
 
 ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
 {
 }
 
-bool ModuleBase_WidgetDoubleValue::storeValue(ObjectPtr theObject) const
+bool ModuleBase_WidgetDoubleValue::storeValue() const
 {
-  DataPtr aData = theObject->data();
+  DataPtr aData = myFeature->data();
   AttributeDoublePtr aReal = aData->real(attributeID());
-  if (aReal->value() != mySpinBox->value()) {
-    aReal->setValue(mySpinBox->value());
-    updateObject(theObject);
-  }
+  aReal->setValue(mySpinBox->value());
+  updateObject(myFeature);
   return true;
 }
 
-bool ModuleBase_WidgetDoubleValue::restoreValue(ObjectPtr theObject)
+bool ModuleBase_WidgetDoubleValue::restoreValue()
 {
-  DataPtr aData = theObject->data();
+  DataPtr aData = myFeature->data();
   AttributeDoublePtr aRef = aData->real(attributeID());
 
   bool isBlocked = mySpinBox->blockSignals(true);
@@ -120,18 +127,3 @@ QList<QWidget*> ModuleBase_WidgetDoubleValue::getControls() const
   aList.append(mySpinBox);
   return aList;
 }
-
-bool ModuleBase_WidgetDoubleValue::eventFilter(QObject *theObject, QEvent *theEvent)
-{
-  if (theObject == mySpinBox) {
-    if (theEvent->type() == QEvent::KeyRelease) {
-      QKeyEvent* aKeyEvent = (QKeyEvent*)theEvent;
-      if (aKeyEvent && aKeyEvent->key() == Qt::Key_Return) {
-        emit focusOutWidget(this);
-      }
-      emit keyReleased(attributeID(), (QKeyEvent*) theEvent);
-      return true;
-    }
-  }
-  return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);
-}