Commit b992acc0 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD #258] drag and drop sorting for the colormapper

parent 9baf9bd7
......@@ -401,6 +401,52 @@ bool WGEColormapping::moveToBottom( osg::ref_ptr< WGETexture3D > texture )
return true;
}
bool WGEColormapping::moveTo( osg::ref_ptr< WGETexture3D > texture, size_t idx )
{
TextureContainerType::WriteTicket w = m_textures.getWriteTicket();
// does the texture exist?
TextureContainerType::Iterator iter = std::find( w->get().begin(), w->get().end(), texture );
if( iter == w->get().end() )
{
return false;
}
// valid index?
// NOTE: we accept index == size as the end iterator.
if( idx > w->get().size() )
{
return false;
}
// is it already there?
if( iter == ( w->get().begin() + idx ) )
{
return false;
}
// after inserting the item somewhere, the index of the original item might change
TextureContainerType::Iterator eraseIdx = iter; // item is inserted behind the current one -> index of the original item stays the same
size_t eraseShift = 0;
// if the inserted element is in front of the old one, the old one's index is increasing
if( ( w->get().begin() + idx ) < iter )
{
eraseShift++;
}
// do the op
// NOTE: this is not the best way to do it. Manually moving items should be better. But as the colormapper has to handle only a small number
// of elements, this is not critical.
w->get().insert( w->get().begin() + idx, texture );
w->get().erase( eraseIdx + eraseShift );
// unlock and call callbacks
w.reset();
m_sortSignal();
return true;
}
size_t WGEColormapping::size() const
{
return m_textures.size();
......
......@@ -218,10 +218,21 @@ public:
* Move the specified texture one item down in the list. Causes the sort signal to fire.
*
* \param texture the texture swapped with its descendant
*
* \return true if swap was successful. False if not (texture not found, texture already at end).
*/
bool moveDown( osg::ref_ptr< WGETexture3D > texture );
/**
* Move the texture to the specified index. If the texture is not in the list, nothing happens.
*
* \param texture the texture to move
* \param idx the target index
*
* \return true if the operation was successful.
*/
bool moveTo( osg::ref_ptr< WGETexture3D > texture, size_t idx );
/**
* Counts the number of textures in the colormapper.
*
......
......@@ -37,6 +37,7 @@
#include <QtGui/QListWidgetItem>
#include <QtGui/QApplication>
#include "core/common/WAssert.h"
#include "core/dataHandler/WDataSet.h"
#include "core/dataHandler/WDataHandler.h"
#include "core/dataHandler/exceptions/WDHNoSuchSubject.h"
......@@ -66,6 +67,11 @@ WQtColormapper::WQtColormapper( QWidget* parent )
this->setFeatures( QDockWidget::AllDockWidgetFeatures );
m_textureListWidget->setDragDropMode( QAbstractItemView::InternalMove );
// be notified when moving items around
connect( m_textureListWidget->model(), SIGNAL( rowsMoved( const QModelIndex&, int, int, const QModelIndex&, int ) ),
this, SLOT( rowsMoved( const QModelIndex&, int, int, const QModelIndex&, int ) ) );
QWidget* panel = new QWidget( this );
m_layout = new QVBoxLayout();
......@@ -292,3 +298,18 @@ void WQtColormapper::selectTexture( boost::shared_ptr< WDataSet > dataSet )
}
}
void WQtColormapper::rowsMoved( const QModelIndex& sourceParent, int sourceStart, int sourceEnd,
const QModelIndex& destinationParent, int destinationRow )
{
WAssert( sourceStart == sourceEnd, "Multiple texture items selected. This should not be the case." );
WAssert( sourceParent == destinationParent, "Source and target parent are not the same. This should not be the case." );
// just utilize WGEColormapper for this:
boost::shared_ptr< WGEColormapping > cm = WGEColormapping::instance();
WQtTextureListItem* item = dynamic_cast< WQtTextureListItem* >( m_textureListWidget->item( m_textureListWidget->currentIndex().row() ) );
if( item )
{
cm->moveTo( item->getTexture(), destinationRow );
}
}
......@@ -170,7 +170,7 @@ private:
boost::signals2::connection m_nameConnection;
/**
* PArent list.
* Parent list.
*/
QListWidget* m_parent;
......@@ -182,6 +182,17 @@ private:
private slots:
/**
* A item was moved into another row
*
* \param sourceParent parent of the item(s) moved.
* \param sourceStart items moved start index
* \param sourceEnd items moved end index (when multiple selected)
* \param destinationParent item moved as childs for this item
* \param destinationRow items moved to this position
*/
void rowsMoved( const QModelIndex& sourceParent, int sourceStart, int sourceEnd, const QModelIndex& destinationParent, int destinationRow );
/**
* Handles a click to a texture in the list
*/
......
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