Salome HOME
42f6f06d0ea436f4bc947d4a886d69a121b73096
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetCreatorFactory.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetCreatorFactory.cpp
4 // Created:     03 Dec 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef MODULEBASE_WIDGETCREATORFACTORY_H_
8 #define MODULEBASE_WIDGETCREATORFACTORY_H_
9
10 #include <ModuleBase.h>
11
12 #include <memory>
13 #include <string>
14
15 #include <QMap>
16
17 #include <ModuleBase_IWidgetCreator.h>
18
19 #include <ModelAPI_Feature.h>
20
21 class ModuleBase_ModelWidget;
22 class ModuleBase_PageBase;
23 class ModuleBase_IWorkshop;
24
25 class QWidget;
26
27 /**
28 * \ingroup GUI
29 * A class for creation of widgets instances in for property panel using XML deskription of
30 * a feature
31 */
32 class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory
33 {
34  public:
35   /// Returns an singular instance of the class if it exists or create it
36   static std::shared_ptr<ModuleBase_WidgetCreatorFactory> get();
37
38   /// Destructor
39   virtual ~ModuleBase_WidgetCreatorFactory();
40
41   /// The creator is added to the internal container 
42   /// to be used when the createWidgetByType is called
43   /// \param theCreator a new widget creator
44   void registerCreator(const WidgetCreatorPtr& theCreator);
45
46   /// Returns true if there is a creator, which can make a panel by the type
47   /// \param theType a type
48   /// \return a boolean value
49   bool hasPanelWidget(const std::string& theType);
50
51   /// Create panel by its type
52   /// \param theType a type
53   /// \param theParent a parent widget
54   /// \param theFeature a feature to fill the panel
55   /// \return a created panel or null
56   QWidget* createPanelByType(const std::string& theType, QWidget* theParent,
57                              const FeaturePtr& theFeature);
58
59   /// Returns true if there is a creator, which can make a page by the type
60   /// \param theType a type
61   /// \return a boolean value
62   bool hasPageWidget(const std::string& theType);
63
64   /// Create page by its type
65   /// \param theType a type
66   /// \param theParent a parent widget
67   /// \param theWidgetApi the widget configuration. 
68   ///                     The attribute of the model widget is obtained from XML
69   /// \return a created page or null
70   ModuleBase_PageBase* createPageByType(const std::string& theType,
71                                         QWidget* theParent,
72                                         Config_WidgetAPI* theWidgetApi);
73
74   /// Create widget by its type
75   /// \param theType a type
76   /// \param theParent a parent widget
77   /// \param theWidgetApi the widget configuration. 
78   ///                     The attribute of the model widget is obtained from XML
79   /// \param theWorkshop a workshop object instance
80   /// \return a created widget or null
81   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
82                                              QWidget* theParent,
83                                              Config_WidgetAPI* theWidgetApi,
84                                              ModuleBase_IWorkshop* theWorkshop);
85
86 private:
87   /// Constructor is hidden
88   ModuleBase_WidgetCreatorFactory();
89
90   /// Map of widget panel in XML to creator
91   QMap<std::string, WidgetCreatorPtr> myPanelToCreator;
92
93   /// Map of widget page in XML to creator
94   QMap<std::string, WidgetCreatorPtr> myPageToCreator;
95
96   /// Map of widget type in XML to creator
97   QMap<std::string, WidgetCreatorPtr> myCreators;
98 };
99
100 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
101
102 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */