From 99e3e0671667732f6a029e9986c41ce5b1559bb3 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 21 Aug 2011 03:51:26 +0200 Subject: [PATCH] * Fixed TWK-442: Provide stable sort ordering in Track- / TreeProxyModel. --- src/libtomahawk/playlist/trackproxymodel.cpp | 9 ++++++++- src/libtomahawk/playlist/treeproxymodel.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/playlist/trackproxymodel.cpp b/src/libtomahawk/playlist/trackproxymodel.cpp index 2a4aba5f3..db02960af 100644 --- a/src/libtomahawk/playlist/trackproxymodel.cpp +++ b/src/libtomahawk/playlist/trackproxymodel.cpp @@ -318,8 +318,8 @@ TrackProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) c unsigned int albumpos1 = 0, albumpos2 = 0; unsigned int bitrate1 = 0, bitrate2 = 0; unsigned int mtime1 = 0, mtime2 = 0; - unsigned int id1 = 0, id2 = 0; unsigned int size1 = 0, size2 = 0; + qint64 id1 = 0, id2 = 0; if ( q1->numResults() ) { @@ -346,6 +346,13 @@ TrackProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) c size2 = r->size(); } + // This makes it a stable sorter and prevents items from randomly jumping about. + if ( id1 == id2 ) + { + id1 = (qint64)&q1; + id2 = (qint64)&q2; + } + if ( left.column() == TrackModel::Artist ) // sort by artist { if ( artist1 == artist2 ) diff --git a/src/libtomahawk/playlist/treeproxymodel.cpp b/src/libtomahawk/playlist/treeproxymodel.cpp index 148934f23..e57e39eba 100644 --- a/src/libtomahawk/playlist/treeproxymodel.cpp +++ b/src/libtomahawk/playlist/treeproxymodel.cpp @@ -145,7 +145,7 @@ TreeProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) co return p1->result()->albumpos() < p2->result()->albumpos(); if ( lefts == rights ) - return p1->result()->dbid() < p2->result()->dbid(); + return (qint64)&p1 < (qint64)&p2; } return QString::localeAwareCompare( lefts, rights ) < 0;