From 079ac3ef2f25e43f40f5b4351eb04fdb286852f2 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sat, 27 Nov 2010 09:26:24 +0100 Subject: [PATCH] * Fix some Drag n Drop bugs in Playlist- / TrackModel code. --- src/infowidgets/sourceinfowidget.ui | 2 +- src/playlist/playlistmodel.cpp | 17 ++++++++++------- src/playlist/playlistmodel.h | 4 ++-- src/playlist/trackmodel.cpp | 5 +++-- src/playlist/trackmodel.h | 5 ++--- src/playlist/trackproxymodel.cpp | 14 +++++++++++++- src/playlist/trackview.cpp | 23 +++++++++++++++-------- 7 files changed, 46 insertions(+), 24 deletions(-) diff --git a/src/infowidgets/sourceinfowidget.ui b/src/infowidgets/sourceinfowidget.ui index d0beceddb..8fc4ef72d 100644 --- a/src/infowidgets/sourceinfowidget.ui +++ b/src/infowidgets/sourceinfowidget.ui @@ -15,7 +15,7 @@ - 22 + 20 75 true diff --git a/src/playlist/playlistmodel.cpp b/src/playlist/playlistmodel.cpp index a60c4db85..d0b09fd21 100644 --- a/src/playlist/playlistmodel.cpp +++ b/src/playlist/playlistmodel.cpp @@ -213,7 +213,7 @@ PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int r Tomahawk::query_ptr* query = reinterpret_cast(qptr); if ( query && !query->isNull() ) { - qDebug() << "Dropped query item:" << query->data()->artist() << "-" << query->data()->track(); + qDebug() << "Dropped query item:" << query->data()->artist() << "-" << query->data()->track() << action; queries << *query; } } @@ -239,6 +239,11 @@ PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int r connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); } emit endInsertRows(); + + if ( action == Qt::CopyAction ) + { + onPlaylistChanged(); + } } return true; @@ -246,7 +251,7 @@ PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int r void -PlaylistModel::onPlaylistChanged() +PlaylistModel::onPlaylistChanged( bool waitForUpdate ) { qDebug() << Q_FUNC_INFO; @@ -254,14 +259,13 @@ PlaylistModel::onPlaylistChanged() return; QList l = playlistEntries(); - if ( !l.count() ) - return; foreach( const plentry_ptr& ple, l ) { qDebug() << "updateinternal:" << ple->query()->toString(); } + m_waitForUpdate = waitForUpdate; QString newrev = uuid(); m_playlist->createNewRevision( newrev, m_playlist->currentrevision(), l ); } @@ -287,16 +291,15 @@ PlaylistModel::playlistEntries() const void -PlaylistModel::removeIndex( const QModelIndex& index ) +PlaylistModel::removeIndex( const QModelIndex& index, bool moreToCome ) { if ( isReadOnly() ) return; TrackModel::removeIndex( index ); - if ( !m_playlist.isNull() ) + if ( !moreToCome && !m_playlist.isNull() ) { - m_waitForUpdate = true; onPlaylistChanged(); } } diff --git a/src/playlist/playlistmodel.h b/src/playlist/playlistmodel.h index 0159aebbc..ee7938b37 100644 --- a/src/playlist/playlistmodel.h +++ b/src/playlist/playlistmodel.h @@ -35,7 +35,7 @@ public: void appendTrack( const Tomahawk::query_ptr& query ); - virtual void removeIndex( const QModelIndex& index ); + virtual void removeIndex( const QModelIndex& index, bool moreToCome = false ); signals: void repeatModeChanged( PlaylistInterface::RepeatMode mode ); @@ -50,7 +50,7 @@ private slots: void onDataChanged(); void onRevisionLoaded( Tomahawk::PlaylistRevision revision ); - void onPlaylistChanged(); + void onPlaylistChanged( bool waitForUpdate = true ); void onTracksAdded( const QList& tracks, const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr() ); diff --git a/src/playlist/trackmodel.cpp b/src/playlist/trackmodel.cpp index 847eae12b..33420fc59 100644 --- a/src/playlist/trackmodel.cpp +++ b/src/playlist/trackmodel.cpp @@ -273,14 +273,15 @@ TrackModel::mimeData( const QModelIndexList &indexes ) const void -TrackModel::removeIndex( const QModelIndex& index ) +TrackModel::removeIndex( const QModelIndex& index, bool moreToCome ) { if ( QThread::currentThread() != thread() ) { qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO; QMetaObject::invokeMethod( this, "removeIndex", Qt::QueuedConnection, - Q_ARG(const QModelIndex, index) + Q_ARG(const QModelIndex, index), + Q_ARG(bool, moreToCome) ); return; } diff --git a/src/playlist/trackmodel.h b/src/playlist/trackmodel.h index 3644002c4..872df06b1 100644 --- a/src/playlist/trackmodel.h +++ b/src/playlist/trackmodel.h @@ -39,8 +39,6 @@ public: virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const; virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const; - virtual void removeIndexes( const QList& indexes ); - virtual Tomahawk::result_ptr siblingItem( int direction ) { return Tomahawk::result_ptr(); } virtual QMimeData* mimeData( const QModelIndexList& indexes ) const; @@ -68,7 +66,8 @@ signals: public slots: virtual void setCurrentItem( const QModelIndex& index ); - virtual void removeIndex( const QModelIndex& index ); + virtual void removeIndex( const QModelIndex& index, bool moreToCome = false ); + virtual void removeIndexes( const QList& indexes ); virtual void setRepeatMode( PlaylistInterface::RepeatMode mode ) {} virtual void setShuffled( bool shuffled ) {} diff --git a/src/playlist/trackproxymodel.cpp b/src/playlist/trackproxymodel.cpp index 8bfe1a42c..225e28d1f 100644 --- a/src/playlist/trackproxymodel.cpp +++ b/src/playlist/trackproxymodel.cpp @@ -176,8 +176,20 @@ TrackProxyModel::removeIndexes( const QList& indexes ) if ( !sourceModel() ) return; + QList pil; foreach( const QModelIndex& idx, indexes ) { - removeIndex( idx ); + 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 ); } } diff --git a/src/playlist/trackview.cpp b/src/playlist/trackview.cpp index c0c2ecef1..1c573bd3e 100644 --- a/src/playlist/trackview.cpp +++ b/src/playlist/trackview.cpp @@ -274,21 +274,28 @@ TrackView::dragMoveEvent( QDragMoveEvent* event ) void TrackView::dropEvent( QDropEvent* event ) { -/* const QPoint pos = event->pos(); - const QModelIndex index = indexAt( pos ); + QTreeView::dropEvent( 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 ); - if ( index.isValid() ) - { - event->acceptProposedAction(); - } - }*/ + qDebug() << "Drop Event accepted at row:" << index.row(); + event->acceptProposedAction(); + + if ( !model()->isReadOnly() ) + { + model()->dropMimeData( event->mimeData(), event->proposedAction(), index.row(), 0, index.parent() ); + } + } - QTreeView::dropEvent( event ); m_dragging = false; }