[QGIS Commit] r15050 - in trunk/qgis/src: core gui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri Jan 14 18:24:26 EST 2011
Author: jef
Date: 2011-01-14 15:24:26 -0800 (Fri, 14 Jan 2011)
New Revision: 15050
Modified:
trunk/qgis/src/core/qgsmaprenderer.cpp
trunk/qgis/src/core/qgsmaprenderer.h
trunk/qgis/src/gui/qgsmapcanvas.cpp
trunk/qgis/src/gui/qgsmapcanvas.h
trunk/qgis/src/gui/qgsmapoverviewcanvas.cpp
trunk/qgis/src/gui/qgsmapoverviewcanvas.h
Log:
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.
Modified: trunk/qgis/src/core/qgsmaprenderer.cpp
===================================================================
--- trunk/qgis/src/core/qgsmaprenderer.cpp 2011-01-14 23:24:15 UTC (rev 15049)
+++ trunk/qgis/src/core/qgsmaprenderer.cpp 2011-01-14 23:24:26 UTC (rev 15050)
@@ -38,9 +38,8 @@
#include <QListIterator>
#include <QSettings>
#include <QTime>
-#include "qgslogger.h"
+#include <QCoreApplication>
-
QgsMapRenderer::QgsMapRenderer()
{
mScaleCalculator = new QgsScaleCalculator;
@@ -229,14 +228,22 @@
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 @@
QgsDebugMsg( "Rendering completed in (seconds): " + QString( "%1" ).arg( renderTime.elapsed() / 1000.0 ) );
mDrawing = false;
-
}
void QgsMapRenderer::setMapUnits( QGis::UnitType u )
@@ -1073,3 +1079,5 @@
mLabelingEngine = iface;
}
+
+bool QgsMapRenderer::mDrawing = false;
Modified: trunk/qgis/src/core/qgsmaprenderer.h
===================================================================
--- trunk/qgis/src/core/qgsmaprenderer.h 2011-01-14 23:24:15 UTC (rev 15049)
+++ trunk/qgis/src/core/qgsmaprenderer.h 2011-01-14 23:24:26 UTC (rev 15050)
@@ -249,7 +249,7 @@
protected:
//! indicates drawing in progress
- bool mDrawing;
+ static bool mDrawing;
//! map units per pixel
double mMapUnitsPerPixel;
Modified: trunk/qgis/src/gui/qgsmapcanvas.cpp
===================================================================
--- trunk/qgis/src/gui/qgsmapcanvas.cpp 2011-01-14 23:24:15 UTC (rev 15049)
+++ trunk/qgis/src/gui/qgsmapcanvas.cpp 2011-01-14 23:24:26 UTC (rev 15050)
@@ -932,52 +932,59 @@
void QgsMapCanvas::resizeEvent( QResizeEvent * e )
{
- static bool isAlreadyIn = false;
- static QSize lastSize = QSize( -1, -1 );
+ mNewSize = e->size();
+}
- lastSize = e->size();
+void QgsMapCanvas::paintEvent( QPaintEvent *e )
+{
+ if( mNewSize.isValid() )
+ {
+ static bool isAlreadyIn = false;
+ static QSize lastSize = QSize();
- if ( isAlreadyIn || mDrawing )
- {
- //cancel current render progress
- if ( mMapRenderer )
+ 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;
}
- isAlreadyIn = false;
-} // resizeEvent
+ QGraphicsView::paintEvent( e );
+} // paintEvent
void QgsMapCanvas::updateCanvasItemPositions()
{
Modified: trunk/qgis/src/gui/qgsmapcanvas.h
===================================================================
--- trunk/qgis/src/gui/qgsmapcanvas.h 2011-01-14 23:24:15 UTC (rev 15049)
+++ trunk/qgis/src/gui/qgsmapcanvas.h 2011-01-14 23:24:26 UTC (rev 15050)
@@ -368,6 +368,9 @@
//! 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 @@
//! Mouse wheel action
WheelAction mWheelAction;
+ //! resize canvas size
+ QSize mNewSize;
+
}; // class QgsMapCanvas
Modified: trunk/qgis/src/gui/qgsmapoverviewcanvas.cpp
===================================================================
--- trunk/qgis/src/gui/qgsmapoverviewcanvas.cpp 2011-01-14 23:24:15 UTC (rev 15049)
+++ trunk/qgis/src/gui/qgsmapoverviewcanvas.cpp 2011-01-14 23:24:26 UTC (rev 15050)
@@ -85,12 +85,24 @@
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() );
+}
+
+
void QgsMapOverviewCanvas::drawExtentRect()
{
const QgsRectangle& extent = mMapCanvas->extent();
@@ -233,16 +245,9 @@
}
-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());
Modified: trunk/qgis/src/gui/qgsmapoverviewcanvas.h
===================================================================
--- trunk/qgis/src/gui/qgsmapoverviewcanvas.h 2011-01-14 23:24:15 UTC (rev 15049)
+++ trunk/qgis/src/gui/qgsmapoverviewcanvas.h 2011-01-14 23:24:26 UTC (rev 15050)
@@ -108,6 +108,9 @@
//! indicates whether antialiasing will be used for rendering
bool mAntiAliasing;
+
+ //! resized canvas size
+ QSize mNewSize;
};
#endif
More information about the QGIS-commit
mailing list