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_DoubleSpinBox.h>
9 #include <ModuleBase_Tools.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_Data.h>
14 #include <Config_Keywords.h>
15 #include <Config_WidgetAPI.h>
17 #include <Events_Loop.h>
18 #include <ModelAPI_Events.h>
21 #include <QFormLayout>
29 #define DBL_MAX 1.7976931348623158e+308
35 ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
36 const Config_WidgetAPI* theData,
37 const std::string& theParentId)
38 : ModuleBase_ModelWidget(theParent, theData, theParentId)
40 QFormLayout* aControlLay = new QFormLayout(this);
41 ModuleBase_Tools::adjustMargins(aControlLay);
43 QString aLabelText = QString::fromStdString(theData->widgetLabel());
44 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
45 myLabel = new QLabel(aLabelText, this);
46 if (!aLabelIcon.isEmpty())
47 myLabel->setPixmap(QPixmap(aLabelIcon));
49 mySpinBox = new ModuleBase_DoubleSpinBox(this);
50 QString anObjName = QString::fromStdString(attributeID());
51 mySpinBox->setObjectName(anObjName);
54 std::string aProp = theData->getProperty(DOUBLE_WDG_MIN);
55 double aMinVal = QString::fromStdString(aProp).toDouble(&isOk);
57 mySpinBox->setMinimum(aMinVal);
59 mySpinBox->setMinimum(-DBL_MAX);
62 aProp = theData->getProperty(DOUBLE_WDG_MAX);
63 double aMaxVal = QString::fromStdString(aProp).toDouble(&isOk);
65 mySpinBox->setMaximum(aMaxVal);
67 mySpinBox->setMaximum(DBL_MAX);
70 aProp = theData->getProperty(DOUBLE_WDG_STEP);
71 double aStepVal = QString::fromStdString(aProp).toDouble(&isOk);
73 double aMinStep = pow(10, -1. * (double) mySpinBox->decimals());
74 if(aStepVal < aMinStep){
77 mySpinBox->setSingleStep(aStepVal);
80 double aDefVal = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
82 mySpinBox->setValue(aDefVal);
85 QString aTTip = QString::fromStdString(theData->widgetTooltip());
86 mySpinBox->setToolTip(aTTip);
88 aControlLay->addRow(myLabel, mySpinBox);
89 connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
92 ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
96 void ModuleBase_WidgetDoubleValue::reset()
98 if (isComputedDefault()) {
100 //if (myFeature->compute(myAttributeID))
105 double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
106 ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0);
111 bool ModuleBase_WidgetDoubleValue::storeValueCustom() const
113 DataPtr aData = myFeature->data();
114 AttributeDoublePtr aReal = aData->real(attributeID());
115 aReal->setValue(mySpinBox->value());
116 updateObject(myFeature);
120 bool ModuleBase_WidgetDoubleValue::restoreValue()
122 DataPtr aData = myFeature->data();
123 AttributeDoublePtr aRef = aData->real(attributeID());
125 ModuleBase_Tools::setSpinValue(mySpinBox, aRef->value());
130 QList<QWidget*> ModuleBase_WidgetDoubleValue::getControls() const
132 QList<QWidget*> aList;
133 aList.append(mySpinBox);