Salome HOME
Issue #1302 Restricting preselection to the first argument only: mirror feature has...
[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   void createWidget(ModuleBase_PageBase* thePage);
43
44   /// Creates one widget for property panel for the widget with given index
45   /// \param theParent a parent widget
46   /// \param theWidgetId a widget index
47   void createWidget(ModuleBase_PageBase* thePage,
48                     const std::string& theWidgetId);
49
50   /// Returns list of model widgets
51   QList<ModuleBase_ModelWidget*> getModelWidgets() const
52   {
53     return myModelWidgets;
54   }
55
56   /// Returns the value of the title key from XML definition of the attribute in the feature
57   /// \param theAttributeId a value of a kind of the attribute under the feature
58   /// \param theTitle the result title
59   void getAttributeTitle(const std::string& theAttributeId,
60                          std::string& theTitle);
61
62   /// Returns the identifier of the first found attribute where greed field value is set and true
63   /// \param theAttributeId an outpup parameter with  attribute
64   void getGreedAttribute(std::string& theAttributeId);
65
66 protected:
67   /// check if ModuleBase_Widget has expandable widgets in getControls
68   bool hasExpandingControls(QWidget* theParent);
69
70   /// Create page by its type
71   /// \param theType a type
72   /// \param theParent a parent widget
73   ModuleBase_PageBase* createPageByType(const std::string& theType,
74                                         QWidget* theParent);
75
76   /// Create widget by its type
77   /// \param theType a type
78   /// \param theParent a parent widget
79   ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
80                                              QWidget* theParent = NULL);
81
82   /// Convert STD string to QT string
83   /// \param theStdString is STD string
84   static QString qs(const std::string& theStdString);
85
86   /// It updates internal config api to point in the structure to given id of widget
87   /// The method is recusive and it stops when the found flag is true
88   /// \param theWidgetId a widget id key value
89   /// \param theFound a flag about found windget and recursive search should be stopped
90   void moveToWidgetId(const std::string& theWidgetId, bool& theFound);
91
92  private:
93    /// API object for XML reading
94   Config_WidgetAPI* myWidgetApi;
95
96   /// Reference to workshop
97   ModuleBase_IWorkshop* myWorkshop;
98
99   /// List of created model widgets
100   QList<ModuleBase_ModelWidget*> myModelWidgets;
101
102   /// Id of current parent
103   std::string myParentId;
104 };
105
106 #endif /* ModuleBase_WidgetFactory_H_ */