1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #ifndef MODULEBASE_WIDGETCREATORFACTORY_H_
21 #define MODULEBASE_WIDGETCREATORFACTORY_H_
23 #include <ModuleBase.h>
30 #include <ModuleBase_IWidgetCreator.h>
32 #include <ModelAPI_Feature.h>
34 class ModuleBase_ModelWidget;
35 class ModuleBase_PageBase;
36 class ModuleBase_IWorkshop;
42 * A class for creation of widgets instances in for property panel using XML deskription of
45 class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory
48 /// Returns an singular instance of the class if it exists or create it
49 static std::shared_ptr<ModuleBase_WidgetCreatorFactory> get();
52 virtual ~ModuleBase_WidgetCreatorFactory();
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);
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);
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);
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);
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,
85 Config_WidgetAPI* theWidgetApi);
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,
96 Config_WidgetAPI* theWidgetApi,
97 ModuleBase_IWorkshop* theWorkshop);
100 /// Constructor is hidden
101 ModuleBase_WidgetCreatorFactory();
103 /// Map of widget panel in XML to creator
104 QMap<std::string, WidgetCreatorPtr> myPanelToCreator;
106 /// Map of widget page in XML to creator
107 QMap<std::string, WidgetCreatorPtr> myPageToCreator;
109 /// Map of widget type in XML to creator
110 QMap<std::string, WidgetCreatorPtr> myCreators;
113 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
115 #endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */