From bd61a9bc4046ea46f8237af5527d4e95846ea2e8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 14 Nov 2010 05:03:38 +0000 Subject: [PATCH] (trunk qt) #3739 "filterbar should use locale info to group thousands' place (ex: 1,000 instead of 1000)" -- done. --- qt/filterbar.cc | 28 ++++++++++++++++------------ qt/filterbar.h | 1 + 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/qt/filterbar.cc b/qt/filterbar.cc index 51219d19a..276f1e461 100644 --- a/qt/filterbar.cc +++ b/qt/filterbar.cc @@ -183,9 +183,9 @@ FilterBarComboBox :: paintEvent( QPaintEvent * e ) } // draw the count - const int count = modelIndex.data( TorrentCountRole ).toInt(); - if( count >= 0 ) { - const QString text = QString::number( count); + QString text = modelIndex.data(TorrentCountRole).toString(); + if( !text.isEmpty( ) ) + { const QPen pen = painter.pen( ); painter.setPen( opt.palette.color( QPalette::Disabled, QPalette::Text ) ); QRect r = s->itemTextRect( painter.fontMetrics(), rect, Qt::AlignRight|Qt::AlignVCenter, false, text ); @@ -195,7 +195,7 @@ FilterBarComboBox :: paintEvent( QPaintEvent * e ) } // draw the text - QString text = modelIndex.data( Qt::DisplayRole ).toString(); + text = modelIndex.data( Qt::DisplayRole ).toString(); text = painter.fontMetrics().elidedText ( text, Qt::ElideRight, rect.width() ); s->drawItemText( &painter, rect, Qt::AlignLeft|Qt::AlignVCenter, opt.palette, true, text ); } @@ -319,14 +319,14 @@ FilterBar :: refreshTrackers( ) } // update the "All" row - myTrackerModel->setData( myTrackerModel->index(0,0), myTorrents.rowCount(), TorrentCountRole ); + myTrackerModel->setData( myTrackerModel->index(0,0), getCountString(myTorrents.rowCount()), TorrentCountRole ); // rows to update foreach( QString host, oldHosts & newHosts ) { const QString name = readableHostName( host ); QStandardItem * row = myTrackerModel->findItems(name).front(); - row->setData( torrentsPerHost[host], TorrentCountRole ); + row->setData( getCountString(torrentsPerHost[host]), TorrentCountRole ); row->setData( favicons.findFromHost(host), Qt::DecorationRole ); } @@ -352,7 +352,7 @@ FilterBar :: refreshTrackers( ) // add the row QStandardItem * row = new QStandardItem( favicons.findFromHost( host ), readableHostName( host ) ); - row->setData( torrentsPerHost[host], TorrentCountRole ); + row->setData( getCountString(torrentsPerHost[host]), TorrentCountRole ); row->setData( favicons.findFromHost(host), Qt::DecorationRole ); row->setData( host, TrackerRole ); myTrackerModel->insertRow( i, row ); @@ -373,7 +373,7 @@ FilterBar :: createTrackerCombo( QStandardItemModel * model ) QStandardItem * row = new QStandardItem( tr( "All" ) ); row->setData( "", TrackerRole ); - row->setData( myTorrents.rowCount(), TorrentCountRole ); + row->setData( getCountString(myTorrents.rowCount()), TorrentCountRole ); model->appendRow( row ); model->appendRow( new QStandardItem ); // separator @@ -549,11 +549,15 @@ FilterBar :: recount ( ) const FilterMode m( i ); QAbstractItemModel * model = myActivityCombo->model( ); QModelIndexList indices = model->match( model->index(0,0), ActivityRole, m.mode(), -1 ); - if( !indices.isEmpty( ) ) { - const int count = myFilter.count( m ); - model->setData( indices.first(), count, TorrentCountRole ); - } + if( !indices.isEmpty( ) ) + model->setData( indices.first(), getCountString(myFilter.count(m)), TorrentCountRole ); } refreshTrackers( ); } + +QString +FilterBar :: getCountString( int n ) const +{ + return n>0 ? QString("%L1").arg(n) : QString(); +} diff --git a/qt/filterbar.h b/qt/filterbar.h index 3e113a191..460f743c3 100644 --- a/qt/filterbar.h +++ b/qt/filterbar.h @@ -71,6 +71,7 @@ class FilterBar: public QWidget QComboBox * createActivityCombo( ); void recountSoon( ); void refreshTrackers( ); + QString getCountString( int n ) const; private: Prefs& myPrefs; -- 2.40.0