1 // File: ModuleBase_Widgets.h
2 // Created: 04 June 2014
3 // Author: Vitaly Smetannikov
5 #include <ModuleBase_WidgetDoubleValue.h>
6 #include <ModuleBase_DoubleSpinBox.h>
8 #include <ModelAPI_AttributeDouble.h>
9 #include <ModelAPI_Data.h>
11 #include <Config_Keywords.h>
12 #include <Config_WidgetAPI.h>
14 #include <Events_Loop.h>
15 #include <ModelAPI_Events.h>
27 #define DBL_MAX 1.7976931348623158e+308
33 ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
34 const Config_WidgetAPI* theData,
35 const std::string& theParentId)
36 : ModuleBase_ModelWidget(theParent, theData, theParentId)
38 myContainer = new QWidget(theParent);
39 QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
40 aControlLay->setContentsMargins(0, 0, 0, 0);
42 QString aLabelText = QString::fromStdString(theData->widgetLabel());
43 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
44 myLabel = new QLabel(aLabelText, myContainer);
45 if (!aLabelIcon.isEmpty())
46 myLabel->setPixmap(QPixmap(aLabelIcon));
47 aControlLay->addWidget(myLabel);
49 mySpinBox = new ModuleBase_DoubleSpinBox(myContainer);
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 aProp = theData->getProperty(DOUBLE_WDG_DEFAULT);
81 double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
83 mySpinBox->setValue(aDefVal);
84 } else if (aProp == DOUBLE_WDG_DEFAULT_COMPUTED){
85 myIsComputedDefault = true;
88 QString aTTip = QString::fromStdString(theData->widgetTooltip());
89 mySpinBox->setToolTip(aTTip);
91 aControlLay->addWidget(mySpinBox);
92 aControlLay->setStretch(1, 1);
94 connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
97 ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
101 bool ModuleBase_WidgetDoubleValue::storeValue() const
103 DataPtr aData = myFeature->data();
104 AttributeDoublePtr aReal = aData->real(attributeID());
105 aReal->setValue(mySpinBox->value());
106 updateObject(myFeature);
110 bool ModuleBase_WidgetDoubleValue::restoreValue()
112 DataPtr aData = myFeature->data();
113 AttributeDoublePtr aRef = aData->real(attributeID());
115 bool isBlocked = mySpinBox->blockSignals(true);
116 mySpinBox->setValue(aRef->value());
117 mySpinBox->blockSignals(isBlocked);
122 QList<QWidget*> ModuleBase_WidgetDoubleValue::getControls() const
124 QList<QWidget*> aList;
125 aList.append(myLabel);
126 aList.append(mySpinBox);