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 aProp = theData->getProperty(ATTR_DEFAULT);
83 double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
85 mySpinBox->setValue(aDefVal);
86 } else if (aProp == DOUBLE_WDG_DEFAULT_COMPUTED){
87 myIsComputedDefault = true;
90 QString aTTip = QString::fromStdString(theData->widgetTooltip());
91 mySpinBox->setToolTip(aTTip);
93 aControlLay->addWidget(mySpinBox);
94 aControlLay->setStretch(1, 1);
96 connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
99 ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
103 bool ModuleBase_WidgetDoubleValue::storeValue() const
105 DataPtr aData = myFeature->data();
106 AttributeDoublePtr aReal = aData->real(attributeID());
107 aReal->setValue(mySpinBox->value());
108 updateObject(myFeature);
112 bool ModuleBase_WidgetDoubleValue::restoreValue()
114 DataPtr aData = myFeature->data();
115 AttributeDoublePtr aRef = aData->real(attributeID());
117 bool isBlocked = mySpinBox->blockSignals(true);
118 mySpinBox->setValue(aRef->value());
119 mySpinBox->blockSignals(isBlocked);
124 QList<QWidget*> ModuleBase_WidgetDoubleValue::getControls() const
126 QList<QWidget*> aList;
127 aList.append(mySpinBox);