Commit 9786280b authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] refactored compatibles -> action mapping, added first submenus for...

[CHANGE] refactored compatibles -> action mapping, added first submenus for tree items to manage connections
parent 55b03299
//---------------------------------------------------------------------------
//
// 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 "QtGui/QMenu"
#include "guiElements/WQtApplyModuleAction.h"
#include "WMainWindow.h"
#include "WQtCombinerActionList.h"
WQtCombinerActionList::WQtCombinerActionList( QWidget* parent, WIconManager* icons, WModuleFactory::CompatiblesList compatibles ):
QList< QAction* >()
{
// create an action for each group:
for ( WModuleFactory::CompatiblesList::const_iterator groups = compatibles.begin(); groups != compatibles.end(); ++groups )
{
// create a new action for this group
WQtApplyModuleAction* group = new WQtApplyModuleAction( parent, icons, *( *groups ).second.begin() );
push_back( group );
// only add a sub menu if there are more than 1 items in the group
if ( ( *groups ).second.size() > 1 )
{
QMenu* groupMenu = new QMenu( parent );
// iterate all the children
for ( WModuleFactory::CompatibleCombiners::const_iterator combiner = ( *groups ).second.begin();
combiner != ( *groups ).second.end(); ++combiner )
{
WQtApplyModuleAction* a = new WQtApplyModuleAction( parent, icons, ( *combiner ), true );
a->setIconVisibleInMenu( true );
groupMenu->addAction( a );
}
group->setMenu( groupMenu );
}
}
}
WQtCombinerActionList::~WQtCombinerActionList()
{
// cleanup
clear();
}
//---------------------------------------------------------------------------
//
// 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 WQTCOMBINERACTIONLIST_H
#define WQTCOMBINERACTIONLIST_H
#include <QtCore/QList>
#include <QtGui/QAction>
#include <QtGui/QWidget>
#include "../../kernel/WModuleFactory.h"
#include "WIconManager.h"
/**
* This class represents a list of actions to apply a bunch of modules to others. It basically interprets the WModuleFactory::CompatiblesList and
* builds a list of appropriate actions. It can be used to build menus, toolbars and so on.
*/
class WQtCombinerActionList: public QList< QAction* >
{
public:
/**
* This constructor creates a list of actions recursively from the specified compatibles list.
* \param parent the parent widget of this widget, i.e. the widget that manages it.
* \param icons the icon manager holding the right icons for all the prototypes
* \param compatibles the list of combiners
*/
WQtCombinerActionList( QWidget* parent, WIconManager* icons, WModuleFactory::CompatiblesList compatibles );
/**
* Destructor.
*/
virtual ~WQtCombinerActionList();
protected:
private:
};
#endif // WQTCOMBINERACTIONLIST_H
......@@ -33,6 +33,7 @@
#include "WMainWindow.h"
#include "WQtToolBar.h"
#include "guiElements/WQtApplyModuleAction.h"
#include "WQtCombinerActionList.h"
#include "WQtCombinerToolbar.h"
......@@ -53,33 +54,8 @@ WQtCombinerToolbar::WQtCombinerToolbar( WMainWindow* parent, WModuleFactory::Com
// cast and set
setToolButtonStyle( static_cast< Qt::ToolButtonStyle >( compToolBarStyle ) );
// create an action for each group:
for ( WModuleFactory::CompatiblesList::const_iterator groups = compatibles.begin(); groups != compatibles.end(); ++groups )
{
// create a new action for this group
WQtApplyModuleAction* group = new WQtApplyModuleAction( this,
parent->getIconManager(),
*( *groups ).second.begin() );
addAction( group );
// only add a sub menu if there are more than 1 items in the group
if ( ( *groups ).second.size() > 1 )
{
QMenu* groupMenu = new QMenu( this );
// iterate all the children
for ( WModuleFactory::CompatibleCombiners::const_iterator combiner = ( *groups ).second.begin();
combiner != ( *groups ).second.end(); ++combiner )
{
WQtApplyModuleAction* a = new WQtApplyModuleAction( this,
parent->getIconManager(),
( *combiner ),
true );
a->setIconVisibleInMenu( true );
groupMenu->addAction( a );
}
group->setMenu( groupMenu );
}
}
// create the list of actions possible
addActions( WQtCombinerActionList( this, parent->getIconManager(), compatibles ) );
// The following makes the bar having button size from the beginning.
QPushButton* dummyButton = new QPushButton;
......
......@@ -49,6 +49,7 @@
#include "../guiElements/WQtApplyModuleAction.h"
#include "../WMainWindow.h"
#include "../WQt4Gui.h"
#include "../WQtCombinerActionList.h"
#include "WQtBranchTreeItem.h"
#include "WQtNumberEdit.h"
#include "WQtNumberEditDouble.h"
......@@ -78,6 +79,13 @@ WQtDatasetBrowser::WQtDatasetBrowser( WMainWindow* parent )
connect( m_deleteModuleAction, SIGNAL( triggered() ), this, SLOT( deleteModuleTreeItem() ) );
m_moduleTreeWidget->addAction( m_deleteModuleAction );
m_connectWithPrototypeAction = new QAction( "Connect with Prototype", m_moduleTreeWidget );
m_moduleTreeWidget->addAction( m_connectWithPrototypeAction );
m_connectWithModuleAction = new QAction( "Connect with Module", m_moduleTreeWidget );
m_moduleTreeWidget->addAction( m_connectWithModuleAction );
m_disconnectAction = new QAction( "Disconnect", m_moduleTreeWidget );
m_moduleTreeWidget->addAction( m_disconnectAction );
m_textureSorter = new WQtTextureSorter( this );
m_textureSorter->setToolTip( "Reorder the textures." );
......@@ -709,6 +717,19 @@ WQtCombinerToolbar* WQtDatasetBrowser::createCompatibleButtons( boost::shared_pt
// every module may have compatibles: create ribbon menu entry
// 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 );
// build the prototype menu
QMenu* m = new QMenu( m_moduleTreeWidget );
m->addActions( WQtCombinerActionList( m, m_mainWindow->getIconManager(), comps ) );
delete( m_connectWithPrototypeAction->menu() ); // ensure that combiners get free'd
m_connectWithPrototypeAction->setMenu( m );
// build the module menu
// TODO(ebaum): do
// build the disconnect menu
// TODO(ebaum): do
return new WQtCombinerToolbar( m_mainWindow, comps );
}
......
......@@ -214,6 +214,21 @@ private:
*/
QAction* m_deleteModuleAction;
/**
* Action which uses a compatibles list (submenu) to connect a selected item with other existing modules.
*/
QAction* m_connectWithModuleAction;
/**
* Action which uses a compatibles list (submenu) to connect a selected item with other prototypes.
*/
QAction* m_connectWithPrototypeAction;
/**
* Action which disconnects a connector from the module.
*/
QAction* m_disconnectAction;
private slots:
/**
* function that gets called when a tree item is selected, on a new select that tab widget
......
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