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