1 // File: ModuleBase_Widgets.h
2 // Created: 04 June 2014
3 // Author: Vitaly Smetannikov
5 #include "ModuleBase_Widgets.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_DoubleValueWidget::ModuleBase_DoubleValueWidget(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_DoubleValueWidget::~ModuleBase_DoubleValueWidget()
84 bool ModuleBase_DoubleValueWidget::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_DoubleValueWidget::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_DoubleValueWidget::getControls() const
109 QList<QWidget*> aList;
110 aList.append(myLabel);
111 aList.append(mySpinBox);
116 //////////////////////////////////////////////////////////////////////////////////
117 ModuleBase_BoolValueWidget::ModuleBase_BoolValueWidget(QWidget* theParent, const Config_WidgetAPI* theData)
118 : ModuleBase_ModelWidget(theParent)
120 myAttributeID = theData->widgetId();
121 QString aText = QString::fromStdString(theData->widgetLabel());
122 QString aToolTip = QString::fromStdString(theData->widgetTooltip());
123 QString aDefault = QString::fromStdString(theData->getProperty("default"));
125 myCheckBox = new QCheckBox(aText, theParent);
126 myCheckBox->setToolTip(aToolTip);
127 myCheckBox->setChecked(aDefault == "true");
129 connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
132 ModuleBase_BoolValueWidget::~ModuleBase_BoolValueWidget()
136 QWidget* ModuleBase_BoolValueWidget::getControl() const
141 bool ModuleBase_BoolValueWidget::storeValue(FeaturePtr theFeature) const
143 DataPtr aData = theFeature->data();
144 boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(myAttributeID);
146 if (aBool->value() != myCheckBox->isChecked()) {
147 aBool->setValue(myCheckBox->isChecked());
148 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
153 bool ModuleBase_BoolValueWidget::restoreValue(FeaturePtr theFeature)
155 DataPtr aData = theFeature->data();
156 boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(myAttributeID);
158 bool isBlocked = myCheckBox->blockSignals(true);
159 myCheckBox->setChecked(aRef->value());
160 myCheckBox->blockSignals(isBlocked);
165 QList<QWidget*> ModuleBase_BoolValueWidget::getControls() const
167 QList<QWidget*> aList;
168 aList.append(myCheckBox);