1 // File: ModuleBase_WidgetPoint2D.cpp
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <ModuleBase_WidgetPoint2D.h>
7 #include <Config_Keywords.h>
8 #include <Config_WidgetAPI.h>
10 #include <Events_Loop.h>
11 #include <Model_Events.h>
13 #include <ModelAPI_Feature.h>
14 #include <ModelAPI_Data.h>
15 #include <ModelAPI_Object.h>
16 #include <GeomDataAPI_Point2D.h>
17 #include <GeomAPI_Pnt2d.h>
20 #include <QGridLayout>
21 #include <QDoubleSpinBox>
29 ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
30 const Config_WidgetAPI* theData)
31 : ModuleBase_ModelWidget(theParent, theData)
33 myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)),
35 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
36 aGroupLay->setContentsMargins(0, 0, 0, 0);
37 aGroupLay->setColumnStretch(1, 1);
39 QLabel* aLabel = new QLabel(myGroupBox);
41 aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
42 aGroupLay->addWidget(aLabel, 0, 0);
44 myXSpin = new QDoubleSpinBox(myGroupBox);
45 myXSpin->setMinimum(-DBL_MAX);
46 myXSpin->setMaximum(DBL_MAX);
47 myXSpin->setToolTip("X");
48 aGroupLay->addWidget(myXSpin, 0, 1);
50 connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
53 QLabel* aLabel = new QLabel(myGroupBox);
55 aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
56 aGroupLay->addWidget(aLabel, 1, 0);
58 myYSpin = new QDoubleSpinBox(myGroupBox);
59 myYSpin->setMinimum(-DBL_MAX);
60 myYSpin->setMaximum(DBL_MAX);
61 myYSpin->setToolTip("X");
62 aGroupLay->addWidget(myYSpin, 1, 1);
64 connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
66 myXSpin->installEventFilter(this);
67 myYSpin->installEventFilter(this);
70 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
74 void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
76 bool isBlocked = this->blockSignals(true);
77 myXSpin->setValue(thePoint->x());
78 myYSpin->setValue(thePoint->y());
79 this->blockSignals(isBlocked);
84 bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) const
86 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
87 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
88 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
90 ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
91 bool isBlocked = that->blockSignals(true);
92 aPoint->setValue(myXSpin->value(), myYSpin->value());
93 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
94 that->blockSignals(isBlocked);
99 bool ModuleBase_WidgetPoint2D::restoreValue(FeaturePtr theFeature)
101 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
102 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
103 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
105 bool isBlocked = this->blockSignals(true);
106 myXSpin->setValue(aPoint->x());
107 myYSpin->setValue(aPoint->y());
108 this->blockSignals(isBlocked);
112 QWidget* ModuleBase_WidgetPoint2D::getControl() const
117 QList<QWidget*> ModuleBase_WidgetPoint2D::getControls() const
119 QList<QWidget*> aControls;
120 aControls.push_back(myXSpin);
121 aControls.push_back(myYSpin);
126 bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent)
128 if (theObject == myXSpin || theObject == myYSpin) {
129 if (theEvent->type() == QEvent::KeyRelease) {
130 emit keyReleased(attributeID(), (QKeyEvent*) theEvent);
134 return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);