--- /dev/null
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+// File: ModuleBase_WidgetCheckDoubleValue.cpp
+// Created: 16 June 2016
+// Author: Clarisse Genrault (CEA)
+
+#include <Config_Keywords.h>
+#include <Config_WidgetAPI.h>
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <ModuleBase_ParamSpinBox.h>
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_WidgetCheckDoubleValue.h>
+#include <ModuleBase_IconFactory.h>
+
+#include <QFormLayout>
+#include <QCheckBox>
+#include <QList>
+#include <QObject>
+#include <QPixmap>
+#include <QString>
+
+#include <cfloat>
+
+#ifndef DBL_MAX
+#define DBL_MAX 1.7976931348623158e+308
+#endif
+#ifdef _DEBUG
+#include <iostream>
+#endif
+
+//#define DEBUG_COMPLETE_WITH_PARAMETERS
+
+ModuleBase_WidgetCheckDoubleValue::ModuleBase_WidgetCheckDoubleValue(QWidget* theParent,
+ const Config_WidgetAPI* theData)
+ : ModuleBase_ModelWidget(theParent, theData)
+{
+ QFormLayout* aControlLay = new QFormLayout(this);
+ ModuleBase_Tools::adjustMargins(aControlLay);
+
+ myCheckAttributeId = theData->getProperty("id_check");
+
+ QString aCheckText = QString::fromStdString(theData->widgetLabel());
+ myCheckBox = new QCheckBox(aCheckText, this);
+
+ bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
+
+ mySpinBox = new ModuleBase_ParamSpinBox(this);
+ mySpinBox->setAcceptVariables(aAcceptVariables);
+ QString anObjName = QString::fromStdString(attributeID());
+ mySpinBox->setObjectName(anObjName);
+
+ bool isOk = false;
+ std::string aProp = theData->getProperty(DOUBLE_WDG_MIN);
+ double aMinVal = QString::fromStdString(aProp).toDouble(&isOk);
+ if (isOk) {
+ mySpinBox->setMinimum(aMinVal);
+ } else {
+ mySpinBox->setMinimum(-DBL_MAX);
+ }
+
+ aProp = theData->getProperty(DOUBLE_WDG_MAX);
+ double aMaxVal = QString::fromStdString(aProp).toDouble(&isOk);
+ if (isOk) {
+ mySpinBox->setMaximum(aMaxVal);
+ } else {
+ mySpinBox->setMaximum(DBL_MAX);
+ }
+
+ aProp = theData->getProperty(DOUBLE_WDG_STEP);
+ double aStepVal = QString::fromStdString(aProp).toDouble(&isOk);
+ if (isOk) {
+ double aMinStep = pow(10, -1. * (double) mySpinBox->decimals());
+ if(aStepVal < aMinStep){
+ aStepVal = aMinStep;
+ }
+ mySpinBox->setSingleStep(aStepVal);
+ }
+
+ double aDefVal = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
+ if (isOk) {
+ mySpinBox->setValue(aDefVal);
+ }
+
+ QString aTTip = QString::fromStdString(theData->widgetTooltip());
+ mySpinBox->setToolTip(aTTip);
+ myCheckBox->setToolTip(aTTip);
+
+ myCheckBox->setChecked(false);
+ mySpinBox->setEnabled(false);
+
+ aControlLay->addRow(myCheckBox, mySpinBox);
+ connect(mySpinBox, SIGNAL(valueChanged(const QString&)), this, SIGNAL(valuesModified()));
+ connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
+}
+
+ModuleBase_WidgetCheckDoubleValue::~ModuleBase_WidgetCheckDoubleValue()
+{
+}
+
+void ModuleBase_WidgetCheckDoubleValue::activateCustom()
+{
+ ModuleBase_ModelWidget::activateCustom();
+#ifdef DEBUG_COMPLETE_WITH_PARAMETERS
+ QStringList aParameters;
+ ModuleBase_Tools::getParameters(aParameters);
+ mySpinBox->setCompletionList(aParameters);
+#endif
+}
+
+bool ModuleBase_WidgetCheckDoubleValue::resetCustom()
+{
+ bool aDone = false;
+ if (!isUseReset() || isComputedDefault() || mySpinBox->hasVariable()) {
+ aDone = false;
+ } else {
+ bool isOk;
+ double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
+ // reset the value just if there is a default value definition in the XML definition
+ // if the value can not be found by the default value, do nothing
+ if (isOk) {
+ ModuleBase_Tools::setSpinValue(mySpinBox, aDefValue);
+ storeValue();
+ aDone = true;
+ }
+ }
+ return aDone;
+}
+
+bool ModuleBase_WidgetCheckDoubleValue::storeValueCustom()
+{
+ DataPtr aData = myFeature->data();
+ AttributeDoublePtr aReal = aData->real(attributeID());
+ AttributeBooleanPtr aBoolean = aData->boolean(myCheckAttributeId);
+
+ if (mySpinBox->hasVariable()) {
+ // Here is a text of a real value or an expression.
+ std::string aText = mySpinBox->text().toStdString();
+ aReal->setText(aText);
+ } else {
+ // it is important to set the empty text value to the attribute before set the value
+ // because setValue tries to calculate the attribute value according to the
+ // attribute current text
+ aReal->setText("");
+ aReal->setValue(mySpinBox->value());
+ }
+
+ // The spinbox is enabled/disabled only if the checkbox is checked/unchecked
+ aBoolean->setValue(myCheckBox->isChecked());
+ mySpinBox->setEnabled(myCheckBox->isChecked());
+
+ updateObject(myFeature);
+ return true;
+}
+
+bool ModuleBase_WidgetCheckDoubleValue::restoreValueCustom()
+{
+ DataPtr aData = myFeature->data();
+ AttributeDoublePtr aRef = aData->real(attributeID());
+ AttributeBooleanPtr aBoolean = aData->boolean(myCheckAttributeId);
+ std::string aTextRepr = aRef->text();
+ if (!aTextRepr.empty()) {
+ ModuleBase_Tools::setSpinText(mySpinBox, QString::fromStdString(aTextRepr));
+ } else {
+ ModuleBase_Tools::setSpinValue(mySpinBox, aRef->value());
+ }
+
+ // The spinbox is enabled/disabled only if the checkbox is checked/unchecked
+ myCheckBox->setChecked(aBoolean->value());
+ mySpinBox->setEnabled(aBoolean->value());
+
+ return true;
+}
+
+void ModuleBase_WidgetCheckDoubleValue::selectContent()
+{
+ mySpinBox->selectAll();
+}
+
+QList<QWidget*> ModuleBase_WidgetCheckDoubleValue::getControls() const
+{
+ QList<QWidget*> aList;
+ aList.append(mySpinBox);
+ aList.append(myCheckBox);
+ return aList;
+}
+
+bool ModuleBase_WidgetCheckDoubleValue::processEnter()
+{
+ bool isModified = getValueState() == ModifiedInPP;
+ if (isModified) {
+ emit valuesChanged();
+ mySpinBox->selectAll();
+ }
+ return isModified;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_WidgetCheckDoubleValue.h
+// Created: 04 June 2014
+// Author: Vitaly Smetannikov
+
+#ifndef ModuleBase_WidgetCheckDoubleValue_H
+#define ModuleBase_WidgetCheckDoubleValue_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
+
+class ModuleBase_ParamSpinBox;
+class Config_WidgetAPI;
+class QWidget;
+class QTimer;
+class QCheckBox;
+
+/**
+* \ingroup GUI
+* A class of property panel widget for double value input
+* It can be defined with "doublevalue" keyword. For example:
+* \code
+* <doublevalue id="x" id_check="y" label="X:" icon=":pictures/x_point.png" tooltip="X coordinate"/>
+* \endcode
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetCheckDoubleValue : public ModuleBase_ModelWidget
+{
+Q_OBJECT
+ public:
+ /// Constructor
+ /// \param theParent the parent object
+ /// \param theData the widget configuation. The attribute of the model widget is obtained from
+ ModuleBase_WidgetCheckDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData);
+
+ virtual ~ModuleBase_WidgetCheckDoubleValue();
+
+ /// The methiod called when widget is activated
+ virtual void activateCustom();
+
+ /// Select the internal content if it can be selected. It is empty in the default realization
+ virtual void selectContent();
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+ /// Returns true if the event is processed.
+ virtual bool processEnter();
+
+ public slots:
+ // Delayed value chnged: when user starts typing something,
+ // it gives him a 0,5 second to finish typing, when sends valueChnaged() signal
+// void onValueChanged();
+
+protected:
+ /// Saves the internal parameters to the given feature
+ /// \return True in success
+ virtual bool storeValueCustom();
+
+ //! Read value of corresponded attribute from data model to the input control
+ // \return True in success
+ virtual bool restoreValueCustom();
+
+ /// Fills the widget with default values
+ /// \return true if the widget current value is reset
+ virtual bool resetCustom();
+
+protected:
+ /// Check box of the widget
+ QCheckBox* myCheckBox;
+
+ /// Input value control
+ ModuleBase_ParamSpinBox* mySpinBox;
+
+private:
+ /// Check attribute
+ std::string myCheckAttributeId;
+};
+
+#endif