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