Salome HOME
updated copyright message
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetCreatorFactory.h
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef MODULEBASE_WIDGETCREATORFACTORY_H_
21 #define MODULEBASE_WIDGETCREATORFACTORY_H_
22
23 #include <ModuleBase.h>
24
25 #include <memory>
26 #include <string>
27
28 #include <QMap>
29
30 #include <ModuleBase_IWidgetCreator.h>
31
32 #include <ModelAPI_Feature.h>
33
34 class ModuleBase_ModelWidget;
35 class ModuleBase_PageBase;
36 class ModuleBase_IWorkshop;
37
38 class QWidget;
39
40 /**
41 * \ingroup GUI
42 * A class for creation of widgets instances in for property panel using XML deskription of
43 * a feature
44 */
45 class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory
46 {
47  public:
48   /// Returns an singular instance of the class if it exists or create it
49   static std::shared_ptr<ModuleBase_WidgetCreatorFactory> get();
50
51   /// Destructor
52   virtual ~ModuleBase_WidgetCreatorFactory();
53
54   /// The creator is added to the internal container
55   /// to be used when the createWidgetByType is called
56   /// \param theCreator a new widget creator
57   void registerCreator(const WidgetCreatorPtr& theCreator);
58
59   /// Returns true if there is a creator, which can make a panel by the type
60   /// \param theType a type
61   /// \return a boolean value
62   bool hasPanelWidget(const std::string& theType);
63
64   /// Create panel by its type
65   /// \param theType a type
66   /// \param theParent a parent widget
67   /// \param theFeature a feature to fill the panel
68   /// \param theWidgetApi the widget configuration.
69   ///                     The attribute of the model widget is obtained from XML
70   /// \return a created panel or null
71   QWidget* createPanelByType(const std::string& theType, QWidget* theParent,
72                              const FeaturePtr& theFeature,
73                              Config_WidgetAPI* theWidgetApi = 0);
74
75   /// Returns true if there is a creator, which can make a page by the type
76   /// \param theType a type
77   /// \return a boolean value
78   bool hasPageWidget(const std::string& theType);
79
80   /// Create page by its type
81   /// \param theType a type
82   /// \param theParent a parent widget
83   /// \param theWidgetApi the widget configuration.
84   ///                     The attribute of the model widget is obtained from XML
85   /// \return a created page or null
86   ModuleBase_PageBase* createPageByType(const std::string& theType,
87                                         QWidget* theParent,
88                                         Config_WidgetAPI* theWidgetApi);
89
90   /// Create widget by its type
91   /// \param theType a type
92   /// \param theParent a parent widget
93   /// \param theWidgetApi the widget configuration.
94   ///                     The attribute of the model widget is obtained from XML
95   /// \param theWorkshop a workshop object instance
96   /// \return a created widget or null
97   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
98                                              QWidget* theParent,
99                                              Config_WidgetAPI* theWidgetApi,
100                                              ModuleBase_IWorkshop* theWorkshop);
101
102 private:
103   /// Constructor is hidden
104   ModuleBase_WidgetCreatorFactory();
105
106   /// Map of widget panel in XML to creator
107   QMap<std::string, WidgetCreatorPtr> myPanelToCreator;
108
109   /// Map of widget page in XML to creator
110   QMap<std::string, WidgetCreatorPtr> myPageToCreator;
111
112   /// Map of widget type in XML to creator
113   QMap<std::string, WidgetCreatorPtr> myCreators;
114 };
115
116 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
117
118 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */