OpenWalnut  1.5.0dev
WPropertyBoolWidget.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/WPropertyVariable.h"
27 
28 #include "WPropertyBoolWidget.h"
29 
30 WPropertyBoolWidget::WPropertyBoolWidget( WPropBool property, QGridLayout* propertyGrid, QWidget* parent ):
31  WPropertyWidget( property, propertyGrid, parent ),
32  m_boolProperty( property ),
33  m_checkbox( &m_parameterWidgets ),
34  m_layout( &m_parameterWidgets ),
35  m_asText( &m_informationWidgets ),
36  m_infoLayout( &m_informationWidgets )
37 {
38  // initialize members
39  update();
40 
41  m_checkbox.setMinimumHeight( WMIN_WIDGET_HEIGHT );
42 
43  // layout both against each other
44  m_layout.addWidget( static_cast< QWidget* >( &m_checkbox ) );
45  m_layout.setMargin( WGLOBAL_MARGIN );
46  m_layout.setSpacing( WGLOBAL_SPACING );
47  m_parameterWidgets.setLayout( &m_layout );
48 
49  // Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
50  m_infoLayout.addWidget( &m_asText );
51  m_infoLayout.setMargin( WGLOBAL_MARGIN );
52  m_infoLayout.setSpacing( WGLOBAL_SPACING );
53  m_informationWidgets.setLayout( &m_infoLayout );
54 
55  // connect the modification signal of m_checkbox with our callback
56  connect( &m_checkbox, SIGNAL( toggled( bool ) ), this, SLOT( checkboxChanged() ) );
57 }
58 
60 {
61  // cleanup
62 }
63 
65 {
66  // simply set the new state
67  m_checkbox.setChecked( m_boolProperty->get() );
68  m_asText.setText( m_boolProperty->get() ? QString( "Yes" ) : QString( "No" ) );
69 }
70 
72 {
73  invalidate( !m_boolProperty->set( m_checkbox.isChecked() ) );
74  m_checkbox.setChecked( m_boolProperty->get() );
75 }
76 
WScaleLabel m_asText
Used to show the property as text.
virtual ~WPropertyBoolWidget()
Destructor.
void checkboxChanged()
called whenever the user modifies the checkbox
WPropertyBoolWidget(WPropBool property, QGridLayout *propertyGrid, QWidget *parent=0)
Constructor.
QHBoxLayout m_infoLayout
The layout used for the pure output (information properties)
QCheckBox m_checkbox
The checkbox - represents the boolean value.
WPropBool m_boolProperty
The boolean property represented by this widget.
virtual void update()
Called whenever the widget should update.
QHBoxLayout m_layout
Layout used to position the label and the checkbox.
Class building the base for all widgets representing properties.
QWidget m_informationWidgets
The widget containing a layout and provides the widgets for showing information properties.
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.
virtual void setText(const QString &text)
reimplemented function to setText
Definition: WScaleLabel.cpp:93