1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-10 08:04:25 +02:00

* Fix some Drag n Drop bugs in Playlist- / TrackModel code.

This commit is contained in:
Christian Muehlhaeuser
2010-11-27 09:26:24 +01:00
parent 1ee05566b4
commit 079ac3ef2f
7 changed files with 46 additions and 24 deletions

View File

@@ -15,7 +15,7 @@
<widget class="QLabel" name="sourceLabel"> <widget class="QLabel" name="sourceLabel">
<property name="font"> <property name="font">
<font> <font>
<pointsize>22</pointsize> <pointsize>20</pointsize>
<weight>75</weight> <weight>75</weight>
<bold>true</bold> <bold>true</bold>
</font> </font>

View File

@@ -213,7 +213,7 @@ PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int r
Tomahawk::query_ptr* query = reinterpret_cast<Tomahawk::query_ptr*>(qptr); Tomahawk::query_ptr* query = reinterpret_cast<Tomahawk::query_ptr*>(qptr);
if ( query && !query->isNull() ) 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; queries << *query;
} }
} }
@@ -239,6 +239,11 @@ PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int r
connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
} }
emit endInsertRows(); emit endInsertRows();
if ( action == Qt::CopyAction )
{
onPlaylistChanged();
}
} }
return true; return true;
@@ -246,7 +251,7 @@ PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int r
void void
PlaylistModel::onPlaylistChanged() PlaylistModel::onPlaylistChanged( bool waitForUpdate )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
@@ -254,14 +259,13 @@ PlaylistModel::onPlaylistChanged()
return; return;
QList<plentry_ptr> l = playlistEntries(); QList<plentry_ptr> l = playlistEntries();
if ( !l.count() )
return;
foreach( const plentry_ptr& ple, l ) foreach( const plentry_ptr& ple, l )
{ {
qDebug() << "updateinternal:" << ple->query()->toString(); qDebug() << "updateinternal:" << ple->query()->toString();
} }
m_waitForUpdate = waitForUpdate;
QString newrev = uuid(); QString newrev = uuid();
m_playlist->createNewRevision( newrev, m_playlist->currentrevision(), l ); m_playlist->createNewRevision( newrev, m_playlist->currentrevision(), l );
} }
@@ -287,16 +291,15 @@ PlaylistModel::playlistEntries() const
void void
PlaylistModel::removeIndex( const QModelIndex& index ) PlaylistModel::removeIndex( const QModelIndex& index, bool moreToCome )
{ {
if ( isReadOnly() ) if ( isReadOnly() )
return; return;
TrackModel::removeIndex( index ); TrackModel::removeIndex( index );
if ( !m_playlist.isNull() ) if ( !moreToCome && !m_playlist.isNull() )
{ {
m_waitForUpdate = true;
onPlaylistChanged(); onPlaylistChanged();
} }
} }

View File

@@ -35,7 +35,7 @@ public:
void appendTrack( const Tomahawk::query_ptr& query ); void appendTrack( const Tomahawk::query_ptr& query );
virtual void removeIndex( const QModelIndex& index ); virtual void removeIndex( const QModelIndex& index, bool moreToCome = false );
signals: signals:
void repeatModeChanged( PlaylistInterface::RepeatMode mode ); void repeatModeChanged( PlaylistInterface::RepeatMode mode );
@@ -50,7 +50,7 @@ private slots:
void onDataChanged(); void onDataChanged();
void onRevisionLoaded( Tomahawk::PlaylistRevision revision ); void onRevisionLoaded( Tomahawk::PlaylistRevision revision );
void onPlaylistChanged(); void onPlaylistChanged( bool waitForUpdate = true );
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr() ); void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr() );

View File

@@ -273,14 +273,15 @@ TrackModel::mimeData( const QModelIndexList &indexes ) const
void void
TrackModel::removeIndex( const QModelIndex& index ) TrackModel::removeIndex( const QModelIndex& index, bool moreToCome )
{ {
if ( QThread::currentThread() != thread() ) if ( QThread::currentThread() != thread() )
{ {
qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO; qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO;
QMetaObject::invokeMethod( this, "removeIndex", QMetaObject::invokeMethod( this, "removeIndex",
Qt::QueuedConnection, Qt::QueuedConnection,
Q_ARG(const QModelIndex, index) Q_ARG(const QModelIndex, index),
Q_ARG(bool, moreToCome)
); );
return; return;
} }

View File

@@ -39,8 +39,6 @@ public:
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const; virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const; virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
virtual void removeIndexes( const QList<QModelIndex>& indexes );
virtual Tomahawk::result_ptr siblingItem( int direction ) { return Tomahawk::result_ptr(); } virtual Tomahawk::result_ptr siblingItem( int direction ) { return Tomahawk::result_ptr(); }
virtual QMimeData* mimeData( const QModelIndexList& indexes ) const; virtual QMimeData* mimeData( const QModelIndexList& indexes ) const;
@@ -68,7 +66,8 @@ signals:
public slots: public slots:
virtual void setCurrentItem( const QModelIndex& index ); 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<QModelIndex>& indexes );
virtual void setRepeatMode( PlaylistInterface::RepeatMode mode ) {} virtual void setRepeatMode( PlaylistInterface::RepeatMode mode ) {}
virtual void setShuffled( bool shuffled ) {} virtual void setShuffled( bool shuffled ) {}

View File

@@ -176,8 +176,20 @@ TrackProxyModel::removeIndexes( const QList<QModelIndex>& indexes )
if ( !sourceModel() ) if ( !sourceModel() )
return; return;
QList<QPersistentModelIndex> pil;
foreach( const QModelIndex& idx, indexes ) 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 );
} }
} }

View File

@@ -274,21 +274,28 @@ TrackView::dragMoveEvent( QDragMoveEvent* event )
void void
TrackView::dropEvent( QDropEvent* event ) TrackView::dropEvent( QDropEvent* event )
{ {
/* const QPoint pos = event->pos(); QTreeView::dropEvent( event );
const QModelIndex index = indexAt( pos );
if ( event->isAccepted() )
{
qDebug() << "Ignoring accepted event!";
return;
}
if ( event->mimeData()->hasFormat( "application/tomahawk.query.list" ) ) if ( event->mimeData()->hasFormat( "application/tomahawk.query.list" ) )
{ {
const QPoint pos = event->pos(); const QPoint pos = event->pos();
const QModelIndex index = indexAt( pos ); const QModelIndex index = indexAt( pos );
if ( index.isValid() ) qDebug() << "Drop Event accepted at row:" << index.row();
{ event->acceptProposedAction();
event->acceptProposedAction();
} if ( !model()->isReadOnly() )
}*/ {
model()->dropMimeData( event->mimeData(), event->proposedAction(), index.row(), 0, index.parent() );
}
}
QTreeView::dropEvent( event );
m_dragging = false; m_dragging = false;
} }