Skip to content
Permalink
Browse files

Fixed handling of map updates

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 2b5c903b58ea1faedb44cc848b108fada8c4ae82
Showing with 47 additions and 46 deletions.
  1. +1 −1 src/app/qgisapp.cpp
  2. +40 −34 src/gui/qgsmapcanvas.cpp
  3. +6 −11 src/gui/qgsmapcanvas.h
@@ -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
@@ -101,7 +101,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
mLastNonZoomMapTool = NULL;

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

setWheelAction( WheelZoom );

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

refresh();

} // QgsMapCanvas ctor


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

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


@@ -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...
@@ -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() )
{
@@ -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
@@ -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 );
@@ -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
@@ -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;

0 comments on commit 2b5c903

Please sign in to comment.
You can’t perform that action at this time.