Skip to content

Commit 185ec5d

Browse files
author
jef
committed
fix #2884:
crashed when two map renderers are simultaneously rendering the layers for the canvas and overview (eg. on resize, when overview is docked). This might fix it. git-svn-id: http://svn.osgeo.org/qgis/trunk@15050 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5e24c9f commit 185ec5d

File tree

6 files changed

+81
-52
lines changed

6 files changed

+81
-52
lines changed

src/core/qgsmaprenderer.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
#include <QListIterator>
3939
#include <QSettings>
4040
#include <QTime>
41-
#include "qgslogger.h"
42-
41+
#include <QCoreApplication>
4342

4443
QgsMapRenderer::QgsMapRenderer()
4544
{
@@ -229,14 +228,22 @@ void QgsMapRenderer::render( QPainter* painter )
229228
return;
230229
}
231230

232-
if ( mDrawing )
231+
QPaintDevice* thePaintDevice = painter->device();
232+
if ( !thePaintDevice )
233233
{
234234
return;
235235
}
236236

237-
QPaintDevice* thePaintDevice = painter->device();
238-
if ( !thePaintDevice )
237+
// wait
238+
if( mDrawing )
239239
{
240+
QgsDebugMsg( "already rendering" );
241+
QCoreApplication::processEvents();
242+
}
243+
244+
if( mDrawing )
245+
{
246+
QgsDebugMsg( "still rendering - skipping" );
240247
return;
241248
}
242249

@@ -599,7 +606,6 @@ void QgsMapRenderer::render( QPainter* painter )
599606
QgsDebugMsg( "Rendering completed in (seconds): " + QString( "%1" ).arg( renderTime.elapsed() / 1000.0 ) );
600607

601608
mDrawing = false;
602-
603609
}
604610

605611
void QgsMapRenderer::setMapUnits( QGis::UnitType u )
@@ -1073,3 +1079,5 @@ void QgsMapRenderer::setLabelingEngine( QgsLabelingEngineInterface* iface )
10731079

10741080
mLabelingEngine = iface;
10751081
}
1082+
1083+
bool QgsMapRenderer::mDrawing = false;

src/core/qgsmaprenderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class CORE_EXPORT QgsMapRenderer : public QObject
249249
protected:
250250

251251
//! indicates drawing in progress
252-
bool mDrawing;
252+
static bool mDrawing;
253253

254254
//! map units per pixel
255255
double mMapUnitsPerPixel;

src/gui/qgsmapcanvas.cpp

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -932,52 +932,59 @@ void QgsMapCanvas::mouseReleaseEvent( QMouseEvent * e )
932932

933933
void QgsMapCanvas::resizeEvent( QResizeEvent * e )
934934
{
935-
static bool isAlreadyIn = false;
936-
static QSize lastSize = QSize( -1, -1 );
937-
938-
lastSize = e->size();
935+
mNewSize = e->size();
936+
}
939937

940-
if ( isAlreadyIn || mDrawing )
938+
void QgsMapCanvas::paintEvent( QPaintEvent *e )
939+
{
940+
if( mNewSize.isValid() )
941941
{
942-
//cancel current render progress
943-
if ( mMapRenderer )
942+
static bool isAlreadyIn = false;
943+
static QSize lastSize = QSize();
944+
945+
lastSize = mNewSize;
946+
mNewSize = QSize();
947+
948+
if ( isAlreadyIn || mDrawing )
944949
{
945-
QgsRenderContext* theRenderContext = mMapRenderer->rendererContext();
946-
if ( theRenderContext )
950+
//cancel current render progress
951+
if ( mMapRenderer )
947952
{
948-
theRenderContext->setRenderingStopped( true );
953+
QgsRenderContext* theRenderContext = mMapRenderer->rendererContext();
954+
if ( theRenderContext )
955+
{
956+
theRenderContext->setRenderingStopped( true );
957+
}
949958
}
959+
return;
950960
}
951-
return;
952-
}
953-
isAlreadyIn = true;
961+
isAlreadyIn = true;
954962

955-
while ( lastSize != QSize( -1, -1 ) )
956-
{
957-
int width = lastSize.width();
958-
int height = lastSize.height();
959-
lastSize = QSize( -1, -1 );
963+
while ( lastSize.isValid() )
964+
{
965+
int width = lastSize.width();
966+
int height = lastSize.height();
967+
lastSize = QSize();
960968

961-
//set map size before scene size helps keep scene indexes updated properly
962-
// this was the cause of rubberband artifacts
963-
mMap->resize( QSize( width, height ) );
964-
mScene->setSceneRect( QRectF( 0, 0, width, height ) );
969+
//set map size before scene size helps keep scene indexes updated properly
970+
// this was the cause of rubberband artifacts
971+
mMap->resize( QSize( width, height ) );
972+
mScene->setSceneRect( QRectF( 0, 0, width, height ) );
965973

966-
// notify canvas items of change
967-
updateCanvasItemPositions();
974+
// notify canvas items of change
975+
updateCanvasItemPositions();
968976

969-
updateScale();
970-
#if QT_VERSION >= 0x40600
971-
// FIXME: temporary workaround for #2714
972-
QTimer::singleShot( 1, this, SLOT( refresh() ) );
973-
#else
974-
refresh();
975-
#endif
976-
emit extentsChanged();
977-
}
977+
updateScale();
978+
979+
refresh();
980+
981+
emit extentsChanged();
982+
}
978983
isAlreadyIn = false;
979-
} // resizeEvent
984+
}
980985

986+
QGraphicsView::paintEvent( e );
987+
} // paintEvent
981988

982989
void QgsMapCanvas::updateCanvasItemPositions()
983990
{

src/gui/qgsmapcanvas.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
368368
//! Overridden resize event
369369
void resizeEvent( QResizeEvent * e );
370370

371+
//! Overridden paint event
372+
void paintEvent( QPaintEvent * e );
373+
371374
//! called when panning is in action, reset indicates end of panning
372375
void moveCanvasContents( bool reset = false );
373376

@@ -451,6 +454,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
451454
//! Mouse wheel action
452455
WheelAction mWheelAction;
453456

457+
//! resize canvas size
458+
QSize mNewSize;
459+
454460
}; // class QgsMapCanvas
455461

456462

src/gui/qgsmapoverviewcanvas.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,21 @@ QgsMapOverviewCanvas::~QgsMapOverviewCanvas()
8585

8686
void QgsMapOverviewCanvas::resizeEvent( QResizeEvent* e )
8787
{
88-
mPixmap = QPixmap( e->size() );
89-
mMapRenderer->setOutputSize( e->size(), mPixmap.logicalDpiX() );
90-
refresh();
88+
mNewSize = e->size();
89+
}
90+
91+
void QgsMapOverviewCanvas::paintEvent( QPaintEvent* pe )
92+
{
93+
if( mNewSize.isValid() )
94+
{
95+
mPixmap = QPixmap( mNewSize );
96+
mMapRenderer->setOutputSize( mNewSize, mPixmap.logicalDpiX() );
97+
mNewSize = QSize();
98+
refresh();
99+
}
100+
101+
QPainter paint( this );
102+
paint.drawPixmap( pe->rect().topLeft(), mPixmap, pe->rect() );
91103
}
92104

93105

@@ -233,16 +245,9 @@ void QgsMapOverviewCanvas::updatePanningWidget( const QPoint& pos )
233245
}
234246

235247

236-
void QgsMapOverviewCanvas::paintEvent( QPaintEvent * pe )
237-
{
238-
QPainter paint( this );
239-
paint.drawPixmap( pe->rect().topLeft(), mPixmap, pe->rect() );
240-
}
241-
242-
243248
void QgsMapOverviewCanvas::refresh()
244249
{
245-
if ( mPixmap.isNull() )
250+
if ( mPixmap.isNull() || mPixmap.paintingActive() )
246251
return;
247252

248253
mPixmap.fill( mBgColor ); //palette().color(backgroundRole());

src/gui/qgsmapoverviewcanvas.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ class GUI_EXPORT QgsMapOverviewCanvas : public QWidget
108108

109109
//! indicates whether antialiasing will be used for rendering
110110
bool mAntiAliasing;
111+
112+
//! resized canvas size
113+
QSize mNewSize;
111114
};
112115

113116
#endif

0 commit comments

Comments
 (0)