1 // File: ModuleBase_Widgets.h
2 // Created: 04 June 2014
3 // Author: Vitaly Smetannikov
5 #include <ModuleBase_WidgetDoubleValue.h>
6 #include <ModuleBase_DoubleSpinBox.h>
7 #include <ModuleBase_Tools.h>
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_Data.h>
12 #include <Config_Keywords.h>
13 #include <Config_WidgetAPI.h>
15 #include <Events_Loop.h>
16 #include <ModelAPI_Events.h>
28 #define DBL_MAX 1.7976931348623158e+308
34 ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
35 const Config_WidgetAPI* theData,
36 const std::string& theParentId)
37 : ModuleBase_ModelWidget(theParent, theData, theParentId)
39 myContainer = new QWidget(theParent);
40 QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
41 ModuleBase_Tools::adjustMargins(aControlLay);
43 QString aLabelText = QString::fromStdString(theData->widgetLabel());
44 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
45 myLabel = new QLabel(aLabelText, myContainer);
46 if (!aLabelIcon.isEmpty())
47 myLabel->setPixmap(QPixmap(aLabelIcon));
48 aControlLay->addWidget(myLabel);
50 mySpinBox = new ModuleBase_DoubleSpinBox(myContainer);
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 aProp = theData->getProperty(ANY_WDG_DEFAULT);
82 double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
84 mySpinBox->setValue(aDefVal);
85 } else if (aProp == DOUBLE_WDG_DEFAULT_COMPUTED){
86 myIsComputedDefault = true;
89 QString aTTip = QString::fromStdString(theData->widgetTooltip());
90 mySpinBox->setToolTip(aTTip);
92 aControlLay->addWidget(mySpinBox);
93 aControlLay->setStretch(1, 1);
95 connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
98 ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
102 bool ModuleBase_WidgetDoubleValue::storeValue() const
104 DataPtr aData = myFeature->data();
105 AttributeDoublePtr aReal = aData->real(attributeID());
106 aReal->setValue(mySpinBox->value());
107 updateObject(myFeature);
111 bool ModuleBase_WidgetDoubleValue::restoreValue()
113 DataPtr aData = myFeature->data();
114 AttributeDoublePtr aRef = aData->real(attributeID());
116 bool isBlocked = mySpinBox->blockSignals(true);
117 mySpinBox->setValue(aRef->value());
118 mySpinBox->blockSignals(isBlocked);
123 QList<QWidget*> ModuleBase_WidgetDoubleValue::getControls() const
125 QList<QWidget*> aList;
126 aList.append(myLabel);
127 aList.append(mySpinBox);