mirror of
https://github.com/transmission/transmission
synced 2024-12-25 09:13:06 +00:00
(trunk qt) #3119 "Showing torrent properties can causes rearranging of torrents if sort != sortByName" -- fixed in trunk for 2.00 by Longinus00
This commit is contained in:
parent
14411f9694
commit
4a9f6b3cc7
2 changed files with 37 additions and 21 deletions
|
@ -85,51 +85,67 @@ TorrentFilter :: setText( QString text )
|
|||
****
|
||||
***/
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T> 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*>();
|
||||
const Torrent * b = sourceModel()->data( right, TorrentModel::TorrentRole ).value<const Torrent*>();
|
||||
bool less;
|
||||
int less = 0;
|
||||
|
||||
switch( myPrefs.get<SortMode>(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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue