From: nds Date: Tue, 29 Mar 2016 09:21:53 +0000 (+0300) Subject: Issue #1368: Creation of a Qt panel. Widget creator interface correction to manage... X-Git-Tag: V_2.3.0~365 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=818bc197ba38350efb1a88e5735687a9da5ed6c3;p=modules%2Fshaper.git Issue #1368: Creation of a Qt panel. Widget creator interface correction to manage Qt panel type. --- diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index daacdbf8b..da2a16f6b 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -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"; diff --git a/src/ModuleBase/ModuleBase_IWidgetCreator.cpp b/src/ModuleBase/ModuleBase_IWidgetCreator.cpp index e0f86d63d..3daffa8bf 100755 --- a/src/ModuleBase/ModuleBase_IWidgetCreator.cpp +++ b/src/ModuleBase/ModuleBase_IWidgetCreator.cpp @@ -4,10 +4,23 @@ ModuleBase_IWidgetCreator::ModuleBase_IWidgetCreator() { - } ModuleBase_IWidgetCreator::~ModuleBase_IWidgetCreator() { +} + +const std::set& ModuleBase_IWidgetCreator::panelTypes() +{ + return std::set(); +} +const std::set& ModuleBase_IWidgetCreator::pageTypes() +{ + return std::set(); +} + +const std::set& ModuleBase_IWidgetCreator::widgetTypes() +{ + return std::set(); } diff --git a/src/ModuleBase/ModuleBase_IWidgetCreator.h b/src/ModuleBase/ModuleBase_IWidgetCreator.h index 3d0789cce..953d494c0 100755 --- a/src/ModuleBase/ModuleBase_IWidgetCreator.h +++ b/src/ModuleBase/ModuleBase_IWidgetCreator.h @@ -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& pageTypes() = 0; + /// \returns list of type names + virtual const std::set& panelTypes(); + + /// Returns a container of possible page types, which this creator can process + /// \returns list of type names + virtual const std::set& pageTypes(); /// Returns a container of possible widget types, which this creator can process - /// \returns types - virtual const std::set& widgetTypes() = 0; + /// \returns list of type names + virtual const std::set& 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 WidgetCreatorPtr; diff --git a/src/ModuleBase/ModuleBase_PageBase.cpp b/src/ModuleBase/ModuleBase_PageBase.cpp index ed9fb7694..38eff9ce7 100644 --- a/src/ModuleBase/ModuleBase_PageBase.cpp +++ b/src/ModuleBase/ModuleBase_PageBase.cpp @@ -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(theWidget); + placeWidget(aWidget); +} diff --git a/src/ModuleBase/ModuleBase_PageBase.h b/src/ModuleBase/ModuleBase_PageBase.h index 63be634d3..7f695f7bd 100644 --- a/src/ModuleBase/ModuleBase_PageBase.h +++ b/src/ModuleBase/ModuleBase_PageBase.h @@ -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. diff --git a/src/ModuleBase/ModuleBase_PageGroupBox.cpp b/src/ModuleBase/ModuleBase_PageGroupBox.cpp index d50d3a594..6d0d55acf 100644 --- a/src/ModuleBase/ModuleBase_PageGroupBox.cpp +++ b/src/ModuleBase/ModuleBase_PageGroupBox.cpp @@ -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(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); } diff --git a/src/ModuleBase/ModuleBase_PageGroupBox.h b/src/ModuleBase/ModuleBase_PageGroupBox.h index a5f33f9f2..63c6ce88a 100644 --- a/src/ModuleBase/ModuleBase_PageGroupBox.h +++ b/src/ModuleBase/ModuleBase_PageGroupBox.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_PageWidget.cpp b/src/ModuleBase/ModuleBase_PageWidget.cpp index 9d32e79e7..135fe23b7 100644 --- a/src/ModuleBase/ModuleBase_PageWidget.cpp +++ b/src/ModuleBase/ModuleBase_PageWidget.cpp @@ -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(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); } diff --git a/src/ModuleBase/ModuleBase_PageWidget.h b/src/ModuleBase/ModuleBase_PageWidget.h index 2528843bb..6ff94ca5e 100644 --- a/src/ModuleBase/ModuleBase_PageWidget.h +++ b/src/ModuleBase/ModuleBase_PageWidget.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp index df32f5b53..cee0ff987 100755 --- a/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp +++ b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp @@ -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(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); } diff --git a/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h index 88995430e..dcb7012ce 100755 --- a/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h +++ b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp b/src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp index 3f2ff9307..6fd77e061 100755 --- a/src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp @@ -34,9 +34,22 @@ ModuleBase_WidgetCreatorFactory::~ModuleBase_WidgetCreatorFactory() void ModuleBase_WidgetCreatorFactory::registerCreator(const WidgetCreatorPtr& theCreator) { + std::set::const_iterator anIt, aLast; + /// fill map of panels + const std::set& 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& aTypes = theCreator->widgetTypes(); - std::set::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& 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); diff --git a/src/ModuleBase/ModuleBase_WidgetCreatorFactory.h b/src/ModuleBase/ModuleBase_WidgetCreatorFactory.h index 1c6991a5a..6373eebba 100755 --- a/src/ModuleBase/ModuleBase_WidgetCreatorFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetCreatorFactory.h @@ -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 myCreators; + /// Map of widget panel in XML to creator + QMap myPanelToCreator; /// Map of widget page in XML to creator QMap myPageToCreator; + + /// Map of widget type in XML to creator + QMap myCreators; }; typedef std::shared_ptr WidgetCreatorFactoryPtr; diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 41709a1ba..e81766962 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -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) { diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index cebeb0bda..180c265b8 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -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