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_Error.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 const std::set<std::string>& aTypes = theCreator->widgetTypes();
38 std::set<std::string>::const_iterator anIt = aTypes.begin(), aLast = aTypes.end();
39 for (; anIt != aLast; anIt++) {
40 std::string aKey = *anIt;
41 if (!myCreators.contains(aKey))
42 myCreators[aKey] = theCreator;
44 Events_Error::send("The" + aKey + " widget XML definition has been already \
45 used by another widget creator");
49 const std::set<std::string>& aPTypes = theCreator->pageTypes();
50 for (anIt = aPTypes.begin(), aLast = aPTypes.end(); anIt != aLast; anIt++) {
51 std::string aKey = *anIt;
52 if (!myPageToCreator.contains(aKey))
53 myPageToCreator[aKey] = theCreator;
55 Events_Error::send("The" + aKey + " page XML definition has been already \
56 used by another widget creator");
61 bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType)
63 return myPageToCreator.contains(theType);
66 ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType(
67 const std::string& theType, QWidget* theParent,
68 Config_WidgetAPI* theWidgetApi)
70 ModuleBase_PageBase* aPage = 0;
72 if (myPageToCreator.contains(theType)) {
73 WidgetCreatorPtr aCreator = myPageToCreator[theType];
74 aPage = aCreator->createPageByType(theType, theParent, theWidgetApi);
81 ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType(
82 const std::string& theType, QWidget* theParent,
83 Config_WidgetAPI* theWidgetApi,
84 ModuleBase_IWorkshop* theWorkshop)
86 ModuleBase_ModelWidget* aWidget = 0;
88 if (myCreators.contains(theType)) {
89 WidgetCreatorPtr aCreator = myCreators[theType];
90 aWidget = aCreator->createWidgetByType(theType, theParent, theWidgetApi, theWorkshop);