1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetCreatorFactory.cpp
4 // Created: 03 Dec 2015
5 // Author: Natalia ERMOLAEVA
7 #include <ModuleBase_WidgetCreatorFactory.h>
8 #include <ModuleBase_IWidgetCreator.h>
10 #include <Config_WidgetAPI.h>
12 #include <Events_InfoMessage.h>
14 #include <QStringList>
16 /// Factory instance that will be initialized by first getting, one per application
17 std::shared_ptr<ModuleBase_WidgetCreatorFactory> MY_WIDGET_CREATOR_FACTORY;
19 std::shared_ptr<ModuleBase_WidgetCreatorFactory> ModuleBase_WidgetCreatorFactory::get()
21 if (!MY_WIDGET_CREATOR_FACTORY) {
22 MY_WIDGET_CREATOR_FACTORY =
23 std::shared_ptr<ModuleBase_WidgetCreatorFactory>(new ModuleBase_WidgetCreatorFactory());
25 return MY_WIDGET_CREATOR_FACTORY;
28 ModuleBase_WidgetCreatorFactory::ModuleBase_WidgetCreatorFactory()
32 ModuleBase_WidgetCreatorFactory::~ModuleBase_WidgetCreatorFactory()
36 void ModuleBase_WidgetCreatorFactory::registerCreator(const WidgetCreatorPtr& theCreator)
38 std::set<std::string>::const_iterator anIt, aLast;
39 /// fill map of panels
40 std::set<std::string> aPanelTypes;
41 theCreator->panelTypes(aPanelTypes);
42 for (anIt = aPanelTypes.begin(), aLast = aPanelTypes.end(); anIt != aLast; anIt++) {
43 std::string aKey = *anIt;
44 if (!myPanelToCreator.contains(aKey))
45 myPanelToCreator[aKey] = theCreator;
47 Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
48 "The %1 panel XML definition has been already used by another widget creator")
53 /// fill map of widgets
54 std::set<std::string> aTypes;
55 theCreator->widgetTypes(aTypes);
56 for (anIt = aTypes.begin(), aLast = aTypes.end(); anIt != aLast; anIt++) {
57 std::string aKey = *anIt;
58 if (!myCreators.contains(aKey))
59 myCreators[aKey] = theCreator;
61 Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
62 "The %1 widget XML definition has been already used by another widget creator")
68 std::set<std::string> aPTypes;
69 theCreator->pageTypes(aPTypes);
70 for (anIt = aPTypes.begin(), aLast = aPTypes.end(); anIt != aLast; anIt++) {
71 std::string aKey = *anIt;
72 if (!myPageToCreator.contains(aKey))
73 myPageToCreator[aKey] = theCreator;
75 Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
76 "The %1 page XML definition has been already used by another widget creator")
82 bool ModuleBase_WidgetCreatorFactory::hasPanelWidget(const std::string& theType)
84 return myPanelToCreator.contains(theType);
87 QWidget* ModuleBase_WidgetCreatorFactory::createPanelByType(const std::string& theType,
89 const FeaturePtr& theFeature)
92 if (myPanelToCreator.contains(theType)) {
93 WidgetCreatorPtr aCreator = myPanelToCreator[theType];
94 aPanel = aCreator->createPanelByType(theType, theParent, theFeature);
99 bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType)
101 return myPageToCreator.contains(theType);
104 ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType(
105 const std::string& theType, QWidget* theParent,
106 Config_WidgetAPI* theWidgetApi)
108 ModuleBase_PageBase* aPage = 0;
110 if (myPageToCreator.contains(theType)) {
111 WidgetCreatorPtr aCreator = myPageToCreator[theType];
112 aPage = aCreator->createPageByType(theType, theParent, theWidgetApi);
119 ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType(
120 const std::string& theType, QWidget* theParent,
121 Config_WidgetAPI* theWidgetApi,
122 ModuleBase_IWorkshop* theWorkshop)
124 ModuleBase_ModelWidget* aWidget = 0;
126 if (myCreators.contains(theType)) {
127 WidgetCreatorPtr aCreator = myCreators[theType];
128 aWidget = aCreator->createWidgetByType(theType, theParent, theWidgetApi, theWorkshop);