Skip to content

Commit 208d4e3

Browse files
committedApr 4, 2013
Merge pull request #500 from matthias-kuhn/rendering-cache-crash
[Bugfix] Make rendering cache more stable
2 parents 1c6ee9f + 45cd49d commit 208d4e3

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed
 

‎src/app/qgsfieldsproperties.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void QgsAttributesTree::dragMoveEvent( QDragMoveEvent *event )
103103

104104
bool QgsAttributesTree::dropMimeData( QTreeWidgetItem * parent, int index, const QMimeData * data, Qt::DropAction action )
105105
{
106+
Q_UNUSED( index )
106107
bool bDropSuccessful = false;
107108

108109
if ( action == Qt::IgnoreAction )

‎src/core/qgsmaplayer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,7 @@ void QgsMapLayer::setCacheImage( QImage * thepImage )
12491249

12501250
if ( mpCacheImage )
12511251
{
1252+
onCacheImageDelete();
12521253
delete mpCacheImage;
12531254
}
12541255
mpCacheImage = thepImage;

‎src/core/qgsmaplayer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ class CORE_EXPORT QgsMapLayer : public QObject
331331
* @note This method was added in QGIS 1.4 **/
332332
void setCacheImage( QImage * thepImage );
333333

334+
/**
335+
* @brief Is called when the cache image is being deleted. Overwrite and use to clean up.
336+
* @note added in 2.0
337+
*/
338+
virtual void onCacheImageDelete() {};
339+
334340
public slots:
335341

336342
/** Event handler for when a coordinate transform fails due to bad vertex error */

‎src/core/qgsmaprenderer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
544544
delete mRenderContext.painter();
545545
mRenderContext.setPainter( mypContextPainter );
546546
//draw from cached image that we created further up
547-
mypContextPainter->drawImage( 0, 0, *( ml->cacheImage() ) );
547+
if ( ml->cacheImage() )
548+
mypContextPainter->drawImage( 0, 0, *( ml->cacheImage() ) );
548549
}
549550
}
550551
disconnect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );

‎src/core/qgsvectorlayer.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
107107
, mDiagramLayerSettings( 0 )
108108
, mValidExtent( false )
109109
, mSymbolFeatureCounted( false )
110+
, mCurrentRendererContext( 0 )
111+
110112
{
111113
mActions = new QgsAttributeAction( this );
112114

@@ -718,6 +720,8 @@ void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext&
718720
if ( !hasGeometryType() )
719721
return;
720722

723+
mCurrentRendererContext = &rendererContext;
724+
721725
QSettings settings;
722726
bool vertexMarkerOnlyForSelection = settings.value( "/qgis/digitizing/marker_only_for_selected", false ).toBool();
723727

@@ -735,10 +739,6 @@ void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext&
735739
if ( !fet.geometry() )
736740
continue; // skip features without geometry
737741

738-
if ( rendererContext.renderingStopped() )
739-
{
740-
break;
741-
}
742742
#ifndef Q_WS_MAC //MH: disable this on Mac for now to avoid problems with resizing
743743
#ifdef Q_WS_X11
744744
if ( !mEnableBackbuffer ) // do not handle events, as we're already inside a paint event
@@ -760,6 +760,11 @@ void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext&
760760
#endif // Q_WS_X11
761761
#endif // Q_WS_MAC
762762

763+
if ( rendererContext.renderingStopped() )
764+
{
765+
break;
766+
}
767+
763768
bool sel = mSelectedFeatureIds.contains( fet.id() );
764769
bool drawMarker = ( mEditBuffer && ( !vertexMarkerOnlyForSelection || sel ) );
765770

@@ -798,6 +803,8 @@ void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext&
798803

799804
stopRendererV2( rendererContext, NULL );
800805

806+
mCurrentRendererContext = NULL;
807+
801808
#ifndef Q_WS_MAC
802809
QgsDebugMsg( QString( "Total features processed %1" ).arg( featureCount ) );
803810
#endif
@@ -4386,6 +4393,12 @@ QString QgsVectorLayer::metadata()
43864393
return myMetadata;
43874394
}
43884395

4396+
void QgsVectorLayer::onCacheImageDelete()
4397+
{
4398+
if ( mCurrentRendererContext )
4399+
mCurrentRendererContext->setRenderingStopped( true );
4400+
}
4401+
43894402
QgsVectorLayer::ValueRelationData &QgsVectorLayer::valueRelation( int idx )
43904403
{
43914404
const QgsFields &fields = pendingFields();

‎src/core/qgsvectorlayer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
879879

880880
inline QgsGeometryCache* cache() { return mCache; }
881881

882+
/**
883+
* @brief Is called when the cache image is being deleted. Overwrite and use to clean up.
884+
* @note added in 2.0
885+
*/
886+
virtual void onCacheImageDelete();
887+
882888
signals:
883889

884890
/** This signal is emited when selection was changed */
@@ -1108,6 +1114,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
11081114
// Feature counts for each renderer symbol
11091115
QMap<QgsSymbolV2*, long> mSymbolFeatureCountMap;
11101116

1117+
QgsRenderContext* mCurrentRendererContext;
1118+
11111119
friend class QgsVectorLayerFeatureIterator;
11121120
};
11131121

0 commit comments

Comments
 (0)
Please sign in to comment.