Skip to content

Commit

Permalink
Avoid 'flashy' status bar progress widget when map renders are fast
Browse files Browse the repository at this point in the history
If previous canvas render took less than 0.5 seconds, delay the appearance of the
'render in progress' status bar widget by a short amount - this avoids the
status bar rapidly appearing and then disappearing for very fast renders
  • Loading branch information
nyalldawson committed Aug 17, 2017
1 parent 26a911c commit 7a314f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8282,11 +8282,32 @@ void QgisApp::refreshMapCanvas()

void QgisApp::canvasRefreshStarted()
{
showProgress( -1, 0 ); // trick to make progress bar show busy indicator
mLastRenderTime.restart();
// if previous render took less than 0.5 seconds, delay the appearance of the
// render in progress status bar by 0.5 seconds - this avoids the status bar
// rapidly appearing and then disappearing for very fast renders
if ( mLastRenderTimeSeconds > 0 && mLastRenderTimeSeconds < 0.5 )
{
mRenderProgressBarTimer.setSingleShot( true );
mRenderProgressBarTimer.setInterval( 500 );
disconnect( mRenderProgressBarTimerConnection );
mRenderProgressBarTimerConnection = connect( &mRenderProgressBarTimer, &QTimer::timeout, [ = ]()
{
showProgress( -1, 0 );
}
);
mRenderProgressBarTimer.start();
}
else
{
showProgress( -1, 0 ); // trick to make progress bar show busy indicator
}
}

void QgisApp::canvasRefreshFinished()
{
mRenderProgressBarTimer.stop();
mLastRenderTimeSeconds = mLastRenderTime.elapsed() / 1000.0;
showProgress( 0, 0 ); // stop the busy indicator
}

Expand Down
5 changes: 5 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,11 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QgsStatusBar *mStatusBar = nullptr;

QTime mLastRenderTime;
double mLastRenderTimeSeconds = 0;
QTimer mRenderProgressBarTimer;
QMetaObject::Connection mRenderProgressBarTimerConnection;

friend class TestQgisAppPython;
};

Expand Down

0 comments on commit 7a314f3

Please sign in to comment.