Salome HOME
5c6ce02d206682299dc4fd3427c580f5eb07e623
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFactory.h
1 // Copyright (C) 2014-2023  CEA, EDF
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_WIDGETFACTORY_H_
21 #define MODULEBASE_WIDGETFACTORY_H_
22
23 #include <ModuleBase.h>
24 #include <ModuleBase_ModelWidget.h>
25
26 #include <QString>
27 #include <QList>
28
29 class QObject;
30 class QWidget;
31 class Config_WidgetAPI;
32 class ModuleBase_IWorkshop;
33 class ModuleBase_PageBase;
34
35 /**
36 * \ingroup GUI
37 * A class for creation of widgets instances in for property panel using XML deskription of 
38 * a feature
39 */
40 class MODULEBASE_EXPORT ModuleBase_WidgetFactory
41 {
42  public:
43    /// Constructor
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();
51
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);
56
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);
61
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);
67
68   /// Returns list of model widgets
69   QList<ModuleBase_ModelWidget*> getModelWidgets() const
70   {
71     return myModelWidgets;
72   }
73
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);
79
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);
83
84   /// Returns widget API from XML
85   const Config_WidgetAPI* widgetAPI() const { return myWidgetApi; }
86
87 protected:
88   /// check if ModuleBase_Widget has expandable widgets in getControls
89   bool hasExpandingControls(QWidget* theParent);
90
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,
95                                         QWidget* theParent);
96
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);
102
103   /// Convert STD string to QT string
104   /// \param theStdString is STD string
105   static QString qs(const std::string& theStdString);
106
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);
112
113  private:
114    /// API object for XML reading
115   Config_WidgetAPI* myWidgetApi;
116
117   /// Reference to workshop
118   ModuleBase_IWorkshop* myWorkshop;
119
120   /// List of created model widgets
121   QList<ModuleBase_ModelWidget*> myModelWidgets;
122 };
123
124 #endif /* ModuleBase_WidgetFactory_H_ */