Salome HOME
Issue #1305: Make different gray color for selectable and non-selectable items
[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 panel by the type
44   /// \param theType a type
45   /// \return a boolean value
46   bool hasPanelWidget(const std::string& theType);
47
48   /// Create panel by its type
49   /// \param theType a type
50   /// \param theParent a parent widget
51   /// \return a created panel or null
52   QWidget* createPanel(const std::string& theType, QWidget* theParent);
53
54   /// Returns true if there is a creator, which can make a page by the type
55   /// \param theType a type
56   /// \return a boolean value
57   bool hasPageWidget(const std::string& theType);
58
59   /// Create page by its type
60   /// \param theType a type
61   /// \param theParent a parent widget
62   /// \return a created page or null
63   ModuleBase_PageBase* createPageByType(const std::string& theType,
64                                         QWidget* theParent,
65                                         Config_WidgetAPI* theWidgetApi);
66
67   /// Create widget by its type
68   /// \param theType a type
69   /// \param theParent a parent widget
70   /// \return a created widget or null
71   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
72                                              QWidget* theParent,
73                                              Config_WidgetAPI* theWidgetApi,
74                                              ModuleBase_IWorkshop* theWorkshop);
75
76 private:
77   /// Constructor is hidden
78   ModuleBase_WidgetCreatorFactory();
79
80   /// Map of widget panel in XML to creator
81   QMap<std::string, WidgetCreatorPtr> myPanelToCreator;
82
83   /// Map of widget page in XML to creator
84   QMap<std::string, WidgetCreatorPtr> myPageToCreator;
85
86   /// Map of widget type in XML to creator
87   QMap<std::string, WidgetCreatorPtr> myCreators;
88 };
89
90 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
91
92 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */