1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 00:04:06 +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: {
const FilterMode m = myPrefs.get<FilterMode>( 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,20 +544,19 @@ FilterBar :: recountSoon( )
if( !myRecountTimer->isActive( ) )
{
myRecountTimer->setSingleShot( true );
myRecountTimer->start( 500 );
myRecountTimer->start( 800 );
}
}
void
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();
QModelIndexList indices = model->match( model->index(0,0), ActivityRole, m.mode(), -1 );
if( !indices.isEmpty( ) )
model->setData( indices.first(), getCountString(myFilter.count(m)), TorrentCountRole );
for (int row=0, n=model->rowCount(); row<n; ++row)
{
QModelIndex index = model->index (row, 0);
const int mode = index.data(ActivityRole).toInt();
model->setData (index, getCountString(myFilter.count(mode)), TorrentCountRole);
}
refreshTrackers ();

View file

@ -41,20 +41,18 @@ QVariant
TorrentModel :: data (const QModelIndex& index, int role) const
{
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)
{
case Qt::DisplayRole:
var = QString( t->name() );
var.setValue (t->name());
break;
case Qt::DecorationRole:
var = t->getMimeTypeIcon( );
var.setValue (t->getMimeTypeIcon());
break;
case TorrentRole:
@ -65,6 +63,7 @@ TorrentModel :: data( const QModelIndex& index, int role ) const
//std::cerr << "Unhandled role: " << role << std::endl;
break;
}
}
return var;
}