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();
74 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
75 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
77 bool isBlocked = this->blockSignals(true);
78 aPoint->setValue(myXSpin->value(), myYSpin->value());
79 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
81 this->blockSignals(isBlocked);
85 bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
87 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
88 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
89 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
91 bool isBlocked = this->blockSignals(true);
92 myXSpin->setValue(aPoint->x());
93 myYSpin->setValue(aPoint->y());
94 this->blockSignals(isBlocked);
98 bool ModuleBase_WidgetPoint2D::focusTo(const std::string& theAttributeName)
100 if (theAttributeName != myFeatureAttributeID)
103 if (!myXSpin->hasFocus() && !myYSpin->hasFocus()) {
110 QWidget* ModuleBase_WidgetPoint2D::getControl() const
115 QList<QWidget*> ModuleBase_WidgetPoint2D::getControls() const
117 QList<QWidget*> aControls;
118 aControls.push_back(myXSpin);
119 aControls.push_back(myYSpin);
124 bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent)
126 if (theObject == myXSpin || theObject == myYSpin) {
127 if (theEvent->type() == QEvent::KeyRelease) {
128 emit keyReleased(myFeatureAttributeID, (QKeyEvent*) theEvent);
132 return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);