Salome HOME
Construction of vertices/edges/faces on the base of sketch: a special group box in...
[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 class ModuleBase_ModelWidget;
20 class ModuleBase_PageBase;
21
22 class QWidget;
23
24 /**
25 * \ingroup GUI
26 * A class for creation of widgets instances in for property panel using XML deskription of 
27 * a feature
28 */
29 class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory
30 {
31  public:
32   // Returns an singular instance of the class if it exists or create it
33   static std::shared_ptr<ModuleBase_WidgetCreatorFactory> get();
34
35   /// Destructor
36   virtual ~ModuleBase_WidgetCreatorFactory();
37
38   /// The creator is added to the internal container to be used when the createWidgetByType is called
39   /// \param theCreator a new widget creator
40   void registerCreator(const WidgetCreatorPtr& theCreator);
41
42   /// Returns true if there is a creator, which can make a page by the type
43   /// \param theType a type
44   bool hasPageWidget(const std::string& theType);
45
46   /// Create page by its type
47   /// \param theType a type
48   /// \param theParent a parent widget
49   ModuleBase_PageBase* createPageByType(const std::string& theType,
50                                         QWidget* theParent = NULL);
51
52   /// Create widget by its type
53   /// \param theType a type
54   /// \param theParent a parent widget
55   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
56                                              QWidget* theParent = NULL);
57
58 private:
59   /// Constructor is hidden
60   ModuleBase_WidgetCreatorFactory();
61
62   /// Map of widget type in XML to creator
63   QMap<std::string, WidgetCreatorPtr> myCreators;
64
65   /// Map of widget page in XML to creator
66   QMap<std::string, WidgetCreatorPtr> myPageToCreator;
67 };
68
69 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
70
71 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */