ResourcesTreeModel: support for dragging ResourceItems

Added initial support for dragging ResourceItems. This is achieved by
using drag'n'drop support offered by Qt's model/view technology.

Signed-off-by: Tobias Doerffel <tobias.doerffel@gmail.com>
This commit is contained in:
Tobias Doerffel
2009-06-22 23:45:26 +02:00
parent 0c73c5bb17
commit dc90c899aa
3 changed files with 66 additions and 5 deletions

View File

@@ -25,12 +25,15 @@
#include "ResourceTreeModel.h"
#include "embed.h"
#include "string_pair_drag.h"
ResourceTreeModel::ResourceTreeModel( ResourceDB * _db, QObject * _parent ) :
QAbstractItemModel( _parent ),
m_db( _db )
{
setSupportedDragActions( Qt::CopyAction );
connect( m_db, SIGNAL( itemsChanged() ),
this, SIGNAL( itemsChanged() ) );
}
@@ -105,6 +108,32 @@ default:
Qt::ItemFlags ResourceTreeModel::flags( const QModelIndex & _index ) const
{
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if( _index.isValid() )
{
switch( item( _index )->type() )
{
case ResourceItem::TypeSample:
case ResourceItem::TypePreset:
case ResourceItem::TypePluginSpecificPreset:
case ResourceItem::TypeProject:
case ResourceItem::TypeMidiFile:
case ResourceItem::TypeImage:
case ResourceItem::TypePlugin:
flags |= Qt::ItemIsDragEnabled;
break;
default:
break;
}
}
return flags;
}
int ResourceTreeModel::rowCount( const QModelIndex & _parent ) const
{
ResourceTreeItem * parentItem;
@@ -182,6 +211,30 @@ QModelIndex ResourceTreeModel::parent( const QModelIndex & _idx ) const
QStringList ResourceTreeModel::mimeTypes() const
{
return QStringList() << ResourceItem::mimeKey();
}
QMimeData * ResourceTreeModel::mimeData( const QModelIndexList & _list ) const
{
// we'll only process first item - look whether it is valid
if( !_list.first().isValid() )
{
return NULL;
}
// create a QMimeData object containing hash of current item
return stringPairDrag::createMimeData( ResourceItem::mimeKey(),
item( _list.first() )->hash() );
}
void ResourceTreeModel::setFilter( const QString & _s )
{
filterItems( m_db->topLevelNode(),