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>
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 myContainer = new QWidget(theParent);
41 QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
42 ModuleBase_Tools::adjustMargins(aControlLay);
44 QString aLabelText = QString::fromStdString(theData->widgetLabel());
45 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
46 myLabel = new QLabel(aLabelText, myContainer);
47 if (!aLabelIcon.isEmpty())
48 myLabel->setPixmap(QPixmap(aLabelIcon));
49 aControlLay->addWidget(myLabel);
51 mySpinBox = new ModuleBase_DoubleSpinBox(myContainer);
52 QString anObjName = QString::fromStdString(attributeID());
53 mySpinBox->setObjectName(anObjName);
56 std::string aProp = theData->getProperty(DOUBLE_WDG_MIN);
57 double aMinVal = QString::fromStdString(aProp).toDouble(&isOk);
59 mySpinBox->setMinimum(aMinVal);
61 mySpinBox->setMinimum(-DBL_MAX);
64 aProp = theData->getProperty(DOUBLE_WDG_MAX);
65 double aMaxVal = QString::fromStdString(aProp).toDouble(&isOk);
67 mySpinBox->setMaximum(aMaxVal);
69 mySpinBox->setMaximum(DBL_MAX);
72 aProp = theData->getProperty(DOUBLE_WDG_STEP);
73 double aStepVal = QString::fromStdString(aProp).toDouble(&isOk);
75 double aMinStep = pow(10, -1. * (double) mySpinBox->decimals());
76 if(aStepVal < aMinStep){
79 mySpinBox->setSingleStep(aStepVal);
82 double aDefVal = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
84 mySpinBox->setValue(aDefVal);
87 QString aTTip = QString::fromStdString(theData->widgetTooltip());
88 mySpinBox->setToolTip(aTTip);
90 aControlLay->addWidget(mySpinBox);
91 aControlLay->setStretch(1, 1);
93 connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
96 ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
100 void ModuleBase_WidgetDoubleValue::reset()
102 if (isComputedDefault()) {
104 //if (myFeature->compute(myAttributeID))
109 double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
110 ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0);
114 bool ModuleBase_WidgetDoubleValue::storeValueCustom() const
116 DataPtr aData = myFeature->data();
117 AttributeDoublePtr aReal = aData->real(attributeID());
118 aReal->setValue(mySpinBox->value());
119 updateObject(myFeature);
123 bool ModuleBase_WidgetDoubleValue::restoreValue()
125 DataPtr aData = myFeature->data();
126 AttributeDoublePtr aRef = aData->real(attributeID());
128 ModuleBase_Tools::setSpinValue(mySpinBox, aRef->value());
133 QList<QWidget*> ModuleBase_WidgetDoubleValue::getControls() const
135 QList<QWidget*> aList;
136 aList.append(mySpinBox);