1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <ModuleBase_WidgetCreatorFactory.h>
21 #include <ModuleBase_IWidgetCreator.h>
23 #include <Config_WidgetAPI.h>
25 #include <Events_InfoMessage.h>
27 #include <QStringList>
29 /// Factory instance that will be initialized by first getting, one per application
30 std::shared_ptr<ModuleBase_WidgetCreatorFactory> MY_WIDGET_CREATOR_FACTORY;
32 std::shared_ptr<ModuleBase_WidgetCreatorFactory> ModuleBase_WidgetCreatorFactory::get()
34 if (!MY_WIDGET_CREATOR_FACTORY) {
35 MY_WIDGET_CREATOR_FACTORY =
36 std::shared_ptr<ModuleBase_WidgetCreatorFactory>(new ModuleBase_WidgetCreatorFactory());
38 return MY_WIDGET_CREATOR_FACTORY;
41 ModuleBase_WidgetCreatorFactory::ModuleBase_WidgetCreatorFactory()
45 ModuleBase_WidgetCreatorFactory::~ModuleBase_WidgetCreatorFactory()
49 void ModuleBase_WidgetCreatorFactory::registerCreator(const WidgetCreatorPtr& theCreator)
51 std::set<std::string>::const_iterator anIt, aLast;
52 /// fill map of panels
53 std::set<std::string> aPanelTypes;
54 theCreator->panelTypes(aPanelTypes);
55 for (anIt = aPanelTypes.begin(), aLast = aPanelTypes.end(); anIt != aLast; anIt++) {
56 std::string aKey = *anIt;
57 if (!myPanelToCreator.contains(aKey))
58 myPanelToCreator[aKey] = theCreator;
60 Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
61 "The %1 panel XML definition has been already used by another widget creator")
66 /// fill map of widgets
67 std::set<std::string> aTypes;
68 theCreator->widgetTypes(aTypes);
69 for (anIt = aTypes.begin(), aLast = aTypes.end(); anIt != aLast; anIt++) {
70 std::string aKey = *anIt;
71 if (!myCreators.contains(aKey))
72 myCreators[aKey] = theCreator;
74 Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
75 "The %1 widget XML definition has been already used by another widget creator")
81 std::set<std::string> aPTypes;
82 theCreator->pageTypes(aPTypes);
83 for (anIt = aPTypes.begin(), aLast = aPTypes.end(); anIt != aLast; anIt++) {
84 std::string aKey = *anIt;
85 if (!myPageToCreator.contains(aKey))
86 myPageToCreator[aKey] = theCreator;
88 Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
89 "The %1 page XML definition has been already used by another widget creator")
95 bool ModuleBase_WidgetCreatorFactory::hasPanelWidget(const std::string& theType)
97 return myPanelToCreator.contains(theType);
100 QWidget* ModuleBase_WidgetCreatorFactory::createPanelByType(const std::string& theType,
102 const FeaturePtr& theFeature)
105 if (myPanelToCreator.contains(theType)) {
106 WidgetCreatorPtr aCreator = myPanelToCreator[theType];
107 aPanel = aCreator->createPanelByType(theType, theParent, theFeature);
112 bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType)
114 return myPageToCreator.contains(theType);
117 ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType(
118 const std::string& theType, QWidget* theParent,
119 Config_WidgetAPI* theWidgetApi)
121 ModuleBase_PageBase* aPage = 0;
123 if (myPageToCreator.contains(theType)) {
124 WidgetCreatorPtr aCreator = myPageToCreator[theType];
125 aPage = aCreator->createPageByType(theType, theParent, theWidgetApi);
132 ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType(
133 const std::string& theType, QWidget* theParent,
134 Config_WidgetAPI* theWidgetApi,
135 ModuleBase_IWorkshop* theWorkshop)
137 ModuleBase_ModelWidget* aWidget = 0;
139 if (myCreators.contains(theType)) {
140 WidgetCreatorPtr aCreator = myCreators[theType];
141 aWidget = aCreator->createWidgetByType(theType, theParent, theWidgetApi, theWorkshop);