Commit 87e9a149 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

fix notifications of current track changes in media play list proxy

fix automated tests of proxy model for media play list

ensure currentTrackChanged signals are emitted only when needed and
update tests accordingly
parent 738c36aa
......@@ -2503,7 +2503,7 @@ void MediaPlayListProxyModelTest::clearPlayListCase()
QCOMPARE(dataChangedSpy.count(), 0);
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 1);
QCOMPARE(currentTrackChangedSpy.count(), 2);
QCOMPARE(currentTrackChangedSpy.count(), 1);
QCOMPARE(myPlayListProxyModel.rowCount(), 6);
......@@ -2559,7 +2559,7 @@ void MediaPlayListProxyModelTest::clearPlayListCase()
QCOMPARE(dataChangedSpy.count(), 0);
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 1);
QCOMPARE(currentTrackChangedSpy.count(), 3);
QCOMPARE(currentTrackChangedSpy.count(), 2);
QCOMPARE(myPlayListProxyModel.rowCount(), 0);
......@@ -2656,7 +2656,7 @@ void MediaPlayListProxyModelTest::undoClearPlayListCase()
QCOMPARE(dataChangedSpy.count(), 0);
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 1);
QCOMPARE(currentTrackChangedSpy.count(), 2);
QCOMPARE(currentTrackChangedSpy.count(), 1);
QCOMPARE(myPlayListProxyModel.rowCount(), 6);
......@@ -2712,7 +2712,7 @@ void MediaPlayListProxyModelTest::undoClearPlayListCase()
QCOMPARE(dataChangedSpy.count(), 0);
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 1);
QCOMPARE(currentTrackChangedSpy.count(), 3);
QCOMPARE(currentTrackChangedSpy.count(), 2);
QCOMPARE(myPlayListProxyModel.rowCount(), 0);
......@@ -2731,7 +2731,7 @@ void MediaPlayListProxyModelTest::undoClearPlayListCase()
QCOMPARE(dataChangedSpy.count(), 0);
QCOMPARE(newTrackByNameInListSpy.count(), 6);
QCOMPARE(newEntryInListSpy.count(), 1);
QCOMPARE(currentTrackChangedSpy.count(), 4);
QCOMPARE(currentTrackChangedSpy.count(), 3);
QCOMPARE(displayUndoNotificationSpy.count(), 1);
QCOMPARE(myPlayListProxyModel.rowCount(), 6);
......@@ -2868,7 +2868,7 @@ void MediaPlayListProxyModelTest::undoReplacePlayListCase()
QCOMPARE(dataChangedSpy.count(), 0);
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 1);
QCOMPARE(currentTrackChangedSpy.count(), 2);
QCOMPARE(currentTrackChangedSpy.count(), 1);
QCOMPARE(myPlayListProxyModel.rowCount(), 6);
......@@ -2929,7 +2929,7 @@ void MediaPlayListProxyModelTest::undoReplacePlayListCase()
QCOMPARE(dataChangedSpy.count(), 0);
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 2);
QCOMPARE(currentTrackChangedSpy.count(), 5);
QCOMPARE(currentTrackChangedSpy.count(), 3);
QCOMPARE(myPlayListProxyModel.data(myPlayListProxyModel.index(0, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track1"));
QCOMPARE(myPlayListProxyModel.data(myPlayListProxyModel.index(0, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1"));
......@@ -2969,7 +2969,7 @@ void MediaPlayListProxyModelTest::undoReplacePlayListCase()
QCOMPARE(dataChangedSpy.count(), 0);
QCOMPARE(newTrackByNameInListSpy.count(), 6);
QCOMPARE(newEntryInListSpy.count(), 2);
QCOMPARE(currentTrackChangedSpy.count(), 7);
QCOMPARE(currentTrackChangedSpy.count(), 5);
QCOMPARE(displayUndoNotificationSpy.count(), 1);
QCOMPARE(myPlayListProxyModel.rowCount(), 6);
......
......@@ -29,6 +29,8 @@ public:
QPersistentModelIndex mCurrentTrack;
bool mCurrentTrackWasValid = false;
QPersistentModelIndex mNextTrack;
QMediaPlaylist mLoadPlaylist;
......@@ -356,6 +358,7 @@ void MediaPlayListProxyModel::sourceRowsAboutToBeRemoved(const QModelIndex &pare
}
}
} else {
d->mCurrentTrackWasValid = d->mCurrentTrack.isValid();
beginRemoveRows(parent, start, end);
}
}
......@@ -370,16 +373,15 @@ void MediaPlayListProxyModel::sourceRowsRemoved(const QModelIndex &parent, int s
}
if (!d->mCurrentTrack.isValid()) {
d->mCurrentTrack = index(d->mCurrentPlayListPosition, 0);
if (d->mCurrentTrack.isValid()) {
if (d->mCurrentTrack.isValid() && d->mCurrentTrackWasValid) {
notifyCurrentTrackChanged();
}
if (!d->mCurrentTrack.isValid()) {
Q_EMIT playListFinished();
determineTracks();
} else {
if (!d->mCurrentTrack.isValid()) {
notifyCurrentTrackChanged();
Q_EMIT playListFinished();
determineTracks();
if (!d->mCurrentTrack.isValid() && d->mCurrentTrackWasValid) {
notifyCurrentTrackChanged();
}
}
}
}
......
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