Commit 9f85fa8b authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD #61] drag and drop support accross branches works.

parent d70127d1
...@@ -43,6 +43,11 @@ class WPickHandler; ...@@ -43,6 +43,11 @@ class WPickHandler;
class WROI : public osg::Geode class WROI : public osg::Geode
{ {
public: public:
/**
* Ref Pointer type.
*/
typedef osg::ref_ptr< WROI > RefPtr;
WROI(); WROI();
/** /**
......
...@@ -85,7 +85,6 @@ void WRMBranch::addRoi( osg::ref_ptr< WROI > roi ) ...@@ -85,7 +85,6 @@ void WRMBranch::addRoi( osg::ref_ptr< WROI > roi )
{ {
m_rois.push_back( roi ); m_rois.push_back( roi );
roi->addROIChangeNotifier( m_changeRoiSignal ); roi->addROIChangeNotifier( m_changeRoiSignal );
setDirty(); setDirty();
} }
......
...@@ -186,7 +186,6 @@ public: ...@@ -186,7 +186,6 @@ public:
*/ */
void addChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier ); void addChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier );
/** /**
* Remove a specified notifier from the list of default notifiers which get connected to each branch * Remove a specified notifier from the list of default notifiers which get connected to each branch
* *
...@@ -194,7 +193,6 @@ public: ...@@ -194,7 +193,6 @@ public:
*/ */
void removeChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier ); void removeChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier );
protected: protected:
/** /**
* initializes properties * initializes properties
......
...@@ -143,3 +143,7 @@ QWidget* WQtBranchTreeItem::getWidget() const ...@@ -143,3 +143,7 @@ QWidget* WQtBranchTreeItem::getWidget() const
return m_itemWidget; return m_itemWidget;
} }
void WQtBranchTreeItem::updateRoiManagerSorting()
{
wlog::error( "WQtBranchTreeItem" )<< "resort not yet implemented";
}
...@@ -77,6 +77,10 @@ public: ...@@ -77,6 +77,10 @@ public:
*/ */
QWidget* getWidget() const; QWidget* getWidget() const;
/**
* Update internal Roi Manager sorting using the sorting of the children of this tree item.
*/
void updateRoiManagerSorting();
protected: protected:
private: private:
boost::shared_ptr< WRMBranch > m_branch; //!< ROI boost::shared_ptr< WRMBranch > m_branch; //!< ROI
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <vector> #include <vector>
#include <QtCore/QList> #include <QtCore/QList>
#include <QtCore/QCoreApplication>
#include <QtGui/QMenu> #include <QtGui/QMenu>
#include <QtGui/QScrollArea> #include <QtGui/QScrollArea>
#include <QtGui/QShortcut> #include <QtGui/QShortcut>
...@@ -59,6 +60,7 @@ ...@@ -59,6 +60,7 @@
#include "../events/WModuleRemovedEvent.h" #include "../events/WModuleRemovedEvent.h"
#include "../events/WRoiAssocEvent.h" #include "../events/WRoiAssocEvent.h"
#include "../events/WRoiRemoveEvent.h" #include "../events/WRoiRemoveEvent.h"
#include "../events/WRoiSortEvent.h"
#include "../guiElements/WQtModuleMetaInfo.h" #include "../guiElements/WQtModuleMetaInfo.h"
#include "../guiElements/WQtMenuFiltered.h" #include "../guiElements/WQtMenuFiltered.h"
#include "../networkEditor/WQtNetworkEditor.h" #include "../networkEditor/WQtNetworkEditor.h"
...@@ -276,6 +278,16 @@ bool WQtControlPanel::event( QEvent* event ) ...@@ -276,6 +278,16 @@ bool WQtControlPanel::event( QEvent* event )
return true; return true;
} }
if( event->type() == WQT_ROI_SORT_EVENT )
{
WRoiSortEvent* e3 = dynamic_cast< WRoiSortEvent* >( event );
if( e3 )
{
e3->getBranch()->updateRoiManagerSorting();
}
return true;
}
// a module got associated with the root container -> add it to the list // a module got associated with the root container -> add it to the list
if( event->type() == WQT_ASSOC_EVENT ) if( event->type() == WQT_ASSOC_EVENT )
...@@ -1247,11 +1259,17 @@ void WQtControlPanel::selectUpperMostEntry() ...@@ -1247,11 +1259,17 @@ void WQtControlPanel::selectUpperMostEntry()
m_tiModules->setSelected( true ); m_tiModules->setSelected( true );
} }
void WQtControlPanel::handleRoiDragDrop( QDropEvent* event ) void WQtControlPanel::handleRoiDragDrop( QDropEvent* /* event */ )
{ {
WROI::RefPtr droppedRoi;
WRMBranch::SPtr droppedBranch;
WQtBranchTreeItem* droppedBranchTreeItem = NULL;
for( int branchID = 0; branchID < m_tiRois->childCount(); ++branchID ) for( int branchID = 0; branchID < m_tiRois->childCount(); ++branchID )
{ {
QTreeWidgetItem* branchTreeItem = m_tiRois->child( branchID ); WQtBranchTreeItem* branchTreeItem = dynamic_cast< WQtBranchTreeItem* >( m_tiRois->child( branchID ) );
// go through each roi
for( int roiID = 0; roiID < branchTreeItem->childCount(); ++roiID ) for( int roiID = 0; roiID < branchTreeItem->childCount(); ++roiID )
{ {
WQtRoiTreeItem* roiTreeItem = dynamic_cast< WQtRoiTreeItem* >( branchTreeItem->child( roiID ) ); WQtRoiTreeItem* roiTreeItem = dynamic_cast< WQtRoiTreeItem* >( branchTreeItem->child( roiID ) );
...@@ -1260,18 +1278,44 @@ void WQtControlPanel::handleRoiDragDrop( QDropEvent* event ) ...@@ -1260,18 +1278,44 @@ void WQtControlPanel::handleRoiDragDrop( QDropEvent* event )
QWidget* w = m_roiTreeWidget->itemWidget( roiTreeItem, 0 ); QWidget* w = m_roiTreeWidget->itemWidget( roiTreeItem, 0 );
if( !w ) if( !w )
{ {
// let us hope that this really is the dropped item
w = roiTreeItem->createWidget(); w = roiTreeItem->createWidget();
m_roiTreeWidget->setItemWidget( roiTreeItem, 0, w ); m_roiTreeWidget->setItemWidget( roiTreeItem, 0, w );
m_roiTreeWidget->setCurrentItem( roiTreeItem ); m_roiTreeWidget->setCurrentItem( roiTreeItem );
// NOTE: there is a bug. After setting the new widget. the treewidget does not update the size of the item. To force this, we // we need this later: the dropped ROI
// collapse and expand the branch here droppedRoi = roiTreeItem->getRoi();
droppedBranch = branchTreeItem->getBranch();
droppedBranchTreeItem = branchTreeItem;
// NOTE: there is a bug. After setting the new widget, the treewidget does not update the size of the item. To force this, we
// collapse and expand the branch here. It looks like expanding is enough.
// roiTreeItem->setSizeHint( 0, w->sizeHint() ); // roiTreeItem->setSizeHint( 0, w->sizeHint() );
//roiTreeItem->parent()->setExpanded( false ); // roiTreeItem->parent()->setExpanded( false );
roiTreeItem->parent()->setExpanded( true ); roiTreeItem->parent()->setExpanded( true );
} }
} }
} }
// something went wrong
if( !( droppedBranch && droppedBranchTreeItem ) )
{
wlog::error( "WQtControlPanel::handleRoiDragDrop" ) << "Was not able to find dropped ROI item. This should not happen!";
}
// as the current branch/Roi code is quite ugly ... we need some manual re-sorting and re-inserting stuff
WRMBranch::SPtr realParent = WKernel::getRunningKernel()->getRoiManager()->getBranch( droppedRoi );
if( realParent != droppedBranch )
{
// ROI changed in branch:
realParent->removeRoi( droppedRoi );
droppedBranch->addRoi( droppedRoi );
}
// initiate re-sorting the widget items. We cannot do this directly, as we might have changed the ROI parent in the lines above. The GUI has
// not yet been updated so that the sorting would fail.
// NOTE: it is enough to re-sort the target branch of a cross-branch moved item.
QCoreApplication::postEvent( this, new WRoiSortEvent( droppedBranchTreeItem ) );
} }
WQtDockWidget* WQtControlPanel::getRoiDock() const WQtDockWidget* WQtControlPanel::getRoiDock() const
......
...@@ -86,4 +86,8 @@ ...@@ -86,4 +86,8 @@
// Log entry added // Log entry added
#define WQT_LOG_EVENT QEvent::User + 18 #define WQT_LOG_EVENT QEvent::User + 18
// re-sort a branch
#define WQT_ROI_SORT_EVENT QEvent::User + 19
#endif // WEVENTTYPES_H #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 "WRoiSortEvent.h"
WRoiSortEvent::WRoiSortEvent( WQtBranchTreeItem* branch )
: QEvent( static_cast< QEvent::Type >( WQT_ROI_SORT_EVENT ) ),
m_branch( branch )
{
// initialize members
}
WRoiSortEvent::~WRoiSortEvent()
{
// cleanup
}
WQtBranchTreeItem* WRoiSortEvent::getBranch()
{
return m_branch;
}
//---------------------------------------------------------------------------
//
// 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 WROISORTEVENT_H
#define WROISORTEVENT_H
#include <boost/shared_ptr.hpp>
#include <QtCore/QEvent>
#include "../controlPanel/WQtBranchTreeItem.h"
/**
* Event signalling that a sorting of the ROIs needs to be done.
*/
class WRoiSortEvent: public QEvent
{
public:
/**
* Constructor
* \param branch the branch to sort.
*/
explicit WRoiSortEvent( WQtBranchTreeItem* branch );
/**
* Destructor
*/
virtual ~WRoiSortEvent();
/**
* Getter for the branch.
*
* \return the branch.
*/
WQtBranchTreeItem* getBranch();
protected:
/**
* The branch to re-sort.
*/
WQtBranchTreeItem* m_branch;
private:
};
#endif // WROISORTEVENT_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