Salome HOME
Construction of vertices/edges/faces on the base of sketch: Widget Creator Factory
[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
21 class QWidget;
22
23 /**
24 * \ingroup GUI
25 * A class for creation of widgets instances in for property panel using XML deskription of 
26 * a feature
27 */
28 class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory
29 {
30  public:
31   // Returns an singular instance of the class if it exists or create it
32   static std::shared_ptr<ModuleBase_WidgetCreatorFactory> get();
33
34   /// Destructor
35   virtual ~ModuleBase_WidgetCreatorFactory();
36
37   /// The creator is added to the internal container to be used when the createWidgetByType is called
38   /// \param theCreator a new widget creator
39   void registerCreator(const WidgetCreatorPtr& theCreator);
40
41   /// Create widget by its type
42   /// \param theType a type
43   /// \param theParent a parent widget
44   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
45                                              QWidget* theParent = NULL);
46
47 private:
48   /// Constructor is hidden
49   ModuleBase_WidgetCreatorFactory();
50
51   /// List of created model widgets
52   QMap<std::string, WidgetCreatorPtr> myModelWidgets;
53 };
54
55 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
56
57 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */