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_WIDGETFACTORY_H_
21 #define MODULEBASE_WIDGETFACTORY_H_
23 #include <ModuleBase.h>
24 #include <ModuleBase_ModelWidget.h>
31 class Config_WidgetAPI;
32 class ModuleBase_IWorkshop;
33 class ModuleBase_PageBase;
37 * A class for creation of widgets instances in for property panel using XML deskription of
40 class MODULEBASE_EXPORT ModuleBase_WidgetFactory
44 /// \param theXmlRepresentation content of XML file
45 /// \param theWorkshop reference to workshop instance
46 /// \param theAttributePrefix prefix that must be added to the attribute name
47 ModuleBase_WidgetFactory(const std::string& theXmlRepresentation,
48 ModuleBase_IWorkshop* theWorkshop,
49 const std::string theAttributePrefix = "");
50 virtual ~ModuleBase_WidgetFactory();
52 /// Creates content widget for property panel
53 /// \param thePage a parent page
54 /// \param alignToTop align to top flag (true by default)
55 void createWidget(ModuleBase_PageBase* thePage, bool alignToTop = true);
57 /// Creates property panel content for the feature
58 /// \param thePage a parent page
59 /// \param theFeature a feature to fill the panel
60 void createPanel(ModuleBase_PageBase* thePage, const FeaturePtr& theFeature);
62 /// Creates one widget for property panel for the widget with given index
63 /// \param thePage a parent widget
64 /// \param theWidgetId a widget index
65 void createWidget(ModuleBase_PageBase* thePage,
66 const std::string& theWidgetId);
68 /// Returns list of model widgets
69 QList<ModuleBase_ModelWidget*> getModelWidgets() const
71 return myModelWidgets;
74 /// Returns the value of the title key from XML definition of the attribute in the feature
75 /// \param theAttributeId a value of a kind of the attribute under the feature
76 /// \param theTitle the result title
77 void getAttributeTitle(const std::string& theAttributeId,
78 std::string& theTitle);
80 /// Returns the identifier of the first found attribute where greed field value is set and true
81 /// \param theAttributeId an outpup parameter with attribute
82 void getGreedAttribute(std::string& theAttributeId);
84 /// Returns widget API from XML
85 const Config_WidgetAPI* widgetAPI() const { return myWidgetApi; }
88 /// check if ModuleBase_Widget has expandable widgets in getControls
89 bool hasExpandingControls(QWidget* theParent);
91 /// Create page by its type
92 /// \param theType a type
93 /// \param theParent a parent widget
94 ModuleBase_PageBase* createPageByType(const std::string& theType,
97 /// Create widget by its type
98 /// \param theType a type
99 /// \param theParent a parent widget
100 ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
101 QWidget* theParent = NULL);
103 /// Convert STD string to QT string
104 /// \param theStdString is STD string
105 static QString qs(const std::string& theStdString);
107 /// It updates internal config api to point in the structure to given id of widget
108 /// The method is recusive and it stops when the found flag is true
109 /// \param theWidgetId a widget id key value
110 /// \param theFound a flag about found windget and recursive search should be stopped
111 void moveToWidgetId(const std::string& theWidgetId, bool& theFound);
114 /// API object for XML reading
115 Config_WidgetAPI* myWidgetApi;
117 /// Reference to workshop
118 ModuleBase_IWorkshop* myWorkshop;
120 /// List of created model widgets
121 QList<ModuleBase_ModelWidget*> myModelWidgets;
124 #endif /* ModuleBase_WidgetFactory_H_ */