1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-13 12:31:52 +02:00

* Fixed some more playlist issues.

This commit is contained in:
Christian Muehlhaeuser 2010-11-27 09:55:25 +01:00
parent 079ac3ef2f
commit 7b81f55079
3 changed files with 48 additions and 29 deletions

View File

@ -171,7 +171,32 @@ TrackProxyModel::removeIndex( const QModelIndex& index )
void
TrackProxyModel::removeIndexes( const QList<QModelIndex>& indexes )
TrackProxyModel::removeIndexes( const QModelIndexList& indexes )
{
if ( !sourceModel() )
return;
QList<QPersistentModelIndex> pil;
foreach( const QModelIndex& idx, indexes )
{
if ( idx.isValid() && idx.column() == 0 )
pil << mapToSource( idx );
}
bool b = true;
foreach( const QPersistentModelIndex& idx, pil )
{
if ( idx == pil.last() )
b = false;
qDebug() << "b is:" << b;
sourceModel()->removeIndex( idx, b );
}
}
void
TrackProxyModel::removeIndexes( const QList<QPersistentModelIndex>& indexes )
{
if ( !sourceModel() )
return;

View File

@ -22,7 +22,8 @@ public:
virtual int trackCount() const { return rowCount( QModelIndex() ); }
virtual void removeIndex( const QModelIndex& index );
virtual void removeIndexes( const QList<QModelIndex>& indexes );
virtual void removeIndexes( const QModelIndexList& indexes );
virtual void removeIndexes( const QList<QPersistentModelIndex>& indexes );
virtual Tomahawk::result_ptr siblingItem( int itemsAway );

View File

@ -279,22 +279,21 @@ TrackView::dropEvent( QDropEvent* event )
if ( event->isAccepted() )
{
qDebug() << "Ignoring accepted event!";
return;
}
if ( event->mimeData()->hasFormat( "application/tomahawk.query.list" ) )
{
const QPoint pos = event->pos();
const QModelIndex index = indexAt( pos );
qDebug() << "Drop Event accepted at row:" << index.row();
event->acceptProposedAction();
if ( !model()->isReadOnly() )
else
if ( event->mimeData()->hasFormat( "application/tomahawk.query.list" ) )
{
model()->dropMimeData( event->mimeData(), event->proposedAction(), index.row(), 0, index.parent() );
const QPoint pos = event->pos();
const QModelIndex index = indexAt( pos );
qDebug() << "Drop Event accepted at row:" << index.row();
event->acceptProposedAction();
if ( !model()->isReadOnly() )
{
model()->dropMimeData( event->mimeData(), event->proposedAction(), index.row(), 0, index.parent() );
}
}
}
m_dragging = false;
}
@ -344,13 +343,14 @@ void
TrackView::startDrag( Qt::DropActions supportedActions )
{
QList<QPersistentModelIndex> pindexes;
QModelIndexList indexes = selectedIndexes();
for( int i = indexes.count() - 1 ; i >= 0; --i )
QModelIndexList indexes;
foreach( const QModelIndex& idx, selectedIndexes() )
{
if ( !( m_proxyModel->flags( indexes.at( i ) ) & Qt::ItemIsDragEnabled ) )
indexes.removeAt( i );
else
pindexes << indexes.at( i );
if ( ( m_proxyModel->flags( idx ) & Qt::ItemIsDragEnabled ) )
{
indexes << idx;
pindexes << idx;
}
}
if ( indexes.count() == 0 )
@ -367,17 +367,10 @@ TrackView::startDrag( Qt::DropActions supportedActions )
drag->setPixmap( p );
drag->setHotSpot( QPoint( -20, -20 ) );
// NOTE: if we support moving items in the model
// in the future, if exec() returns Qt::MoveAction
// we need to clean up ourselves.
Qt::DropAction action = drag->exec( supportedActions, Qt::CopyAction );
if ( action == Qt::MoveAction )
{
foreach ( const QPersistentModelIndex& idx, pindexes )
{
m_proxyModel->removeIndex( idx );
}
m_proxyModel->removeIndexes( pindexes );
}
}