OpenWalnut  1.5.0dev
WQtPropertyBoolAction.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 <QApplication>
26 
27 #include "core/common/WPropertyVariable.h"
28 
29 #include "../events/WEventTypes.h"
30 #include "../events/WPropertyChangedEvent.h"
31 
32 #include "WQtPropertyBoolAction.h"
33 
34 WQtPropertyBoolAction::WQtPropertyBoolAction( WPropBool property, QWidget* parent ):
35  QAction( parent ),
36  m_boolProperty( property )
37 {
38  setCheckable( true );
39 
40  setToolTip( QString::fromStdString( property->getDescription() ) );
41  setText( QString::fromStdString( property->getName() ) );
42 
43  // initialize members
44  update();
45 
46  m_connection = property->getUpdateCondition()->subscribeSignal( boost::bind( &WQtPropertyBoolAction::propertyChangeNotifier, this ) );
47 
48  // connect the modification signal of m_checkbox with our callback
49  connect( this, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) );
50 }
51 
53 {
54  // cleanup
55 }
56 
58 {
59  // simply set the new state
60  setChecked( m_boolProperty->get() );
61 }
62 
64 {
65  m_boolProperty->set( isChecked() );
66  setChecked( m_boolProperty->get() );
67 }
68 
70 {
71  QCoreApplication::postEvent( this, new WPropertyChangedEvent() );
72 }
73 
75 {
76  // a property changed
77  if( event->type() == WQT_PROPERTY_CHANGED_EVENT )
78  {
79  update();
80  return true;
81  }
82 
83  return QAction::event( event );
84 }
85 
Event signalling a new module has been associated with the root container in the kernel.
WPropBool m_boolProperty
The boolean property represented by this widget.
virtual bool event(QEvent *event)
Custom event dispatcher.
virtual ~WQtPropertyBoolAction()
Destructor.
WQtPropertyBoolAction(WPropBool property, QWidget *parent=0)
Constructor.
void changed()
called whenever the user modifies the action
virtual void propertyChangeNotifier()
Callback for WPropertyBase::getChangeCondition.
boost::signals2::connection m_connection
The connection for propertyChangeNotifier().
virtual void update()
Called whenever the widget should update.