1 // File: ModuleBase_WidgetPoint2D.cpp
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <ModuleBase_WidgetPoint2D.h>
7 #include <Config_Keywords.h>
9 #include <Events_Loop.h>
10 #include <Model_Events.h>
12 #include <ModelAPI_Feature.h>
13 #include <ModelAPI_Data.h>
14 #include <ModelAPI_Object.h>
15 #include <GeomDataAPI_Point2D.h>
18 #include <QGridLayout>
19 #include <QDoubleSpinBox>
27 ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle,
28 const std::string& theFeatureAttributeID)
29 : ModuleBase_ModelWidget(theParent), myFeatureAttributeID(theFeatureAttributeID)
31 myGroupBox = new QGroupBox(theTitle, theParent);
32 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
33 aGroupLay->setContentsMargins(0, 0, 0, 0);
34 aGroupLay->setColumnStretch(1, 1);
36 QLabel* aLabel = new QLabel(myGroupBox);
38 aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
39 aGroupLay->addWidget(aLabel, 0, 0);
41 myXSpin = new QDoubleSpinBox(myGroupBox);
42 myXSpin->setMinimum(-DBL_MAX);
43 myXSpin->setMaximum(DBL_MAX);
44 myXSpin->setToolTip("X");
45 aGroupLay->addWidget(myXSpin, 0, 1);
47 connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
50 QLabel* aLabel = new QLabel(myGroupBox);
52 aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
53 aGroupLay->addWidget(aLabel, 1, 0);
55 myYSpin = new QDoubleSpinBox(myGroupBox);
56 myYSpin->setMinimum(-DBL_MAX);
57 myYSpin->setMaximum(DBL_MAX);
58 myYSpin->setToolTip("X");
59 aGroupLay->addWidget(myYSpin, 1, 1);
61 connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
63 myXSpin->installEventFilter(this);
64 myYSpin->installEventFilter(this);
67 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
71 bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
73 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
75 ObjectPtr anObj = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
76 if (anObj) aData = anObj->featureRef()->data();
78 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
79 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
81 bool isBlocked = this->blockSignals(true);
82 aPoint->setValue(myXSpin->value(), myYSpin->value());
83 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
85 this->blockSignals(isBlocked);
89 bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
91 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
93 ObjectPtr anObj = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
94 if (anObj) aData = anObj->featureRef()->data();
96 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
97 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
99 bool isBlocked = this->blockSignals(true);
100 myXSpin->setValue(aPoint->x());
101 myYSpin->setValue(aPoint->y());
102 this->blockSignals(isBlocked);
106 bool ModuleBase_WidgetPoint2D::focusTo(const std::string& theAttributeName)
108 if (theAttributeName != myFeatureAttributeID)
111 if (!myXSpin->hasFocus() && !myYSpin->hasFocus()) {
118 QWidget* ModuleBase_WidgetPoint2D::getControl() const
123 QList<QWidget*> ModuleBase_WidgetPoint2D::getControls() const
125 QList<QWidget*> aControls;
126 aControls.push_back(myXSpin);
127 aControls.push_back(myYSpin);
132 bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent)
134 if (theObject == myXSpin || theObject == myYSpin) {
135 if (theEvent->type() == QEvent::KeyRelease) {
136 emit keyReleased(myFeatureAttributeID, (QKeyEvent*) theEvent);
140 return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);