Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom into Dev_0.7.1
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetEditor.cpp
index 9774a52bbb86c664001846b2e9cf190a42ad1fe3..7f77acd5a97ac1064fdfd533699a7e85dd71b4ad 100644 (file)
@@ -1,8 +1,12 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        ModuleBase_WidgetEditor.cpp
 // Created:     25 Apr 2014
 // Author:      Natalia ERMOLAEVA
 
 #include <ModuleBase_WidgetEditor.h>
+#include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_Tools.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
 #include <QTimer>
 #include <QDialog>
 #include <QLayout>
-#include <QDoubleSpinBox>
+#include <QApplication>
 
 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
-                                                 const Config_WidgetAPI* theData, 
+                                                 const Config_WidgetAPI* theData,
                                                  const std::string& theParentId)
-: ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
-{
-}
-
-ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, const std::string& theAttribute)
-: ModuleBase_WidgetDoubleValue(theParent, 0, "")
+    : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
 {
-  setAttributeID(theAttribute);
 }
 
 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
@@ -46,7 +44,7 @@ double editedValue(double theValue, bool& isDone)
   QDialog aDlg;
   aDlg.setWindowFlags(Qt::FramelessWindowHint);
   QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
-  aLay->setContentsMargins(0,0,0,0);
+  ModuleBase_Tools::zeroMargins(aLay);
 
   QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg);
   aEditor->setValidator(new QDoubleValidator(aEditor));
@@ -65,6 +63,16 @@ double editedValue(double theValue, bool& isDone)
 
 bool ModuleBase_WidgetEditor::focusTo()
 {
+  // We can not launch here modal process for value editing because 
+  // it can be called on other focusOutWidget event and will block it
+  QTimer::singleShot(1, this, SLOT(showPopupEditor()));
+  return true;
+}
+
+void ModuleBase_WidgetEditor::showPopupEditor()
+{
+  // White while all events will be processed
+  QApplication::processEvents();
   double aValue = mySpinBox->value();
   bool isDone;
   aValue = editedValue(aValue, isDone);
@@ -76,11 +84,10 @@ bool ModuleBase_WidgetEditor::focusTo()
   }
   emit valuesChanged();
   emit focusOutWidget(this);
-
-  return false;
 }
 
-void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature, const std::string theAttribute)
+void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature,
+                                               const std::string theAttribute)
 {
   DataPtr aData = theFeature->data();
   AttributeDoublePtr aRef = aData->real(theAttribute);