Salome HOME
Correction for reentrant tangent arc
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetEditor.cpp
index aa4cd79b70bdaa0d9af645402e6779dd43788e61..3adc21b0d452e653b5a0c32ed4665bdfb3caca70 100644 (file)
 #include <QLayout>
 
 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
-                                                 const Config_WidgetAPI* theData,
-                                                 const std::string& theParentId)
-: ModuleBase_WidgetDoubleValue(theParent, theData, theParentId),
-  //myIsEnterPressedEmitted(false),
+                                                 const Config_WidgetAPI* theData)
+: ModuleBase_WidgetDoubleValue(theParent, theData),
   myXPosition(-1), myYPosition(-1)
 {
 }
@@ -45,17 +43,16 @@ ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
 {
 }
 
-void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText)
+bool ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText)
 {
+  bool isValueAccepted = false;
+
   QDialog aDlg(QApplication::desktop(), Qt::FramelessWindowHint);
   QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
   aLay->setContentsMargins(2, 2, 2, 2);
 
   ModuleBase_ParamSpinBox* anEditor = new ModuleBase_ParamSpinBox(&aDlg);
   anEditor->enableKeyPressEvent(true);
-  //if (!myIsEditing) {
-  //  connect(anEditor, SIGNAL(enterPressed()), this, SLOT(onEnterPressed()));
-  //}
 
   anEditor->setMinimum(0);
   anEditor->setMaximum(DBL_MAX);
@@ -75,19 +72,17 @@ void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText)
     aPoint = QPoint(myXPosition, myYPosition);
 
   aDlg.move(aPoint);
-  aDlg.exec();
-
-  //if (!myIsEditing) {
-  //  disconnect(anEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SLOT(onEnterPressed()));
-  //}
-
-  outText = anEditor->text();
-  bool isDouble;
-  double aValue = outText.toDouble(&isDouble);
-  if (isDouble) {
-    outValue = aValue;
-    outText = ""; // return empty string, if it's can be converted to a double
+  isValueAccepted = aDlg.exec() == QDialog::Accepted;
+  if (isValueAccepted) {
+    outText = anEditor->text();
+    bool isDouble;
+    double aValue = outText.toDouble(&isDouble);
+    if (isDouble) {
+      outValue = aValue;
+      outText = ""; // return empty string, if it's can be converted to a double
+    }
   }
+  return isValueAccepted;
 }
 
 bool ModuleBase_WidgetEditor::focusTo()
@@ -96,10 +91,9 @@ bool ModuleBase_WidgetEditor::focusTo()
   return true;
 }
 
-void ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals)
+bool ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals)
 {
-  //myIsEnterPressedEmitted = false;
-
+  bool isValueAccepted = false;
   // we need to emit the focus in event manually in order to save the widget as an active
   // in the property panel before the mouse leave event happens in the viewer. The module
   // ask an active widget and change the feature visualization if the widget is not the current one.
@@ -114,30 +108,28 @@ void ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals)
   if (mySpinBox->hasVariable())
     aText = mySpinBox->text();
 
-  editedValue(aValue, aText);
-  if (aText.isEmpty()) {
-    ModuleBase_Tools::setSpinValue(mySpinBox, aValue);
-  } else {
-    ModuleBase_Tools::setSpinText(mySpinBox, aText);
+  isValueAccepted = editedValue(aValue, aText);
+  if (isValueAccepted) {
+    if (aText.isEmpty()) {
+      ModuleBase_Tools::setSpinValue(mySpinBox, aValue);
+    } else {
+      ModuleBase_Tools::setSpinText(mySpinBox, aText);
+    }
+    if (theSendSignals) {
+      emit valuesChanged();
+      // the focus leaves the control automatically by the Enter/Esc event
+      // it is processed in operation manager
+      //emit focusOutWidget(this);
+    }
+    else
+      storeValue();
   }
-  if (theSendSignals) {
-    emit valuesChanged();
-    // the focus leaves the control automatically by the Enter/Esc event
-    // it is processed in operation manager
-    //emit focusOutWidget(this);
-
-    //if (myIsEnterPressedEmitted)
-    if (!myIsEditing)
-      emit enterClicked();
-  }
-  else
-    storeValue();
-}
 
-/*void ModuleBase_WidgetEditor::onEnterPressed()
-{
-  myIsEnterPressedEmitted = true;
-}*/
+  if (theSendSignals && !myIsEditing)
+    emit enterClicked(this);
+
+  return isValueAccepted;
+}
 
 void ModuleBase_WidgetEditor::setCursorPosition(const int theX, const int theY)
 {