Skip to content

Commit

Permalink
Show busy indicator while rendering in map canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jun 2, 2014
1 parent 5852c8e commit 1c0ccb7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 22 deletions.
8 changes: 4 additions & 4 deletions python/gui/qgsmapcanvas.sip
Expand Up @@ -363,15 +363,15 @@ class QgsMapCanvas : QGraphicsView
//! - additional drawing shall be done directly within the renderer job or independently as a map canvas item
void renderComplete( QPainter * );

// ### QGIS 3: renamte to mapRefreshFinished()
/** Emitted when canvas finished a refresh request.
\note Added in 2.0 */
//! @deprecated since 2.4 - anything related to rendering progress is not visible outside of map canvas
void mapCanvasRefreshed() /Deprecated/;
void mapCanvasRefreshed();

// ### QGIS 3: rename to mapRefreshStarted()
/** Emitted when the canvas is about to be rendered.
\note Added in 1.5 */
//! @deprecated since 2.4 - anything related to rendering progress is not visible outside of map canvas
void renderStarting() /Deprecated/;
void renderStarting();

//! Emitted when a new set of layers has been received
void layersChanged();
Expand Down
40 changes: 31 additions & 9 deletions src/app/qgisapp.cpp
Expand Up @@ -1670,6 +1670,10 @@ void QgisApp::createStatusBar()
mProgressBar->setWhatsThis( tr( "Progress bar that displays the status "
"of rendering layers and other time-intensive operations" ) );
statusBar()->addPermanentWidget( mProgressBar, 1 );

connect( mMapCanvas, SIGNAL( renderStarting() ), this, SLOT( canvasRefreshStarted() ) );
connect( mMapCanvas, SIGNAL( mapCanvasRefreshed() ), this, SLOT( canvasRefreshFinished() ) );

// Bumped the font up one point size since 8 was too
// small on some platforms. A point size of 9 still provides
// plenty of display space on 1024x768 resolutions
Expand Down Expand Up @@ -3196,11 +3200,6 @@ void QgisApp::addMssqlLayer()
void QgisApp::addOracleLayer()
{
#ifdef HAVE_ORACLE
if ( mMapCanvas && mMapCanvas->isDrawing() )
{
return;
}

// show the Oracle dialog
QDialog *dbs = dynamic_cast<QDialog*>( QgsProviderRegistry::instance()->selectWidget( "oracle", this ) );
if ( !dbs )
Expand Down Expand Up @@ -5730,10 +5729,6 @@ void QgisApp::addRing()

void QgisApp::fillRing()
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
{
return;
}
mMapCanvas->setMapTool( mMapTools.mFillRing );
}

Expand Down Expand Up @@ -6147,6 +6142,16 @@ void QgisApp::refreshMapCanvas()
mMapCanvas->refresh();
}

void QgisApp::canvasRefreshStarted()
{
showProgress( -1, 0 ); // trick to make progress bar show busy indicator
}

void QgisApp::canvasRefreshFinished()
{
showProgress( 0, 0 ); // stop the busy indicator
}

void QgisApp::toggleMapTips()
{
mMapTipsVisible = !mMapTipsVisible;
Expand Down Expand Up @@ -8342,6 +8347,23 @@ void QgisApp::showProgress( int theProgress, int theTotalSteps )
}
mProgressBar->setMaximum( theTotalSteps );
mProgressBar->setValue( theProgress );

if ( mProgressBar->maximum() == 0 )
{
// for busy indicator (when minimum equals to maximum) the oxygen Qt style (used in KDE)
// has some issues and does not start busy indicator animation. This is an ugly fix
// that forces creation of a temporary progress bar that somehow resumes the animations.
// Caution: looking at the code below may introduce mild pain in stomach.
if ( strcmp( QApplication::style()->metaObject()->className(), "Oxygen::Style" ) == 0 )
{
QProgressBar pb;
pb.setAttribute( Qt::WA_DontShowOnScreen ); // no visual annoyance
pb.setMaximum( 0 );
pb.show();
qApp->processEvents();
}
}

}
}

Expand Down
5 changes: 5 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1019,6 +1019,11 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! refresh map canvas
void refreshMapCanvas();

//! start "busy" progress bar
void canvasRefreshStarted();
//! stop "busy" progress bar
void canvasRefreshFinished();

/** Dialog for verification of action on many edits
* @note added in 1.9 */
bool verifyEditsActionDialog( const QString& act, const QString& upon );
Expand Down
5 changes: 0 additions & 5 deletions src/app/qgsmaptooladdfeature.cpp
Expand Up @@ -47,11 +47,6 @@ bool QgsMapToolAddFeature::addFeature( QgsVectorLayer *vlayer, QgsFeature *f )

void QgsMapToolAddFeature::activate()
{
if ( !mCanvas || mCanvas->isDrawing() )
{
return;
}

QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( vlayer && vlayer->geometryType() == QGis::NoGeometry )
{
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -635,6 +635,8 @@ void QgsMapCanvas::refreshMap()
mJob->start();

mMapUpdateTimer.start();

emit renderStarting();
}


Expand Down Expand Up @@ -695,6 +697,8 @@ void QgsMapCanvas::rendererJobFinished()
// so the class is still valid when the execution returns to the class
mJob->deleteLater();
mJob = 0;

emit mapCanvasRefreshed();
}

void QgsMapCanvas::mapUpdateTimeout()
Expand Down
8 changes: 4 additions & 4 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -443,15 +443,15 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! - additional drawing shall be done directly within the renderer job or independently as a map canvas item
void renderComplete( QPainter * );

// ### QGIS 3: renamte to mapRefreshFinished()
/** Emitted when canvas finished a refresh request.
\note Added in 2.0 */
//! @deprecated since 2.4 - anything related to rendering progress is not visible outside of map canvas
Q_DECL_DEPRECATED void mapCanvasRefreshed();
void mapCanvasRefreshed();

// ### QGIS 3: rename to mapRefreshStarted()
/** Emitted when the canvas is about to be rendered.
\note Added in 1.5 */
//! @deprecated since 2.4 - anything related to rendering progress is not visible outside of map canvas
Q_DECL_DEPRECATED void renderStarting();
void renderStarting();

//! Emitted when a new set of layers has been received
void layersChanged();
Expand Down

0 comments on commit 1c0ccb7

Please sign in to comment.