1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef MODULEBASE_WIDGETCREATORFACTORY_H_
22 #define MODULEBASE_WIDGETCREATORFACTORY_H_
24 #include <ModuleBase.h>
31 #include <ModuleBase_IWidgetCreator.h>
33 #include <ModelAPI_Feature.h>
35 class ModuleBase_ModelWidget;
36 class ModuleBase_PageBase;
37 class ModuleBase_IWorkshop;
43 * A class for creation of widgets instances in for property panel using XML deskription of
46 class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory
49 /// Returns an singular instance of the class if it exists or create it
50 static std::shared_ptr<ModuleBase_WidgetCreatorFactory> get();
53 virtual ~ModuleBase_WidgetCreatorFactory();
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);
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);
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);
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);
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,
86 Config_WidgetAPI* theWidgetApi);
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,
97 Config_WidgetAPI* theWidgetApi,
98 ModuleBase_IWorkshop* theWorkshop);
101 /// Constructor is hidden
102 ModuleBase_WidgetCreatorFactory();
104 /// Map of widget panel in XML to creator
105 QMap<std::string, WidgetCreatorPtr> myPanelToCreator;
107 /// Map of widget page in XML to creator
108 QMap<std::string, WidgetCreatorPtr> myPageToCreator;
110 /// Map of widget type in XML to creator
111 QMap<std::string, WidgetCreatorPtr> myCreators;
114 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
116 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */