#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);
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);
}
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));
}
/// \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();
QLabel* myLabelValue; ///< A label value control
double myValue; ///< A cashed value to avoid a string conversion
+ int myPrecision; ///< Precision value
};
#endif
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);
}
QList<QWidget*> ModuleBase_WidgetLabelValue::getControls() const
{
- return QList<QWidget*>();
+ QList<QWidget*> aControls;
+ aControls.append(myLabel);
+ return aControls;
}
bool ModuleBase_WidgetLabelValue::restoreValueCustom()
/// \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
};
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;
}
#include <ModuleBase_IViewer.h>
#include <ModuleBase_Tools.h>
#include <ModuleBase_WidgetValidator.h>
+#include <ModuleBase_LabelValue.h>
#include <GeomAPI_Pnt2d.h>
#include <Config_WidgetAPI.h>
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");
bool PartSet_WidgetPoint2dDistance::resetCustom()
{
bool aDone = false;
- if (!isUseReset() || isComputedDefault() || mySpinBox->hasVariable()) {
+ if (!isUseReset() || isComputedDefault() /*|| mySpinBox->hasVariable()*/) {
aDone = false;
}
else {
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;
}
if (aReal && (aReal->value() != aValue)) {
aReal->setValue(aValue);
- ModuleBase_Tools::setSpinValue(mySpinBox, aValue);
+ myLabel->setValue(aValue);
storeValue();
}
}
if (theEvent->button() != Qt::LeftButton)
return;
- if (mySpinBox->hasVariable())
- return;
+ //if (mySpinBox->hasVariable())
+ // return;
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
if (isEditingMode())
return;
- if (mySpinBox->hasVariable())
- return;
+ //if (mySpinBox->hasVariable())
+ // return;
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
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()
myValueIsCashed = false;
myIsFeatureVisibleInCash = true;
- ModuleBase_Tools::setSpinValue(mySpinBox, myValueInCash);
+ myLabel->setValue(myValueInCash);
// store value to the model
storeValueCustom();
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;
}
#include "PartSet.h"
#include "PartSet_MouseProcessor.h"
-#include <ModuleBase_WidgetDoubleValue.h>
+#include <ModuleBase_WidgetLabelValue.h>
#include <ModelAPI_CompositeFeature.h>
* </point2ddistance>
* \endcode
*/
-class PARTSET_EXPORT PartSet_WidgetPoint2dDistance : public ModuleBase_WidgetDoubleValue,
+class PARTSET_EXPORT PartSet_WidgetPoint2dDistance : public ModuleBase_WidgetLabelValue,
public PartSet_MouseProcessor
{
Q_OBJECT
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;