Salome HOME
Fix suite_FEATURE_REVOLUTION tests: difference in few pixels
[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                                         std::string theParentId);
54
55   /// Create widget by its type
56   /// \param theType a type
57   /// \param theParent a parent widget
58   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
59                                              QWidget* theParent,
60                                              Config_WidgetAPI* theWidgetApi,
61                                              std::string theParentId,
62                                              ModuleBase_IWorkshop* theWorkshop);
63
64 private:
65   /// Constructor is hidden
66   ModuleBase_WidgetCreatorFactory();
67
68   /// Map of widget type in XML to creator
69   QMap<std::string, WidgetCreatorPtr> myCreators;
70
71   /// Map of widget page in XML to creator
72   QMap<std::string, WidgetCreatorPtr> myPageToCreator;
73 };
74
75 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
76
77 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */