From: nds Date: Fri, 6 Jun 2014 13:38:45 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~307 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=79d1b40e0b4470fd0687077933d4b049c210400d;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc Code correction to set the focus widget for all ModelWidget children. --- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 22c359484..4593a68fe 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -20,6 +20,7 @@ SET(PROJECT_SOURCES ModuleBase_IOperation.cpp ModuleBase_Operation.cpp ModuleBase_OperationDescription.cpp + ModuleBase_ModelWidget.cpp ModuleBase_WidgetBoolValue.cpp ModuleBase_WidgetDoubleValue.cpp ModuleBase_WidgetFactory.cpp diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp new file mode 100644 index 000000000..089b1e637 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -0,0 +1,38 @@ +// File: ModuleBase_ModelWidget.h +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include "ModuleBase_ModelWidget.h" + +#include "Config_WidgetAPI.h" + +#include + +ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData) + : QObject(theParent) +{ + myAttributeID = theData ? theData->widgetId() : ""; +} + +bool ModuleBase_ModelWidget::canFocusTo(const std::string& theAttributeName) const +{ + return theAttributeName == attributeID(); +} + +void ModuleBase_ModelWidget::focusTo() +{ + QList aControls = getControls(); + QList::const_iterator anIt = aControls.begin(), aLast = aControls.end(); + for (; anIt != aLast; anIt++) { + QWidget* aWidget = *anIt; + if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) { + aWidget->setFocus(); + break; + } + } +} + +std::string ModuleBase_ModelWidget::attributeID() const +{ + return myAttributeID; +} diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index c20357942..286d16f06 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -13,6 +13,7 @@ #include +class Config_WidgetAPI; class ModelAPI_Feature; class QKeyEvent; @@ -30,7 +31,8 @@ class MODULEBASE_EXPORT ModuleBase_ModelWidget : public QObject public: /// Constructor /// \theParent the parent object - ModuleBase_ModelWidget(QObject* theParent) :QObject(theParent) {}; + /// \theData the widget configuation. The attribute of the model widget is obtained from + ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData); /// Destructor virtual ~ModuleBase_ModelWidget() {}; @@ -42,10 +44,11 @@ public: /// Returns whether the widget can accept focus, or if it corresponds to the given attribute /// \param theAttribute name - virtual bool canFocusTo(const std::string& theAttributeName) const { return false; } + bool canFocusTo(const std::string& theAttributeName) const; - /// Set focus to the current widget if it corresponds to the given attribute - virtual void focusTo() {} + /// Set focus to the first control of the current widget. The focus policy of the control is checked. + /// If the widget has the NonFocus focus policy, it is skipped. + virtual void focusTo(); /// Returns list of widget controls /// \return a control list @@ -58,6 +61,14 @@ signals: /// \param theAttributeName a name of the attribute /// \param theEvent key release event void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent); + +protected: + /// Returns the attribute name + /// \returns the string value + std::string attributeID() const; + +private: + std::string myAttributeID; /// the attribute name of the model feature }; #endif diff --git a/src/ModuleBase/ModuleBase_SelectorWidget.cpp b/src/ModuleBase/ModuleBase_SelectorWidget.cpp index f6945234c..f3f19b152 100644 --- a/src/ModuleBase/ModuleBase_SelectorWidget.cpp +++ b/src/ModuleBase/ModuleBase_SelectorWidget.cpp @@ -27,10 +27,8 @@ ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent), myWorkshop(theWorkshop), myActivateOnStart(false) +: ModuleBase_ModelWidget(theParent, theData), myWorkshop(theWorkshop), myActivateOnStart(false) { - myFeatureAttributeID = theData->widgetId(); - myContainer = new QWidget(theParent); QHBoxLayout* aLayout = new QHBoxLayout(myContainer); @@ -74,7 +72,7 @@ bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature) const { DataPtr aData = theFeature->data(); boost::shared_ptr aRef = - boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); + boost::dynamic_pointer_cast(aData->attribute(attributeID())); FeaturePtr aFeature = aRef->value(); if (!(aFeature && aFeature->isSame(mySelectedFeature))) { @@ -88,7 +86,7 @@ bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature) const bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature) { DataPtr aData = theFeature->data(); - boost::shared_ptr aRef = aData->reference(myFeatureAttributeID); + boost::shared_ptr aRef = aData->reference(attributeID()); bool isBlocked = this->blockSignals(true); mySelectedFeature = aRef->value(); diff --git a/src/ModuleBase/ModuleBase_SelectorWidget.h b/src/ModuleBase/ModuleBase_SelectorWidget.h index 45ef3d64f..48e3984ff 100644 --- a/src/ModuleBase/ModuleBase_SelectorWidget.h +++ b/src/ModuleBase/ModuleBase_SelectorWidget.h @@ -63,8 +63,6 @@ private: void updateSelectionName(); void raisePanel() const; - std::string myFeatureAttributeID; - QWidget* myContainer; QLabel* myLabel; QLineEdit* myTextLine; diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp index d55bd18e0..a34a73d6f 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp @@ -4,7 +4,6 @@ #include -#include #include #include @@ -16,14 +15,11 @@ #include #include -#include -#include #include ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData) - : ModuleBase_ModelWidget(theParent) + : ModuleBase_ModelWidget(theParent, theData) { - myAttributeID = theData->widgetId(); QString aText = QString::fromStdString(theData->widgetLabel()); QString aToolTip = QString::fromStdString(theData->widgetTooltip()); QString aDefault = QString::fromStdString(theData->getProperty("default")); @@ -47,7 +43,7 @@ QWidget* ModuleBase_WidgetBoolValue::getControl() const bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const { DataPtr aData = theFeature->data(); - boost::shared_ptr aBool = aData->boolean(myAttributeID); + boost::shared_ptr aBool = aData->boolean(attributeID()); if (aBool->value() != myCheckBox->isChecked()) { aBool->setValue(myCheckBox->isChecked()); @@ -59,7 +55,7 @@ bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const bool ModuleBase_WidgetBoolValue::restoreValue(FeaturePtr theFeature) { DataPtr aData = theFeature->data(); - boost::shared_ptr aRef = aData->boolean(myAttributeID); + boost::shared_ptr aRef = aData->boolean(attributeID()); bool isBlocked = myCheckBox->blockSignals(true); myCheckBox->setChecked(aRef->value()); diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.h b/src/ModuleBase/ModuleBase_WidgetBoolValue.h index 8753c4cfd..6f32ef3ef 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.h +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.h @@ -10,14 +10,15 @@ class Config_WidgetAPI; class QWidget; -class QLabel; -class QDoubleSpinBox; class QCheckBox; class MODULEBASE_EXPORT ModuleBase_WidgetBoolValue: public ModuleBase_ModelWidget { Q_OBJECT public: + /// Constructor + /// \theParent the parent object + /// \theData the widget configuation. The attribute of the model widget is obtained from ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData); virtual ~ModuleBase_WidgetBoolValue(); @@ -37,8 +38,6 @@ public: QWidget* getControl() const; private: - std::string myAttributeID; - QCheckBox* myCheckBox; }; diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index d65091fd1..6ec34c3ca 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -18,11 +17,10 @@ #include #include #include -#include ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData) - : ModuleBase_ModelWidget(theParent) + : ModuleBase_ModelWidget(theParent, theData) { myContainer = new QWidget(theParent); QHBoxLayout* aControlLay = new QHBoxLayout(myContainer); @@ -34,9 +32,8 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, c myLabel->setPixmap(QPixmap(aLabelIcon)); aControlLay->addWidget(myLabel); - myAttributeID = theData->widgetId(); mySpinBox = new QDoubleSpinBox(myContainer); - QString anObjName = QString::fromStdString(myAttributeID); + QString anObjName = QString::fromStdString(attributeID()); mySpinBox->setObjectName(anObjName); bool isOk = false; @@ -84,7 +81,7 @@ ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue() bool ModuleBase_WidgetDoubleValue::storeValue(FeaturePtr theFeature) const { DataPtr aData = theFeature->data(); - boost::shared_ptr aReal = aData->real(myAttributeID); + boost::shared_ptr aReal = aData->real(attributeID()); if (aReal->value() != mySpinBox->value()) { aReal->setValue(mySpinBox->value()); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); @@ -95,7 +92,7 @@ bool ModuleBase_WidgetDoubleValue::storeValue(FeaturePtr theFeature) const bool ModuleBase_WidgetDoubleValue::restoreValue(FeaturePtr theFeature) { DataPtr aData = theFeature->data(); - boost::shared_ptr aRef = aData->real(myAttributeID); + boost::shared_ptr aRef = aData->real(attributeID()); bool isBlocked = mySpinBox->blockSignals(true); mySpinBox->setValue(aRef->value()); diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h index caab19556..024e12ab7 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -12,12 +12,14 @@ class Config_WidgetAPI; class QWidget; class QLabel; class QDoubleSpinBox; -class QCheckBox; class MODULEBASE_EXPORT ModuleBase_WidgetDoubleValue: public ModuleBase_ModelWidget { Q_OBJECT public: + /// Constructor + /// \theParent the parent object + /// \theData the widget configuation. The attribute of the model widget is obtained from ModuleBase_WidgetDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData); virtual ~ModuleBase_WidgetDoubleValue(); @@ -37,8 +39,6 @@ public: QWidget* getControl() const { return myContainer; } private: - std::string myAttributeID; - QWidget* myContainer; QLabel* myLabel; QDoubleSpinBox* mySpinBox; diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 1f2f6a673..4c011a454 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -163,9 +163,7 @@ QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent) QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent) { - ModuleBase_WidgetPoint2D* aWidget = new ModuleBase_WidgetPoint2D(theParent, - qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)), - myWidgetApi->widgetId()); + ModuleBase_WidgetPoint2D* aWidget = new ModuleBase_WidgetPoint2D(theParent, myWidgetApi); connectWidget(aWidget, WDG_POINT_SELECTOR); myModelWidgets.append(aWidget); return aWidget->getControl(); diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index 2d8c81479..4bfda9ed8 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -24,11 +25,12 @@ #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); + 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); @@ -72,7 +74,7 @@ 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())); ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this; bool isBlocked = that->blockSignals(true); @@ -87,7 +89,7 @@ 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()); @@ -96,17 +98,6 @@ bool ModuleBase_WidgetPoint2D::restoreValue(FeaturePtr theFeature) return true; } -bool ModuleBase_WidgetPoint2D::canFocusTo(const std::string& theAttributeName) -{ - return theAttributeName == myFeatureAttributeID; -} - -void ModuleBase_WidgetPoint2D::focusTo() -{ - if (!myXSpin->hasFocus() && !myYSpin->hasFocus()) - myXSpin->setFocus(); -} - QWidget* ModuleBase_WidgetPoint2D::getControl() const { return myGroupBox; @@ -125,7 +116,7 @@ bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent) { if (theObject == myXSpin || theObject == myYSpin) { if (theEvent->type() == QEvent::KeyRelease) { - emit keyReleased(myFeatureAttributeID, (QKeyEvent*) theEvent); + emit keyReleased(attributeID(), (QKeyEvent*) theEvent); return true; } } diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.h b/src/ModuleBase/ModuleBase_WidgetPoint2D.h index 85c4c938d..4e4dd152f 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.h +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.h @@ -25,10 +25,9 @@ class MODULEBASE_EXPORT ModuleBase_WidgetPoint2D : public ModuleBase_ModelWidget public: /// Constructor /// \theParent the parent object - /// \theTitle the group box title - /// \theFeatureAttributeID the identifier of the feature attribute - ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle, - const std::string& theFeatureAttributeID); + /// \theParent the parent object + /// \theData the widget configuation. The attribute of the model widget is obtained from + ModuleBase_WidgetPoint2D(QWidget* theParent, const Config_WidgetAPI* theData); /// Destructor virtual ~ModuleBase_WidgetPoint2D(); @@ -38,13 +37,6 @@ public: virtual bool restoreValue(FeaturePtr theFeature); - /// Returns whether the widget can accept focus, or if it corresponds to the given attribute - /// \param theAttribute name - virtual bool canFocusTo(const std::string& theAttributeName); - - /// Set focus to the current widget if it corresponds to the given attribute - virtual void focusTo(); - /// Returns the internal parent wiget control, that can be shown anywhere /// \returns the widget QWidget* getControl() const; @@ -56,7 +48,6 @@ public: virtual bool eventFilter(QObject *theObject, QEvent *theEvent); private: - std::string myFeatureAttributeID; ///< the identifier of the feature attribute QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets QDoubleSpinBox* myXSpin; ///< the spin box for the X coordinate QDoubleSpinBox* myYSpin; ///< the spin box for the Y coordinate