Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetCreatorFactory.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef MODULEBASE_WIDGETCREATORFACTORY_H_
22 #define MODULEBASE_WIDGETCREATORFACTORY_H_
23
24 #include <ModuleBase.h>
25
26 #include <memory>
27 #include <string>
28
29 #include <QMap>
30
31 #include <ModuleBase_IWidgetCreator.h>
32
33 #include <ModelAPI_Feature.h>
34
35 class ModuleBase_ModelWidget;
36 class ModuleBase_PageBase;
37 class ModuleBase_IWorkshop;
38
39 class QWidget;
40
41 /**
42 * \ingroup GUI
43 * A class for creation of widgets instances in for property panel using XML deskription of
44 * a feature
45 */
46 class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory
47 {
48  public:
49   /// Returns an singular instance of the class if it exists or create it
50   static std::shared_ptr<ModuleBase_WidgetCreatorFactory> get();
51
52   /// Destructor
53   virtual ~ModuleBase_WidgetCreatorFactory();
54
55   /// The creator is added to the internal container
56   /// to be used when the createWidgetByType is called
57   /// \param theCreator a new widget creator
58   void registerCreator(const WidgetCreatorPtr& theCreator);
59
60   /// Returns true if there is a creator, which can make a panel by the type
61   /// \param theType a type
62   /// \return a boolean value
63   bool hasPanelWidget(const std::string& theType);
64
65   /// Create panel by its type
66   /// \param theType a type
67   /// \param theParent a parent widget
68   /// \param theFeature a feature to fill the panel
69   /// \return a created panel or null
70   QWidget* createPanelByType(const std::string& theType, QWidget* theParent,
71                              const FeaturePtr& theFeature);
72
73   /// Returns true if there is a creator, which can make a page by the type
74   /// \param theType a type
75   /// \return a boolean value
76   bool hasPageWidget(const std::string& theType);
77
78   /// Create page by its type
79   /// \param theType a type
80   /// \param theParent a parent widget
81   /// \param theWidgetApi the widget configuration.
82   ///                     The attribute of the model widget is obtained from XML
83   /// \return a created page or null
84   ModuleBase_PageBase* createPageByType(const std::string& theType,
85                                         QWidget* theParent,
86                                         Config_WidgetAPI* theWidgetApi);
87
88   /// Create widget by its type
89   /// \param theType a type
90   /// \param theParent a parent widget
91   /// \param theWidgetApi the widget configuration.
92   ///                     The attribute of the model widget is obtained from XML
93   /// \param theWorkshop a workshop object instance
94   /// \return a created widget or null
95   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
96                                              QWidget* theParent,
97                                              Config_WidgetAPI* theWidgetApi,
98                                              ModuleBase_IWorkshop* theWorkshop);
99
100 private:
101   /// Constructor is hidden
102   ModuleBase_WidgetCreatorFactory();
103
104   /// Map of widget panel in XML to creator
105   QMap<std::string, WidgetCreatorPtr> myPanelToCreator;
106
107   /// Map of widget page in XML to creator
108   QMap<std::string, WidgetCreatorPtr> myPageToCreator;
109
110   /// Map of widget type in XML to creator
111   QMap<std::string, WidgetCreatorPtr> myCreators;
112 };
113
114 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
115
116 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */