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_AttributeBoolean.h>
9 #include <ModelAPI_Data.h>
11 #include <Config_Keywords.h>
12 #include <Config_WidgetAPI.h>
14 #include <Events_Loop.h>
15 #include <Model_Events.h>
20 #include <QDoubleSpinBox>
24 ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData)
25 : ModuleBase_ModelWidget(theParent)
27 myContainer = new QWidget(theParent);
28 QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
29 aControlLay->setContentsMargins(0, 0, 0, 0);
31 QString aLabelText = QString::fromStdString(theData->widgetLabel());
32 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
33 myLabel = new QLabel(aLabelText, myContainer);
34 myLabel->setPixmap(QPixmap(aLabelIcon));
35 aControlLay->addWidget(myLabel);
37 myAttributeID = theData->widgetId();
38 mySpinBox = new QDoubleSpinBox(myContainer);
39 QString anObjName = QString::fromStdString(myAttributeID);
40 mySpinBox->setObjectName(anObjName);
43 std::string aProp = theData->getProperty(DOUBLE_WDG_MIN);
44 double aMinVal = QString::fromStdString(aProp).toDouble(&isOk);
46 mySpinBox->setMinimum(aMinVal);
48 mySpinBox->setMinimum(-DBL_MAX);
51 aProp = theData->getProperty(DOUBLE_WDG_MAX);
52 double aMaxVal = QString::fromStdString(aProp).toDouble(&isOk);
54 mySpinBox->setMaximum(aMaxVal);
56 mySpinBox->setMaximum(DBL_MAX);
59 aProp = theData->getProperty(DOUBLE_WDG_STEP);
60 double aStepVal = QString::fromStdString(aProp).toDouble(&isOk);
62 mySpinBox->setSingleStep(aStepVal);
65 aProp = theData->getProperty(DOUBLE_WDG_DFLT);
66 double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
68 mySpinBox->setValue(aDefVal);
71 QString aTTip = QString::fromStdString(theData->widgetTooltip());
72 mySpinBox->setToolTip(aTTip);
74 aControlLay->addWidget(mySpinBox);
75 aControlLay->setStretch(1, 1);
77 connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
80 ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
84 bool ModuleBase_WidgetDoubleValue::storeValue(FeaturePtr theFeature) const
86 DataPtr aData = theFeature->data();
87 boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(myAttributeID);
88 if (aReal->value() != mySpinBox->value()) {
89 aReal->setValue(mySpinBox->value());
90 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
95 bool ModuleBase_WidgetDoubleValue::restoreValue(FeaturePtr theFeature)
97 DataPtr aData = theFeature->data();
98 boost::shared_ptr<ModelAPI_AttributeDouble> aRef = aData->real(myAttributeID);
100 bool isBlocked = mySpinBox->blockSignals(true);
101 mySpinBox->setValue(aRef->value());
102 mySpinBox->blockSignals(isBlocked);
107 QList<QWidget*> ModuleBase_WidgetDoubleValue::getControls() const
109 QList<QWidget*> aList;
110 aList.append(myLabel);
111 aList.append(mySpinBox);