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