Commit 9e1c8b62 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - GUI now supports modules with multiple inputs/outputs in the tree

parent 60615a25
......@@ -298,13 +298,27 @@ void WQt4Gui::slotRemoveDatasetOrModuleInBrowser( boost::shared_ptr< WModule > m
void WQt4Gui::slotConnectionEstablished( boost::shared_ptr<WModuleConnector> in, boost::shared_ptr<WModuleConnector> out )
{
// create a new event for this and insert it into event queue
QCoreApplication::postEvent( m_mainWindow->getDatasetBrowser(), new WModuleConnectEvent( in, out ) );
if ( in->isInputConnector() )
{
QCoreApplication::postEvent( m_mainWindow->getDatasetBrowser(), new WModuleConnectEvent( in, out ) );
}
else
{
QCoreApplication::postEvent( m_mainWindow->getDatasetBrowser(), new WModuleConnectEvent( out, in ) );
}
}
void WQt4Gui::slotConnectionClosed( boost::shared_ptr<WModuleConnector> in, boost::shared_ptr<WModuleConnector> out )
{
// create a new event for this and insert it into event queue
QCoreApplication::postEvent( m_mainWindow->getDatasetBrowser(), new WModuleDisconnectEvent( in, out ) );
if ( in->isInputConnector() )
{
QCoreApplication::postEvent( m_mainWindow->getDatasetBrowser(), new WModuleDisconnectEvent( in, out ) );
}
else
{
QCoreApplication::postEvent( m_mainWindow->getDatasetBrowser(), new WModuleDisconnectEvent( out, in ) );
}
}
boost::shared_ptr< WModule > WQt4Gui::getSelectedModule()
......
......@@ -75,7 +75,6 @@ WQtDatasetBrowser::WQtDatasetBrowser( WMainWindow* parent )
m_moduleTreeWidget->setDragEnabled( false );
m_moduleTreeWidget->viewport()->setAcceptDrops( true );
m_moduleTreeWidget->setDropIndicatorShown( true );
m_moduleTreeWidget->setDragDropMode( QAbstractItemView::InternalMove );
m_moduleTreeWidget->setMinimumHeight( 250 );
// create context menu for tree items
......@@ -293,6 +292,8 @@ bool WQtDatasetBrowser::event( QEvent* event )
boost::shared_ptr< WModule > mIn = e->getInput()->getModule();
boost::shared_ptr< WModule > mOut = e->getOutput()->getModule();
// NOTE: the following is ugly. We definitely should rethink our GUI
// at this moment items for each input connector are inside the tree.
// search the items not yet associated with some other module for the first item
std::list< WQtTreeItem* > items = findItemsByModule( mIn, m_tiModules );
......@@ -329,7 +330,45 @@ bool WQtDatasetBrowser::event( QEvent* event )
return true;
}
// TODO(ebaum): handle it and place tree items appropriately
// get the module of the input involved in this connection
boost::shared_ptr< WModule > mIn = e->getInput()->getModule();
boost::shared_ptr< WModule > mOut = e->getOutput()->getModule();
// NOTE: the following is ugly. We definitely should rethink our GUI
// at this moment items for each input connector are inside the tree.
// search all items an find those containing a children which belongs to the connection input
std::list< WQtTreeItem* > items = findItemsByModule( mOut );
for ( std::list< WQtTreeItem* >::const_iterator iter = items.begin(); iter != items.end(); ++iter )
{
// each of them can contain a child with the involved input
std::list< WQtTreeItem* > childs = findItemsByModule( mIn, *iter );
for ( std::list< WQtTreeItem* >::const_iterator citer = childs.begin(); citer != childs.end(); ++citer )
{
if ( ( *citer )->getHandledInput() == e->getInput()->getName() )
{
( *iter )->removeChild( *citer );
// move it back to the reservoir in m_tiModules
m_tiModules->addChild( *citer );
( *citer )->setHidden( true );
( *citer )->setHandledInput( "" );
( *citer )->setHandledOutput( "" );
}
}
}
// we need to ensure that at least one item for mIn is visible somewhere
items = findItemsByModule( mIn );
bool oneVisible = false;
for ( std::list< WQtTreeItem* >::const_iterator iter = items.begin(); iter != items.end(); ++iter )
{
oneVisible = oneVisible || !( *iter )->isHidden();
}
if ( !oneVisible )
{
( *items.begin() )->setHidden( false );
}
}
// a module tree item should be deleted
......
......@@ -41,6 +41,8 @@
#include "WModule.h"
#include "WModuleConnectorSignals.h"
#include "WModuleContainer.h"
#include "WModuleInputConnector.h"
#include "WModuleOutputConnector.h"
#include "combiner/WDisconnectCombiner.h"
#include "exceptions/WModuleConnectionFailed.h"
#include "exceptions/WModuleConnectionInvalid.h"
......@@ -360,3 +362,13 @@ void WModuleConnector::notifyConnectionClosed( boost::shared_ptr<WModuleConnecto
// do nothing by default
}
boost::shared_ptr< WModuleInputConnector > WModuleConnector::toInputConnector()
{
return boost::shared_dynamic_cast< WModuleInputConnector >( shared_from_this() );
}
boost::shared_ptr< WModuleOutputConnector > WModuleConnector::toOutputConnector()
{
return boost::shared_dynamic_cast< WModuleOutputConnector >( shared_from_this() );
}
......@@ -38,6 +38,9 @@
#include "WModuleCombinerTypes.h"
#include "WModuleConnectorSignals.h"
class WModuleInputConnector;
class WModuleOutputConnector;
/**
* Base class for modelling connections between kernel modules. It contains several pure virtual member functions and can
* therefore not instantiated directly.
......@@ -169,7 +172,7 @@ public:
*
* \return true if compatible.
*/
virtual bool connectable( boost::shared_ptr<WModuleConnector> con )=0;
virtual bool connectable( boost::shared_ptr<WModuleConnector> con ) = 0;
/**
* Returns a list of possible disconnections for this connector. Please be aware that the connections might change during the life-time of
......@@ -179,6 +182,34 @@ public:
*/
WCombinerTypes::WOneToOneCombiners getPossibleDisconnections();
/**
* Tries to convert this instance to an input connector.
*
* \return this as input connector
*/
boost::shared_ptr< WModuleInputConnector > toInputConnector();
/**
* Tries to convert this instance to an output connector.
*
* \return this as output connector
*/
boost::shared_ptr< WModuleOutputConnector > toOutputConnector();
/**
* Returns true if this instance is an WModuleInputConnector.
*
* \return true if castable to WModuleInputConnector.
*/
virtual bool isInputConnector() const = 0;
/**
* Returns true if this instance is an WModuleOutputConnector.
*
* \return true if castable to WModuleOutputConnector.
*/
virtual bool isOutputConnector() const = 0;
protected:
/**
......
......@@ -117,3 +117,12 @@ void WModuleInputConnector::notifyConnectionEstablished( boost::shared_ptr<WModu
WModuleConnector::notifyConnectionEstablished( here, there );
}
bool WModuleInputConnector::isInputConnector() const
{
return true;
}
bool WModuleInputConnector::isOutputConnector() const
{
return false;
}
......@@ -78,7 +78,21 @@ public:
* \param signal the signal to connect to.
* \param notifier the notifier function to bind.
*/
boost::signals2::connection subscribeSignal( MODULE_CONNECTOR_SIGNAL signal, t_GenericSignalHandlerType notifier );
boost::signals2::connection subscribeSignal( MODULE_CONNECTOR_SIGNAL signal, t_GenericSignalHandlerType notifier );
/**
* Returns true if this instance is an WModuleInputConnector.
*
* \return true if castable to WModuleInputConnector.
*/
virtual bool isInputConnector() const;
/**
* Returns true if this instance is an WModuleOutputConnector.
*
* \return true if castable to WModuleOutputConnector.
*/
virtual bool isOutputConnector() const;
protected:
......
......@@ -74,3 +74,12 @@ void WModuleOutputConnector::propagateDataChange()
signal_DataChanged( boost::shared_ptr<WModuleConnector>(), shared_from_this() );
}
bool WModuleOutputConnector::isInputConnector() const
{
return false;
}
bool WModuleOutputConnector::isOutputConnector() const
{
return true;
}
......@@ -94,6 +94,20 @@ public:
*/
virtual const boost::shared_ptr< WTransferable > getRawData() const = 0;
/**
* Returns true if this instance is an WModuleInputConnector.
*
* \return true if castable to WModuleInputConnector.
*/
virtual bool isInputConnector() const;
/**
* Returns true if this instance is an WModuleOutputConnector.
*
* \return true if castable to WModuleOutputConnector.
*/
virtual bool isOutputConnector() const;
protected:
// If you want to add additional signals an output connector should subscribe FROM an input connector, overwrite
......
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