Salome HOME
5cbc34c06bc2bb582cc295e85193548bc4906204
[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 to be used when the createWidgetByType is called
42   /// \param theCreator a new widget creator
43   void registerCreator(const WidgetCreatorPtr& theCreator);
44
45   /// Returns true if there is a creator, which can make a panel by the type
46   /// \param theType a type
47   /// \return a boolean value
48   bool hasPanelWidget(const std::string& theType);
49
50   /// Create panel by its type
51   /// \param theType a type
52   /// \param theParent a parent widget
53   /// \param theFeature a feature to fill the panel
54   /// \return a created panel or null
55   QWidget* createPanelByType(const std::string& theType, QWidget* theParent,
56                              const FeaturePtr& theFeature);
57
58   /// Returns true if there is a creator, which can make a page by the type
59   /// \param theType a type
60   /// \return a boolean value
61   bool hasPageWidget(const std::string& theType);
62
63   /// Create page by its type
64   /// \param theType a type
65   /// \param theParent a parent widget
66   /// \return a created page or null
67   ModuleBase_PageBase* createPageByType(const std::string& theType,
68                                         QWidget* theParent,
69                                         Config_WidgetAPI* theWidgetApi);
70
71   /// Create widget by its type
72   /// \param theType a type
73   /// \param theParent a parent widget
74   /// \return a created widget or null
75   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
76                                              QWidget* theParent,
77                                              Config_WidgetAPI* theWidgetApi,
78                                              ModuleBase_IWorkshop* theWorkshop);
79
80 private:
81   /// Constructor is hidden
82   ModuleBase_WidgetCreatorFactory();
83
84   /// Map of widget panel in XML to creator
85   QMap<std::string, WidgetCreatorPtr> myPanelToCreator;
86
87   /// Map of widget page in XML to creator
88   QMap<std::string, WidgetCreatorPtr> myPageToCreator;
89
90   /// Map of widget type in XML to creator
91   QMap<std::string, WidgetCreatorPtr> myCreators;
92 };
93
94 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
95
96 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */