Ticket #3119: fixSorting.patch

File fixSorting.patch, 3.5 KB (added by Longinus00, 12 years ago)

really no subtraction operations, also changed the last comparison to hash strings instead of id as hashstrings will survive a restart

  • qt/torrent-filter.cc

    diff --git qt/torrent-filter.cc qt/torrent-filter.cc
    index e526ef5..6fed7e4 100644
    TorrentFilter :: setText( QString text ) 
    8585****
    8686***/
    8787
     88template <typename T>
     89int compare( const T a, const T b ) {
     90    if( a < b ) return -1;
     91    if( b < a ) return 1;
     92    return 0;
     93}
     94
    8895bool
    8996TorrentFilter :: lessThan( const QModelIndex& left, const QModelIndex& right ) const
    9097{
    9198    const Torrent * a = sourceModel()->data( left, TorrentModel::TorrentRole ).value<const Torrent*>();
    9299    const Torrent * b = sourceModel()->data( right, TorrentModel::TorrentRole ).value<const Torrent*>();
    93     bool less;
     100    int less = 0;
    94101
    95102    switch( myPrefs.get<SortMode>(Prefs::SORT_MODE).mode() )
    96103    {
    97104        case SortMode :: SORT_BY_SIZE:
    98             less = a->sizeWhenDone() < b->sizeWhenDone();
     105            less = compare( a->sizeWhenDone(), b->sizeWhenDone() );
    99106            break;
    100107        case SortMode :: SORT_BY_ACTIVITY:
    101             less = a->downloadSpeed() + a->uploadSpeed() < b->downloadSpeed() + b->uploadSpeed();
     108            less = compare( a->downloadSpeed() + a->uploadSpeed(), b->downloadSpeed() + b->uploadSpeed() );
     109            if( !less )
     110                less = compare( a->uploadedEver(), b->uploadedEver() );
    102111            break;
    103112        case SortMode :: SORT_BY_AGE:
    104             less = a->dateAdded() < b->dateAdded();
     113            less = compare( a->dateAdded().toTime_t(), b->dateAdded().toTime_t() );
    105114            break;
    106115        case SortMode :: SORT_BY_ID:
    107             less = a->id() < b->id();
    108             break;
    109         case SortMode :: SORT_BY_RATIO:
    110             less = a->compareRatio( *b ) < 0;
    111             break;
    112         case SortMode :: SORT_BY_PROGRESS:
    113             less = a->percentDone() < b->percentDone();
    114             break;
    115         case SortMode :: SORT_BY_ETA:
    116             less = a->compareETA( *b ) < 0;
     116            less = compare( a->id(), b->id() );
    117117            break;
    118118        case SortMode :: SORT_BY_STATE:
    119119            if( a->hasError() != b->hasError() )
    120120                less = a->hasError();
    121121            else
    122                 less = a->getActivity() < b->getActivity();
     122                less = compare( a->getActivity(), b->getActivity() );
     123            if( less )
     124                break;
     125        case SortMode :: SORT_BY_PROGRESS:
     126            less = compare( a->percentDone(), b->percentDone() );
     127            if( less )
     128                break;
     129        case SortMode :: SORT_BY_RATIO:
     130            less = a->compareRatio( *b );
     131            break;
     132        case SortMode :: SORT_BY_ETA:
     133            less = a->compareETA( *b );
    123134            break;
    124135        case SortMode :: SORT_BY_TRACKER:
    125             less = a->compareTracker( *b ) < 0;
     136            less = a->compareTracker( *b );
    126137            break;
    127138        default:
    128             less = a->name().compare( b->name(), Qt::CaseInsensitive ) > 0;
    129139            break;
    130140    }
    131 
    132     return less;
     141    if( less == 0 )
     142        less = -a->name().compare( b->name(), Qt::CaseInsensitive );
     143    if( less == 0 )
     144        less = compare( a->hashString(), b->hashString() );
     145    return less < 0;
    133146}
    134147
    135148
  • qt/torrent.cc

    diff --git qt/torrent.cc qt/torrent.cc
    index 6698bf1..cf27849 100644
    Torrent :: compareETA( const Torrent& that ) const 
    383383    const bool haveA( hasETA( ) );
    384384    const bool haveB( that.hasETA( ) );
    385385    if( haveA && haveB ) return getETA() - that.getETA();
    386     if( haveA ) return -1;
    387     if( haveB ) return 1;
     386    if( haveA ) return 1;
     387    if( haveB ) return -1;
    388388    return 0;
    389389}
    390390