Commit a60792b4 authored by Robert Frohl's avatar Robert Frohl
Browse files

[FIX] - deleting moduls should work with NetworkEditor

parent 3f9c8622
......@@ -1070,20 +1070,28 @@ QAction* WQtControlPanel::toggleViewAction() const
void WQtControlPanel::deleteModuleTreeItem()
{
if ( m_moduleTreeWidget->selectedItems().count() > 0 )
// TODO(rfrohl): check if there is a better way to check for focus
if( m_moduleTreeWidget->hasFocus() )
{
if ( ( m_moduleTreeWidget->selectedItems().at( 0 )->type() == MODULE ) ||
( m_moduleTreeWidget->selectedItems().at( 0 )->type() == DATASET ) )
if ( m_moduleTreeWidget->selectedItems().count() > 0 )
{
// remove from the container. It will create a new event in the GUI after it has been removed which is then handled by the tree item.
// This method deep removes the module ( it also removes depending modules )
WKernel::getRunningKernel()->getRootContainer()->removeDeep(
static_cast< WQtTreeItem* >( m_moduleTreeWidget->selectedItems().at( 0 ) )->getModule()
);
// select another item
m_moduleTreeWidget->setCurrentItem( m_moduleTreeWidget->topLevelItem( 0 ) );
if ( ( m_moduleTreeWidget->selectedItems().at( 0 )->type() == MODULE ) ||
( m_moduleTreeWidget->selectedItems().at( 0 )->type() == DATASET ) )
{
// remove from the container. It will create a new event in the GUI after it has been removed which is then handled by the tree item.
// This method deep removes the module ( it also removes depending modules )
WKernel::getRunningKernel()->getRootContainer()->removeDeep(
static_cast< WQtTreeItem* >( m_moduleTreeWidget->selectedItems().at( 0 ) )->getModule()
);
// select another item
m_moduleTreeWidget->setCurrentItem( m_moduleTreeWidget->topLevelItem( 0 ) );
}
}
}
else if ( m_mainWindow->getNetworkEditor()->isActiveWindow() )
{
m_mainWindow->getNetworkEditor()->deleteSelectedItems();
}
}
void WQtControlPanel::deleteROITreeItem()
......
......@@ -33,7 +33,6 @@ WQtTreeWidget::WQtTreeWidget( QWidget* parent )
setSelectionMode( QAbstractItemView::SingleSelection );
}
WQtTreeWidget::~WQtTreeWidget()
{
}
......
......@@ -39,6 +39,8 @@
#include "WQtNetworkEditor.h"
#include "WQtNetworkPort.h"
#include "../../../kernel/combiner/WDisconnectCombiner.h"
#include "../../../kernel/WKernel.h"
#include "../../../kernel/WModule.h"
#include "../../../kernel/WModuleFactory.h"
#include "../controlPanel/WQtControlPanel.h"
......@@ -122,6 +124,50 @@ void WQtNetworkEditor::selectItem()
}
}
void WQtNetworkEditor::deleteSelectedItems()
{
QList< WQtNetworkItem *> itemList;
QList< WQtNetworkArrow *> arrowList;
foreach( QGraphicsItem *item, m_scene->selectedItems() )
{
if ( item->type() == WQtNetworkItem::Type )
{
WQtNetworkItem *netItem = qgraphicsitem_cast<WQtNetworkItem *>( item );
itemList.append( netItem );
}
else if( item->type() == WQtNetworkArrow::Type )
{
WQtNetworkArrow *netArrow = qgraphicsitem_cast<WQtNetworkArrow *>( item );
arrowList.append( netArrow );
}
}
foreach( WQtNetworkArrow *ar, arrowList )
{
if( ar != 0 )
{
boost::shared_ptr< WDisconnectCombiner > disconnectCombiner =
boost::shared_ptr< WDisconnectCombiner >( new WDisconnectCombiner(
ar->getStartPort()->getConnector()->getModule(),
ar->getStartPort()->getConnector()->getName(),
ar->getEndPort()->getConnector()->getModule(),
ar->getEndPort()->getConnector()->getName() ) );
disconnectCombiner->run();
disconnectCombiner->wait();
}
}
foreach( WQtNetworkItem *it, itemList )
{
if( it != 0 )
{
WKernel::getRunningKernel()->getRootContainer()->remove( it->getModule() );
}
}
itemList.clear();
arrowList.clear();
}
void WQtNetworkEditor::addModule( boost::shared_ptr< WModule > module )
{
WQtNetworkItem *netItem = new WQtNetworkItem( this, module );
......
......@@ -89,6 +89,11 @@ public:
*/
void itemMoved();
/**
* Deletes all items in the scene who are selected.
**/
void deleteSelectedItems();
protected:
/**
......
......@@ -26,7 +26,6 @@
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <QtGui/QGraphicsRectItem>
#include <QtGui/QStyleOptionGraphicsItem>
#include "WQtNetworkArrow.h"
......@@ -184,6 +183,8 @@ void WQtNetworkItem::mouseMoveEvent( QGraphicsSceneMouseEvent *mouseEvent )
void WQtNetworkItem::mousePressEvent ( QGraphicsSceneMouseEvent *event )
{
// TODO(rfrohl): select the item in the module tree?
// boost::shared_ptr< WModule > m_module; //!< the module
setSelected(true);
return QGraphicsItem::mousePressEvent( event );
}
......
......@@ -29,18 +29,13 @@
#include <QtGui/QDockWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QKeyEvent>
#include <QtGui/QGraphicsScene>
#include <QtGui/QGraphicsView>
#include <QtGui/QGraphicsItem>
#include <QtGui/QGraphicsItemGroup>
#include <QtGui/QGraphicsSceneMouseEvent>
#include "WQtNetworkScene.h"
#include "WQtNetworkItem.h"
#include "WQtNetworkPort.h"
#include "../../../kernel/combiner/WDisconnectCombiner.h"
#include "../../../kernel/WKernel.h"
WQtNetworkScene::WQtNetworkScene()
: QGraphicsScene()
......@@ -51,56 +46,6 @@ WQtNetworkScene::~WQtNetworkScene()
{
}
void WQtNetworkScene::keyPressEvent( QKeyEvent *keyEvent )
{
switch ( keyEvent->key() )
{
case Qt::Key_Delete:
{
QList< WQtNetworkItem *> itemList;
QList< WQtNetworkArrow *> arrowList;
foreach( QGraphicsItem *item, this->selectedItems() )
{
if ( item->type() == WQtNetworkItem::Type )
{
WQtNetworkItem *netItem = qgraphicsitem_cast<WQtNetworkItem *>( item );
itemList.append( netItem );
}
else if( item->type() == WQtNetworkArrow::Type )
{
WQtNetworkArrow *netArrow = qgraphicsitem_cast<WQtNetworkArrow *>( item );
arrowList.append( netArrow );
}
}
foreach( WQtNetworkArrow *ar, arrowList )
{
if( ar != 0 )
{
boost::shared_ptr< WDisconnectCombiner > disconnectCombiner =
boost::shared_ptr< WDisconnectCombiner >( new WDisconnectCombiner(
ar->getStartPort()->getConnector()->getModule(),
ar->getStartPort()->getConnector()->getName(),
ar->getEndPort()->getConnector()->getModule(),
ar->getEndPort()->getConnector()->getName() ) );
disconnectCombiner->run();
disconnectCombiner->wait();
}
}
foreach( WQtNetworkItem *it, itemList )
{
if( it != 0 )
{
WKernel::getRunningKernel()->getRootContainer()->remove( it->getModule() );
}
}
itemList.clear();
arrowList.clear();
}
}
}
void WQtNetworkScene::mousePressEvent( QGraphicsSceneMouseEvent *mouseEvent )
{
QList<QGraphicsItem *> item = this->items( mouseEvent->scenePos() );
......
......@@ -69,14 +69,6 @@ protected:
*/
void mousePressEvent( QGraphicsSceneMouseEvent* mouseEvent );
/**
* Controls how to respond on key events.
* Current it only delets selected items.
*
* \param keyEvent the key press event
*/
void keyPressEvent( QKeyEvent* keyEvent );
private:
QGraphicsItem *m_fakeItem; //!< the fakeitem for the forcebased layout
};
......
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