1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_Widgets.h
4 // Created: 04 June 2014
5 // Author: Vitaly Smetannikov
7 #include <ModuleBase_WidgetDoubleValue.h>
8 #include <ModuleBase_ParamSpinBox.h>
9 #include <ModuleBase_Tools.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_AttributeString.h>
13 #include <ModelAPI_Data.h>
15 #include <Config_Keywords.h>
16 #include <Config_WidgetAPI.h>
18 #include <Events_Loop.h>
19 #include <ModelAPI_Events.h>
22 #include <QFormLayout>
30 #define DBL_MAX 1.7976931348623158e+308
36 ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
37 const Config_WidgetAPI* theData,
38 const std::string& theParentId)
39 : ModuleBase_ModelWidget(theParent, theData, theParentId)
41 QFormLayout* aControlLay = new QFormLayout(this);
42 ModuleBase_Tools::adjustMargins(aControlLay);
44 QString aLabelText = QString::fromStdString(theData->widgetLabel());
45 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
46 myLabel = new QLabel(aLabelText, this);
47 if (!aLabelIcon.isEmpty())
48 myLabel->setPixmap(QPixmap(aLabelIcon));
50 mySpinBox = new ModuleBase_ParamSpinBox(this);
51 QString anObjName = QString::fromStdString(attributeID());
52 mySpinBox->setObjectName(anObjName);
55 std::string aProp = theData->getProperty(DOUBLE_WDG_MIN);
56 double aMinVal = QString::fromStdString(aProp).toDouble(&isOk);
58 mySpinBox->setMinimum(aMinVal);
60 mySpinBox->setMinimum(-DBL_MAX);
63 aProp = theData->getProperty(DOUBLE_WDG_MAX);
64 double aMaxVal = QString::fromStdString(aProp).toDouble(&isOk);
66 mySpinBox->setMaximum(aMaxVal);
68 mySpinBox->setMaximum(DBL_MAX);
71 aProp = theData->getProperty(DOUBLE_WDG_STEP);
72 double aStepVal = QString::fromStdString(aProp).toDouble(&isOk);
74 double aMinStep = pow(10, -1. * (double) mySpinBox->decimals());
75 if(aStepVal < aMinStep){
78 mySpinBox->setSingleStep(aStepVal);
81 double aDefVal = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
83 mySpinBox->setValue(aDefVal);
86 QString aTTip = QString::fromStdString(theData->widgetTooltip());
87 mySpinBox->setToolTip(aTTip);
89 aControlLay->addRow(myLabel, mySpinBox);
90 connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
93 ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
97 void ModuleBase_WidgetDoubleValue::reset()
99 if (isComputedDefault()) {
101 //if (myFeature->compute(myAttributeID))
106 double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
107 ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0);
112 bool ModuleBase_WidgetDoubleValue::storeValueCustom() const
114 DataPtr aData = myFeature->data();
115 AttributeDoublePtr aReal = aData->real(attributeID());
116 aReal->setValue(mySpinBox->value());
117 std::string aTextRepr;
118 if (mySpinBox->hasVariables()) {
119 aTextRepr = mySpinBox->text().toStdString();
121 aReal->setText(aTextRepr);
122 updateObject(myFeature);
126 bool ModuleBase_WidgetDoubleValue::restoreValue()
128 DataPtr aData = myFeature->data();
129 AttributeDoublePtr aRef = aData->real(attributeID());
130 std::string aTextRepr = aRef->text();
131 if (!aTextRepr.empty()) {
132 mySpinBox->setText(QString::fromStdString(aTextRepr));
134 ModuleBase_Tools::setSpinValue(mySpinBox, aRef->value());
139 QList<QWidget*> ModuleBase_WidgetDoubleValue::getControls() const
141 QList<QWidget*> aList;
142 aList.append(mySpinBox);