Skip to content

Commit 2b5c903

Browse files
committedNov 26, 2013
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.
1 parent 879f051 commit 2b5c903

File tree

3 files changed

+47
-46
lines changed

3 files changed

+47
-46
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7200,7 +7200,7 @@ bool QgisApp::saveDirty()
72007200
QSettings settings;
72017201
bool askThem = settings.value( "qgis/askToSaveProjectChanges", true ).toBool();
72027202

7203-
if ( askThem && ( QgsProject::instance()->isDirty() || mMapCanvas->isDirty() ) && QgsMapLayerRegistry::instance()->count() > 0 )
7203+
if ( askThem && QgsProject::instance()->isDirty() && QgsMapLayerRegistry::instance()->count() > 0 )
72047204
{
72057205
// flag project as dirty since dirty state of canvas is reset if "dirty"
72067206
// is based on a zoom or pan

‎src/gui/qgsmapcanvas.cpp

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
101101
mLastNonZoomMapTool = NULL;
102102

103103
mFrozen = false;
104-
mDirty = true;
104+
mRefreshScheduled = false;
105105

106106
setWheelAction( WheelZoom );
107107

@@ -145,6 +145,9 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
145145
grabGesture( Qt::PinchGesture );
146146
viewport()->setAttribute( Qt::WA_AcceptTouchEvents );
147147
#endif
148+
149+
refresh();
150+
148151
} // QgsMapCanvas ctor
149152

150153

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

238241
bool QgsMapCanvas::isDirty() const
239242
{
240-
return mDirty;
243+
return false;
241244
}
242245

243246

@@ -429,11 +432,18 @@ QgsMapLayer* QgsMapCanvas::currentLayer()
429432

430433
void QgsMapCanvas::refresh()
431434
{
432-
stopRendering(); // if any...
435+
if ( mRefreshScheduled )
436+
{
437+
qDebug("CANVAS refresh already scheduled");
438+
return;
439+
}
440+
441+
mRefreshScheduled = true;
433442

434-
qDebug("CANVAS calling update");
435-
mDirty = true;
436-
mMap->update();
443+
qDebug("CANVAS refresh scheduling");
444+
445+
// schedule a refresh
446+
QTimer::singleShot( 1, this, SLOT(refreshMap()));
437447

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

488498
} // refresh
489499

500+
void QgsMapCanvas::refreshMap()
501+
{
502+
Q_ASSERT( mRefreshScheduled );
503+
504+
qDebug("CANVAS refresh!");
505+
506+
stopRendering(); // if any...
507+
508+
// from now on we can accept refresh requests again
509+
mRefreshScheduled = false;
510+
511+
// create the renderer job
512+
Q_ASSERT( mJob == 0 );
513+
mJobCancelled = false;
514+
if ( mUseParallelRendering )
515+
mJob = new QgsMapRendererParallelJob( mSettings );
516+
else
517+
mJob = new QgsMapRendererSequentialJob( mSettings );
518+
connect(mJob, SIGNAL( finished() ), SLOT( rendererJobFinished() ) );
519+
mJob->start();
520+
521+
mMapUpdateTimer.start();
522+
}
490523

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

495528
mMapUpdateTimer.stop();
496529

497-
mDirty = false;
498-
499530
// TODO: would be better to show the errors in message bar
500531
foreach ( const QgsMapRendererJob::Error& error, mJob->errors() )
501532
{
@@ -1061,32 +1092,7 @@ void QgsMapCanvas::resizeEvent( QResizeEvent * e )
10611092

10621093
void QgsMapCanvas::paintEvent( QPaintEvent *e )
10631094
{
1064-
qDebug("CANVAS paint()");
1065-
1066-
if ( mDirty )
1067-
{
1068-
if ( mJob )
1069-
{
1070-
qDebug("CANVAS already rendering");
1071-
}
1072-
else
1073-
{
1074-
qDebug("CANVAS need to render");
1075-
1076-
// create the renderer job
1077-
Q_ASSERT( mJob == 0 );
1078-
mJobCancelled = false;
1079-
if ( mUseParallelRendering )
1080-
mJob = new QgsMapRendererParallelJob( mSettings );
1081-
else
1082-
mJob = new QgsMapRendererSequentialJob( mSettings );
1083-
connect(mJob, SIGNAL( finished() ), SLOT( rendererJobFinished() ) );
1084-
mJob->start();
1085-
1086-
mMapUpdateTimer.start();
1087-
}
1088-
}
1089-
1095+
// no custom event handling anymore
10901096

10911097
QGraphicsView::paintEvent( e );
10921098
} // paintEvent

‎src/gui/qgsmapcanvas.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
238238
Q_DECL_DEPRECATED void setDirty( bool _dirty );
239239

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

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

346347
void mapUpdateTimeout();
347348

349+
void refreshMap();
350+
348351
signals:
349352
/** Let the owner know how far we are with render operations */
350353
//! @deprecated since 2.1 - already unused in 2.0 anyway
@@ -491,16 +494,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
491494
//! Flag indicating if the map canvas is frozen.
492495
bool mFrozen;
493496

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

505500
//! determines whether user has requested to suppress rendering
506501
bool mRenderFlag;

0 commit comments

Comments
 (0)
Please sign in to comment.