1 // File: ModuleBase_Widgets.h
2 // Created: 04 June 2014
3 // Author: Vitaly Smetannikov
5 #include <ModuleBase_WidgetDoubleValue.h>
7 #include <ModelAPI_AttributeDouble.h>
8 #include <ModelAPI_Data.h>
10 #include <Config_Keywords.h>
11 #include <Config_WidgetAPI.h>
13 #include <Events_Loop.h>
14 #include <Model_Events.h>
19 #include <QDoubleSpinBox>
22 ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData)
23 : ModuleBase_ModelWidget(theParent, theData)
25 myContainer = new QWidget(theParent);
26 QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
27 aControlLay->setContentsMargins(0, 0, 0, 0);
29 QString aLabelText = QString::fromStdString(theData->widgetLabel());
30 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
31 myLabel = new QLabel(aLabelText, myContainer);
32 myLabel->setPixmap(QPixmap(aLabelIcon));
33 aControlLay->addWidget(myLabel);
35 mySpinBox = new QDoubleSpinBox(myContainer);
36 QString anObjName = QString::fromStdString(attributeID());
37 mySpinBox->setObjectName(anObjName);
40 std::string aProp = theData->getProperty(DOUBLE_WDG_MIN);
41 double aMinVal = QString::fromStdString(aProp).toDouble(&isOk);
43 mySpinBox->setMinimum(aMinVal);
45 mySpinBox->setMinimum(-DBL_MAX);
48 aProp = theData->getProperty(DOUBLE_WDG_MAX);
49 double aMaxVal = QString::fromStdString(aProp).toDouble(&isOk);
51 mySpinBox->setMaximum(aMaxVal);
53 mySpinBox->setMaximum(DBL_MAX);
56 aProp = theData->getProperty(DOUBLE_WDG_STEP);
57 double aStepVal = QString::fromStdString(aProp).toDouble(&isOk);
59 mySpinBox->setSingleStep(aStepVal);
62 aProp = theData->getProperty(DOUBLE_WDG_DFLT);
63 double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
65 mySpinBox->setValue(aDefVal);
68 QString aTTip = QString::fromStdString(theData->widgetTooltip());
69 mySpinBox->setToolTip(aTTip);
71 aControlLay->addWidget(mySpinBox);
72 aControlLay->setStretch(1, 1);
74 connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
77 ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
81 bool ModuleBase_WidgetDoubleValue::storeValue(FeaturePtr theFeature) const
83 DataPtr aData = theFeature->data();
84 boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(attributeID());
85 if (aReal->value() != mySpinBox->value()) {
86 aReal->setValue(mySpinBox->value());
87 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
92 bool ModuleBase_WidgetDoubleValue::restoreValue(FeaturePtr theFeature)
94 DataPtr aData = theFeature->data();
95 boost::shared_ptr<ModelAPI_AttributeDouble> aRef = aData->real(attributeID());
97 bool isBlocked = mySpinBox->blockSignals(true);
98 mySpinBox->setValue(aRef->value());
99 mySpinBox->blockSignals(isBlocked);
104 QList<QWidget*> ModuleBase_WidgetDoubleValue::getControls() const
106 QList<QWidget*> aList;
107 aList.append(myLabel);
108 aList.append(mySpinBox);