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 (!myModelWidgets.contains(aKey))
40 myModelWidgets[aKey] = theCreator;
42 Events_Error::send("The" + aKey + " widget XML definition has been already\
43 used by another widget creator");
48 ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType(
49 const std::string& theType, QWidget* theParent)
51 ModuleBase_ModelWidget* aWidget = 0;
53 if (myModelWidgets.contains(theType)) {
54 WidgetCreatorPtr aCreator = myModelWidgets[theType];
55 aWidget = aCreator->createWidgetByType(theType, theParent);