OpenWalnut  1.5.0dev
WPropertyStructWidget.cpp
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 #include "../WGuiConsts.h"
26 #include "core/common/WAssert.h"
27 #include "WPropertyStructWidget.h"
28 
29 WPropertyStructWidget::WPropertyStructWidget( WPropertyGroupBase::SPtr property, QGridLayout* propertyGrid, QWidget* parent ):
30  WPropertyWidget( property, propertyGrid, parent ),
31  m_struct( property ),
32  m_layout( &m_parameterWidgets )
33 {
34  // although we could also work with other group types, we limit this widget to PV_STRUCT properties, because they have fixed size and cannot
35  // be modified somehow. If you remove this assert, ensure the widget is able to handle dynamic updates in the group!
36  WAssert( property->getType() == PV_STRUCT, "WPropertyStructWidget is only compatible with WPropertyStruct instances." );
37 
38  // go through the widgets
40  for( WPropertyGroupBase::PropertyConstIterator iter = r->get().begin(); iter != r->get().end(); ++iter )
41  {
42  WAssert( ( *iter )->getType() != PV_GROUP, "WPropertyStructWidget does not support PV_GROUP properties in a struct." );
43 
44  // create the widget. Leave the control layout NULL to only get the info widget and parameter widget without label
45  WPropertyWidget* w = WPropertyWidget::construct( *iter, NULL, this );
46  WAssert( w, "WPropertyStructWidget does not support other unsupported properties in a struct." );
47 
48  // add the widgets
49  m_layout.addWidget( w );
50 
51  // store the list of widgets to later forward the update calls
52  m_widgets.push_back( w );
53  }
54 
55  // layout both against each other
56  m_layout.setMargin( WGLOBAL_MARGIN );
57  m_layout.setSpacing( WGLOBAL_SPACING );
58  m_parameterWidgets.setLayout( &m_layout );
59 
60  // NOTE: an info layout is not needed. This is automatically done by the child widgets
61 }
62 
64 {
65  // cleanup
66 }
67 
69 {
70  for( WidgetList::const_iterator iter = m_widgets.begin(); iter != m_widgets.end(); ++iter )
71  {
72  ( *iter )->requestUpdate();
73  }
74 }
75 
PropertyContainerType::const_iterator PropertyConstIterator
The const iterator type of the container.
std::shared_ptr< WPropertyGroupBase > SPtr
Convenience typedef for a std::shared_ptr< WPropertyGroupBase >.
virtual ~WPropertyStructWidget()
Destructor.
virtual void update()
Called whenever the widget should update.
QHBoxLayout m_layout
Layout used to position the label and the checkbox.
WidgetList m_widgets
list of widgets maintained to forward update calls
WPropertyStructWidget(WPropertyGroupBase::SPtr property, QGridLayout *propertyGrid, QWidget *parent=0)
Constructor.
Class building the base for all widgets representing properties.
static WPropertyWidget * construct(WPropertyBase::SPtr property, QGridLayout *propertyGrid=NULL, QWidget *parent=NULL)
Constructs a proper widget for the specified property.
QWidget m_parameterWidgets
The widget containing a layout and provides the edit widgets for the property.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:65