Salome HOME
Temporary comment (somehow inform the user about the scale of the view: line lenght...
[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   /// \param theWidgetApi the widget configuration. The attribute of the model widget is obtained from XML
67   /// \return a created page or null
68   ModuleBase_PageBase* createPageByType(const std::string& theType,
69                                         QWidget* theParent,
70                                         Config_WidgetAPI* theWidgetApi);
71
72   /// Create widget by its type
73   /// \param theType a type
74   /// \param theParent a parent widget
75   /// \param theWidgetApi the widget configuration. The attribute of the model widget is obtained from XML
76   /// \param theWorkshop a workshop object instance
77   /// \return a created widget or null
78   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
79                                              QWidget* theParent,
80                                              Config_WidgetAPI* theWidgetApi,
81                                              ModuleBase_IWorkshop* theWorkshop);
82
83 private:
84   /// Constructor is hidden
85   ModuleBase_WidgetCreatorFactory();
86
87   /// Map of widget panel in XML to creator
88   QMap<std::string, WidgetCreatorPtr> myPanelToCreator;
89
90   /// Map of widget page in XML to creator
91   QMap<std::string, WidgetCreatorPtr> myPageToCreator;
92
93   /// Map of widget type in XML to creator
94   QMap<std::string, WidgetCreatorPtr> myCreators;
95 };
96
97 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
98
99 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */