1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 08:13:27 +00:00

(trunk, qt) minor speedups to filterbar::recount()

This commit is contained in:
Jordan Lee 2012-12-29 01:20:22 +00:00
parent 765ed4a0d2
commit a8a2d5c775
2 changed files with 25 additions and 27 deletions

View file

@ -472,7 +472,7 @@ FilterBar :: refreshPref( int key )
case Prefs :: FILTER_MODE: { case Prefs :: FILTER_MODE: {
const FilterMode m = myPrefs.get<FilterMode>( key ); const FilterMode m = myPrefs.get<FilterMode>( key );
QAbstractItemModel * model = myActivityCombo->model( ); 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( ) ); myActivityCombo->setCurrentIndex( indices.isEmpty() ? 0 : indices.first().row( ) );
break; break;
} }
@ -544,20 +544,19 @@ FilterBar :: recountSoon( )
if( !myRecountTimer->isActive( ) ) if( !myRecountTimer->isActive( ) )
{ {
myRecountTimer->setSingleShot( true ); myRecountTimer->setSingleShot( true );
myRecountTimer->start( 500 ); myRecountTimer->start( 800 );
} }
} }
void void
FilterBar :: recount () FilterBar :: recount ()
{ {
// recount the activity combobox...
for( int i=0, n=FilterMode::NUM_MODES; i<n; ++i )
{
const FilterMode m( i );
QAbstractItemModel * model = myActivityCombo->model(); QAbstractItemModel * model = myActivityCombo->model();
QModelIndexList indices = model->match( model->index(0,0), ActivityRole, m.mode(), -1 );
if( !indices.isEmpty( ) ) for (int row=0, n=model->rowCount(); row<n; ++row)
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 ();

View file

@ -41,20 +41,18 @@ QVariant
TorrentModel :: data (const QModelIndex& index, int role) const TorrentModel :: data (const QModelIndex& index, int role) const
{ {
QVariant var; QVariant var;
const int row = index.row( );
if( row<0 || row>=myTorrents.size() )
return QVariant( );
const Torrent* t = myTorrents.at( row );
const Torrent * t = myTorrents.value (index.row(), 0);
if (t != 0)
{
switch (role) switch (role)
{ {
case Qt::DisplayRole: case Qt::DisplayRole:
var = QString( t->name() ); var.setValue (t->name());
break; break;
case Qt::DecorationRole: case Qt::DecorationRole:
var = t->getMimeTypeIcon( ); var.setValue (t->getMimeTypeIcon());
break; break;
case TorrentRole: case TorrentRole:
@ -65,6 +63,7 @@ TorrentModel :: data( const QModelIndex& index, int role ) const
//std::cerr << "Unhandled role: " << role << std::endl; //std::cerr << "Unhandled role: " << role << std::endl;
break; break;
} }
}
return var; return var;
} }