OpenWalnut  1.5.0dev
WQtPropertyTriggerAction.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 "WQtPropertyTriggerAction.h"
33 
34 WQtPropertyTriggerAction::WQtPropertyTriggerAction( WPropTrigger property, QWidget* parent ):
35  QAction( parent ),
36  m_triggerProperty( 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( &WQtPropertyTriggerAction::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
61 }
62 
64 {
65  // the module should reset to PV_TRIGGER_READY
66  if( !isChecked() )
67  {
68  setChecked( true );
69  return;
70  }
72  setChecked( m_triggerProperty->get() );
73 }
74 
76 {
77  QCoreApplication::postEvent( this, new WPropertyChangedEvent() );
78 }
79 
81 {
82  // a property changed
83  if( event->type() == WQT_PROPERTY_CHANGED_EVENT )
84  {
85  update();
86  return true;
87  }
88 
89  return QAction::event( event );
90 }
91 
Event signalling a new module has been associated with the root container in the kernel.
virtual void propertyChangeNotifier()
Callback for WPropertyBase::getChangeCondition.
WPropTrigger m_triggerProperty
The trigger property represented by this widget.
virtual bool event(QEvent *event)
Custom event dispatcher.
virtual void update()
Called whenever the widget should update.
virtual ~WQtPropertyTriggerAction()
Destructor.
WQtPropertyTriggerAction(WPropTrigger property, QWidget *parent=0)
Constructor.
boost::signals2::connection m_connection
The connection for propertyChangeNotifier().
void changed()
called whenever the user modifies the action
@ PV_TRIGGER_TRIGGERED
Trigger property: got triggered.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)