Salome HOME
Update copyrights
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetCreatorFactory.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
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   /// \return a created panel or null
69   QWidget* createPanelByType(const std::string& theType, QWidget* theParent,
70                              const FeaturePtr& theFeature);
71
72   /// Returns true if there is a creator, which can make a page by the type
73   /// \param theType a type
74   /// \return a boolean value
75   bool hasPageWidget(const std::string& theType);
76
77   /// Create page by its type
78   /// \param theType a type
79   /// \param theParent a parent widget
80   /// \param theWidgetApi the widget configuration.
81   ///                     The attribute of the model widget is obtained from XML
82   /// \return a created page or null
83   ModuleBase_PageBase* createPageByType(const std::string& theType,
84                                         QWidget* theParent,
85                                         Config_WidgetAPI* theWidgetApi);
86
87   /// Create widget by its type
88   /// \param theType a type
89   /// \param theParent a parent widget
90   /// \param theWidgetApi the widget configuration.
91   ///                     The attribute of the model widget is obtained from XML
92   /// \param theWorkshop a workshop object instance
93   /// \return a created widget or null
94   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
95                                              QWidget* theParent,
96                                              Config_WidgetAPI* theWidgetApi,
97                                              ModuleBase_IWorkshop* theWorkshop);
98
99 private:
100   /// Constructor is hidden
101   ModuleBase_WidgetCreatorFactory();
102
103   /// Map of widget panel in XML to creator
104   QMap<std::string, WidgetCreatorPtr> myPanelToCreator;
105
106   /// Map of widget page in XML to creator
107   QMap<std::string, WidgetCreatorPtr> myPageToCreator;
108
109   /// Map of widget type in XML to creator
110   QMap<std::string, WidgetCreatorPtr> myCreators;
111 };
112
113 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
114
115 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */