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 #ifndef MODULEBASE_WIDGETCREATORFACTORY_H_
8 #define MODULEBASE_WIDGETCREATORFACTORY_H_
10 #include <ModuleBase.h>
17 #include <ModuleBase_IWidgetCreator.h>
19 class ModuleBase_ModelWidget;
20 class ModuleBase_PageBase;
21 class ModuleBase_IWorkshop;
27 * A class for creation of widgets instances in for property panel using XML deskription of
30 class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory
33 // Returns an singular instance of the class if it exists or create it
34 static std::shared_ptr<ModuleBase_WidgetCreatorFactory> get();
37 virtual ~ModuleBase_WidgetCreatorFactory();
39 /// The creator is added to the internal container to be used when the createWidgetByType is called
40 /// \param theCreator a new widget creator
41 void registerCreator(const WidgetCreatorPtr& theCreator);
43 /// Returns true if there is a creator, which can make a panel by the type
44 /// \param theType a type
45 /// \return a boolean value
46 bool hasPanelWidget(const std::string& theType);
48 /// Create panel by its type
49 /// \param theType a type
50 /// \param theParent a parent widget
51 /// \return a created panel or null
52 QWidget* createPanel(const std::string& theType, QWidget* theParent);
54 /// Returns true if there is a creator, which can make a page by the type
55 /// \param theType a type
56 /// \return a boolean value
57 bool hasPageWidget(const std::string& theType);
59 /// Create page by its type
60 /// \param theType a type
61 /// \param theParent a parent widget
62 /// \return a created page or null
63 ModuleBase_PageBase* createPageByType(const std::string& theType,
65 Config_WidgetAPI* theWidgetApi);
67 /// Create widget by its type
68 /// \param theType a type
69 /// \param theParent a parent widget
70 /// \return a created widget or null
71 ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
73 Config_WidgetAPI* theWidgetApi,
74 ModuleBase_IWorkshop* theWorkshop);
77 /// Constructor is hidden
78 ModuleBase_WidgetCreatorFactory();
80 /// Map of widget panel in XML to creator
81 QMap<std::string, WidgetCreatorPtr> myPanelToCreator;
83 /// Map of widget page in XML to creator
84 QMap<std::string, WidgetCreatorPtr> myPageToCreator;
86 /// Map of widget type in XML to creator
87 QMap<std::string, WidgetCreatorPtr> myCreators;
90 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
92 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */