Skip to content

Commit

Permalink
fix #2884:
Browse files Browse the repository at this point in the history
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/qgis@15050 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jan 14, 2011
1 parent 4e9965c commit af87923
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 52 deletions.
20 changes: 14 additions & 6 deletions src/core/qgsmaprenderer.cpp
Expand Up @@ -38,8 +38,7 @@
#include <QListIterator>
#include <QSettings>
#include <QTime>
#include "qgslogger.h"

#include <QCoreApplication>

QgsMapRenderer::QgsMapRenderer()
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -1073,3 +1079,5 @@ void QgsMapRenderer::setLabelingEngine( QgsLabelingEngineInterface* iface )

mLabelingEngine = iface;
}

bool QgsMapRenderer::mDrawing = false;
2 changes: 1 addition & 1 deletion src/core/qgsmaprenderer.h
Expand Up @@ -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;
Expand Down
75 changes: 41 additions & 34 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -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()
{
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -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 );

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

//! resize canvas size
QSize mNewSize;

}; // class QgsMapCanvas


Expand Down
27 changes: 16 additions & 11 deletions src/gui/qgsmapoverviewcanvas.cpp
Expand Up @@ -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() );
}


Expand Down Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsmapoverviewcanvas.h
Expand Up @@ -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 af87923

Please sign in to comment.