From: nds Date: Thu, 1 Dec 2016 13:22:44 +0000 (+0300) Subject: Issue #1852 In the Sketcher, replace all disabled real inputs by labels X-Git-Tag: V_2.6.0~27 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cfe233250e41da5c4f0a14c3a4e60e1b58591a7d;p=modules%2Fshaper.git Issue #1852 In the Sketcher, replace all disabled real inputs by labels --- diff --git a/src/ModuleBase/ModuleBase_LabelValue.cpp b/src/ModuleBase/ModuleBase_LabelValue.cpp index 15ac0080e..46cf12aee 100644 --- a/src/ModuleBase/ModuleBase_LabelValue.cpp +++ b/src/ModuleBase/ModuleBase_LabelValue.cpp @@ -9,10 +9,12 @@ #include #include +#include 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)); } diff --git a/src/ModuleBase/ModuleBase_LabelValue.h b/src/ModuleBase/ModuleBase_LabelValue.h index 69e1df97b..641b48364 100644 --- a/src/ModuleBase/ModuleBase_LabelValue.h +++ b/src/ModuleBase/ModuleBase_LabelValue.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetLabelValue.cpp b/src/ModuleBase/ModuleBase_WidgetLabelValue.cpp index aafbb4ba2..9037e84eb 100644 --- a/src/ModuleBase/ModuleBase_WidgetLabelValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetLabelValue.cpp @@ -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 ModuleBase_WidgetLabelValue::getControls() const { - return QList(); + QList aControls; + aControls.append(myLabel); + return aControls; } bool ModuleBase_WidgetLabelValue::restoreValueCustom() diff --git a/src/ModuleBase/ModuleBase_WidgetLabelValue.h b/src/ModuleBase/ModuleBase_WidgetLabelValue.h index f1fb4d6f9..afe8e07f4 100644 --- a/src/ModuleBase/ModuleBase_WidgetLabelValue.h +++ b/src/ModuleBase/ModuleBase_WidgetLabelValue.h @@ -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 }; diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 59330ec50..64070b492 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -284,40 +284,11 @@ bool PartSet_WidgetPoint2D::restoreValueCustom() std::shared_ptr aData = myFeature->data(); std::shared_ptr aPoint = std::dynamic_pointer_cast( 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; } diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index 2427983ac..b87b470c0 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -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 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; } diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.h b/src/PartSet/PartSet_WidgetPoint2dDistance.h index c6597a0aa..0ad39f03c 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.h +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.h @@ -10,7 +10,7 @@ #include "PartSet.h" #include "PartSet_MouseProcessor.h" -#include +#include #include @@ -36,7 +36,7 @@ class QMouseEvent; * * \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& theFirstPnt, const std::shared_ptr& theCurrentPnt); + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValueCustom(); + protected: /// A reference to workshop ModuleBase_IWorkshop* myWorkshop;