Salome HOME
Issue #1368: Creation of a Qt panel. Widget creator interface correction to manage...
authornds <nds@opencascade.com>
Tue, 29 Mar 2016 09:21:53 +0000 (12:21 +0300)
committernds <nds@opencascade.com>
Tue, 29 Mar 2016 09:21:53 +0000 (12:21 +0300)
15 files changed:
src/Config/Config_Keywords.h
src/ModuleBase/ModuleBase_IWidgetCreator.cpp
src/ModuleBase/ModuleBase_IWidgetCreator.h
src/ModuleBase/ModuleBase_PageBase.cpp
src/ModuleBase/ModuleBase_PageBase.h
src/ModuleBase/ModuleBase_PageGroupBox.cpp
src/ModuleBase/ModuleBase_PageGroupBox.h
src/ModuleBase/ModuleBase_PageWidget.cpp
src/ModuleBase/ModuleBase_PageWidget.h
src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp
src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h
src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp
src/ModuleBase/ModuleBase_WidgetCreatorFactory.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetFactory.h

index daacdbf8b5ccf5f4758708e6f964fa0fddfcc0ba..da2a16f6b257d70f9642ea1630f75022c1d88e49 100644 (file)
@@ -21,6 +21,9 @@ const static char* NODE_VALIDATOR = "validator";
 const static char* NODE_SELFILTER = "selection_filter";
 const static char* NODE_XMLPARENT = "libxml_parent";
 
+// Property panels
+const static char* PROPERTY_PANEL_ID = "property_panel_id";
+
 // Widgets
 const static char* WDG_INFO = "label";
 const static char* WDG_ERRORINFO = "error_label";
index e0f86d63d12619d4e1ee329ff1d3fa683c654a6b..3daffa8bf532e4ef505676edf0d3088c0f3e0ff5 100755 (executable)
@@ -4,10 +4,23 @@
 
 ModuleBase_IWidgetCreator::ModuleBase_IWidgetCreator()
 {
-
 }
 
 ModuleBase_IWidgetCreator::~ModuleBase_IWidgetCreator()
 {
+}
+
+const std::set<std::string>& ModuleBase_IWidgetCreator::panelTypes()
+{
+  return std::set<std::string>();
+}
 
+const std::set<std::string>& ModuleBase_IWidgetCreator::pageTypes()
+{
+  return std::set<std::string>();
+}
+
+const std::set<std::string>& ModuleBase_IWidgetCreator::widgetTypes()
+{
+  return std::set<std::string>();
 }
index 3d0789cceeb969252377a0aae21480cf2b862b33..953d494c0c7a8349663ebd18f21461979efa2ac5 100755 (executable)
@@ -31,12 +31,23 @@ public:
   ~ModuleBase_IWidgetCreator();
 
   /// Returns a container of possible page types, which this creator can process
-  /// \returns types
-  virtual const std::set<std::string>& pageTypes() = 0;
+  /// \returns list of type names
+  virtual const std::set<std::string>& panelTypes();
+
+  /// Returns a container of possible page types, which this creator can process
+  /// \returns list of type names
+  virtual const std::set<std::string>& pageTypes();
 
   /// Returns a container of possible widget types, which this creator can process
-  /// \returns types
-  virtual const std::set<std::string>& widgetTypes() = 0;
+  /// \returns list of type names
+  virtual const std::set<std::string>& widgetTypes();
+
+  /// Create panel control by its type.
+  /// \param theType a panel type
+  /// \param theParent a parent widget
+  /// \return created widget or null
+  virtual QWidget* createPanelByType(const std::string& theType,
+                                     QWidget* theParent) {};
 
   /// Create page by its type
   /// \param theType a type
@@ -44,7 +55,7 @@ public:
   /// \param theData a low-level API for reading xml definitions of widgets
   virtual ModuleBase_PageBase* createPageByType(const std::string& theType,
                                                 QWidget* theParent,
-                                                Config_WidgetAPI* theWidgetApi) = 0;
+                                                Config_WidgetAPI* theWidgetApi) {};
 
   /// Create widget by its type
   /// \param theType a type
@@ -53,7 +64,7 @@ public:
   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
                                                      QWidget* theParent,
                                                      Config_WidgetAPI* theWidgetApi,
-                                                     ModuleBase_IWorkshop* theWorkshop) = 0;
+                                                     ModuleBase_IWorkshop* theWorkshop) {};
 };
 
 typedef std::shared_ptr<ModuleBase_IWidgetCreator> WidgetCreatorPtr;
index ed9fb7694031d374eb4120e8ee216a60a9afe5bd..38eff9ce719eafdbd10c57e5577a898551ddf116 100644 (file)
@@ -38,6 +38,11 @@ void ModuleBase_PageBase::addPageWidget(ModuleBase_PageBase* thePage)
   placePageWidget(thePage);
 }
 
+void ModuleBase_PageBase::addWidget(QWidget* theWidget)
+{
+  placeWidget(theWidget);
+}
+
 void ModuleBase_PageBase::clearPage()
 {
   myWidgetList.clear();
@@ -99,3 +104,9 @@ void ModuleBase_PageBase::alignToTop()
     addPageStretch();
   }
 }
+
+void ModuleBase_PageBase::placePageWidget(ModuleBase_PageBase* theWidget)
+{
+  QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
+  placeWidget(aWidget);
+}
index 63be634d3996e1ef547fb3bdfec3ab58b706e92a..7f695f7bd5f5b9893a9a5f3fa647c2c016810851 100644 (file)
@@ -32,6 +32,8 @@ class MODULEBASE_EXPORT ModuleBase_PageBase
   void addModelWidget(ModuleBase_ModelWidget* theWidget);
   /// Adds the given ModuleBase_PageBase to the page
   void addPageWidget(ModuleBase_PageBase* theWidget);
+  /// Adds the given widget to the page
+  void addWidget(QWidget* theWidget);
   /// Removes all items from page's layout
   void clearPage();
   /// Passes focus from page to the first ModuleBase_ModelWidget contained on the page
@@ -45,7 +47,9 @@ class MODULEBASE_EXPORT ModuleBase_PageBase
   /// Pure Virtual. Allows to derived class to lay out the widget properly;
   virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget) = 0;
   /// Pure Virtual. Allows to derived class to lay out the page properly;
-  virtual void placePageWidget(ModuleBase_PageBase* theWidget) = 0;
+  virtual void placePageWidget(ModuleBase_PageBase* theWidget);
+  /// Pure Virtual. Allows to derived class to lay out the page properly;
+  virtual void placeWidget(QWidget* theWidget) = 0;
   /// Pure Virtual. Returns layout of the page.
   virtual QLayout* pageLayout() = 0;
   /// Pure Virtual. Allows to derived class to insert page stretch properly.
index d50d3a594f08c08df1c6751299178909bf82a54c..6d0d55acfa4d5934daa6c813a240089e6b57b629 100644 (file)
@@ -39,10 +39,9 @@ void ModuleBase_PageGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget
 
 }
 
-void ModuleBase_PageGroupBox::placePageWidget(ModuleBase_PageBase* theWidget)
+void ModuleBase_PageGroupBox::placeWidget(QWidget* theWidget)
 {
-  QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
-  if (!aWidget) {
+  if (!theWidget) {
     #ifdef _DEBUG
     std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl;
     #endif
@@ -50,7 +49,7 @@ void ModuleBase_PageGroupBox::placePageWidget(ModuleBase_PageBase* theWidget)
   }
   const int kCol = 0;
   const int kRow = myMainLayout->count();
-  myMainLayout->addWidget(aWidget, kRow, kCol);
+  myMainLayout->addWidget(theWidget, kRow, kCol);
   myMainLayout->setRowStretch(kRow, 0);
 }
 
index a5f33f9f2897aeec44b9b003e71cce9182b9e647..63c6ce88aefaadd10566cf0dcb5f372fd42c7c0b 100644 (file)
@@ -35,7 +35,7 @@ class MODULEBASE_EXPORT ModuleBase_PageGroupBox : public QGroupBox, public Modul
   /// Adds the given widget to page's layout
   virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
   /// Adds the given page to page's layout
-  virtual void placePageWidget(ModuleBase_PageBase* theWidget);
+  virtual void placeWidget(QWidget* theWidget);
   /// Returns page's layout (QGridLayout)
   virtual QLayout* pageLayout();
   /// Adds a stretch to page's layout
index 9d32e79e7946699d7bb6c9f0d7e8866389eb5ee8..135fe23b78b0e9de603917de390e4df36cd0d202 100644 (file)
@@ -38,10 +38,9 @@ void ModuleBase_PageWidget::placeModelWidget(ModuleBase_ModelWidget* theWidget)
   myMainLayout->setRowStretch(kRow, 0);
 }
 
-void ModuleBase_PageWidget::placePageWidget(ModuleBase_PageBase* theWidget)
+void ModuleBase_PageWidget::placeWidget(QWidget* theWidget)
 {
-  QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
-  if (!aWidget) {
+  if (!theWidget) {
     #ifdef _DEBUG
     std::cout << "ModuleBase_PageWidget::placePageWidget: can not cast page" << std::endl;
     #endif
@@ -49,7 +48,7 @@ void ModuleBase_PageWidget::placePageWidget(ModuleBase_PageBase* theWidget)
   }
   const int kCol = 0;
   const int kRow = myMainLayout->count();
-  myMainLayout->addWidget(aWidget, kRow, kCol);
+  myMainLayout->addWidget(theWidget, kRow, kCol);
   myMainLayout->setRowStretch(kRow, 0);
 }
 
index 2528843bb1db9b915004a9cd3cbe9187246a08db..6ff94ca5ee35b7ef544fc5c5abfca7479ab4da72 100644 (file)
@@ -34,7 +34,7 @@ class MODULEBASE_EXPORT ModuleBase_PageWidget : public QFrame, public ModuleBase
   /// Adds the given widget to page's layout
   virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
   /// Adds the given page to page's layout
-  virtual void placePageWidget(ModuleBase_PageBase* theWidget);
+  virtual void placeWidget(QWidget* theWidget);
   /// Returns page's layout (QGridLayout)
   virtual QLayout* pageLayout();
   /// Adds a stretch to page's layout
index df32f5b53ea8c09dff7a8d6a24d11c7975443fa2..cee0ff9872170b0ddfcf00076a1dfc57b8dbc1ed 100755 (executable)
@@ -84,10 +84,9 @@ void ModuleBase_WidgetCheckGroupBox::placeModelWidget(ModuleBase_ModelWidget* th
 
 }
 
-void ModuleBase_WidgetCheckGroupBox::placePageWidget(ModuleBase_PageBase* theWidget)
+void ModuleBase_WidgetCheckGroupBox::placeWidget(QWidget* theWidget)
 {
-  QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
-  if (!aWidget) {
+  if (!theWidget) {
 #ifdef _DEBUG
     std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl;
 #endif
@@ -95,7 +94,7 @@ void ModuleBase_WidgetCheckGroupBox::placePageWidget(ModuleBase_PageBase* theWid
   }
   const int kCol = 0;
   const int kRow = myMainLayout->count();
-  myMainLayout->addWidget(aWidget, kRow, kCol);
+  myMainLayout->addWidget(theWidget, kRow, kCol);
   myMainLayout->setRowStretch(kRow, 0);
 }
 
index 88995430e59997c683e1a1d520c99113ff192585..dcb7012ce8a3fd6e28eda2bae92632d9f5b4dded 100755 (executable)
@@ -51,7 +51,7 @@ protected:
   /// Adds the given widget to page's layout
   virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
   /// Adds the given page to page's layout
-  virtual void placePageWidget(ModuleBase_PageBase* theWidget);
+  virtual void placeWidget(QWidget* theWidget);
   /// Returns page's layout (QGridLayout)
   virtual QLayout* pageLayout();
   /// Adds a stretch to page's layout
index 3f2ff93079c0e633f0caf23126abbd48b14d3e29..6fd77e0615ccea862d6e9118f1ebe82c38f2ed4f 100755 (executable)
@@ -34,9 +34,22 @@ ModuleBase_WidgetCreatorFactory::~ModuleBase_WidgetCreatorFactory()
 
 void ModuleBase_WidgetCreatorFactory::registerCreator(const WidgetCreatorPtr& theCreator)
 {
+  std::set<std::string>::const_iterator anIt, aLast;
+  /// fill map of panels
+  const std::set<std::string>& aPanelTypes = theCreator->panelTypes();
+  for (anIt = aPanelTypes.begin(), aLast = aPanelTypes.end(); anIt != aLast; anIt++) {
+    std::string aKey = *anIt;
+    if (!myPanelToCreator.contains(aKey))
+      myPanelToCreator[aKey] = theCreator;
+    else {
+      Events_Error::send("The" + aKey + " panel XML definition has been already \
+used by another widget creator");
+    }
+  }
+
+  /// fill map of widgets
   const std::set<std::string>& aTypes = theCreator->widgetTypes();
-  std::set<std::string>::const_iterator anIt = aTypes.begin(), aLast = aTypes.end();
-  for (; anIt != aLast; anIt++) {
+  for (anIt = aTypes.begin(), aLast = aTypes.end(); anIt != aLast; anIt++) {
     std::string aKey = *anIt;
     if (!myCreators.contains(aKey))
       myCreators[aKey] = theCreator;
@@ -46,6 +59,7 @@ used by another widget creator");
     }
   }
 
+  /// fill map of pages
   const std::set<std::string>& aPTypes = theCreator->pageTypes();
   for (anIt = aPTypes.begin(), aLast = aPTypes.end(); anIt != aLast; anIt++) {
     std::string aKey = *anIt;
@@ -58,6 +72,21 @@ used by another widget creator");
   }
 }
 
+bool ModuleBase_WidgetCreatorFactory::hasPanelWidget(const std::string& theType)
+{
+  return myPanelToCreator.contains(theType);
+}
+
+QWidget* ModuleBase_WidgetCreatorFactory::createPanel(const std::string& theType, QWidget* theParent)
+{
+  QWidget* aPanel = 0;
+  if (myPanelToCreator.contains(theType)) {
+    WidgetCreatorPtr aCreator = myPanelToCreator[theType];
+    aPanel = aCreator->createPanelByType(theType, theParent);
+  }
+  return aPanel;
+}
+
 bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType)
 {
   return myPageToCreator.contains(theType);
index 1c6991a5a44a405543af9334774ee4e75b7ab44f..6373eebba0b99b64b2bb4a5a635e1d8cce567aab 100755 (executable)
@@ -40,13 +40,26 @@ class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory
   /// \param theCreator a new widget creator
   void registerCreator(const WidgetCreatorPtr& theCreator);
 
+  /// Returns true if there is a creator, which can make a panel by the type
+  /// \param theType a type
+  /// \return a boolean value
+  bool hasPanelWidget(const std::string& theType);
+
+  /// Create panel by its type
+  /// \param theType a type
+  /// \param theParent a parent widget
+  /// \return a created panel or null
+  QWidget* createPanel(const std::string& theType, QWidget* theParent);
+
   /// Returns true if there is a creator, which can make a page by the type
   /// \param theType a type
+  /// \return a boolean value
   bool hasPageWidget(const std::string& theType);
 
   /// Create page by its type
   /// \param theType a type
   /// \param theParent a parent widget
+  /// \return a created page or null
   ModuleBase_PageBase* createPageByType(const std::string& theType,
                                         QWidget* theParent,
                                         Config_WidgetAPI* theWidgetApi);
@@ -54,6 +67,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory
   /// Create widget by its type
   /// \param theType a type
   /// \param theParent a parent widget
+  /// \return a created widget or null
   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
                                              QWidget* theParent,
                                              Config_WidgetAPI* theWidgetApi,
@@ -63,11 +77,14 @@ private:
   /// Constructor is hidden
   ModuleBase_WidgetCreatorFactory();
 
-  /// Map of widget type in XML to creator
-  QMap<std::string, WidgetCreatorPtr> myCreators;
+  /// Map of widget panel in XML to creator
+  QMap<std::string, WidgetCreatorPtr> myPanelToCreator;
 
   /// Map of widget page in XML to creator
   QMap<std::string, WidgetCreatorPtr> myPageToCreator;
+
+  /// Map of widget type in XML to creator
+  QMap<std::string, WidgetCreatorPtr> myCreators;
 };
 
 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
index 41709a1bab606d016a88ba838bcfbd1439f5ce81..e8176696254d4ce51b8a1c0d0aae89c4cdfa22ad 100644 (file)
@@ -71,6 +71,13 @@ ModuleBase_WidgetFactory::~ModuleBase_WidgetFactory()
 
 void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
 {
+  std::string aWType = myWidgetApi->widgetType();
+  if (aWType == NODE_FEATURE) {
+    QWidget* aPanel = createPanel(thePage->pageWidget());
+    thePage->addWidget(aPanel);
+    return;
+  }
+
   if (!myWidgetApi->toChildWidget())
     return;
 
@@ -217,6 +224,15 @@ void ModuleBase_WidgetFactory::moveToWidgetId(const std::string& theWidgetId, bo
   } while (!theFound && myWidgetApi->toNextWidget());
 }
 
+QWidget* ModuleBase_WidgetFactory::createPanel(QWidget* theParent)
+{
+  QWidget* aPanel = 0;
+  std::string aPanelName = myWidgetApi->getProperty(PROPERTY_PANEL_ID);
+  if (!aPanelName.empty() && ModuleBase_WidgetCreatorFactory::get()->hasPanelWidget(aPanelName))
+    aPanel = ModuleBase_WidgetCreatorFactory::get()->createPanel(aPanelName, theParent);
+  return aPanel;
+}
+
 ModuleBase_PageBase* ModuleBase_WidgetFactory::createPageByType(const std::string& theType,
                                                                 QWidget* theParent)
 {
index cebeb0bda77b4b0db7be809ac6b7731773291c24..180c265b8279b9ec0fcd6bfff3369236c1a44e0a 100644 (file)
@@ -67,6 +67,11 @@ protected:
   /// check if ModuleBase_Widget has expandable widgets in getControls
   bool hasExpandingControls(QWidget* theParent);
 
+  /// creates panel control, if the corresponded parameter is provided by feature
+  /// \param theParent a parent widget
+  /// \return true if the panel is created
+  QWidget* createPanel(QWidget* theParent);
+
   /// Create page by its type
   /// \param theType a type
   /// \param theParent a parent widget