OpenWalnut  1.5.0dev
WQtPropertyGroupWidget.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WQTPROPERTYGROUPWIDGET_H
26 #define WQTPROPERTYGROUPWIDGET_H
27 
28 #include <string>
29 #include <map>
30 
31 #include <QGridLayout>
32 #include <QWidget>
33 
34 #include "WPropertyBoolWidget.h"
35 #include "WPropertyIntWidget.h"
36 #include "WPropertyStringWidget.h"
37 #include "WPropertyDoubleWidget.h"
38 #include "WPropertyColorWidget.h"
39 #include "WPropertyFilenameWidget.h"
40 #include "WPropertyTriggerWidget.h"
41 #include "WPropertySelectionWidget.h"
42 #include "WPropertyPositionWidget.h"
43 #include "WPropertyMatrix4X4Widget.h"
44 #include "WPropertyTransferFunctionWidget.h"
45 #include "WPropertyStructWidget.h"
46 
47 #ifndef Q_MOC_RUN
48 // There is an issue with the moc compiler and some boost headers where
49 // moc for qt versions < 5.0 is not able to do a macro substitution.
50 // The issue occurs in the boost library versions 1.48 and higher,
51 // and is tested in boost version 1.52 using moc version 4.8.4
52 // Excluding the relevant headers removes the problem.
53 #include "core/common/WPropertyVariable.h"
54 #include "core/common/WPropertyStruct.h"
55 #include "core/common/WPropertyGroupBase.h"
56 #endif
57 
58 /**
59  * Container widget to contain a number of properties for the module context in the control panel.
60  */
61 class WQtPropertyGroupWidget : public QWidget
62 {
63  Q_OBJECT
64 
65 public:
66  /**
67  * Creates new widget for a property group. Use this constructor to provide automatic hidden-flag management.
68  * \param group The group
69  * \param depth the nesting depth of this group, it usually is parents depth + 1.
70  * \param parent The widget managing this widget
71  */
72  WQtPropertyGroupWidget( WPropertyGroupBase::SPtr group, size_t depth = 0, QWidget* parent = 0 );
73 
74  /**
75  * This function creates the fancy box around your specified group widget.
76  *
77  * \param widget the widget to put into the box
78  * \param asScrollArea if true, the widget is embedded into a scroll area
79  * \param parent the parent widget
80  * \param title the title to use for the box. If empty, the property group name is used.
81  * \param nestingLevel the nesting level (defines color)
82  *
83  * \return the box widget
84  */
85  static QWidget* createPropertyGroupBox( QWidget* widget, bool asScrollArea = false, QWidget* parent = NULL,
86  const QString& title = "", int nestingLevel = 0 );
87 
88  /**
89  * Create a property widget using the given group.
90  *
91  * \param group the property group to represent
92  * \param title the title of the widget
93  * \param depth the nesting depth
94  * \param parent the parent widget
95  *
96  * \return the widget.
97  */
98  static QWidget* createPropertyGroupBox( WPropertyGroupBase::SPtr group, const QString& title = "", size_t depth = 0, QWidget* parent = 0 );
99 
100  /**
101  * Create a property widget using the given group.
102  *
103  * \param group the property group to represent
104  * \param title the title of the widget
105  * \param depth the nesting depth
106  * \param parent the parent widget
107  * \param asScrollArea if true, add a scroll area around the group
108  *
109  * \return the widget.
110  */
111  static QWidget* createPropertyGroupBox( WPropertyGroupBase::SPtr group, bool asScrollArea, const QString& title = "", size_t depth = 0,
112  QWidget* parent = 0 );
113 
114 
115  /**
116  * Create a property widget using the given group. The difference to \ref createPropertyGroupBox is that this call only creates the plain
117  * WQtPropertyGroupWidget which can be embedded somewhere else.
118  *
119  * \param group the property group to represent
120  * \param title the title of the widget
121  * \param depth the nesting depth
122  * \param parent the parent widget
123  *
124  * \return the widget.
125  */
126  static WQtPropertyGroupWidget* createPropertyGroupWidget( WPropertyGroupBase::SPtr group, const QString& title = "", size_t depth = 0,
127  QWidget* parent = 0 );
128 
129  /**
130  * destructor
131  */
132  virtual ~WQtPropertyGroupWidget();
133 
134  /**
135  * True if there are no widgets inside.
136  *
137  * \return true if number of widgets is 0.
138  */
139  bool isEmpty() const;
140 
141  /**
142  * helper function to add a generic button
143  * \param label Text on the push button
144  *
145  * \return the push button instance
146  */
147  QPushButton* addPushButton( QString label );
148 
149  /**
150  * Adds a new property widget to the PropertyGroup. Returns NULL if property not supported. This also supports groups.
151  *
152  * \param property the property to add.
153  */
154  void addProp( WPropertyBase::SPtr property );
155 
156  /**
157  * Adds an widget containing another property group to this widget. It encloses it with a GroupBox.
158  *
159  * \param widget the widget
160  * \param asScrollArea true if the group should be embedded into a scroll area
161  */
162  void addGroup( WQtPropertyGroupWidget* widget, bool asScrollArea = false );
163 
164  /**
165  * Add the given prop group to this widget.
166  *
167  * \param prop the property group
168  */
169  void addGroup( WPropertyGroupBase::SPtr prop );
170 
171  /**
172  * helper function to add a spacer at the end
173  */
174  void addSpacer();
175 
176  /**
177  * The property group name.
178  *
179  * \return the group name
180  */
181  QString getName();
182 
183  /**
184  * Sets the name of this widget.
185  *
186  * \param name the name.
187  */
188  void setName( QString name );
189 
190  /**
191  * Get the managed group of this widget.
192  *
193  * \return the group
194  */
196 
197 signals:
198 
199  /**
200  * A Signal which gets emitted whenever the widget should be hidden. This is a useful signal for containers which embed this group.
201  *
202  * \param hide if true, the widget should be hidden.
203  */
204  void hideSignal( bool hide );
205 
206 protected:
207  /**
208  * Callback for WPropertyBase::getChangeCondition. It emits an event to ensure all updates are done in gui thread.
209  */
210  virtual void propertyChangeNotifier();
211 
212  /**
213  * Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
214  * processes property change events.
215  *
216  * \note QT Doc says: use event() for custom events.
217  * \param event the event that got transmitted.
218  *
219  * \return true if the event got handled properly.
220  */
221  virtual bool event( QEvent* event );
222 
223 private:
224  /**
225  * The name used for this widget.
226  */
227  QString m_name;
228 
229  /**
230  * Layout used for each "widget combination".
231  */
232  QGridLayout *m_controlLayout;
233 
234  /**
235  * Layout used for the whole widget.
236  */
237  QVBoxLayout *m_pageLayout;
238 
239  /**
240  * The number of widgets inside this one.
241  */
242  unsigned int m_numberOfWidgets;
243 
244  /**
245  * The property group handled here.
246  */
248 
249  /**
250  * The map between a prop and the widget handling it.
251  */
252  typedef std::map< WPropertyBase::SPtr, QWidget* > PropertyWidgets;
253 
254  /**
255  * The map if property pointer to actual property widget.
256  */
258 
259  /**
260  * The connection for propertyChangeNotifier().
261  */
262  boost::signals2::connection m_connection;
263 
264  /**
265  * The depth of this group.
266  */
268 };
269 
270 #endif // WQTPROPERTYGROUPWIDGET_H
std::shared_ptr< WPropertyBase > SPtr
Convenience typedef for a std::shared_ptr< WPropertyBase >
Definition: WPropertyBase.h:53
std::shared_ptr< WPropertyGroupBase > SPtr
Convenience typedef for a std::shared_ptr< WPropertyGroupBase >.
Container widget to contain a number of properties for the module context in the control panel.
QGridLayout * m_controlLayout
Layout used for each "widget combination".
QString m_name
The name used for this widget.
virtual ~WQtPropertyGroupWidget()
destructor
PropertyWidgets m_propWidgets
The map if property pointer to actual property widget.
std::map< WPropertyBase::SPtr, QWidget * > PropertyWidgets
The map between a prop and the widget handling it.
boost::signals2::connection m_connection
The connection for propertyChangeNotifier().
void hideSignal(bool hide)
A Signal which gets emitted whenever the widget should be hidden.
QString getName()
The property group name.
unsigned int m_numberOfWidgets
The number of widgets inside this one.
QVBoxLayout * m_pageLayout
Layout used for the whole widget.
virtual bool event(QEvent *event)
Custom event dispatcher.
void setName(QString name)
Sets the name of this widget.
void addSpacer()
helper function to add a spacer at the end
WPropertyGroupBase::SPtr m_group
The property group handled here.
QPushButton * addPushButton(QString label)
helper function to add a generic button
size_t m_nestingDepth
The depth of this group.
static QWidget * createPropertyGroupBox(QWidget *widget, bool asScrollArea=false, QWidget *parent=NULL, const QString &title="", int nestingLevel=0)
This function creates the fancy box around your specified group widget.
virtual void propertyChangeNotifier()
Callback for WPropertyBase::getChangeCondition.
WQtPropertyGroupWidget(WPropertyGroupBase::SPtr group, size_t depth=0, QWidget *parent=0)
Creates new widget for a property group.
static WQtPropertyGroupWidget * createPropertyGroupWidget(WPropertyGroupBase::SPtr group, const QString &title="", size_t depth=0, QWidget *parent=0)
Create a property widget using the given group.
WPropertyGroupBase::SPtr getPropertyGroup()
Get the managed group of this widget.
void addProp(WPropertyBase::SPtr property)
Adds a new property widget to the PropertyGroup.
bool isEmpty() const
True if there are no widgets inside.
void addGroup(WQtPropertyGroupWidget *widget, bool asScrollArea=false)
Adds an widget containing another property group to this widget.