Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFactory.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_WIDGETFACTORY_H_
22 #define MODULEBASE_WIDGETFACTORY_H_
23
24 #include <ModuleBase.h>
25 #include <ModuleBase_ModelWidget.h>
26
27 #include <QString>
28 #include <QList>
29
30 class QObject;
31 class QWidget;
32 class Config_WidgetAPI;
33 class ModuleBase_IWorkshop;
34 class ModuleBase_PageBase;
35
36 /**
37 * \ingroup GUI
38 * A class for creation of widgets instances in for property panel using XML deskription of 
39 * a feature
40 */
41 class MODULEBASE_EXPORT ModuleBase_WidgetFactory
42 {
43  public:
44    /// Constructor
45    /// \param theXmlRepresentation content of XML file
46    /// \param theWorkshop reference to workshop instance
47   ModuleBase_WidgetFactory(const std::string& theXmlRepresentation,
48                            ModuleBase_IWorkshop* theWorkshop);
49   virtual ~ModuleBase_WidgetFactory();
50
51   /// Creates content widget for property panel
52   /// \param thePage a parent page
53   /// \param alignToTop align to top flag (true by default)
54   void createWidget(ModuleBase_PageBase* thePage, bool alignToTop = true);
55
56   /// Creates property panel content for the feature
57   /// \param thePage a parent page
58   /// \param theFeature a feature to fill the panel
59   void createPanel(ModuleBase_PageBase* thePage, const FeaturePtr& theFeature);
60
61   /// Creates one widget for property panel for the widget with given index
62   /// \param thePage a parent widget
63   /// \param theWidgetId a widget index
64   void createWidget(ModuleBase_PageBase* thePage,
65                     const std::string& theWidgetId);
66
67   /// Returns list of model widgets
68   QList<ModuleBase_ModelWidget*> getModelWidgets() const
69   {
70     return myModelWidgets;
71   }
72
73   /// Returns the value of the title key from XML definition of the attribute in the feature
74   /// \param theAttributeId a value of a kind of the attribute under the feature
75   /// \param theTitle the result title
76   void getAttributeTitle(const std::string& theAttributeId,
77                          std::string& theTitle);
78
79   /// Returns the identifier of the first found attribute where greed field value is set and true
80   /// \param theAttributeId an outpup parameter with  attribute
81   void getGreedAttribute(std::string& theAttributeId);
82
83   /// Returns widget API from XML
84   const Config_WidgetAPI* widgetAPI() const { return myWidgetApi; }
85
86 protected:
87   /// check if ModuleBase_Widget has expandable widgets in getControls
88   bool hasExpandingControls(QWidget* theParent);
89
90   /// Create page by its type
91   /// \param theType a type
92   /// \param theParent a parent widget
93   ModuleBase_PageBase* createPageByType(const std::string& theType,
94                                         QWidget* theParent);
95
96   /// Create widget by its type
97   /// \param theType a type
98   /// \param theParent a parent widget
99   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
100                                              QWidget* theParent = NULL);
101
102   /// Convert STD string to QT string
103   /// \param theStdString is STD string
104   static QString qs(const std::string& theStdString);
105
106   /// It updates internal config api to point in the structure to given id of widget
107   /// The method is recusive and it stops when the found flag is true
108   /// \param theWidgetId a widget id key value
109   /// \param theFound a flag about found windget and recursive search should be stopped
110   void moveToWidgetId(const std::string& theWidgetId, bool& theFound);
111
112  private:
113    /// API object for XML reading
114   Config_WidgetAPI* myWidgetApi;
115
116   /// Reference to workshop
117   ModuleBase_IWorkshop* myWorkshop;
118
119   /// List of created model widgets
120   QList<ModuleBase_ModelWidget*> myModelWidgets;
121 };
122
123 #endif /* ModuleBase_WidgetFactory_H_ */