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 <Events_Error.h>
12 #include <QStringList>
14 /// Factory instance that will be initialized by first getting, one per application
15 std::shared_ptr<ModuleBase_WidgetCreatorFactory> MY_WIDGET_CREATOR_FACTORY;
17 std::shared_ptr<ModuleBase_WidgetCreatorFactory> ModuleBase_WidgetCreatorFactory::get()
19 if (!MY_WIDGET_CREATOR_FACTORY) {
20 MY_WIDGET_CREATOR_FACTORY = std::shared_ptr<ModuleBase_WidgetCreatorFactory>(new ModuleBase_WidgetCreatorFactory());
22 return MY_WIDGET_CREATOR_FACTORY;
25 ModuleBase_WidgetCreatorFactory::ModuleBase_WidgetCreatorFactory()
29 ModuleBase_WidgetCreatorFactory::~ModuleBase_WidgetCreatorFactory()
33 void ModuleBase_WidgetCreatorFactory::registerCreator(const WidgetCreatorPtr& theCreator)
35 const std::set<std::string>& aTypes = theCreator->widgetTypes();
36 std::set<std::string>::const_iterator anIt = aTypes.begin(), aLast = aTypes.end();
37 for (; anIt != aLast; anIt++) {
38 std::string aKey = *anIt;
39 if (!myCreators.contains(aKey))
40 myCreators[aKey] = theCreator;
42 Events_Error::send("The" + aKey + " widget XML definition has been already \
43 used by another widget creator");
47 const std::set<std::string>& aPTypes = theCreator->pageTypes();
48 for (anIt = aPTypes.begin(), aLast = aPTypes.end(); anIt != aLast; anIt++) {
49 std::string aKey = *anIt;
50 if (!myPageToCreator.contains(aKey))
51 myPageToCreator[aKey] = theCreator;
53 Events_Error::send("The" + aKey + " page XML definition has been already \
54 used by another widget creator");
59 bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType)
61 return myPageToCreator.contains(theType);
64 ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType(
65 const std::string& theType, QWidget* theParent)
67 ModuleBase_PageBase* aPage = 0;
69 if (myPageToCreator.contains(theType)) {
70 WidgetCreatorPtr aCreator = myPageToCreator[theType];
71 aPage = aCreator->createPageByType(theType, theParent);
78 ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType(
79 const std::string& theType, QWidget* theParent)
81 ModuleBase_ModelWidget* aWidget = 0;
83 if (myCreators.contains(theType)) {
84 WidgetCreatorPtr aCreator = myCreators[theType];
85 aWidget = aCreator->createWidgetByType(theType, theParent);