Skip to content

Commit

Permalink
Fixed handling of map updates
Browse files Browse the repository at this point in the history
Previously there was a problem that if user panned too quickly,
the map item could get completely out of the view of the graphics
view and no new paint events would be created for some time.
  • Loading branch information
wonder-sk committed Nov 26, 2013
1 parent 879f051 commit 2b5c903
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -7200,7 +7200,7 @@ bool QgisApp::saveDirty()
QSettings settings;
bool askThem = settings.value( "qgis/askToSaveProjectChanges", true ).toBool();

if ( askThem && ( QgsProject::instance()->isDirty() || mMapCanvas->isDirty() ) && QgsMapLayerRegistry::instance()->count() > 0 )
if ( askThem && QgsProject::instance()->isDirty() && QgsMapLayerRegistry::instance()->count() > 0 )
{
// flag project as dirty since dirty state of canvas is reset if "dirty"
// is based on a zoom or pan
Expand Down
74 changes: 40 additions & 34 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -101,7 +101,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
mLastNonZoomMapTool = NULL;

mFrozen = false;
mDirty = true;
mRefreshScheduled = false;

setWheelAction( WheelZoom );

Expand Down Expand Up @@ -145,6 +145,9 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
grabGesture( Qt::PinchGesture );
viewport()->setAttribute( Qt::WA_AcceptTouchEvents );
#endif

refresh();

} // QgsMapCanvas ctor


Expand Down Expand Up @@ -237,7 +240,7 @@ void QgsMapCanvas::setDirty( bool dirty )

bool QgsMapCanvas::isDirty() const
{
return mDirty;
return false;
}


Expand Down Expand Up @@ -429,11 +432,18 @@ QgsMapLayer* QgsMapCanvas::currentLayer()

void QgsMapCanvas::refresh()
{
stopRendering(); // if any...
if ( mRefreshScheduled )
{
qDebug("CANVAS refresh already scheduled");
return;
}

mRefreshScheduled = true;

qDebug("CANVAS calling update");
mDirty = true;
mMap->update();
qDebug("CANVAS refresh scheduling");

// schedule a refresh
QTimer::singleShot( 1, this, SLOT(refreshMap()));

/*
// we can't draw again if already drawing...
Expand Down Expand Up @@ -487,15 +497,36 @@ void QgsMapCanvas::refresh()

} // refresh

void QgsMapCanvas::refreshMap()
{
Q_ASSERT( mRefreshScheduled );

qDebug("CANVAS refresh!");

stopRendering(); // if any...

// from now on we can accept refresh requests again
mRefreshScheduled = false;

// create the renderer job
Q_ASSERT( mJob == 0 );
mJobCancelled = false;
if ( mUseParallelRendering )
mJob = new QgsMapRendererParallelJob( mSettings );
else
mJob = new QgsMapRendererSequentialJob( mSettings );
connect(mJob, SIGNAL( finished() ), SLOT( rendererJobFinished() ) );
mJob->start();

mMapUpdateTimer.start();
}

void QgsMapCanvas::rendererJobFinished()
{
qDebug("CANVAS finish! %d", !mJobCancelled );

mMapUpdateTimer.stop();

mDirty = false;

// TODO: would be better to show the errors in message bar
foreach ( const QgsMapRendererJob::Error& error, mJob->errors() )
{
Expand Down Expand Up @@ -1061,32 +1092,7 @@ void QgsMapCanvas::resizeEvent( QResizeEvent * e )

void QgsMapCanvas::paintEvent( QPaintEvent *e )
{
qDebug("CANVAS paint()");

if ( mDirty )
{
if ( mJob )
{
qDebug("CANVAS already rendering");
}
else
{
qDebug("CANVAS need to render");

// create the renderer job
Q_ASSERT( mJob == 0 );
mJobCancelled = false;
if ( mUseParallelRendering )
mJob = new QgsMapRendererParallelJob( mSettings );
else
mJob = new QgsMapRendererSequentialJob( mSettings );
connect(mJob, SIGNAL( finished() ), SLOT( rendererJobFinished() ) );
mJob->start();

mMapUpdateTimer.start();
}
}

// no custom event handling anymore

QGraphicsView::paintEvent( e );
} // paintEvent
Expand Down
17 changes: 6 additions & 11 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -238,7 +238,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
Q_DECL_DEPRECATED void setDirty( bool _dirty );

//! Return the state of the canvas (dirty or not)
bool isDirty() const;
//! @deprecated since 2.1 - dirty flag is not kept anymore - always returns false
Q_DECL_DEPRECATED bool isDirty() const;

//! Set map units (needed by project properties dialog)
void setMapUnits( QGis::UnitType mapUnits );
Expand Down Expand Up @@ -345,6 +346,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView

void mapUpdateTimeout();

void refreshMap();

signals:
/** Let the owner know how far we are with render operations */
//! @deprecated since 2.1 - already unused in 2.0 anyway
Expand Down Expand Up @@ -491,16 +494,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Flag indicating if the map canvas is frozen.
bool mFrozen;

/*! \brief Flag to track the state of the Map canvas.
*
* The canvas is
* flagged as dirty by any operation that changes the state of
* the layers or the view extent. If the canvas is not dirty, paint
* events are handled by bit-blitting the stored canvas bitmap to
* the canvas. This improves performance by not reading the data source
* when no real change has occurred
*/
bool mDirty;
//! Flag that allows squashing multiple refresh() calls into just one delayed rendering job
bool mRefreshScheduled;

//! determines whether user has requested to suppress rendering
bool mRenderFlag;
Expand Down

0 comments on commit 2b5c903

Please sign in to comment.