From a8a2d5c775eec2b926c9f6566a5b80ab63f60312 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sat, 29 Dec 2012 01:20:22 +0000 Subject: [PATCH] (trunk, qt) minor speedups to filterbar::recount() --- qt/filterbar.cc | 21 ++++++++++----------- qt/torrent-model.cc | 31 +++++++++++++++---------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/qt/filterbar.cc b/qt/filterbar.cc index 95d4fac9b..4d36b3bb0 100644 --- a/qt/filterbar.cc +++ b/qt/filterbar.cc @@ -472,7 +472,7 @@ FilterBar :: refreshPref( int key ) case Prefs :: FILTER_MODE: { const FilterMode m = myPrefs.get( key ); QAbstractItemModel * model = myActivityCombo->model( ); - QModelIndexList indices = model->match( model->index(0,0), ActivityRole, m.mode(), -1 ); + QModelIndexList indices = model->match( model->index(0,0), ActivityRole, m.mode() ); myActivityCombo->setCurrentIndex( indices.isEmpty() ? 0 : indices.first().row( ) ); break; } @@ -544,23 +544,22 @@ FilterBar :: recountSoon( ) if( !myRecountTimer->isActive( ) ) { myRecountTimer->setSingleShot( true ); - myRecountTimer->start( 500 ); + myRecountTimer->start( 800 ); } } void -FilterBar :: recount ( ) +FilterBar :: recount () { - // recount the activity combobox... - for( int i=0, n=FilterMode::NUM_MODES; imodel(); + + for (int row=0, n=model->rowCount(); rowmodel( ); - QModelIndexList indices = model->match( model->index(0,0), ActivityRole, m.mode(), -1 ); - if( !indices.isEmpty( ) ) - model->setData( indices.first(), getCountString(myFilter.count(m)), TorrentCountRole ); + QModelIndex index = model->index (row, 0); + const int mode = index.data(ActivityRole).toInt(); + model->setData (index, getCountString(myFilter.count(mode)), TorrentCountRole); } - refreshTrackers( ); + refreshTrackers (); } QString diff --git a/qt/torrent-model.cc b/qt/torrent-model.cc index a71dfb9b0..2f5e0dcea 100644 --- a/qt/torrent-model.cc +++ b/qt/torrent-model.cc @@ -38,35 +38,34 @@ TorrentModel :: rowCount( const QModelIndex& parent ) const } QVariant -TorrentModel :: data( const QModelIndex& index, int role ) const +TorrentModel :: data (const QModelIndex& index, int role) const { - QVariant var; - const int row = index.row( ); - if( row<0 || row>=myTorrents.size() ) - return QVariant( ); + QVariant var; - const Torrent* t = myTorrents.at( row ); - - switch( role ) + const Torrent * t = myTorrents.value (index.row(), 0); + if (t != 0) { - case Qt::DisplayRole: - var = QString( t->name() ); + switch (role) + { + case Qt::DisplayRole: + var.setValue (t->name()); break; - case Qt::DecorationRole: - var = t->getMimeTypeIcon( ); + case Qt::DecorationRole: + var.setValue (t->getMimeTypeIcon()); break; - case TorrentRole: - var = qVariantFromValue( t ); + case TorrentRole: + var = qVariantFromValue(t); break; - default: + default: //std::cerr << "Unhandled role: " << role << std::endl; break; + } } - return var; + return var; } /***