Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Fri, 6 Jun 2014 13:38:45 +0000 (17:38 +0400)
committernds <natalia.donis@opencascade.com>
Fri, 6 Jun 2014 13:38:45 +0000 (17:38 +0400)
Code correction to set the focus widget for all ModelWidget children.

12 files changed:
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_ModelWidget.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_SelectorWidget.cpp
src/ModuleBase/ModuleBase_SelectorWidget.h
src/ModuleBase/ModuleBase_WidgetBoolValue.cpp
src/ModuleBase/ModuleBase_WidgetBoolValue.h
src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp
src/ModuleBase/ModuleBase_WidgetDoubleValue.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetPoint2D.cpp
src/ModuleBase/ModuleBase_WidgetPoint2D.h

index 22c359484374cdee38fcc68eda2918bc4fa64045..4593a68fe499a7c5c8ed37b28979c1f9d8238bc9 100644 (file)
@@ -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 (file)
index 0000000..089b1e6
--- /dev/null
@@ -0,0 +1,38 @@
+// File:        ModuleBase_ModelWidget.h
+// Created:     25 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#include "ModuleBase_ModelWidget.h"
+
+#include "Config_WidgetAPI.h"
+
+#include <QWidget>
+
+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<QWidget*> aControls = getControls();
+  QList<QWidget*>::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;
+}
index c203579420b29a78e13f0c0d7e907d9678e348ab..286d16f06b2baeeda38fc5875ce3b8789ff915e9 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <boost/shared_ptr.hpp>
 
+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
index f6945234c70eaff528582abe1819314cc5688087..f3f19b152adac3eb91733aa5463e41638e5d44cd 100644 (file)
 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<ModelAPI_AttributeReference> aRef = 
-    boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
+    boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(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<ModelAPI_AttributeReference> aRef = aData->reference(myFeatureAttributeID);
+  boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
 
   bool isBlocked = this->blockSignals(true);
   mySelectedFeature = aRef->value();
index 45ef3d64f82edbb7f0260c5b2d5a71879e7c0e9c..48e3984ff13e994307bd8c856b35c4dfb2854cb6 100644 (file)
@@ -63,8 +63,6 @@ private:
   void updateSelectionName();
   void raisePanel() const;
 
-  std::string myFeatureAttributeID;
-
   QWidget*     myContainer;
   QLabel*      myLabel;
   QLineEdit*   myTextLine;
index d55bd18e05620013e0f3c6abd7c8b3df079ef6c2..a34a73d6f02bedf6c2250345486d16cff2c3dff3 100644 (file)
@@ -4,7 +4,6 @@
 
 #include <ModuleBase_WidgetBoolValue.h>
 
-#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_Data.h>
 
 
 #include <QWidget>
 #include <QLayout>
-#include <QLabel>
-#include <QDoubleSpinBox>
 #include <QCheckBox>
 
 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<ModelAPI_AttributeBoolean> aBool = aData->boolean(myAttributeID);
+  boost::shared_ptr<ModelAPI_AttributeBoolean> 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<ModelAPI_AttributeBoolean> aRef = aData->boolean(myAttributeID);
+  boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
 
   bool isBlocked = myCheckBox->blockSignals(true);
   myCheckBox->setChecked(aRef->value());
index 8753c4cfd5ba91dca9377c8a4a465ce9d8d21253..6f32ef3ef87183b2961ead0fb7389d444a4a77c9 100644 (file)
 
 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;
 };
 
index d65091fd1a321cc2e97e3257a404baf660b20152..6ec34c3cae73dbf2fe57d8da3e0e2f7506a0f80b 100644 (file)
@@ -5,7 +5,6 @@
 #include <ModuleBase_WidgetDoubleValue.h>
 
 #include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_Data.h>
 
 #include <Config_Keywords.h>
 #include <QLayout>
 #include <QLabel>
 #include <QDoubleSpinBox>
-#include <QCheckBox>
 
 
 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<ModelAPI_AttributeDouble> aReal = aData->real(myAttributeID);
+  boost::shared_ptr<ModelAPI_AttributeDouble> 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<ModelAPI_AttributeDouble> aRef = aData->real(myAttributeID);
+  boost::shared_ptr<ModelAPI_AttributeDouble> aRef = aData->real(attributeID());
 
   bool isBlocked = mySpinBox->blockSignals(true);
   mySpinBox->setValue(aRef->value());
index caab1955678fb6350606ba9f138f2afb33574aac..024e12ab7eadeca3383a58a106d472446eb5eb3d 100644 (file)
@@ -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;
index 1f2f6a673f3fe603a9b8df7adca4f5400123a1b3..4c011a454f7d05974be69764bf676f708b2d3af9 100644 (file)
@@ -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();
index 2d8c814798d423fb16cbbe8a1f1dee2bc1865ae9..4bfda9ed88af3056e82806e180c2b9d7b7dddcba 100644 (file)
@@ -5,6 +5,7 @@
 #include <ModuleBase_WidgetPoint2D.h>
 
 #include <Config_Keywords.h>
+#include <Config_WidgetAPI.h>
 
 #include <Events_Loop.h>
 #include <Model_Events.h>
 #include <cfloat>
 #include <climits>
 
-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<ModelAPI_Data> aData = theFeature->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
-    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(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<ModelAPI_Data> aData = theFeature->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
-    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(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;
     }
   }
index 85c4c938d5aa0e6dfd69a2b768debcfd44f74bff..4e4dd152f28536057150fd7925ea9e75b890778f 100644 (file)
@@ -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