OpenWalnut  1.5.0dev
WPropertyWidget.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 WPROPERTYWIDGET_H
26 #define WPROPERTYWIDGET_H
27 
28 #include <memory>
29 #include <string>
30 
31 #include <QFrame>
32 #include <QGridLayout>
33 #include <QLabel>
34 #include <QStackedWidget>
35 #include <QWidget>
36 
37 #include "../guiElements/WScaleLabel.h"
38 #include "core/common/WPropertyBase.h"
39 #include "core/common/WPropertyTypes.h"
40 
41 /**
42  * Class building the base for all widgets representing properties. It simply contains the handled property object.
43  */
45 {
46  Q_OBJECT
47 
48 public:
49  /**
50  * Constructor. Creates a new widget appropriate for the specified property.
51  *
52  * \param property the property to handle
53  * \param parent the parent widget.
54  * \param propertyGrid the grid used to layout the labels and property widgets
55  */
56  WPropertyWidget( std::shared_ptr< WPropertyBase > property, QGridLayout* propertyGrid, QWidget* parent = 0 );
57 
58  /**
59  * Destructor.
60  */
61  virtual ~WPropertyWidget();
62 
63  /**
64  * Returns the handled property.
65  *
66  * \return the property
67  */
68  std::shared_ptr< WPropertyBase > getProperty();
69 
70  /**
71  * This method marks this widget as invalid. This is useful to let the user know about wrong inputs.
72  *
73  * \param invalid true whenever the property widget should be marked as invalid
74  */
75  virtual void invalidate( bool invalid = true );
76 
77  /**
78  * Gets the tooltip that should be used for this widget.
79  *
80  * \return the tooltip.
81  */
82  virtual std::string getTooltip() const;
83 
84  /**
85  * Returns the parameter widget for this property.
86  *
87  * \return the widget
88  */
89  QWidget* getParameterWidgets();
90 
91  /**
92  * Returns the info widget for this property.
93  *
94  * \return the widget.
95  */
96  QWidget* getInformationWidgets();
97 
98  /**
99  * Constructs a proper widget for the specified property. If the widget type is not supported, NULL is returned.
100  *
101  * \param property the property to create the widget for
102  * \param propertyGrid grid to provide to he widget
103  * \param parent parent of the widget
104  *
105  * \return widget
106  */
107  static WPropertyWidget* construct( WPropertyBase::SPtr property, QGridLayout* propertyGrid = NULL, QWidget* parent = NULL );
108 
109  /**
110  * Request an update of the property widget. Can be called from any thread.
111  */
112  virtual void requestUpdate();
113 
114  /**
115  * Force the widget to use the information widgets.
116  *
117  * \param force true to force
118  */
119  void forceInformationMode( bool force = true );
120 protected:
121  /**
122  * Called whenever the widget should update itself.
123  */
124  virtual void update() = 0;
125 
126  /**
127  * The property handled by the widget.
128  */
129  std::shared_ptr< WPropertyBase > m_property;
130 
131  /**
132  * The grid used to layout label and widget.
133  */
134  QGridLayout* m_propertyGrid;
135 
136  /**
137  * The label used to name the property
138  */
140 
141  /**
142  * Separator after each property
143  */
144  QWidget m_separator;
145 
146  /**
147  * If set to true, the widgets uses the control layout to combine the widget with a label
148  */
150 
151  /**
152  * The widget containing a layout and provides the edit widgets for the property.
153  */
155 
156  /**
157  * The widget containing a layout and provides the widgets for showing information properties.
158  */
160 
161  /**
162  * Flag denoting whether the widget is set to an invalid value.
163  */
164  bool m_invalid;
165 
166  /**
167  * Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
168  * processes property change events.
169  *
170  * \note QT Doc says: use event() for custom events.
171  * \param event the event that got transmitted.
172  *
173  * \return true if the event got handled properly.
174  */
175  virtual bool event( QEvent* event );
176 
177  /**
178  * The connection for propertyChangeNotifier().
179  */
180  boost::signals2::connection m_connection;
181 
182  /**
183  * The color to use for separators.
184  */
185  QColor m_sepCol;
186 
187  /**
188  * The color to use for the property labels
189  */
190  QColor m_labelCol;
191 
192  /**
193  * The color to use for property widgets
194  */
196 
197  /**
198  * Color used for indicating errors
199  */
200  QColor m_errorCol;
201 private:
202 };
203 
204 #endif // WPROPERTYWIDGET_H
205 
std::shared_ptr< WPropertyBase > SPtr
Convenience typedef for a std::shared_ptr< WPropertyBase >
Definition: WPropertyBase.h:53
Class building the base for all widgets representing properties.
std::shared_ptr< WPropertyBase > m_property
The property handled by the widget.
QGridLayout * m_propertyGrid
The grid used to layout label and widget.
bool m_useLabel
If set to true, the widgets uses the control layout to combine the widget with a label.
QWidget m_informationWidgets
The widget containing a layout and provides the widgets for showing information properties.
QWidget m_separator
Separator after each property.
QWidget * getInformationWidgets()
Returns the info widget for this property.
static WPropertyWidget * construct(WPropertyBase::SPtr property, QGridLayout *propertyGrid=NULL, QWidget *parent=NULL)
Constructs a proper widget for the specified property.
WScaleLabel m_label
The label used to name the property.
WPropertyWidget(std::shared_ptr< WPropertyBase > property, QGridLayout *propertyGrid, QWidget *parent=0)
Constructor.
void forceInformationMode(bool force=true)
Force the widget to use the information widgets.
QColor m_errorCol
Color used for indicating errors.
virtual void requestUpdate()
Request an update of the property widget.
QWidget * getParameterWidgets()
Returns the parameter widget for this property.
QColor m_labelCol
The color to use for the property labels.
QColor m_propertyCol
The color to use for property widgets.
bool m_invalid
Flag denoting whether the widget is set to an invalid value.
boost::signals2::connection m_connection
The connection for propertyChangeNotifier().
QWidget m_parameterWidgets
The widget containing a layout and provides the edit widgets for the property.
virtual void invalidate(bool invalid=true)
This method marks this widget as invalid.
std::shared_ptr< WPropertyBase > getProperty()
Returns the handled property.
virtual ~WPropertyWidget()
Destructor.
QColor m_sepCol
The color to use for separators.
virtual void update()=0
Called whenever the widget should update itself.
virtual bool event(QEvent *event)
Custom event dispatcher.
virtual std::string getTooltip() const
Gets the tooltip that should be used for this widget.
Special Label that can shrink and expand in a layout.
Definition: WScaleLabel.h:37