Skip to content
Permalink
Browse files
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
  • Loading branch information
jef committed Jan 14, 2011
1 parent 5e24c9f commit 185ec5db69258715c5c106336b467e864ed702dc
@@ -38,8 +38,7 @@
#include <QListIterator>
#include <QSettings>
#include <QTime>
#include "qgslogger.h"

#include <QCoreApplication>

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

if ( mDrawing )
QPaintDevice* thePaintDevice = painter->device();
if ( !thePaintDevice )
{
return;
}

QPaintDevice* thePaintDevice = painter->device();
if ( !thePaintDevice )
// wait
if( mDrawing )
{
QgsDebugMsg( "already rendering" );
QCoreApplication::processEvents();
}

if( mDrawing )
{
QgsDebugMsg( "still rendering - skipping" );
return;
}

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

mDrawing = false;

}

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

mLabelingEngine = iface;
}

bool QgsMapRenderer::mDrawing = false;
@@ -249,7 +249,7 @@ class CORE_EXPORT QgsMapRenderer : public QObject
protected:

//! indicates drawing in progress
bool mDrawing;
static bool mDrawing;

//! map units per pixel
double mMapUnitsPerPixel;
@@ -932,52 +932,59 @@ void QgsMapCanvas::mouseReleaseEvent( QMouseEvent * e )

void QgsMapCanvas::resizeEvent( QResizeEvent * e )
{
static bool isAlreadyIn = false;
static QSize lastSize = QSize( -1, -1 );

lastSize = e->size();
mNewSize = e->size();
}

if ( isAlreadyIn || mDrawing )
void QgsMapCanvas::paintEvent( QPaintEvent *e )
{
if( mNewSize.isValid() )
{
//cancel current render progress
if ( mMapRenderer )
static bool isAlreadyIn = false;
static QSize lastSize = QSize();

lastSize = mNewSize;
mNewSize = QSize();

if ( isAlreadyIn || mDrawing )
{
QgsRenderContext* theRenderContext = mMapRenderer->rendererContext();
if ( theRenderContext )
//cancel current render progress
if ( mMapRenderer )
{
theRenderContext->setRenderingStopped( true );
QgsRenderContext* theRenderContext = mMapRenderer->rendererContext();
if ( theRenderContext )
{
theRenderContext->setRenderingStopped( true );
}
}
return;
}
return;
}
isAlreadyIn = true;
isAlreadyIn = true;

while ( lastSize != QSize( -1, -1 ) )
{
int width = lastSize.width();
int height = lastSize.height();
lastSize = QSize( -1, -1 );
while ( lastSize.isValid() )
{
int width = lastSize.width();
int height = lastSize.height();
lastSize = QSize();

//set map size before scene size helps keep scene indexes updated properly
// this was the cause of rubberband artifacts
mMap->resize( QSize( width, height ) );
mScene->setSceneRect( QRectF( 0, 0, width, height ) );
//set map size before scene size helps keep scene indexes updated properly
// this was the cause of rubberband artifacts
mMap->resize( QSize( width, height ) );
mScene->setSceneRect( QRectF( 0, 0, width, height ) );

// notify canvas items of change
updateCanvasItemPositions();
// notify canvas items of change
updateCanvasItemPositions();

updateScale();
#if QT_VERSION >= 0x40600
// FIXME: temporary workaround for #2714
QTimer::singleShot( 1, this, SLOT( refresh() ) );
#else
refresh();
#endif
emit extentsChanged();
}
updateScale();

refresh();

emit extentsChanged();
}
isAlreadyIn = false;
} // resizeEvent
}

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

void QgsMapCanvas::updateCanvasItemPositions()
{
@@ -368,6 +368,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Overridden resize event
void resizeEvent( QResizeEvent * e );

//! Overridden paint event
void paintEvent( QPaintEvent * e );

//! called when panning is in action, reset indicates end of panning
void moveCanvasContents( bool reset = false );

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

//! resize canvas size
QSize mNewSize;

}; // class QgsMapCanvas


@@ -85,9 +85,21 @@ QgsMapOverviewCanvas::~QgsMapOverviewCanvas()

void QgsMapOverviewCanvas::resizeEvent( QResizeEvent* e )
{
mPixmap = QPixmap( e->size() );
mMapRenderer->setOutputSize( e->size(), mPixmap.logicalDpiX() );
refresh();
mNewSize = e->size();
}

void QgsMapOverviewCanvas::paintEvent( QPaintEvent* pe )
{
if( mNewSize.isValid() )
{
mPixmap = QPixmap( mNewSize );
mMapRenderer->setOutputSize( mNewSize, mPixmap.logicalDpiX() );
mNewSize = QSize();
refresh();
}

QPainter paint( this );
paint.drawPixmap( pe->rect().topLeft(), mPixmap, pe->rect() );
}


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


void QgsMapOverviewCanvas::paintEvent( QPaintEvent * pe )
{
QPainter paint( this );
paint.drawPixmap( pe->rect().topLeft(), mPixmap, pe->rect() );
}


void QgsMapOverviewCanvas::refresh()
{
if ( mPixmap.isNull() )
if ( mPixmap.isNull() || mPixmap.paintingActive() )
return;

mPixmap.fill( mBgColor ); //palette().color(backgroundRole());
@@ -108,6 +108,9 @@ class GUI_EXPORT QgsMapOverviewCanvas : public QWidget

//! indicates whether antialiasing will be used for rendering
bool mAntiAliasing;

//! resized canvas size
QSize mNewSize;
};

#endif

0 comments on commit 185ec5d

Please sign in to comment.