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 = std::shared_ptr<ModuleBase_WidgetCreatorFactory>(new ModuleBase_WidgetCreatorFactory());
24 return MY_WIDGET_CREATOR_FACTORY;
27 ModuleBase_WidgetCreatorFactory::ModuleBase_WidgetCreatorFactory()
31 ModuleBase_WidgetCreatorFactory::~ModuleBase_WidgetCreatorFactory()
35 void ModuleBase_WidgetCreatorFactory::registerCreator(const WidgetCreatorPtr& theCreator)
37 std::set<std::string>::const_iterator anIt, aLast;
38 /// fill map of panels
39 std::set<std::string> aPanelTypes;
40 theCreator->panelTypes(aPanelTypes);
41 for (anIt = aPanelTypes.begin(), aLast = aPanelTypes.end(); anIt != aLast; anIt++) {
42 std::string aKey = *anIt;
43 if (!myPanelToCreator.contains(aKey))
44 myPanelToCreator[aKey] = theCreator;
46 Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
47 "The %1 panel XML definition has been already used by another widget creator").arg(aKey).send();
51 /// fill map of widgets
52 std::set<std::string> aTypes;
53 theCreator->widgetTypes(aTypes);
54 for (anIt = aTypes.begin(), aLast = aTypes.end(); anIt != aLast; anIt++) {
55 std::string aKey = *anIt;
56 if (!myCreators.contains(aKey))
57 myCreators[aKey] = theCreator;
59 Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
60 "The %1 widget XML definition has been already used by another widget creator").arg(aKey).send();
65 std::set<std::string> aPTypes;
66 theCreator->pageTypes(aPTypes);
67 for (anIt = aPTypes.begin(), aLast = aPTypes.end(); anIt != aLast; anIt++) {
68 std::string aKey = *anIt;
69 if (!myPageToCreator.contains(aKey))
70 myPageToCreator[aKey] = theCreator;
72 Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
73 "The %1 page XML definition has been already used by another widget creator").arg(aKey).send();
78 bool ModuleBase_WidgetCreatorFactory::hasPanelWidget(const std::string& theType)
80 return myPanelToCreator.contains(theType);
83 QWidget* ModuleBase_WidgetCreatorFactory::createPanelByType(const std::string& theType,
85 const FeaturePtr& theFeature)
88 if (myPanelToCreator.contains(theType)) {
89 WidgetCreatorPtr aCreator = myPanelToCreator[theType];
90 aPanel = aCreator->createPanelByType(theType, theParent, theFeature);
95 bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType)
97 return myPageToCreator.contains(theType);
100 ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType(
101 const std::string& theType, QWidget* theParent,
102 Config_WidgetAPI* theWidgetApi)
104 ModuleBase_PageBase* aPage = 0;
106 if (myPageToCreator.contains(theType)) {
107 WidgetCreatorPtr aCreator = myPageToCreator[theType];
108 aPage = aCreator->createPageByType(theType, theParent, theWidgetApi);
115 ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType(
116 const std::string& theType, QWidget* theParent,
117 Config_WidgetAPI* theWidgetApi,
118 ModuleBase_IWorkshop* theWorkshop)
120 ModuleBase_ModelWidget* aWidget = 0;
122 if (myCreators.contains(theType)) {
123 WidgetCreatorPtr aCreator = myCreators[theType];
124 aWidget = aCreator->createWidgetByType(theType, theParent, theWidgetApi, theWorkshop);