Commit 02c9444d authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[FIX #45] compatibles buttons update on output connector update of the currently selected module

parent 5aef766c
......@@ -54,6 +54,16 @@ friend class WModuleProjectFileCombiner;
public:
/**
* Shared pointer to this class.
*/
typedef boost::shared_ptr< WModuleConnector > SPtr;
/**
* Const shared pointer to this class.
*/
typedef boost::shared_ptr< const WModuleConnector > ConstSPtr;
/**
* Constructor.
*
......
......@@ -48,6 +48,7 @@
#include "../events/WEventTypes.h"
#include "../events/WModuleAssocEvent.h"
#include "../events/WModuleConnectEvent.h"
#include "../events/WModuleConnectorEvent.h"
#include "../events/WModuleDeleteEvent.h"
#include "../events/WModuleDisconnectEvent.h"
#include "../events/WModuleReadyEvent.h"
......@@ -471,6 +472,27 @@ bool WQtControlPanel::event( QEvent* event )
return true;
}
// a connector was updated
if( event->type() == WQT_MODULE_CONNECTOR_EVENT )
{
// convert event to ready event
WModuleConnectorEvent* e1 = dynamic_cast< WModuleConnectorEvent* >( event ); // NOLINT
if( e1 )
{
// iterate tree items and find proper one -> check if selected
// NOTE: This could return multiple items here. But, the GUI always selects all of the same module or none. So it is enough to check
// the first item if it is selected to check whether the current module is active.
std::list< WQtTreeItem* > items = findItemsByModule( e1->getModule() );
if( !items.empty() && ( *items.begin() )->isSelected() )
{
// ok, the module is selected. Now, update the connectables lists (buttons and menu)
createCompatibleButtons( e1->getModule() );
}
}
return true;
}
return QDockWidget::event( event );
}
......
......@@ -31,6 +31,7 @@
#include "core/common/WProgressCombiner.h"
#include "core/common/WProgress.h"
#include "core/common/WLogger.h"
#include "core/kernel/WModuleInputConnector.h"
#include "core/kernel/WModuleOutputConnector.h"
......@@ -38,6 +39,8 @@
#include "../events/WModuleDeleteEvent.h"
#include "../events/WEventTypes.h"
#include "../events/WPropertyChangedEvent.h"
#include "../events/WModuleConnectorEvent.h"
#include "../WQt4Gui.h"
#include "../WMainWindow.h"
......@@ -87,10 +90,25 @@ WQtTreeItem::WQtTreeItem( QTreeWidgetItem * parent, WTreeItemType type, boost::s
m_updateTimer = boost::shared_ptr< QTimer >( new QTimer() );
connect( m_updateTimer.get(), SIGNAL( timeout() ), this, SLOT( update() ) );
m_updateTimer->start( 500 );
// we need to get informed about updated outputs.
const WModule::OutputConnectorList& outs = module->getOutputConnectors();
t_GenericSignalHandlerType changeSignal = boost::bind( &WQtTreeItem::slotDataChanged, this, _2 );
for( WModule::OutputConnectorList::const_iterator iter = outs.begin(); iter != outs.end(); ++iter )
{
// subscribe each connectors update signal
m_outputUpdateConnections.push_back( ( *iter )->subscribeSignal( DATA_CHANGED, changeSignal ) );
}
}
WQtTreeItem::~WQtTreeItem()
{
// disconnect each subscription
for( std::vector< boost::signals2::connection >::iterator iter = m_outputUpdateConnections.begin();
iter != m_outputUpdateConnections.end(); ++iter )
{
( *iter ).disconnect();
}
}
boost::shared_ptr< WModule > WQtTreeItem::getModule()
......@@ -144,6 +162,12 @@ void WQtTreeItem::updateTooltip( std::string progress )
setToolTip( 0, tooltip.c_str() );
}
void WQtTreeItem::slotDataChanged( boost::shared_ptr<WModuleConnector> connector )
{
// post event
QCoreApplication::postEvent( WQt4Gui::getMainWindow()->getControlPanel(), new WModuleConnectorEvent( m_module, connector ) );
}
void WQtTreeItem::update()
{
updateState();
......
......@@ -26,6 +26,9 @@
#define WQTTREEITEM_H
#include <string>
#include <vector>
#include <boost/signals2/connection.hpp>
#include <QtGui/QTreeWidgetItem>
#include <QtGui/QProgressBar>
......@@ -62,7 +65,7 @@ public:
*
* \return the pointer to the module associated with this item.
*/
boost::shared_ptr< WModule > getModule();
WModule::SPtr getModule();
/**
* Returns the name used for this tree item.
......@@ -176,6 +179,18 @@ private:
* Called when the name property changes.
*/
void nameChanged();
/**
* The output connector update connections. The NEED to be disconnected on destruction manually!
*/
std::vector< boost::signals2::connection > m_outputUpdateConnections;
/**
* Called on output-connector update.
*
* \param connector the connector that was updated.
*/
void slotDataChanged( boost::shared_ptr< WModuleConnector > connector );
};
#endif // WQTTREEITEM_H
......@@ -69,4 +69,7 @@
// a frame got rendered
#define WQT_RENDERED_FRAME_EVENT QEvent::User + 12
// a connector of a module changed state or value
#define WQT_MODULE_CONNECTOR_EVENT QEvent::User + 13
#endif // WEVENTTYPES_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WEventTypes.h"
#include "WModuleConnectorEvent.h"
WModuleConnectorEvent::WModuleConnectorEvent( WModule::SPtr module, WModuleConnector::SPtr connector ):
QEvent( static_cast< QEvent::Type >( WQT_MODULE_CONNECTOR_EVENT ) ),
m_module( module ),
m_connector( connector )
{
// initialize
}
WModuleConnectorEvent::~WModuleConnectorEvent()
{
// cleanup
}
WModuleConnector::SPtr WModuleConnectorEvent::getConnector() const
{
return m_connector;
}
WModule::SPtr WModuleConnectorEvent::getModule() const
{
return m_module;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMODULECONNECTOREVENT_H
#define WMODULECONNECTOREVENT_H
#include <boost/shared_ptr.hpp>
#include <QtCore/QEvent>
#include "core/kernel/WModuleConnector.h"
#include "core/kernel/WModule.h"
/**
* Event signalling a module connector changed its data.
*/
class WModuleConnectorEvent: public QEvent
{
public:
/**
* Creates a new event denoting the updated connector of a module.
*
* \param module the module
* \param connector the output changed
*/
WModuleConnectorEvent( WModule::SPtr module, WModuleConnector::SPtr connector );
/**
* Destructor.
*/
virtual ~WModuleConnectorEvent();
/**
* Gets the connector that has changed.
*
* \return the connector.
*/
WModuleConnector::SPtr getConnector() const;
/**
* Gets the module (owner) of the connector.
*
* \return the module.
*/
WModule::SPtr getModule() const;
protected:
/**
* The module.
*/
WModule::SPtr m_module;
/**
* The connector.
*/
WModuleConnector::SPtr m_connector;
private:
};
#endif // WMODULECONNECTOREVENT_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment