Salome HOME
Issue #2998: Add help description for automatic creation of constraints
[modules/shaper.git] / src / ModuleBase / ModuleBase_ParamSpinBox.cpp
index 349eec6b69a0a08624334d1a9415c45d47d83c28..e7836e656126d0378c8c3e5befcee38549d4de70 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "ModuleBase_ParamSpinBox.h"
@@ -46,11 +45,10 @@ bool isVariableSymbol(const QChar& theChar) {
 
 ModuleBase_ParamSpinBox::ModuleBase_ParamSpinBox(QWidget* theParent, int thePrecision)
   : QAbstractSpinBox(theParent),
-  myPrecision(thePrecision),
   myIsEquation(false),
   myAcceptVariables(true),
   mySingleStep(1),
-  myMinimum(DBL_MIN),
+  myMinimum(-DBL_MAX),
   myMaximum(DBL_MAX)
 {
   myCompleter = new QCompleter(this);
@@ -75,7 +73,7 @@ ModuleBase_ParamSpinBox::ModuleBase_ParamSpinBox(QWidget* theParent, int thePrec
   myValidator = new QDoubleValidator(this);
   myValidator->setLocale(locale());
   myValidator->setRange(myMinimum, myMaximum);
-  myValidator->setDecimals(myPrecision);
+  myValidator->setDecimals(thePrecision);
 }
 
 void ModuleBase_ParamSpinBox::setCompletionList(QStringList& theList)
@@ -110,7 +108,7 @@ void ModuleBase_ParamSpinBox::stepBy(int steps)
   double aVal = lineEdit()->text().toDouble();
   aVal += steps * mySingleStep;
   setValue(aVal);
-  QAbstractSpinBox::stepBy(steps);
+  //QAbstractSpinBox::stepBy(steps);
 }
 
 void ModuleBase_ParamSpinBox::onTextChanged(const QString& theText)
@@ -153,8 +151,11 @@ void ModuleBase_ParamSpinBox::setValue(double value)
     aVal = myMinimum;
   else if (aVal > myMaximum)
     aVal = myMaximum;
-  QString aText = QString::number(aVal, 'g', decimals());
+  QString aText = (myValidator->decimals() == 0) ? QString::number((int)aVal) :
+    QString::number(aVal, 'g', decimals());
+  lineEdit()->blockSignals(true);
   lineEdit()->setText(aText);
+  lineEdit()->blockSignals(false);
   emit textChanged(aText);
 }
 
@@ -174,6 +175,12 @@ void ModuleBase_ParamSpinBox::setText(const QString& value)
     lineEdit()->setText(value);
     emit textChanged(value);
   }
+  else {
+    bool isConv = false;
+    double aVal = value.toDouble(&isConv);
+    if (isConv)
+      setValue(aVal);
+  }
 }
 
 /*!
@@ -209,13 +216,18 @@ bool ModuleBase_ParamSpinBox::hasVariable(const QString& theText) const
   return !isDouble;
 }
 
-void ModuleBase_ParamSpinBox::showCompletion()
+void ModuleBase_ParamSpinBox::showCompletion(bool checkPrefix)
 {
   myCompletePos = lineEdit()->cursorPosition();
   int aStart, aEnd;
   QString aPrefix;
   aPrefix = getPrefix(aStart, aEnd);
-  if (aPrefix.length() > 0) {
+  if (checkPrefix) {
+    if (aPrefix.length() > 0) {
+      myCompleter->setCompletionPrefix(aPrefix);
+      myCompleter->complete();
+    }
+  } else {
     myCompleter->setCompletionPrefix(aPrefix);
     myCompleter->complete();
   }
@@ -227,7 +239,10 @@ void ModuleBase_ParamSpinBox::keyReleaseEvent(QKeyEvent* e)
 
   switch (e->key()) {
   case Qt::Key_Backspace:
-    showCompletion();
+    if (myCompleter->popup()->isVisible()) {
+      myCompleter->popup()->hide();
+    }
+    showCompletion(true);
     break;
   case Qt::Key_Return:
   case Qt::Key_Enter:
@@ -237,12 +252,16 @@ void ModuleBase_ParamSpinBox::keyReleaseEvent(QKeyEvent* e)
     }
     emit textChanged(lineEdit()->text());
     break;
-  default:
+  case Qt::Key_Space:
+    if (e->modifiers() & Qt::ControlModifier) {
+      showCompletion(false);
+    }
+    break;  default:
     aText = e->text();
     if (aText.length() == 1) {
       QChar aChar = aText.at(0);
       if (isVariableSymbol(aChar)) {
-        showCompletion();
+        showCompletion(true);
       }
     }
   }