Commit 6fa7f7db authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - compatibles toolbar now supports modules with multiple connectors

parent 11a2bce9
......@@ -15,7 +15,7 @@ SET(GUI_QT4_MOC_HDRS
WQtConfigWidget.h
WQtNavGLWidget.h
guiElements/WQtPushButton.h
guiElements/WQtApplyModulePushButton.h
guiElements/WQtApplyModuleAction.h
datasetbrowser/WPropertyWidget.h
datasetbrowser/WPropertyBoolWidget.h
datasetbrowser/WPropertyIntWidget.h
......
......@@ -232,7 +232,7 @@ void WMainWindow::setupPermanentToolBar()
m_iconManager.addIcon( std::string( "coronal" ), cor_xpm );
m_iconManager.addIcon( std::string( "sagittal" ), sag_xpm );
// TODO(all): this should be QActions to allow the toolbar style to work properly
WQtPushButton* loadButton = new WQtPushButton( m_iconManager.getIcon( "load" ), "load", m_permanentToolBar );
WQtPushButton* roiButton = new WQtPushButton( m_iconManager.getIcon( "ROI" ), "ROI", m_permanentToolBar );
WQtPushButton* projectLoadButton = new WQtPushButton( m_iconManager.getIcon( "loadProject" ), "loadProject", m_permanentToolBar );
......
......@@ -263,7 +263,8 @@ void WQtConfigWidget::registerComponents()
m_defaultProperties->addProperty( "qt4gui.useToolBarBreak", "use ToolBarBreak", true, m_propCondition );
m_defaultProperties->addProperty( "general.allowOnlyOneFiberDataSet", "allow only one FiberDataSet", false, m_propCondition );
WPropInt tbs = m_defaultProperties->addProperty( "qt4gui.toolBarStyle", "The style of all toolbars in OpenWalnut", 0, m_propCondition );
WPropInt ctbs = m_defaultProperties->addProperty( "qt4gui.compatiblesToolBarStyle", "The style of all compatibles toolbar in OpenWalnut", 0, m_propCondition );
WPropInt ctbs = m_defaultProperties->addProperty( "qt4gui.compatiblesToolBarStyle", "The style of all compatibles toolbar in OpenWalnut", 0,
m_propCondition );
tbs->setMin( 0 );
tbs->setMax( 3 );
ctbs->setMin( 0 );
......
......@@ -48,7 +48,7 @@
#include "../events/WModuleDeleteEvent.h"
#include "../events/WModuleRemovedEvent.h"
#include "../events/WEventTypes.h"
#include "../guiElements/WQtApplyModulePushButton.h"
#include "../guiElements/WQtApplyModuleAction.h"
#include "../WMainWindow.h"
#include "../WQt4Gui.h"
#include "WQtNumberEdit.h"
......@@ -707,95 +707,33 @@ void WQtDatasetBrowser::createCompatibleButtons( boost::shared_ptr< WModule >mod
// NOTE: if module is NULL, getCompatiblePrototypes returns the list of modules without input connector (nav slices and so on)
WModuleFactory::CompatiblesList comps = WModuleFactory::getModuleFactory()->getCompatiblePrototypes( module );
// create an action for each group:
for ( WModuleFactory::CompatiblesList::const_iterator groups = comps.begin(); groups != comps.end(); ++groups )
{
// create a new action for this group
QAction* group = new QAction( m_mainWindow->getCompatiblesToolBar() );
// set some stuff ( icon, tooltip etc. )
group->setIcon( m_mainWindow->getIconManager()->getIcon( ( *groups ).first->getName().c_str() ) );
group->setIconText( ( *groups ).first->getName().c_str() );
group->setText( ( *groups ).first->getName().c_str() );
/*WQtApplyModulePushButton* currentButton = new WQtApplyModulePushButton( m_mainWindow->getCompatiblesToolBar(), m_mainWindow->getIconManager(),
*( *groups ).second.begin(), m_showToolBarText
);
m_mainWindow->getCompatiblesToolBar()->addWidget( currentButton );*/
WQtApplyModuleAction* group = new WQtApplyModuleAction( m_mainWindow->getCompatiblesToolBar(),
m_mainWindow->getIconManager(),
*( *groups ).second.begin() );
m_mainWindow->getCompatiblesToolBar()->addAction( group );
}
/*
boost::shared_ptr< WModule > currentModule; // always save the current module to identify consecutive applycombiners with equal target
typedef std::vector< std::vector< QAction* > > ActionList;
ActionList actions;
// each combiner can now be added to an existing group or
for ( std::vector< boost::shared_ptr< WApplyPrototypeCombiner > >::const_iterator iter = comps.begin(); iter != comps.end(); ++iter )
{
// This combiner does not belong to the previous group --> create a new toolbutton
if ( currentModule != ( *iter )->getTargetPrototype() )
{
// it is different from the previous one -> create a new button and add it
currentModule = ( *iter )->getTargetPrototype();
currentButton = new WQtApplyModulePushButton( m_mainWindow->getCompatiblesToolBar(), m_mainWindow->getIconManager(),
*iter, m_showToolBarText
);
m_mainWindow->getCompatiblesToolBar()->addWidget( currentButton );
}
else
{
}
*/
// ensure that only modules in the whitelist cause buttons to be created
/*if( !m_moduleWhiteList.empty() )
// only add a sub menu if there are more than 1 items in the group
if ( ( *groups ).second.size() > 1 )
{
const std::string tmpName = ( *iter )->getTargetPrototype()->getName();
if( std::find( m_moduleWhiteList.begin(), m_moduleWhiteList.end(), tmpName ) == m_moduleWhiteList.end() )
QMenu* groupMenu = new QMenu( m_mainWindow->getCompatiblesToolBar() );
// iterate all the children
for ( WModuleFactory::CompatibleCombiners::const_iterator combiner = ( *groups ).second.begin();
combiner != ( *groups ).second.end(); ++combiner )
{
continue; // do nothing for modules that are not in white list
WQtApplyModuleAction* a = new WQtApplyModuleAction( m_mainWindow->getCompatiblesToolBar(),
m_mainWindow->getIconManager(),
( *combiner ),
true );
a->setIconVisibleInMenu( true );
groupMenu->addAction( a );
}
}*/
// This combiner does not belong to the previous group --> create a new toolbutton
/*if ( currentModule != ( *iter )->getTargetPrototype() )
{
// it is different from the previous one -> create a new button and add it
currentModule = ( *iter )->getTargetPrototype();
currentButton = new WQtApplyModulePushButton( m_mainWindow->getCompatiblesToolBar(), m_mainWindow->getIconManager(),
*iter, m_showToolBarText
);
m_mainWindow->getCompatiblesToolBar()->addWidget( currentButton );
group->setMenu( groupMenu );
}
else
{
// the previous element also targeted the same module -> add item to the menu of the buttons
QMenu* menu = currentButton->menu();
if ( !menu )
{
menu = new QMenu( currentButton );
currentButton->setMenu( menu );
}
// setting this property here ensures that buttons without menu do not provide this little menu arrow
currentButton->setPopupMode( QToolButton::MenuButtonPopup );
// add an action item for this combiner
std::string name = ( *iter )->getSrcModule()->getName() + ":" + ( *iter )->getSrcConnector() + " -> " +
( *iter )->getTargetPrototype()->getName() + ":" + ( *iter )->getTargetConnector();
menu->addAction( name.c_str() );
}*/
// }
}
}
void WQtDatasetBrowser::changeTreeItem()
......
......@@ -24,42 +24,39 @@
#include <string>
#include "WQtApplyModulePushButton.h"
#include "WQtApplyModuleAction.h"
WQtApplyModulePushButton::WQtApplyModulePushButton( QWidget* parent, WIconManager* iconManager,
boost::shared_ptr< WApplyPrototypeCombiner > combiner, bool useText ):
QToolButton( parent ),
WQtApplyModuleAction::WQtApplyModuleAction( QWidget* parent, WIconManager* iconManager, boost::shared_ptr< WApplyPrototypeCombiner > combiner,
bool advancedText ):
QAction( parent ),
m_combiner( combiner )
{
setIcon( iconManager->getIcon( combiner->getTargetPrototype()->getName().c_str() ) );
setAutoRaise( false );
// nice tooltip
std::string from = "";
// NOTE: all the tooltips and so on for this action are used from the first combiner in the group
// might be null ( for example if a module should be added that does not require an input)
if ( combiner->getSrcModule() )
if ( m_combiner->getSrcModule() )
{
from = combiner->getSrcModule()->getName() + ":" + combiner->getSrcConnector() + " -> ";
from = m_combiner->getSrcModule()->getName() + ":" + m_combiner->getSrcConnector() + " -> ";
}
std::string tooltip = from + combiner->getTargetPrototype()->getName() + ":" + combiner->getTargetConnector();
std::string tooltip = from + m_combiner->getTargetPrototype()->getName() + ":" + m_combiner->getTargetConnector();
setToolTip( tooltip.c_str() );
if ( useText )
{
setText( combiner->getTargetPrototype()->getName().c_str() );
}
setText( advancedText ? tooltip.c_str() : m_combiner->getTargetPrototype()->getName().c_str() );
setIconText( advancedText ? tooltip.c_str() : m_combiner->getTargetPrototype()->getName().c_str() );
setIcon( iconManager->getIcon( m_combiner->getTargetPrototype()->getName().c_str() ) );
// we need to use released signal here, as the pushed signal also gets emitted on newly created buttons which are under the mouse pointer with
// pressed left button.
connect( this, SIGNAL( released() ), this, SLOT( emitPressed() ) );
connect( this, SIGNAL( triggered() ), this, SLOT( applyCombiner() ) );
}
WQtApplyModulePushButton::~WQtApplyModulePushButton()
WQtApplyModuleAction::~WQtApplyModuleAction()
{
}
void WQtApplyModulePushButton::emitPressed()
void WQtApplyModuleAction::applyCombiner()
{
m_combiner->run();
}
......
......@@ -22,48 +22,48 @@
//
//---------------------------------------------------------------------------
#ifndef WQTAPPLYMODULEPUSHBUTTON_H
#define WQTAPPLYMODULEPUSHBUTTON_H
#ifndef WQTAPPLYMODULEACTION_H
#define WQTAPPLYMODULEACTION_H
#include <string>
#include <boost/shared_ptr.hpp>
#include <QtGui/QPushButton>
#include <QtGui/QToolButton>
#include <QtGui/QAction>
#include "../WIconManager.h"
#include "../../../kernel/combiner/WApplyPrototypeCombiner.h"
#include "../../../kernel/WModuleFactory.h"
/**
* Implements a Button which applies the specified combiner if pressed.
* Implements a action which applies the specified combiners (of the specified group) if pressed.
*/
class WQtApplyModulePushButton : public QToolButton
class WQtApplyModuleAction : public QAction
{
Q_OBJECT
public:
/**
* Constructor creating a module application button.
* Constructor creating a module application action.
*
* \param parent the parent
* \param iconManager the icon manager to use
* \param combiner the combiner that is represented by this button
* \param useText true if a text should be shown.
* \param combiner the apply combiner which gets applied when triggered
* \param advancedText if true a more complex text showing the used connectors is used instead of the plane target-module name
*/
WQtApplyModulePushButton( QWidget* parent, WIconManager* iconManager,
boost::shared_ptr< WApplyPrototypeCombiner > combiner, bool useText = true );
WQtApplyModuleAction( QWidget* parent, WIconManager* iconManager, boost::shared_ptr< WApplyPrototypeCombiner > combiner,
bool advancedText = false );
/**
* destructor
*/
virtual ~WQtApplyModulePushButton();
virtual ~WQtApplyModuleAction();
protected:
/**
* The combiner used in this button.
* The combiner of this action
*/
boost::shared_ptr< WApplyPrototypeCombiner > m_combiner;
......@@ -71,9 +71,9 @@ private:
public slots:
/**
* Slot getting called when the button got pressed. It applies the combiner.
* Gets called by the action if it was triggered.
*/
void emitPressed();
void applyCombiner();
};
#endif // WQTAPPLYMODULEPUSHBUTTON_H
#endif // WQTAPPLYMODULEACTION_H
......@@ -27,6 +27,7 @@
#include <set>
#include <string>
#include <utility>
#include <vector>
#include <boost/shared_ptr.hpp>
......@@ -143,10 +144,15 @@ public:
template <typename T>
static bool isA( boost::shared_ptr< WModule > module );
/**
* A list of all combiners. Used in CompatiblesGroup.
*/
typedef std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > CompatibleCombiners;
/**
* A group of compatibles connections to and from a specified module.
*/
typedef std::pair< boost::shared_ptr< WModule >, std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > > CompatiblesGroup;
typedef std::pair< boost::shared_ptr< WModule >, CompatibleCombiners > CompatiblesGroup;
/**
* A type used for defining lists of properties. It basically is a list of lists, each containing several ApplyPrototypeCombiner instances.
......
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