From 4a9f6b3cc780af824e74389dc9a09fa9b67c9232 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 7 Apr 2010 13:37:08 +0000 Subject: [PATCH] (trunk qt) #3119 "Showing torrent properties can causes rearranging of torrents if sort != sortByName" -- fixed in trunk for 2.00 by Longinus00 --- qt/torrent-filter.cc | 54 ++++++++++++++++++++++++++++---------------- qt/torrent.cc | 4 ++-- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/qt/torrent-filter.cc b/qt/torrent-filter.cc index e526ef540..4a4c6e0e3 100644 --- a/qt/torrent-filter.cc +++ b/qt/torrent-filter.cc @@ -85,51 +85,67 @@ TorrentFilter :: setText( QString text ) **** ***/ +namespace +{ + template int compare( const T a, const T b ) + { + if( a < b ) return -1; + if( b < a ) return 1; + return 0; + } +} + bool TorrentFilter :: lessThan( const QModelIndex& left, const QModelIndex& right ) const { const Torrent * a = sourceModel()->data( left, TorrentModel::TorrentRole ).value(); const Torrent * b = sourceModel()->data( right, TorrentModel::TorrentRole ).value(); - bool less; + int less = 0; switch( myPrefs.get(Prefs::SORT_MODE).mode() ) { case SortMode :: SORT_BY_SIZE: - less = a->sizeWhenDone() < b->sizeWhenDone(); + less = compare( a->sizeWhenDone(), b->sizeWhenDone() ); break; case SortMode :: SORT_BY_ACTIVITY: - less = a->downloadSpeed() + a->uploadSpeed() < b->downloadSpeed() + b->uploadSpeed(); + less = compare( a->downloadSpeed() + a->uploadSpeed(), b->downloadSpeed() + b->uploadSpeed() ); + if( !less ) + less = compare( a->uploadedEver(), b->uploadedEver() ); break; case SortMode :: SORT_BY_AGE: - less = a->dateAdded() < b->dateAdded(); + less = compare( a->dateAdded().toTime_t(), b->dateAdded().toTime_t() ); break; case SortMode :: SORT_BY_ID: - less = a->id() < b->id(); - break; - case SortMode :: SORT_BY_RATIO: - less = a->compareRatio( *b ) < 0; - break; - case SortMode :: SORT_BY_PROGRESS: - less = a->percentDone() < b->percentDone(); - break; - case SortMode :: SORT_BY_ETA: - less = a->compareETA( *b ) < 0; + less = compare( a->id(), b->id() ); break; case SortMode :: SORT_BY_STATE: if( a->hasError() != b->hasError() ) less = a->hasError(); else - less = a->getActivity() < b->getActivity(); + less = compare( a->getActivity(), b->getActivity() ); + if( less ) + break; + case SortMode :: SORT_BY_PROGRESS: + less = compare( a->percentDone(), b->percentDone() ); + if( less ) + break; + case SortMode :: SORT_BY_RATIO: + less = a->compareRatio( *b ); + break; + case SortMode :: SORT_BY_ETA: + less = a->compareETA( *b ); break; case SortMode :: SORT_BY_TRACKER: - less = a->compareTracker( *b ) < 0; + less = a->compareTracker( *b ); break; default: - less = a->name().compare( b->name(), Qt::CaseInsensitive ) > 0; break; } - - return less; + if( less == 0 ) + less = -a->name().compare( b->name(), Qt::CaseInsensitive ); + if( less == 0 ) + less = compare( a->hashString(), b->hashString() ); + return less < 0; } diff --git a/qt/torrent.cc b/qt/torrent.cc index 6698bf154..cf2784942 100644 --- a/qt/torrent.cc +++ b/qt/torrent.cc @@ -383,8 +383,8 @@ Torrent :: compareETA( const Torrent& that ) const const bool haveA( hasETA( ) ); const bool haveB( that.hasETA( ) ); if( haveA && haveB ) return getETA() - that.getETA(); - if( haveA ) return -1; - if( haveB ) return 1; + if( haveA ) return 1; + if( haveB ) return -1; return 0; }