Skip to content

Commit 7a314f3

Browse files
committed
Avoid 'flashy' status bar progress widget when map renders are fast
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
1 parent 26a911c commit 7a314f3

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/app/qgisapp.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8282,11 +8282,32 @@ void QgisApp::refreshMapCanvas()
82828282

82838283
void QgisApp::canvasRefreshStarted()
82848284
{
8285-
showProgress( -1, 0 ); // trick to make progress bar show busy indicator
8285+
mLastRenderTime.restart();
8286+
// if previous render took less than 0.5 seconds, delay the appearance of the
8287+
// render in progress status bar by 0.5 seconds - this avoids the status bar
8288+
// rapidly appearing and then disappearing for very fast renders
8289+
if ( mLastRenderTimeSeconds > 0 && mLastRenderTimeSeconds < 0.5 )
8290+
{
8291+
mRenderProgressBarTimer.setSingleShot( true );
8292+
mRenderProgressBarTimer.setInterval( 500 );
8293+
disconnect( mRenderProgressBarTimerConnection );
8294+
mRenderProgressBarTimerConnection = connect( &mRenderProgressBarTimer, &QTimer::timeout, [ = ]()
8295+
{
8296+
showProgress( -1, 0 );
8297+
}
8298+
);
8299+
mRenderProgressBarTimer.start();
8300+
}
8301+
else
8302+
{
8303+
showProgress( -1, 0 ); // trick to make progress bar show busy indicator
8304+
}
82868305
}
82878306

82888307
void QgisApp::canvasRefreshFinished()
82898308
{
8309+
mRenderProgressBarTimer.stop();
8310+
mLastRenderTimeSeconds = mLastRenderTime.elapsed() / 1000.0;
82908311
showProgress( 0, 0 ); // stop the busy indicator
82918312
}
82928313

src/app/qgisapp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,11 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
20672067

20682068
QgsStatusBar *mStatusBar = nullptr;
20692069

2070+
QTime mLastRenderTime;
2071+
double mLastRenderTimeSeconds = 0;
2072+
QTimer mRenderProgressBarTimer;
2073+
QMetaObject::Connection mRenderProgressBarTimerConnection;
2074+
20702075
friend class TestQgisAppPython;
20712076
};
20722077

0 commit comments

Comments
 (0)