Salome HOME
Issue #1852 In the Sketcher, replace all disabled real inputs by labels
authornds <nds@opencascade.com>
Thu, 1 Dec 2016 13:22:44 +0000 (16:22 +0300)
committernds <nds@opencascade.com>
Thu, 1 Dec 2016 13:22:44 +0000 (16:22 +0300)
src/ModuleBase/ModuleBase_LabelValue.cpp
src/ModuleBase/ModuleBase_LabelValue.h
src/ModuleBase/ModuleBase_WidgetLabelValue.cpp
src/ModuleBase/ModuleBase_WidgetLabelValue.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetPoint2dDistance.cpp
src/PartSet/PartSet_WidgetPoint2dDistance.h

index 15ac0080e1c0be60201f6b0ea2d9f477ff923b39..46cf12aee5ca6a29a93d66cb18ac526f4b142e1f 100644 (file)
@@ -9,10 +9,12 @@
 
 #include <QHBoxLayout>
 #include <QLabel>
+#include <QLocale>
 
 ModuleBase_LabelValue::ModuleBase_LabelValue(QWidget* theParent, const QString& theText,
-                                             const QString& theToolTip, const QString& theIcon)
-: QWidget(theParent)
+                                             const QString& theToolTip, const QString& theIcon,
+                                             int thePrecision)
+: QWidget(theParent), myPrecision(thePrecision), myValue(0)
 {
   QHBoxLayout* aLayout = new QHBoxLayout(this);
   aLayout->setContentsMargins(2, 0, 0, 0);
@@ -29,6 +31,14 @@ ModuleBase_LabelValue::ModuleBase_LabelValue(QWidget* theParent, const QString&
   myLabelValue = new QLabel("", this);
   aLayout->addWidget(myLabelValue, 1);
 
+  // VSR 01/07/2010: Disable thousands separator for spin box
+  // (to avoid inconsistency of double-2-string and string-2-double conversion)
+  QLocale loc;
+  loc.setNumberOptions(loc.numberOptions() |
+                       QLocale::OmitGroupSeparator |
+                       QLocale::RejectGroupSeparator);
+  setLocale(loc);
+
   aLayout->addStretch(1);
 }
 
@@ -39,6 +49,8 @@ ModuleBase_LabelValue::~ModuleBase_LabelValue()
 void ModuleBase_LabelValue::setValue(const double theValue)
 {
   myValue = theValue;
-  myLabelValue->setText(QString::number(theValue));
+
+  QString aStrValue = locale().toString(theValue, myPrecision >= 0 ? 'f' : 'g', qAbs(myPrecision));
+  myLabelValue->setText(aStrValue);
   myLabelValue->setToolTip(QString::number(theValue));
 }
index 69e1df97b22aeee66800efc7d45e009d89028145..641b48364317489c22d33491b33fd64e8ba0b890 100644 (file)
@@ -28,7 +28,8 @@ public:
   /// \param theIcon a icon value
   ModuleBase_LabelValue(QWidget* theParent, const QString& theText,
                         const QString& theToolTip = "",
-                        const QString& theIcon = "");
+                        const QString& theIcon = "",
+                        int thePrecision = -12);
 
   virtual ~ModuleBase_LabelValue();
 
@@ -45,6 +46,7 @@ protected:
   QLabel* myLabelValue; ///< A label value control
 
   double myValue; ///< A cashed value to avoid a string conversion
+  int myPrecision; ///< Precision value
 };
 
 #endif
index aafbb4ba2e07ac20d164aef0e290c9f460e2ce67..9037e84ebb0552b5f9c1955e588c52d0c32fe9db 100644 (file)
@@ -28,6 +28,12 @@ ModuleBase_WidgetLabelValue::ModuleBase_WidgetLabelValue(QWidget* theParent,
   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
 
   myLabel = new ModuleBase_LabelValue(theParent, aText, aToolTip, aLabelIcon);
+  bool isOk;
+  double aDefVal = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
+  if (isOk) {
+    myLabel->setValue(aDefVal);
+  }
+
   aLayout->addWidget(myLabel);
 }
 
@@ -37,7 +43,9 @@ ModuleBase_WidgetLabelValue::~ModuleBase_WidgetLabelValue()
 
 QList<QWidget*> ModuleBase_WidgetLabelValue::getControls() const
 {
-  return QList<QWidget*>();
+  QList<QWidget*> aControls;
+  aControls.append(myLabel);
+  return aControls;
 }
 
 bool ModuleBase_WidgetLabelValue::restoreValueCustom()
index f1fb4d6f92cc124134f5c9b9e951f2fae4275154..afe8e07f413a6f8e1dc52b2d2add35f2ee1f206f 100644 (file)
@@ -36,7 +36,10 @@ protected:
   /// \return True in success
   virtual bool storeValueCustom();
 
-private:
+  //! Switch On/Off highlighting of the widget
+  virtual void setHighlighted(bool isHighlighted) {}
+
+protected:
   ModuleBase_LabelValue* myLabel;  ///< A label control
 };
 
index 59330ec50c2a7639ebbea2ecb5babecb4cb0768f..64070b492cd280fdf1e28f25e68a054785d8bbcc 100644 (file)
@@ -284,40 +284,11 @@ bool PartSet_WidgetPoint2D::restoreValueCustom()
   std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
   std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(attributeID()));
-  QString aTextX = QString::fromStdString(aPoint->isInitialized() ? aPoint->textX() : "0");
-  QString aTextY = QString::fromStdString(aPoint->isInitialized() ? aPoint->textY() : "0");
-
-  bool isDouble = false;
-  double aVal = 0;
-  if (aTextX.isEmpty()) {
-    myXSpin->setValue(aPoint->x());
-    //ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x());
-  } else {
-    aVal = aTextX.toDouble(&isDouble);
-    myXSpin->setValue(aVal);
-    /*if (isDouble)
-      ModuleBase_Tools::setSpinValue(myXSpin, aVal);
-    else
-      ModuleBase_Tools::setSpinText(myXSpin, aTextX);*/
-  }
-  if (aTextY.isEmpty()) {
-    myYSpin->setValue(aPoint->y());
-    //ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y());
-  } else {
-    aVal = aTextY.toDouble(&isDouble);
-    myYSpin->setValue(aVal);
-    //if (isDouble)
-    //  ModuleBase_Tools::setSpinValue(myYSpin, aVal);
-    //else
-    //  ModuleBase_Tools::setSpinText(myYSpin, aTextY);
-  }
-  //if (aTextX.empty() || aTextY.empty()) {
-  //  ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x());
-  //  ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y());
-  //} else {
-  //  ModuleBase_Tools::setSpinText(myXSpin, QString::fromStdString(aTextX));
-  //  ModuleBase_Tools::setSpinText(myYSpin, QString::fromStdString(aTextY));
-  //}
+  double aValueX = aPoint->isInitialized() ? aPoint->x() : 0.;
+  double aValueY = aPoint->isInitialized() ? aPoint->y() : 0.;
+  myXSpin->setValue(aValueX);
+  myYSpin->setValue(aValueY);
+
   return true;
 }
 
index 2427983aceefc37af3ba3930061a27a94b188aaa..b87b470c0daef002d467193a92a31b5538ba0d99 100644 (file)
@@ -17,6 +17,7 @@
 #include <ModuleBase_IViewer.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_WidgetValidator.h>
+#include <ModuleBase_LabelValue.h>
 
 #include <GeomAPI_Pnt2d.h>
 #include <Config_WidgetAPI.h>
@@ -30,7 +31,7 @@
 PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent,
                                                              ModuleBase_IWorkshop* theWorkshop,
                                                              const Config_WidgetAPI* theData)
-: ModuleBase_WidgetDoubleValue(theParent, theData), myWorkshop(theWorkshop),
+: ModuleBase_WidgetLabelValue(theParent, theData), myWorkshop(theWorkshop),
   myValueIsCashed(false), myIsFeatureVisibleInCash(true), myValueInCash(0)
 {
   myFirstPntName = theData->getProperty("first_point");
@@ -50,7 +51,7 @@ bool PartSet_WidgetPoint2dDistance::isValidSelectionCustom(
 bool PartSet_WidgetPoint2dDistance::resetCustom()
 {
   bool aDone = false;
-  if (!isUseReset() || isComputedDefault() || mySpinBox->hasVariable()) {
+  if (!isUseReset() || isComputedDefault() /*|| mySpinBox->hasVariable()*/) {
     aDone = false;
   }
   else {
@@ -60,8 +61,15 @@ bool PartSet_WidgetPoint2dDistance::resetCustom()
       aDone = restoreCurentValue();
       emit objectUpdated();
     }
-    else
-      aDone = ModuleBase_WidgetDoubleValue::resetCustom();
+    else {
+      bool isOk;
+      double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
+      // it is important to block the spin box control in order to do not through out the
+      // locking of the validating state.
+      myLabel->setValue(isOk ? aDefValue : 0.0);
+      storeValue();
+      aDone = true;
+    }
   }
   return aDone;
 }
@@ -80,7 +88,7 @@ void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
   if (aReal && (aReal->value() != aValue)) {
     aReal->setValue(aValue);
 
-    ModuleBase_Tools::setSpinValue(mySpinBox, aValue);
+    myLabel->setValue(aValue);
     storeValue();
   }
 }
@@ -99,8 +107,8 @@ void PartSet_WidgetPoint2dDistance::mouseReleased(ModuleBase_IViewWindow* theWnd
   if (theEvent->button() != Qt::LeftButton)
     return;
 
-  if (mySpinBox->hasVariable())
-    return;
+  //if (mySpinBox->hasVariable())
+  //  return;
 
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
 
@@ -121,8 +129,8 @@ void PartSet_WidgetPoint2dDistance::mouseMoved(ModuleBase_IViewWindow* theWnd,
   if (isEditingMode())
     return;
 
-  if (mySpinBox->hasVariable())
-    return;
+  //if (mySpinBox->hasVariable())
+  //  return;
 
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
 
@@ -142,13 +150,13 @@ void PartSet_WidgetPoint2dDistance::mouseMoved(ModuleBase_IViewWindow* theWnd,
 void PartSet_WidgetPoint2dDistance::storeCurentValue()
 {
   // do not use cash if a variable is used
-  if (mySpinBox->hasVariable())
-    return;
+  //if (mySpinBox->hasVariable())
+  //  return;
 
   myValueIsCashed = true;
   myIsFeatureVisibleInCash = XGUI_Displayer::isVisible(
                        XGUI_Tools::workshop(myWorkshop)->displayer(), myFeature);
-  myValueInCash = mySpinBox->value();
+  myValueInCash = myLabel->value();
 }
 
 bool PartSet_WidgetPoint2dDistance::restoreCurentValue()
@@ -160,7 +168,7 @@ bool PartSet_WidgetPoint2dDistance::restoreCurentValue()
 
   myValueIsCashed = false;
   myIsFeatureVisibleInCash = true;
-  ModuleBase_Tools::setSpinValue(mySpinBox, myValueInCash);
+  myLabel->setValue(myValueInCash);
 
   // store value to the model
   storeValueCustom();
@@ -176,10 +184,26 @@ bool PartSet_WidgetPoint2dDistance::restoreCurentValue()
 
 bool PartSet_WidgetPoint2dDistance::processEnter()
 {
+  return false;
+  /*
   bool isModified = getValueState() == ModifiedInPP;
   if (isModified) {
     emit valuesChanged();
-    mySpinBox->selectAll();
+    //mySpinBox->selectAll();
   }
-  return isModified;
+  return isModified;*/
+}
+
+bool PartSet_WidgetPoint2dDistance::storeValueCustom()
+{
+  std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
+  if (!aData) // can be on abort of sketcher element
+    return false;
+  AttributeDoublePtr anAttribute = myFeature->data()->real(attributeID());
+  anAttribute->setValue(myLabel->value());
+
+  // after movement the solver will call the update event: optimization
+  updateObject(myFeature);
+
+  return true;
 }
index c6597a0aa80e5f206b195eaaab3eaae1d3ded47f..0ad39f03cda875779d7f4c54de9eefb706db925e 100644 (file)
@@ -10,7 +10,7 @@
 #include "PartSet.h"
 #include "PartSet_MouseProcessor.h"
 
-#include <ModuleBase_WidgetDoubleValue.h>
+#include <ModuleBase_WidgetLabelValue.h>
 
 #include <ModelAPI_CompositeFeature.h>
 
@@ -36,7 +36,7 @@ class QMouseEvent;
 * </point2ddistance>
 * \endcode
 */ 
-class PARTSET_EXPORT PartSet_WidgetPoint2dDistance : public ModuleBase_WidgetDoubleValue,
+class PARTSET_EXPORT PartSet_WidgetPoint2dDistance : public ModuleBase_WidgetLabelValue,
                                                      public PartSet_MouseProcessor
 {
 Q_OBJECT
@@ -97,6 +97,10 @@ protected:
   virtual double computeValue(const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPnt,
                               const std::shared_ptr<GeomAPI_Pnt2d>& theCurrentPnt);
 
+  /// Saves the internal parameters to the given feature
+  /// \return True in success
+  virtual bool storeValueCustom();
+
 protected:
   /// A reference to workshop
   ModuleBase_IWorkshop* myWorkshop;