From 5216da50bdd6bdf31b0698d1005b6ee74d6ec900 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Tue, 19 Jul 2011 21:19:18 +0000 Subject: [PATCH] (trunk qt) #4369 "Typing text into the main window's filter field causes high CPU" -- fixed. --- qt/mainwin.cc | 25 +++++++++++++++++++------ qt/mainwin.h | 2 ++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/qt/mainwin.cc b/qt/mainwin.cc index f5ca4b159..aa91c855b 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -91,7 +91,8 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode myLastSendTime( 0 ), myLastReadTime( 0 ), myNetworkTimer( this ), - myRefreshTrayIconTimer( this ) + myRefreshTrayIconTimer( this ), + myRefreshActionSensitivityTimer( this ) { setAcceptDrops( true ); @@ -190,8 +191,8 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshVisibleCount())); connect( &myFilterModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(refreshVisibleCount())); - connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivity())); - connect( &myFilterModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivity())); + connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivitySoon())); + connect( &myFilterModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivitySoon())); connect( ui.action_Quit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit()) ); @@ -203,7 +204,7 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode connect( &myModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(refreshTrayIconSoon())); ui.listView->setModel( &myFilterModel ); - connect( ui.listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(refreshActionSensitivity())); + connect( ui.listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(refreshActionSensitivitySoon())); QActionGroup * actionGroup = new QActionGroup( this ); actionGroup->addAction( ui.action_SortByActivity ); @@ -275,9 +276,10 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode } connect( &myRefreshTrayIconTimer, SIGNAL(timeout()), this, SLOT(refreshTrayIcon()) ); + connect( &myRefreshActionSensitivityTimer, SIGNAL(timeout()), this, SLOT(refreshActionSensitivity()) ); - refreshActionSensitivity( ); + refreshActionSensitivitySoon( ); refreshTrayIconSoon( ); refreshStatusBar( ); refreshTitle( ); @@ -320,7 +322,7 @@ TrMainWindow :: onModelReset( ) { refreshTitle( ); refreshVisibleCount( ); - refreshActionSensitivity( ); + refreshActionSensitivitySoon( ); refreshStatusBar( ); refreshTrayIconSoon( ); } @@ -707,6 +709,17 @@ TrMainWindow :: refreshStatusBar( ) myStatsLabel->setText( str ); } + + +void +TrMainWindow :: refreshActionSensitivitySoon( ) +{ + if( !myRefreshActionSensitivityTimer.isActive( ) ) + { + myRefreshActionSensitivityTimer.setSingleShot( true ); + myRefreshActionSensitivityTimer.start( 500 ); + } +} void TrMainWindow :: refreshActionSensitivity( ) { diff --git a/qt/mainwin.h b/qt/mainwin.h index 4eea853b0..fe96c1aad 100644 --- a/qt/mainwin.h +++ b/qt/mainwin.h @@ -76,6 +76,7 @@ class TrMainWindow: public QMainWindow time_t myLastReadTime; QTimer myNetworkTimer; QTimer myRefreshTrayIconTimer; + QTimer myRefreshActionSensitivityTimer; QAction * myDlimitOffAction; QAction * myDlimitOnAction; QAction * myUlimitOffAction; @@ -178,6 +179,7 @@ class TrMainWindow: public QMainWindow void setStatusbarVisible( bool ); void setCompactView( bool ); void refreshActionSensitivity( ); + void refreshActionSensitivitySoon( ); void wrongAuthentication( ); public: