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 <GeomDataAPI_Point2D.h>
17 #include <QGridLayout>
18 #include <QDoubleSpinBox>
26 ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle,
27 const std::string& theFeatureAttributeID)
28 : ModuleBase_ModelWidget(theParent), myFeatureAttributeID(theFeatureAttributeID)
30 myGroupBox = new QGroupBox(theTitle, theParent);
31 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
32 aGroupLay->setContentsMargins(0, 0, 0, 0);
33 aGroupLay->setColumnStretch(1, 1);
35 QLabel* aLabel = new QLabel(myGroupBox);
37 aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
38 aGroupLay->addWidget(aLabel, 0, 0);
40 myXSpin = new QDoubleSpinBox(myGroupBox);
41 myXSpin->setMinimum(-DBL_MAX);
42 myXSpin->setMaximum(DBL_MAX);
43 myXSpin->setToolTip("X");
44 aGroupLay->addWidget(myXSpin, 0, 1);
46 connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
49 QLabel* aLabel = new QLabel(myGroupBox);
51 aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
52 aGroupLay->addWidget(aLabel, 1, 0);
54 myYSpin = new QDoubleSpinBox(myGroupBox);
55 myYSpin->setMinimum(-DBL_MAX);
56 myYSpin->setMaximum(DBL_MAX);
57 myYSpin->setToolTip("X");
58 aGroupLay->addWidget(myYSpin, 1, 1);
60 connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
62 myXSpin->installEventFilter(this);
63 myYSpin->installEventFilter(this);
66 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
70 bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
72 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
73 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
74 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
76 bool isBlocked = this->blockSignals(true);
77 aPoint->setValue(myXSpin->value(), myYSpin->value());
78 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
80 this->blockSignals(isBlocked);
84 bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
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(myFeatureAttributeID));
90 bool isBlocked = this->blockSignals(true);
91 myXSpin->setValue(aPoint->x());
92 myYSpin->setValue(aPoint->y());
93 this->blockSignals(isBlocked);
97 bool ModuleBase_WidgetPoint2D::focusTo(const std::string& theAttributeName)
99 if (theAttributeName != myFeatureAttributeID)
102 if (!myXSpin->hasFocus() && !myYSpin->hasFocus()) {
109 QWidget* ModuleBase_WidgetPoint2D::getControl() const
114 QList<QWidget*> ModuleBase_WidgetPoint2D::getControls() const
116 QList<QWidget*> aControls;
117 aControls.push_back(myXSpin);
118 aControls.push_back(myYSpin);
123 bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent)
125 if (theObject == myXSpin || theObject == myYSpin) {
126 if (theEvent->type() == QEvent::KeyRelease) {
127 emit keyReleased(myFeatureAttributeID, (QKeyEvent*) theEvent);
131 return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);