Salome HOME
refs #226: the next non-filled widget should have focus after preselection processing
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetPoint2D.cpp
index 5e447ef1deeeaa74f9fd8cc17ccc4dba815d6e4a..21cef047dc80351fff5b0ca7a32d1aaa36d132b8 100644 (file)
@@ -4,6 +4,8 @@
 
 #include <ModuleBase_WidgetPoint2D.h>
 #include <ModuleBase_WidgetValueFeature.h>
+#include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_Tools.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
 
 #include <QGroupBox>
 #include <QGridLayout>
-#include <QDoubleSpinBox>
 #include <QLabel>
 #include <QEvent>
-#include <QKeyEvent>
 
 #include <cfloat>
 #include <climits>
@@ -33,10 +33,12 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
     : ModuleBase_ModelWidget(theParent, theData, theParentId)
 {
   myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
-  myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)),
-                             theParent);
+  QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
+  myGroupBox = new QGroupBox(aPageName, theParent);
+  myGroupBox->setFlat(false);
+
   QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
-  aGroupLay->setContentsMargins(0, 0, 0, 0);
+  ModuleBase_Tools::adjustMargins(aGroupLay);
   aGroupLay->setColumnStretch(1, 1);
   {
     QLabel* aLabel = new QLabel(myGroupBox);
@@ -44,7 +46,7 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
     aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
     aGroupLay->addWidget(aLabel, 0, 0);
 
-    myXSpin = new QDoubleSpinBox(myGroupBox);
+    myXSpin = new ModuleBase_DoubleSpinBox(myGroupBox);
     myXSpin->setMinimum(-DBL_MAX);
     myXSpin->setMaximum(DBL_MAX);
     myXSpin->setToolTip("X");
@@ -58,7 +60,7 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
     aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
     aGroupLay->addWidget(aLabel, 1, 0);
 
-    myYSpin = new QDoubleSpinBox(myGroupBox);
+    myYSpin = new ModuleBase_DoubleSpinBox(myGroupBox);
     myYSpin->setMinimum(-DBL_MAX);
     myYSpin->setMaximum(DBL_MAX);
     myYSpin->setToolTip("X");
@@ -66,8 +68,6 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
 
     connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
   }
-  myXSpin->installEventFilter(this);
-  myYSpin->installEventFilter(this);
 }
 
 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
@@ -107,11 +107,18 @@ bool ModuleBase_WidgetPoint2D::storeValue() const
   boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(attributeID()));
-
+  
   ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
   bool isBlocked = that->blockSignals(true);
+  bool isImmutable = aPoint->setImmutable(true);
+#ifdef _DEBUG
+  std::string _attr_name = myAttributeID;
+  double _X = myXSpin->value();
+  double _Y = myYSpin->value();
+#endif
   aPoint->setValue(myXSpin->value(), myYSpin->value());
   updateObject(myFeature);
+  aPoint->setImmutable(isImmutable);
   that->blockSignals(isBlocked);
 
   return true;
@@ -123,6 +130,11 @@ bool ModuleBase_WidgetPoint2D::restoreValue()
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(attributeID()));
 
+#ifdef _DEBUG
+  std::string _attr_name = myAttributeID;
+  double _X = aPoint->x();
+  double _Y = aPoint->y();
+#endif
   bool isBlocked = this->blockSignals(true);
   myXSpin->setValue(aPoint->x());
   myYSpin->setValue(aPoint->y());
@@ -144,21 +156,6 @@ QList<QWidget*> ModuleBase_WidgetPoint2D::getControls() const
   return aControls;
 }
 
-bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent)
-{
-  if (theObject == myXSpin || theObject == myYSpin) {
-    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);
-}
-
 bool ModuleBase_WidgetPoint2D::initFromPrevious(ObjectPtr theObject)
 {
   if (myOptionParam.length() == 0)