Salome HOME
Property pannel refactoring: focus processing in paged widgets
authorsbh <sergey.belash@opencascade.com>
Fri, 6 Mar 2015 08:23:59 +0000 (11:23 +0300)
committersbh <sergey.belash@opencascade.com>
Fri, 6 Mar 2015 08:23:59 +0000 (11:23 +0300)
21 files changed:
src/Config/Config_WidgetAPI.cpp
src/Config/Config_WidgetAPI.h
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_PageBase.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_PageBase.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_PageGroupBox.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_PageGroupBox.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_PageWidget.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_PageWidget.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetFactory.h
src/ModuleBase/ModuleBase_WidgetSwitch.cpp
src/ModuleBase/ModuleBase_WidgetSwitch.h
src/ModuleBase/ModuleBase_WidgetToolbox.cpp
src/ModuleBase/ModuleBase_WidgetToolbox.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_PropertyPanel.h
src/XGUI/XGUI_Workshop.cpp

index bcf543bd17e21d93e81cfa832545a3672d594d8c..1249f9ab817ecd59e05b037d57a0390ad19caa40 100644 (file)
@@ -72,16 +72,16 @@ std::string Config_WidgetAPI::widgetType() const
   return result;
 }
 
-bool Config_WidgetAPI::isContainerWidget() const
+bool Config_WidgetAPI::isGroupBoxWidget() const
 {
   return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP,
-  NULL);
+                NULL);
 }
 
 bool Config_WidgetAPI::isPagedWidget() const
 {
   return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH,
-  NULL);
+                NULL);
 }
 
 std::string Config_WidgetAPI::getProperty(const char* thePropName) const
index a44ce55a42cae5ab7ee18d7469b7d7e6fdcb258e..e9531e49fb7af27c9615c666c2e172a0a7af2df9 100644 (file)
@@ -40,7 +40,7 @@ class CONFIG_EXPORT Config_WidgetAPI
   //! Returns name of widget's node (attribute)
   std::string widgetType() const;
   //! Returns true if widget has container type, which means it able to contain other widgets
-  bool isContainerWidget() const;
+  bool isGroupBoxWidget() const;
   //! Returns true if widget has page type;
   //! Page is container widget with combo box control to switch between pages
   bool isPagedWidget() const;
index 8104818536889a5862e6e440cbbe911b93f91394..ea3235e1982f7c6642c5d1f815b5bcbda724631c 100644 (file)
@@ -45,6 +45,9 @@ SET(PROJECT_HEADERS
        ModuleBase_Preferences.h
        ModuleBase_ActionInfo.h
        ModuleBase_WidgetToolbox.h
+       ModuleBase_PageBase.h
+       ModuleBase_PageWidget.h 
+       ModuleBase_PageGroupBox.h
 )
 
 SET(PROJECT_SOURCES
@@ -80,6 +83,9 @@ SET(PROJECT_SOURCES
        ModuleBase_Preferences.cpp
        ModuleBase_ActionInfo.cpp
        ModuleBase_WidgetToolbox.cpp
+       ModuleBase_PageBase.cpp
+       ModuleBase_PageWidget.cpp
+       ModuleBase_PageGroupBox.cpp
 )
 
 SET(PROJECT_LIBRARIES
index 3c3d33878f7462ccc7db2fcf54b4d2b2705d7dbb..9d59e0ffe2797383d3212ab5fab534d5e98ab8e9 100644 (file)
@@ -86,9 +86,8 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
   /// \param theWidgetApi the widget configuation. The attribute of the model widget is obtained from\r
   /// \param theParentId is Id of a parent of the current attribute\r
   /// \param theModelWidgets list of widget objects\r
-  virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
-                                      Config_WidgetAPI* theWidgetApi, std::string theParentId,\r
-                                      QList<ModuleBase_ModelWidget*>& theModelWidgets)\r
+  virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
+                                      Config_WidgetAPI* theWidgetApi, std::string theParentId)\r
   {\r
     return 0;\r
   }\r
diff --git a/src/ModuleBase/ModuleBase_PageBase.cpp b/src/ModuleBase/ModuleBase_PageBase.cpp
new file mode 100644 (file)
index 0000000..5adaebf
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * ModuleBase_PageBase.cpp
+ *
+ *  Created on: Mar 4, 2015
+ *      Author: sbh
+ */
+
+#include <ModuleBase_PageBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+#include <QLayout>
+
+class QWidget;
+
+ModuleBase_PageBase::ModuleBase_PageBase()
+{
+
+}
+
+ModuleBase_PageBase::~ModuleBase_PageBase()
+{
+
+}
+
+void ModuleBase_PageBase::addModelWidget(ModuleBase_ModelWidget* theWidget)
+{
+  placeModelWidget(theWidget);
+  myWidgetList.append(theWidget);
+}
+
+void ModuleBase_PageBase::addPageWidget(ModuleBase_PageBase* thePage)
+{
+  placePageWidget(thePage);
+}
+
+void ModuleBase_PageBase::clearPage()
+{
+  qDeleteAll(pageLayout()->children());
+  myWidgetList.clear();
+}
+
+
+void ModuleBase_PageBase::takeFocus()
+{
+  if(myWidgetList.isEmpty())
+    return;
+
+  myWidgetList.first()->focusTo();
+}
+
+QList<ModuleBase_ModelWidget*> ModuleBase_PageBase::modelWidgets()
+{
+  return myWidgetList;
+}
diff --git a/src/ModuleBase/ModuleBase_PageBase.h b/src/ModuleBase/ModuleBase_PageBase.h
new file mode 100644 (file)
index 0000000..3b8bdf3
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * ModuleBase_PageBase.h
+ *
+ *  Created on: Mar 4, 2015
+ *      Author: sbh
+ */
+
+#ifndef MODULEBASE_PAGEBASE_H_
+#define MODULEBASE_PAGEBASE_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_Tools.h>
+
+class ModuleBase_ModelWidget;
+class QLayout;
+class QWidget;
+
+/*!
+ * Represent a property panel's list of ModuleBase_ModelWidgets.
+ */
+class MODULEBASE_EXPORT ModuleBase_PageBase
+{
+ public:
+  ModuleBase_PageBase();
+  virtual ~ModuleBase_PageBase();
+
+  void addModelWidget(ModuleBase_ModelWidget* theWidget);
+  void addPageWidget(ModuleBase_PageBase* theWidget);
+
+  void clearPage();
+  void takeFocus();
+  QList<ModuleBase_ModelWidget*> modelWidgets();
+
+ protected:
+  virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget) = 0;
+  virtual void placePageWidget(ModuleBase_PageBase* theWidget) = 0;
+  virtual QLayout* pageLayout() = 0;
+
+ private:
+  QList<ModuleBase_ModelWidget*> myWidgetList;
+
+};
+
+#endif /* MODULEBASE_PAGEBASE_H_ */
diff --git a/src/ModuleBase/ModuleBase_PageGroupBox.cpp b/src/ModuleBase/ModuleBase_PageGroupBox.cpp
new file mode 100644 (file)
index 0000000..1043a02
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * ModuleBase_PageGroupBox.cpp
+ *
+ *  Created on: Mar 4, 2015
+ *      Author: sbh
+ */
+
+#include <ModuleBase_PageGroupBox.h>
+#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_Tools.h>
+
+#include <QGridLayout>
+
+ModuleBase_PageGroupBox::ModuleBase_PageGroupBox(QWidget* theParent)
+: QGroupBox(theParent)
+{
+  myMainLayout = new QGridLayout(this);
+  ModuleBase_Tools::adjustMargins(myMainLayout);
+  setLayout(myMainLayout);
+}
+
+ModuleBase_PageGroupBox::~ModuleBase_PageGroupBox()
+{
+}
+
+void ModuleBase_PageGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget)
+{
+  const int kCol = 0;
+  const int kRow = myMainLayout->count();
+  myMainLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft);
+}
+
+void ModuleBase_PageGroupBox::placePageWidget(ModuleBase_PageBase* theWidget)
+{
+  QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
+  if (!aWidget) {
+    #ifdef _DEBUG
+    std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl;
+    #endif
+    return;
+  }
+  const int kCol = 0;
+  const int kRow = myMainLayout->count();
+  myMainLayout->addWidget(aWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft);
+}
+
+QLayout* ModuleBase_PageGroupBox::pageLayout()
+{
+  return myMainLayout;
+}
diff --git a/src/ModuleBase/ModuleBase_PageGroupBox.h b/src/ModuleBase/ModuleBase_PageGroupBox.h
new file mode 100644 (file)
index 0000000..dfc1ada
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * ModuleBase_PageGroupBox.h
+ *
+ *  Created on: Mar 4, 2015
+ *      Author: sbh
+ */
+
+#ifndef MODULEBASE_PAGEGROUPBOX_H_
+#define MODULEBASE_PAGEGROUPBOX_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_PageBase.h>
+
+#include <QGroupBox>
+#include <QList>
+
+class ModuleBase_ModelWidget;
+class QGridLayout;
+
+
+/*!
+ * Represent a property panel's list of ModuleBase_ModelWidgets.
+ */
+class MODULEBASE_EXPORT ModuleBase_PageGroupBox : public QGroupBox, public ModuleBase_PageBase
+{
+ public:
+  explicit ModuleBase_PageGroupBox(QWidget* theParent = 0);
+  virtual ~ModuleBase_PageGroupBox();
+
+ protected:
+  virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
+  virtual void placePageWidget(ModuleBase_PageBase* theWidget);
+  virtual QLayout* pageLayout();
+
+ private:
+  QGridLayout* myMainLayout;
+};
+
+#endif /* MODULEBASE_PAGEGROUPBOX_H_ */
diff --git a/src/ModuleBase/ModuleBase_PageWidget.cpp b/src/ModuleBase/ModuleBase_PageWidget.cpp
new file mode 100644 (file)
index 0000000..a75a6cf
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * ModuleBase_PageWidget.cpp
+ *
+ *  Created on: Mar 4, 2015
+ *      Author: sbh
+ */
+
+#include <ModuleBase_PageWidget.h>
+#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_Tools.h>
+
+#include <QGridLayout>
+
+ModuleBase_PageWidget::ModuleBase_PageWidget(QWidget* theParent)
+: QFrame(theParent)
+{
+  myMainLayout = new QGridLayout(this);
+  ModuleBase_Tools::adjustMargins(myMainLayout);
+  setLayout(myMainLayout);
+}
+
+ModuleBase_PageWidget::~ModuleBase_PageWidget()
+{
+}
+
+void ModuleBase_PageWidget::placeModelWidget(ModuleBase_ModelWidget* theWidget)
+{
+  const int kCol = 0;
+  const int kRow = myMainLayout->count();
+  myMainLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft);
+}
+
+void ModuleBase_PageWidget::placePageWidget(ModuleBase_PageBase* theWidget)
+{
+  QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
+  if (!aWidget) {
+    #ifdef _DEBUG
+    std::cout << "ModuleBase_PageWidget::placePageWidget: can not cast page" << std::endl;
+    #endif
+    return;
+  }
+  const int kCol = 0;
+  const int kRow = myMainLayout->count();
+  myMainLayout->addWidget(aWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft);
+}
+
+QLayout* ModuleBase_PageWidget::pageLayout()
+{
+  return myMainLayout;
+}
diff --git a/src/ModuleBase/ModuleBase_PageWidget.h b/src/ModuleBase/ModuleBase_PageWidget.h
new file mode 100644 (file)
index 0000000..a39d660
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * ModuleBase_PageWidget.h
+ *
+ *  Created on: Mar 4, 2015
+ *      Author: sbh
+ */
+
+#ifndef MODULEBASE_PAGEWIDGET_H_
+#define MODULEBASE_PAGEWIDGET_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_PageBase.h>
+
+#include <QFrame>
+#include <QList>
+
+class ModuleBase_ModelWidget;
+class QGridLayout;
+
+/*!
+ * Represent a property panel's list of ModuleBase_ModelWidgets.
+ */
+class MODULEBASE_EXPORT ModuleBase_PageWidget : public QFrame, public ModuleBase_PageBase
+{
+ public:
+  explicit ModuleBase_PageWidget(QWidget* theParent = 0);
+  virtual ~ModuleBase_PageWidget();
+
+ protected:
+  virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
+  virtual void placePageWidget(ModuleBase_PageBase* theWidget);
+  virtual QLayout* pageLayout();
+
+ private:
+  QGridLayout* myMainLayout;
+};
+
+#endif /* MODULEBASE_PAGEWIDGET_H_ */
index c5e6e58e8e0ab09104641196eaa4f74613ecdc3e..25f3c1979f87c9ecbfb1ddf35c780104317705a8 100644 (file)
@@ -28,6 +28,9 @@
 #include <ModuleBase_WidgetMultiSelector.h>
 #include <ModuleBase_WidgetLabel.h>
 #include <ModuleBase_WidgetToolbox.h>
+#include <ModuleBase_PageBase.h>
+#include <ModuleBase_PageGroupBox.h>
+#include <ModuleBase_PageWidget.h>
 
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
@@ -64,60 +67,67 @@ ModuleBase_WidgetFactory::~ModuleBase_WidgetFactory()
   delete myWidgetApi;
 }
 
-void ModuleBase_WidgetFactory::createWidget(QWidget* theParent)
+void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
 {
   myParentId = myWidgetApi->widgetId();
   if (!myWidgetApi->toChildWidget())
     return;
 
-  QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent);
-  bool isStretchLayout = false;
+  //bool isStretchLayout = false;
+  QWidget* aPageWidget = dynamic_cast<QWidget*>(thePage);
+  if(!aPageWidget) {
+    #ifdef _DEBUG
+    std::cout << "ModuleBase_WidgetFactory::createWidget: can not reinterpret_cast thePage" << std::endl;
+    #endif
+  }
   do {  //Iterate over each node
     std::string aWdgType = myWidgetApi->widgetType();
-    //Create a widget (doublevalue, groupbox, toolbox, etc.
-    QWidget* aWidget = createWidgetByType(aWdgType, theParent);
-    if (aWidget) {
-      if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) {
-        aWidgetLay->addWidget(aWidget);
-      } else {
-        aWidget->setVisible(false);
-      }
-    }
-    if (myWidgetApi->isContainerWidget()) {
+    // Create PageGroup TODO: extract
+    if (myWidgetApi->isGroupBoxWidget()) {
       //if current widget is groupbox (container) process it's children recursively
       QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
-      createWidget(aWidget);
-      ModuleBase_Tools::adjustMargins(aWidget);
-      QGroupBox* aGrBox = qobject_cast<QGroupBox*>(aWidget);
-      aGrBox->setTitle(aGroupName);
-    }
-    if (myWidgetApi->isPagedWidget()) {
-      //If current widget is toolbox or switch-casebox then fetch all
-      //it's pages recursively and setup into the widget.
-      myWidgetApi->toChildWidget();
-      do {
-        QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
-        QString aCaseId = qs(myWidgetApi->getProperty(_ID));
-        QWidget* aPage = new QWidget(aWidget);
-        createWidget(aPage);
-        ModuleBase_Tools::adjustMargins(aPage);
-        if (aWdgType == WDG_SWITCH) {
-          ModuleBase_WidgetSwitch* aSwitch = qobject_cast<ModuleBase_WidgetSwitch*>(aWidget);
-          aSwitch->addPage(aPage, aPageName);
-        } else if (aWdgType == WDG_TOOLBOX) {
-          ModuleBase_WidgetToolbox* aToolbox = qobject_cast<ModuleBase_WidgetToolbox*>(aWidget);
-          aToolbox->addPage(aPage, aPageName, aCaseId);
+      ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(aPageWidget);
+      aPage->setTitle(aGroupName);
+      createWidget(aPage);
+      thePage->addPageWidget(aPage);
+    } else {
+      // Create a ModelWidget
+      ModuleBase_ModelWidget* aWidget = createWidgetByType(aWdgType, aPageWidget);
+      if (aWidget) {
+        if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) {
+          thePage->addModelWidget(aWidget);
+        } else {
+          aWidget->setVisible(false);
         }
-      } while (myWidgetApi->toNextWidget());
-    }
-    if (aWidget && !isStretchLayout) {
-      isStretchLayout = !hasExpandingControls(aWidget);
+      }
+      // Create PagedContainer TODO: extract
+      if (myWidgetApi->isPagedWidget()) {
+        //If current widget is toolbox or switch-casebox then fetch all
+        //it's pages recursively and setup into the widget.
+        myWidgetApi->toChildWidget();
+        do {
+          QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
+          QString aCaseId = qs(myWidgetApi->getProperty(_ID));
+          ModuleBase_PageBase* aPage = new ModuleBase_PageWidget(aWidget);
+          createWidget(aPage);
+          QWidget* aCasePageWidget = dynamic_cast<QWidget*>(aPage);
+          if (aWdgType == WDG_SWITCH) {
+            ModuleBase_WidgetSwitch* aSwitch = qobject_cast<ModuleBase_WidgetSwitch*>(aWidget);
+            aSwitch->addPage(aCasePageWidget, aPageName);
+          } else if (aWdgType == WDG_TOOLBOX) {
+            ModuleBase_WidgetToolbox* aToolbox = qobject_cast<ModuleBase_WidgetToolbox*>(aWidget);
+            aToolbox->addPage(aCasePageWidget, aPageName, aCaseId);
+          }
+        } while (myWidgetApi->toNextWidget());
+      }
     }
+//    if (aWidget && !isStretchLayout) {
+//      isStretchLayout = !hasExpandingControls(aWidget);
+//    }
   } while (myWidgetApi->toNextWidget());
-  if (isStretchLayout) {
-    aWidgetLay->addStretch(1);
-  }
-  theParent->setLayout(aWidgetLay);
+//  if (isStretchLayout) {
+//    aWidgetLay->addStretch(1);
+//  }
 }
 
 bool ModuleBase_WidgetFactory::hasExpandingControls(QWidget* theParent)
@@ -138,142 +148,59 @@ bool ModuleBase_WidgetFactory::hasExpandingControls(QWidget* theParent)
   return result;
 }
 
-QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType,
-                                                      QWidget* theParent)
+ModuleBase_ModelWidget* ModuleBase_WidgetFactory
+::createWidgetByType(const std::string& theType, QWidget* theParent)
 {
-  QWidget* result = NULL;
-  if (theType == WDG_DOUBLEVALUE) {
-    result = doubleSpinBoxControl(theParent);
+  ModuleBase_ModelWidget* result = NULL;
+
+  if (theType == WDG_INFO) {
+    result = new ModuleBase_WidgetLabel(theParent, myWidgetApi, myParentId);
 
-  } else if (theType == WDG_INFO) {
-    result = labelControl(theParent);
+  } else if (theType == WDG_DOUBLEVALUE) {
+    result = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId);
 
   } else if (theType == WDG_SHAPE_SELECTOR) {
-    result = shapeSelectorControl(theParent);
+    result =  new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId);
 
   } else if (theType == WDG_BOOLVALUE) {
-    result = booleanControl(theParent);
+    result = new ModuleBase_WidgetBoolValue(theParent, myWidgetApi, myParentId);
 
   } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
-    result = doubleValueEditor(theParent);
+    result = new ModuleBase_WidgetEditor(theParent, myWidgetApi, myParentId);
 
   } else if (theType == WDG_FILE_SELECTOR) {
-    result = fileSelectorControl(theParent);
+    result = new ModuleBase_WidgetFileSelector(theParent, myWidgetApi, myParentId);
 
   } else if (theType == WDG_CHOICE) {
-    result = choiceControl(theParent);
+    result = new ModuleBase_WidgetChoice(theParent, myWidgetApi,myParentId);
 
   } else if (theType == WDG_STRINGVALUE) {
-    result = lineEditControl(theParent);
+    result = new ModuleBase_WidgetLineEdit(theParent, myWidgetApi,myParentId);
 
   } else if (theType == WDG_MULTISELECTOR) {
-    result = multiSelectorControl(theParent);
+    result = new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi,myParentId);
+
+  } else if (theType == WDG_TOOLBOX) {
+    result = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId);
 
-  } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
-    result = createContainer(theType, theParent);
+  } else if (theType == WDG_SWITCH) {
+    result = new ModuleBase_WidgetSwitch(theParent, myWidgetApi, myParentId);
+    return result;
+
+  } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) {
+    // Do nothing for "box" and "case"
+    result = NULL;
   } else {
     result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi,
-                                                      myParentId, myModelWidgets);
+                                                      myParentId);
 #ifdef _DEBUG
     if (!result) {qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type");}
 #endif
   }
-  return result;
-}
-
-QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, QWidget* theParent)
-{
-  QWidget* aResult = NULL;
-  if (theType == WDG_GROUP || theType == WDG_CHECK_GROUP) {
-    QGroupBox* aGroupBox = new QGroupBox(theParent);
-    aGroupBox->setCheckable(theType == WDG_CHECK_GROUP);
-    aResult = aGroupBox;
-  } else if (theType == WDG_TOOLBOX) {
-    ModuleBase_WidgetToolbox* aWdg = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId);
-    myModelWidgets.append(aWdg);
-    aResult = aWdg;
-  } else if (theType == WDG_SWITCH) {
-    aResult = new ModuleBase_WidgetSwitch(theParent);
-  } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) {
-    // Do nothing for "box" and "case"
-    aResult = NULL;
+  if (result) {
+    myModelWidgets.append(result);
   }
-#ifdef _DEBUG
-  else {qDebug() << "ModuleBase_WidgetFactory::fillWidget: find bad container type";}
-#endif
-  return aResult;
-}
-
-QWidget* ModuleBase_WidgetFactory::labelControl(QWidget* theParent)
-{
-  ModuleBase_WidgetLabel* aWgt =
-      new ModuleBase_WidgetLabel(theParent, myWidgetApi, myParentId);
-  myModelWidgets.append(aWgt);
-  return aWgt;
-}
-
-QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent)
-{
-  ModuleBase_WidgetDoubleValue* aDblWgt =
-      new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId);
-  myModelWidgets.append(aDblWgt);
-  return aDblWgt;
-}
-
-QWidget* ModuleBase_WidgetFactory::doubleValueEditor(QWidget* theParent)
-{
-  ModuleBase_WidgetEditor* aWidget =
-      new ModuleBase_WidgetEditor(theParent, myWidgetApi, myParentId);
-  myModelWidgets.append(aWidget);
-  return aWidget;
-}
-
-QWidget* ModuleBase_WidgetFactory::shapeSelectorControl(QWidget* theParent)
-{
-  ModuleBase_WidgetShapeSelector* aSelector =
-      new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId);
-  myModelWidgets.append(aSelector);
-  return aSelector;
-}
-
-QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent)
-{
-  ModuleBase_WidgetBoolValue* aBoolWgt =
-      new ModuleBase_WidgetBoolValue(theParent, myWidgetApi, myParentId);
-  myModelWidgets.append(aBoolWgt);
-  return aBoolWgt;
-}
-
-QWidget* ModuleBase_WidgetFactory::fileSelectorControl(QWidget* theParent)
-{
-  ModuleBase_WidgetFileSelector* aFileSelectorWgt =
-      new ModuleBase_WidgetFileSelector(theParent, myWidgetApi, myParentId);
-  myModelWidgets.append(aFileSelectorWgt);
-  return aFileSelectorWgt;
-}
-
-QWidget* ModuleBase_WidgetFactory::choiceControl(QWidget* theParent)
-{
-  ModuleBase_WidgetChoice* aChoiceWgt =
-      new ModuleBase_WidgetChoice(theParent, myWidgetApi,myParentId);
-  myModelWidgets.append(aChoiceWgt);
-  return aChoiceWgt;
-}
-
-QWidget* ModuleBase_WidgetFactory::lineEditControl(QWidget* theParent)
-{
-  ModuleBase_WidgetLineEdit* aLineEditWgt =
-      new ModuleBase_WidgetLineEdit(theParent, myWidgetApi,myParentId);
-  myModelWidgets.append(aLineEditWgt);
-  return aLineEditWgt;
-}
-
-QWidget* ModuleBase_WidgetFactory::multiSelectorControl(QWidget* theParent)
-{
-  ModuleBase_WidgetMultiSelector* aMultiselectorWgt =
-      new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi,myParentId);
-  myModelWidgets.append(aMultiselectorWgt);
-  return aMultiselectorWgt;
+  return result;
 }
 
 QString ModuleBase_WidgetFactory::qs(const std::string& theStdString)
index 71834e86d3db0d8bfe80e377eff9eef5c6400c14..1e1f29fa76e8dfc54e6de9b682f1efc2881cc0f5 100644 (file)
@@ -7,11 +7,11 @@
  *      Author: sbh
  */
 
-#ifndef ModuleBase_WidgetFactory_H_
-#define ModuleBase_WidgetFactory_H_
+#ifndef MODULEBASE_WIDGETFACTORY_H_
+#define MODULEBASE_WIDGETFACTORY_H_
 
-#include "ModuleBase.h"
-#include "ModuleBase_ModelWidget.h"
+#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
 
 #include <QString>
 #include <QList>
@@ -20,6 +20,7 @@ class QObject;
 class QWidget;
 class Config_WidgetAPI;
 class ModuleBase_IWorkshop;
+class ModuleBase_PageBase;
 
 /**
 * \ingroup GUI
@@ -38,7 +39,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory
 
   /// Creates content widget for property panel
   /// \param theParent a parent widget
-  void createWidget(QWidget* theParent);
+  void createWidget(ModuleBase_PageBase* theParent);
 
 
   /// Returns list of model widgets
@@ -53,48 +54,8 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory
    /// Create widget by its type
    /// \param theType a type
    /// \param theParent a parent widget
-  QWidget* createWidgetByType(const std::string& theType, QWidget* theParent = NULL);
-
-   /// Create a widget of container type
-   /// \param theType a type
-   /// \param theParent a parent widget
-  QWidget* createContainer(const std::string& theType, QWidget* theParent);
-
-  /// Create label widget
-  /// \param theParent a parent widget
-  QWidget* labelControl(QWidget* theParent);
-
-  /// Create double spin box widget
-  /// \param theParent a parent widget
-  QWidget* doubleSpinBoxControl(QWidget* theParent);
-
-  /// Create double value editor widget
-  /// \param theParent a parent widget
-  QWidget* doubleValueEditor(QWidget* theParent);
-
-  /// Create shape selector widget
-  /// \param theParent a parent widget
-  QWidget* shapeSelectorControl(QWidget* theParent);
-
-  /// Create boolean input widget
-  /// \param theParent a parent widget
-  QWidget* booleanControl(QWidget* theParent);
-
-  /// Create file selector widget
-  /// \param theParent a parent widget
-  QWidget* fileSelectorControl(QWidget* theParent);
-
-  /// Create choice widget (combo box)
-  /// \param theParent a parent widget
-  QWidget* choiceControl(QWidget* theParent);
-
-  /// Create line edit widget
-  /// \param theParent a parent widget
-  QWidget* lineEditControl(QWidget* theParent);
-
-  /// Create multi selector widget
-  /// \param theParent a parent widget
-  QWidget* multiSelectorControl(QWidget* theParent);
+  ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
+                                             QWidget* theParent = NULL);
 
   /// Convert STD string to QT string
   /// \param theStdString is STD string
index e1571cab161848fa45b510b48aa75cbc410ca996..aec77a6b99403faccf2023d2ce21d5c00184cada 100644 (file)
@@ -8,20 +8,24 @@
  */
 
 #include <ModuleBase_WidgetSwitch.h>
+#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_PageBase.h>
 
 #include <QComboBox>
 #include <QVBoxLayout>
 #include <QSpacerItem>
 
-ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* parent)
-    : QFrame(parent)
+
+ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* theParent, const Config_WidgetAPI* theData,
+                                                 const std::string& theParentId)
+: ModuleBase_ModelWidget(theParent, theData, theParentId)
 {
   myMainLay = new QVBoxLayout(this);
   myMainLay->setContentsMargins(2, 4, 2, 2);
   myCombo = new QComboBox(this);
   myCombo->hide();
   myMainLay->addWidget(myCombo);
-  this->setFrameShape(QFrame::StyledPanel);
+  //this->setFrameShape(QFrame::StyledPanel);
   connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentIndex(int)));
   connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(currentPageChanged(int)));
 
@@ -31,6 +35,13 @@ ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
 {
 }
 
+QList<QWidget*> ModuleBase_WidgetSwitch::getControls() const
+{
+  QList<QWidget*> aList;
+  aList << myCombo;
+  return aList;
+}
+
 int ModuleBase_WidgetSwitch::addPage(QWidget* theWidget, const QString& theName)
 {
   return insertPage(count(), theWidget, theName);
index f105bc6fda25ba4c75eb4220ecc5f581f445c5bc..1f10c2eead1072a7116d95eeaf2e156248d7a4d8 100644 (file)
@@ -11,7 +11,7 @@
 #define ModuleBase_WidgetSwitch_H_
 
 #include <ModuleBase.h>
-#include <QFrame>
+#include <ModuleBase_ModelWidget.h>
 
 class QComboBox;
 class QVBoxLayout;
@@ -20,19 +20,31 @@ class QVBoxLayout;
 * \ingroup GUI
 * Implements a model widget for swithch as a container widget. It can be defined in XML with "switch" keyword
 */
-class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public QFrame
+class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public ModuleBase_ModelWidget
 {
-Q_OBJECT
+  Q_OBJECT
  public:
    /// Constructor
    /// \param parent a parent widget
-  ModuleBase_WidgetSwitch(QWidget* parent = NULL);
+  ModuleBase_WidgetSwitch(QWidget* theParent,
+                          const Config_WidgetAPI* theData,
+                          const std::string& theParentId);
   virtual ~ModuleBase_WidgetSwitch();
 
+  virtual bool restoreValue() {
+    return false;
+  }
+
+  virtual QList<QWidget*> getControls() const;
+
+  virtual bool focusTo() {
+    return false;
+  }
+
   /// Add a page to the widget
   /// \param theWidget a page widget
   /// \param theName a name of page
-  int addPage(QWidget * theWidget, const QString & theName);
+  int addPage(QWidget* theWidget, const QString & theName);
 
   /// Returns count of pages
   int count() const;
@@ -94,6 +106,9 @@ signals:
   void currentPageChanged(int);
 
  protected:
+  virtual bool storeValueCustom() const {
+    return false;
+  }
   /// Update widget
   void refresh();
 
index 220be9b70616faf476bf0e9e85f41cff02907350..aeab11bbb0738f6402ea3fe7e44f5f6ca9224a2f 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include <ModuleBase_WidgetToolbox.h>
+#include <ModuleBase_PageBase.h>
 #include <ModuleBase_Tools.h>
 
 #include <ModelAPI_AttributeString.h>
@@ -71,6 +72,11 @@ QList<QWidget*> ModuleBase_WidgetToolbox::getControls() const
   return aList;
 }
 
+bool ModuleBase_WidgetToolbox::focusTo()
+{
+  return false;
+}
+
 bool ModuleBase_WidgetToolbox::storeValueCustom() const
 {
   // A rare case when plugin was not loaded.
index c57c75e02d625061ab943ebb23e93d3ce179939f..867623105adabfda81f8439cef0b90e85841df58 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <QToolBox>
 
+class ModuleBase_PageBase;
+
 class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget
 {
   Q_OBJECT
@@ -22,6 +24,7 @@ class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget
 
   virtual bool restoreValue();
   virtual QList<QWidget*> getControls() const;
+  virtual bool focusTo();
 
   int addPage(QWidget* theWidget, const QString& theName, const QString& theCaseId);
 
index d31bf8f7c65fa5894e17120e87272916c46ac7ca..44accc6cca089e6a07c24f17815c0679f2f09ed1 100644 (file)
@@ -436,9 +436,8 @@ void PartSet_Module::onVertexSelected()
   }
 }
 
-QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
-                                            Config_WidgetAPI* theWidgetApi, std::string theParentId,
-                                            QList<ModuleBase_ModelWidget*>& theModelWidgets)
+ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
+                                            Config_WidgetAPI* theWidgetApi, std::string theParentId)
 {
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
   XGUI_Workshop* aWorkshop = aConnector->workshop();
@@ -471,8 +470,6 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
     aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
     aWgt = aConstraintShapeSelectorWgt;
   }
-  if(aWgt)
-    theModelWidgets.append(aWgt);
   return aWgt;
 }
 
index 2bf2f44b063fc17a8c866b96d4d874e1754bafbf..aa5215e75abc71e4b2cfcc80f1239d277d2b1906 100644 (file)
@@ -52,9 +52,8 @@ public:
   virtual ~PartSet_Module();
 
   /// Creates custom widgets for property panel
-  virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
-                                      Config_WidgetAPI* theWidgetApi, std::string theParentId,
-                                      QList<ModuleBase_ModelWidget*>& theModelWidgets);
+  virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
+                                                     Config_WidgetAPI* theWidgetApi, std::string theParentId);
 
   /// Call back forlast tuning of property panel before operation performance
   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
index 1779431f5511a3dc204568139f8b334c7e9f72eb..0f02c5d933d964f5d5358477f45e01a29814dada 100644 (file)
@@ -12,6 +12,8 @@
 //#include <AppElements_Constants.h>
 #include <ModuleBase_WidgetMultiSelector.h>
 #include <ModuleBase_Tools.h>
+#include <ModuleBase_PageBase.h>
+#include <ModuleBase_PageWidget.h>
 
 #include <QEvent>
 #include <QFrame>
@@ -31,7 +33,8 @@
 
 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
     : ModuleBase_IPropertyPanel(theParent), 
-    myActiveWidget(NULL)
+    myActiveWidget(NULL),
+    myPanelPage(NULL)
 {
   this->setWindowTitle(tr("Property Panel"));
   QAction* aViewAct = this->toggleViewAction();
@@ -39,10 +42,10 @@ XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
   setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
 
   QWidget* aContent = new QWidget(this);
-  myMainLayout = new QGridLayout(aContent);
+  QGridLayout* aMainLayout = new QGridLayout(aContent);
   const int kPanelColumn = 0;
   int aPanelRow = 0;
-  myMainLayout->setContentsMargins(3, 3, 3, 3);
+  aMainLayout->setContentsMargins(3, 3, 3, 3);
   this->setWidget(aContent);
 
   QFrame* aFrm = new QFrame(aContent);
@@ -50,7 +53,7 @@ XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
   aFrm->setFrameShape(QFrame::Panel);
   QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
   ModuleBase_Tools::zeroMargins(aBtnLay);
-  myMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn);
+  aMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn);
 
   QStringList aBtnNames;
   aBtnNames << QString(PROP_PANEL_HELP)
@@ -64,10 +67,9 @@ XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
   }
   aBtnLay->insertStretch(1, 1);
 
-  myCustomWidget = new QWidget(aContent);
-  myCustomWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
-  myMainLayout->addWidget(myCustomWidget, aPanelRow, kPanelColumn);
-  setStretchEnabled(true);
+  myPanelPage = new ModuleBase_PageWidget(aContent);
+  myPanelPage->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
+  aMainLayout->addWidget(myPanelPage, aPanelRow, kPanelColumn);
 }
 
 XGUI_PropertyPanel::~XGUI_PropertyPanel()
@@ -79,7 +81,7 @@ void XGUI_PropertyPanel::cleanContent()
   if (myActiveWidget)
     myActiveWidget->deactivate();
   myWidgets.clear();
-  qDeleteAll(myCustomWidget->children());
+  myPanelPage->clearPage();
   myActiveWidget = NULL;
   setWindowTitle(tr("Property Panel"));
 }
@@ -116,9 +118,10 @@ const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
   return myWidgets;
 }
 
-QWidget* XGUI_PropertyPanel::contentWidget()
+ModuleBase_PageBase* XGUI_PropertyPanel::contentWidget()
 {
-  return myCustomWidget;
+
+  return static_cast<ModuleBase_PageBase*>(myPanelPage);
 }
 
 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
@@ -162,14 +165,6 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
   //}
 }
 
-void XGUI_PropertyPanel::setStretchEnabled(bool isEnabled)
-{
-  int aStretchIdx = myMainLayout->rowCount() - 1;
-  if (aStretchIdx < 0)
-    return;
-  myMainLayout->setRowStretch(aStretchIdx, isEnabled ? 1 : 0);
-}
-
 void XGUI_PropertyPanel::activateNextWidget()
 {
   activateNextWidget(myActiveWidget);
index 5d17060424687a4b5187498deb8a9841c9752665..cc9ba8aeb45453793c1b5cf1f08d4e9c64cedfa1 100644 (file)
@@ -20,6 +20,8 @@
 class XGUI_ActionsMgr;
 class QKeyEvent;
 class QGridLayout;
+class ModuleBase_PageBase;
+class ModuleBase_PageWidget;
 
 /// Internal name of property panel widget
 const static char* PROP_PANEL = "property_panel_dock";
@@ -50,7 +52,7 @@ Q_OBJECT
 
   /// Returns main widget of the property panel, which children will be created
   /// by WidgetFactory using the XML definition
-  QWidget* contentWidget();
+  ModuleBase_PageBase* contentWidget();
 
   /// Brings back all widget created by widget factory for signal/slot
   /// connections and further processing
@@ -72,9 +74,6 @@ Q_OBJECT
   /// Activate the next from current widget in the property panel
   virtual void activateNextWidget();
 
-  /// \brief Enable/Disable stretch area in the panel
-  void setStretchEnabled(bool isEnabled);
-
   /// Set Enable/Disable state of Cancel button
   /// \param theEnabled Enable/Disable state of Cancel button
   virtual void setCancelEnabled(bool theEnabled);
@@ -104,9 +103,8 @@ Q_OBJECT
   virtual void activateWidget(ModuleBase_ModelWidget* theWidget);
 
  private:
-  QWidget* myCustomWidget;
+  ModuleBase_PageWidget* myPanelPage;
   QList<ModuleBase_ModelWidget*> myWidgets;
-  QGridLayout* myMainLayout;
 
   /// Currently active widget
   ModuleBase_ModelWidget* myActiveWidget;
index 99311b558daec401d533944b8e7841cb295b80a7..ff3347b02c3cfa371121b43c86049441565a11e2 100644 (file)
@@ -646,7 +646,6 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
 
   myPropertyPanel->cleanContent();
   aFactory.createWidget(myPropertyPanel->contentWidget());
-  ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
 
   QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
   foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {