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>
19 #include <QGridLayout>
20 #include <QDoubleSpinBox>
28 ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
29 const Config_WidgetAPI* theData)
30 : ModuleBase_ModelWidget(theParent, theData)
32 myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)),
34 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
35 aGroupLay->setContentsMargins(0, 0, 0, 0);
36 aGroupLay->setColumnStretch(1, 1);
38 QLabel* aLabel = new QLabel(myGroupBox);
40 aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
41 aGroupLay->addWidget(aLabel, 0, 0);
43 myXSpin = new QDoubleSpinBox(myGroupBox);
44 myXSpin->setMinimum(-DBL_MAX);
45 myXSpin->setMaximum(DBL_MAX);
46 myXSpin->setToolTip("X");
47 aGroupLay->addWidget(myXSpin, 0, 1);
49 connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
52 QLabel* aLabel = new QLabel(myGroupBox);
54 aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
55 aGroupLay->addWidget(aLabel, 1, 0);
57 myYSpin = new QDoubleSpinBox(myGroupBox);
58 myYSpin->setMinimum(-DBL_MAX);
59 myYSpin->setMaximum(DBL_MAX);
60 myYSpin->setToolTip("X");
61 aGroupLay->addWidget(myYSpin, 1, 1);
63 connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
65 myXSpin->installEventFilter(this);
66 myYSpin->installEventFilter(this);
69 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
73 bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) const
75 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
76 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
77 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
79 ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
80 bool isBlocked = that->blockSignals(true);
81 aPoint->setValue(myXSpin->value(), myYSpin->value());
82 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
83 that->blockSignals(isBlocked);
88 bool ModuleBase_WidgetPoint2D::restoreValue(FeaturePtr theFeature)
90 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
91 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
92 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
94 bool isBlocked = this->blockSignals(true);
95 myXSpin->setValue(aPoint->x());
96 myYSpin->setValue(aPoint->y());
97 this->blockSignals(isBlocked);
101 QWidget* ModuleBase_WidgetPoint2D::getControl() const
106 QList<QWidget*> ModuleBase_WidgetPoint2D::getControls() const
108 QList<QWidget*> aControls;
109 aControls.push_back(myXSpin);
110 aControls.push_back(myYSpin);
115 bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent)
117 if (theObject == myXSpin || theObject == myYSpin) {
118 if (theEvent->type() == QEvent::KeyRelease) {
119 emit keyReleased(attributeID(), (QKeyEvent*) theEvent);
123 return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);