X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetPoint2D.cpp;h=baa7285b054873ef2bf7f8c59defbac16ebd0f05;hb=f4bd13ed4b2456d13a8d58fd0bc4029264592815;hp=4d99d01be7fccfd41897cc5c04ea5d594e8f1548;hpb=b6efbb487078ba0dd475dcd0447c0aadb879429a;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index 4d99d01be..baa7285b0 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -3,29 +3,37 @@ // Author: Natalia ERMOLAEVA #include +#include #include +#include #include #include #include #include +#include #include +#include #include #include #include #include +#include +#include #include #include -ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle, - const std::string& theFeatureAttributeID) -: ModuleBase_ModelWidget(theParent), myFeatureAttributeID(theFeatureAttributeID) +ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, + const Config_WidgetAPI* theData) +: ModuleBase_ModelWidget(theParent, theData) { - myGroupBox = new QGroupBox(theTitle, theParent); + myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM); + myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)), + theParent); QGridLayout* aGroupLay = new QGridLayout(myGroupBox); aGroupLay->setContentsMargins(0, 0, 0, 0); aGroupLay->setColumnStretch(1, 1); @@ -57,31 +65,62 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString t connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); } + myXSpin->installEventFilter(this); + myYSpin->installEventFilter(this); } ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D() { } -bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr theFeature) +bool ModuleBase_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue) +{ + bool isDone = false; + if (theValue) { + ModuleBase_WidgetValueFeature* aFeatureValue = + dynamic_cast(theValue); + if (aFeatureValue) { + boost::shared_ptr aPoint = aFeatureValue->point(); + if (aPoint) { + setPoint(aPoint); + isDone = true; + } + } + } + return isDone; +} + +void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr& thePoint) +{ + + bool isBlocked = this->blockSignals(true); + myXSpin->setValue(thePoint->x()); + myYSpin->setValue(thePoint->y()); + this->blockSignals(isBlocked); + + emit valuesChanged(); +} + +bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) const { boost::shared_ptr aData = theFeature->data(); boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); + boost::dynamic_pointer_cast(aData->attribute(attributeID())); - bool isBlocked = this->blockSignals(true); + ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this; + bool isBlocked = that->blockSignals(true); aPoint->setValue(myXSpin->value(), myYSpin->value()); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); + that->blockSignals(isBlocked); - this->blockSignals(isBlocked); return true; } -bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr theFeature) +bool ModuleBase_WidgetPoint2D::restoreValue(FeaturePtr theFeature) { boost::shared_ptr aData = theFeature->data(); boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); + boost::dynamic_pointer_cast(aData->attribute(attributeID())); bool isBlocked = this->blockSignals(true); myXSpin->setValue(aPoint->x()); @@ -94,3 +133,47 @@ QWidget* ModuleBase_WidgetPoint2D::getControl() const { return myGroupBox; } + +QList ModuleBase_WidgetPoint2D::getControls() const +{ + QList aControls; + aControls.push_back(myXSpin); + aControls.push_back(myYSpin); + + return aControls; +} + +bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent) +{ + if (theObject == myXSpin || theObject == myYSpin) { + if (theEvent->type() == QEvent::KeyRelease) { + QKeyEvent* aKeyEvent = (QKeyEvent*)theEvent; + if (aKeyEvent && aKeyEvent->key() == Qt::Key_Return) { + emit focusOutWidget(this); + } + emit keyReleased(attributeID(), (QKeyEvent*) theEvent); + return true; + } + } + return ModuleBase_ModelWidget::eventFilter(theObject, theEvent); +} + +bool ModuleBase_WidgetPoint2D::initFromPrevious(FeaturePtr theFeature) +{ + if (myOptionParam.length() == 0) + return false; + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(myOptionParam)); + if (aPoint) { + bool isBlocked = this->blockSignals(true); + myXSpin->setValue(aPoint->x()); + myYSpin->setValue(aPoint->y()); + this->blockSignals(isBlocked); + + emit valuesChanged(); + emit storedPoint2D(theFeature, myOptionParam); + return true; + } + return false; +}