Skip to content

Commit 036b25e

Browse files
committedNov 18, 2013
Stop using QgsMapLayer's setCacheImage()
That caching mechanism is too coarse - it is expected that there is only one map renderer. Instead, caching would need to be done on higher level, e.g. in QgsMapCanvas
1 parent 68e2951 commit 036b25e

12 files changed

+13
-148
lines changed
 

‎src/app/legend/qgslegend.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,7 +2802,6 @@ void QgsLegend::legendLayerZoomNative()
28022802
QgsDebugMsg( "Raster units per pixel : " + QString::number( layer->rasterUnitsPerPixelX() ) );
28032803
QgsDebugMsg( "MapUnitsPerPixel before : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
28042804

2805-
layer->setCacheImage( NULL );
28062805
if ( mMapCanvas->hasCrsTransformEnabled() )
28072806
{
28082807
// get legth of central canvas pixel width in source raster crs
@@ -2842,7 +2841,6 @@ void QgsLegend::legendLayerStretchUsingCurrentExtent()
28422841
myRectangle = mMapCanvas->mapSettings().outputExtentToLayerExtent( layer, mMapCanvas->extent() );
28432842
layer->setContrastEnhancement( contrastEnhancementAlgorithm, QgsRaster::ContrastEnhancementMinMax, myRectangle );
28442843

2845-
layer->setCacheImage( NULL );
28462844
refreshLayerSymbology( layer->id() );
28472845
mMapCanvas->refresh();
28482846
}

‎src/app/qgisapp.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5815,8 +5815,6 @@ void QgisApp::copyFeatures( QgsFeatureStore & featureStore )
58155815

58165816
void QgisApp::refreshMapCanvas()
58175817
{
5818-
//clear all caches first
5819-
QgsMapLayerRegistry::instance()->clearAllLayerCaches();
58205818
//reload cached provider data
58215819
QgsMapLayerRegistry::instance()->reloadAllLayers();
58225820
//then refresh
@@ -6856,7 +6854,6 @@ void QgisApp::histogramStretch( bool visibleAreaOnly, QgsRaster::ContrastEnhance
68566854

68576855
myRasterLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, theLimits, myRectangle );
68586856

6859-
myRasterLayer->setCacheImage( NULL );
68606857
mMapCanvas->refresh();
68616858
}
68626859

@@ -6913,7 +6910,6 @@ void QgisApp::adjustBrightnessContrast( int delta, bool updateBrightness )
69136910
brightnessFilter->setContrast( brightnessFilter->contrast() + delta );
69146911
}
69156912

6916-
myRasterLayer->setCacheImage( NULL );
69176913
mMapCanvas->refresh();
69186914
}
69196915

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,6 @@ void QgsRasterLayerProperties::apply()
930930
// update symbology
931931
emit refreshLegend( mRasterLayer->id(), false );
932932

933-
//no need to delete the old one, maplayer will do it if needed
934-
mRasterLayer->setCacheImage( 0 );
935-
936933
//make sure the layer is redrawn
937934
mRasterLayer->triggerRepaint();
938935

‎src/app/qgsvectorlayerproperties.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,6 @@ void QgsVectorLayerProperties::apply()
532532
// update symbology
533533
emit refreshLegend( layer->id(), QgsLegendItem::DontChange );
534534

535-
//no need to delete the old one, maplayer will do it if needed
536-
layer->setCacheImage( 0 );
537-
538535
layer->triggerRepaint();
539536
// notify the project we've made a change
540537
QgsProject::instance()->dirty( true );

‎src/core/qgsmaplayer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,6 @@ void QgsMapLayer::setValid( bool valid )
13411341

13421342
void QgsMapLayer::clearCacheImage()
13431343
{
1344-
setCacheImage( 0 );
13451344
}
13461345

13471346
QString QgsMapLayer::metadata()

‎src/core/qgsmaplayer.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,12 @@ class CORE_EXPORT QgsMapLayer : public QObject
360360
/** Return pointer to layer's undo stack */
361361
QUndoStack* undoStack();
362362

363-
/** \note Deprecated from 2.1 - returns NULL */
364-
QImage *cacheImage() { return 0; }
365-
/** \note Deprecated from 2.1 - does nothing */
366-
void setCacheImage( QImage * ) {}
367-
/** @note Deprecated from 2.1 - does nothing */
368-
virtual void onCacheImageDelete() {}
363+
/** @deprecated since 2.1 - returns NULL */
364+
Q_DECL_DEPRECATED QImage *cacheImage() { return 0; }
365+
/** @deprecated since 2.1 - does nothing */
366+
Q_DECL_DEPRECATED void setCacheImage( QImage * ) {}
367+
/** @deprecated since 2.1 - does nothing */
368+
Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
369369

370370
public slots:
371371

@@ -386,7 +386,8 @@ class CORE_EXPORT QgsMapLayer : public QObject
386386

387387
/** Clear cached image
388388
* added in 1.5 */
389-
void clearCacheImage();
389+
//! @deprecated in 2.1 - does nothing
390+
Q_DECL_DEPRECATED void clearCacheImage();
390391

391392
/** \brief Obtain Metadata for this layer */
392393
virtual QString metadata();

‎src/core/qgsmaplayerregistry.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,9 @@ void QgsMapLayerRegistry::removeAllMapLayers()
151151
mMapLayers.clear();
152152
} // QgsMapLayerRegistry::removeAllMapLayers()
153153

154-
//Added in QGIS 1.4
155154
void QgsMapLayerRegistry::clearAllLayerCaches()
156155
{
157-
QMap<QString, QgsMapLayer *>::iterator it;
158-
for ( it = mMapLayers.begin(); it != mMapLayers.end() ; ++it )
159-
{
160-
//the map layer will take care of deleting the QImage
161-
it.value()->setCacheImage( 0 );
162-
}
163-
} // QgsMapLayerRegistry::clearAllLayerCaches()
156+
}
164157

165158
void QgsMapLayerRegistry::reloadAllLayers()
166159
{

‎src/core/qgsmaplayerregistry.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
150150
*
151151
* @note Added in QGIS 1.4
152152
*/
153-
void clearAllLayerCaches();
153+
//! @deprecated since 2.1 - does nothing
154+
Q_DECL_DEPRECATED void clearAllLayerCaches();
154155

155156
/**
156157
* Reload all provider data caches (currently used for WFS and WMS providers)

‎src/core/qgsmaprenderer.cpp

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -329,18 +329,6 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
329329
if ( mLabelingEngine )
330330
mLabelingEngine->init( this );
331331

332-
// know we know if this render is just a repeat of the last time, we
333-
// can clear caches if it has changed
334-
if ( !mySameAsLastFlag )
335-
{
336-
//clear the cache pixmap if we changed resolution / extent
337-
QSettings mySettings;
338-
if ( mySettings.value( "/qgis/enable_render_caching", false ).toBool() )
339-
{
340-
QgsMapLayerRegistry::instance()->clearAllLayerCaches();
341-
}
342-
}
343-
344332
// render all layers in the stack, starting at the base
345333
QListIterator<QString> li( mLayerSet );
346334
li.toBack();
@@ -439,58 +427,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
439427
scaleRaster = true;
440428
}
441429

442-
// Force render of layers that are being edited
443-
// or if there's a labeling engine that needs the layer to register features
444-
if ( ml->type() == QgsMapLayer::VectorLayer )
445-
{
446-
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
447-
if ( vl->isEditable() ||
448-
( mRenderContext.labelingEngine() && mRenderContext.labelingEngine()->willUseLayer( vl ) ) )
449-
{
450-
ml->setCacheImage( 0 );
451-
}
452-
}
453-
454430
QSettings mySettings;
455-
bool useRenderCaching = false;
456-
if ( ! split )//render caching does not yet cater for split extents
457-
{
458-
if ( mySettings.value( "/qgis/enable_render_caching", false ).toBool() )
459-
{
460-
useRenderCaching = true;
461-
if ( !mySameAsLastFlag || ml->cacheImage() == 0 )
462-
{
463-
QgsDebugMsg( "Caching enabled but layer redraw forced by extent change or empty cache" );
464-
QImage * mypImage = new QImage( mRenderContext.painter()->device()->width(),
465-
mRenderContext.painter()->device()->height(), QImage::Format_ARGB32 );
466-
if ( mypImage->isNull() )
467-
{
468-
QgsDebugMsg( "insufficient memory for image " + QString::number( mRenderContext.painter()->device()->width() ) + "x" + QString::number( mRenderContext.painter()->device()->height() ) );
469-
emit drawError( ml );
470-
painter->end(); // drawError is not caught by anyone, so we end painting to notify caller
471-
return;
472-
}
473-
mypImage->fill( 0 );
474-
ml->setCacheImage( mypImage ); //no need to delete the old one, maplayer does it for you
475-
QPainter * mypPainter = new QPainter( ml->cacheImage() );
476-
// Changed to enable anti aliasing by default in QGIS 1.7
477-
if ( mySettings.value( "/qgis/enable_anti_aliasing", true ).toBool() )
478-
{
479-
mypPainter->setRenderHint( QPainter::Antialiasing );
480-
}
481-
mRenderContext.setPainter( mypPainter );
482-
}
483-
else if ( mySameAsLastFlag )
484-
{
485-
//draw from cached image
486-
QgsDebugMsg( "Caching enabled --- drawing layer from cached image" );
487-
mypContextPainter->drawImage( 0, 0, *( ml->cacheImage() ) );
488-
disconnect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
489-
//short circuit as there is nothing else to do...
490-
continue;
491-
}
492-
}
493-
}
494431

495432
// If we are drawing with an alternative blending mode then we need to render to a separate image
496433
// before compositing this on the map. This effectively flattens the layer and prevents
@@ -500,8 +437,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
500437
if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) )
501438
{
502439
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
503-
if (( !useRenderCaching )
504-
&& (( vl->blendMode() != QPainter::CompositionMode_SourceOver )
440+
if ( (( vl->blendMode() != QPainter::CompositionMode_SourceOver )
505441
|| ( vl->featureBlendMode() != QPainter::CompositionMode_SourceOver )
506442
|| ( vl->layerTransparency() != 0 ) ) )
507443
{
@@ -589,17 +525,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
589525
}
590526
}
591527

592-
if ( useRenderCaching )
593-
{
594-
// composite the cached image into our view and then clean up from caching
595-
// by reinstating the painter as it was swapped out for caching renders
596-
delete mRenderContext.painter();
597-
mRenderContext.setPainter( mypContextPainter );
598-
//draw from cached image that we created further up
599-
if ( ml->cacheImage() )
600-
mypContextPainter->drawImage( 0, 0, *( ml->cacheImage() ) );
601-
}
602-
else if ( flattenedLayer )
528+
if ( flattenedLayer )
603529
{
604530
// If we flattened this layer for alternate blend modes, composite it now
605531
delete mRenderContext.painter();

‎src/core/qgsvectorlayer.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
133133
, mDiagramLayerSettings( 0 )
134134
, mValidExtent( false )
135135
, mSymbolFeatureCounted( false )
136-
, mCurrentRendererContext( 0 )
137136

138137
{
139138
mActions = new QgsAttributeAction( this );
@@ -388,8 +387,6 @@ void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext&
388387
if ( !hasGeometryType() )
389388
return;
390389

391-
mCurrentRendererContext = &rendererContext;
392-
393390
QSettings settings;
394391
bool vertexMarkerOnlyForSelection = settings.value( "/qgis/digitizing/marker_only_for_selected", false ).toBool();
395392

@@ -441,8 +438,6 @@ void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext&
441438
}
442439

443440
stopRendererV2( rendererContext, NULL );
444-
445-
mCurrentRendererContext = NULL;
446441
}
447442

448443
void QgsVectorLayer::drawRendererV2Levels( QgsFeatureIterator &fit, QgsRenderContext& rendererContext, bool labeling )
@@ -647,31 +642,27 @@ void QgsVectorLayer::select( const QgsFeatureId& fid )
647642
{
648643
mSelectedFeatureIds.insert( fid );
649644

650-
setCacheImage( 0 );
651645
emit selectionChanged( QgsFeatureIds() << fid, QgsFeatureIds(), false );
652646
}
653647

654648
void QgsVectorLayer::select( const QgsFeatureIds& featureIds )
655649
{
656650
mSelectedFeatureIds.unite( featureIds );
657651

658-
setCacheImage( 0 );
659652
emit selectionChanged( featureIds, QgsFeatureIds(), false );
660653
}
661654

662655
void QgsVectorLayer::deselect( const QgsFeatureId fid )
663656
{
664657
mSelectedFeatureIds.remove( fid );
665658

666-
setCacheImage( 0 );
667659
emit selectionChanged( QgsFeatureIds(), QgsFeatureIds() << fid, false );
668660
}
669661

670662
void QgsVectorLayer::deselect( const QgsFeatureIds& featureIds )
671663
{
672664
mSelectedFeatureIds.subtract( featureIds );
673665

674-
setCacheImage( 0 );
675666
emit selectionChanged( QgsFeatureIds(), featureIds, false );
676667
}
677668

@@ -715,8 +706,6 @@ void QgsVectorLayer::modifySelection( QgsFeatureIds selectIds, QgsFeatureIds des
715706
mSelectedFeatureIds -= deselectIds;
716707
mSelectedFeatureIds += selectIds;
717708

718-
setCacheImage( 0 );
719-
720709
emit selectionChanged( selectIds, deselectIds - intersectingIds, false );
721710
}
722711

@@ -1127,9 +1116,6 @@ bool QgsVectorLayer::setSubsetString( QString subset )
11271116
mDataSource = mDataProvider->dataSourceUri();
11281117
updateExtents();
11291118

1130-
if ( res )
1131-
setCacheImage( 0 );
1132-
11331119
return res;
11341120
}
11351121

@@ -1252,8 +1238,6 @@ bool QgsVectorLayer::deleteSelectedFeatures()
12521238
deleteFeature( fid ); // removes from selection
12531239
}
12541240

1255-
// invalidate cache
1256-
setCacheImage( 0 );
12571241
triggerRepaint();
12581242
updateExtents();
12591243

@@ -2572,9 +2556,6 @@ bool QgsVectorLayer::commitChanges()
25722556
updateFields();
25732557
mDataProvider->updateExtents();
25742558

2575-
//clear the cache image so markers don't appear anymore on next draw
2576-
setCacheImage( 0 );
2577-
25782559
return success;
25792560
}
25802561

@@ -2616,9 +2597,6 @@ bool QgsVectorLayer::rollBack( bool deleteBuffer )
26162597
mCache->deleteCachedGeometries();
26172598
}
26182599

2619-
// invalidate the cache so the layer updates properly to show its original
2620-
// after the rollback
2621-
setCacheImage( 0 );
26222600
return true;
26232601
}
26242602

@@ -2642,9 +2620,6 @@ void QgsVectorLayer::setSelectedFeatures( const QgsFeatureIds& ids )
26422620
}
26432621
}
26442622

2645-
// invalidate cache
2646-
setCacheImage( 0 );
2647-
26482623
emit selectionChanged( ids, deselectedFeatures, true );
26492624
}
26502625

@@ -3763,12 +3738,6 @@ QString QgsVectorLayer::metadata()
37633738
return myMetadata;
37643739
}
37653740

3766-
void QgsVectorLayer::onCacheImageDelete()
3767-
{
3768-
if ( mCurrentRendererContext )
3769-
mCurrentRendererContext->setRenderingStopped( true );
3770-
}
3771-
37723741
void QgsVectorLayer::invalidateSymbolCountedFlag()
37733742
{
37743743
mSymbolFeatureCounted = false;

‎src/core/qgsvectorlayer.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,12 +1418,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
14181418
@note added in 1.7 */
14191419
void checkJoinLayerRemove( QString theLayerId );
14201420

1421-
/**
1422-
* @brief Is called when the cache image is being deleted. Overwrite and use to clean up.
1423-
* @note added in 2.0
1424-
*/
1425-
virtual void onCacheImageDelete();
1426-
14271421
protected slots:
14281422
void invalidateSymbolCountedFlag();
14291423

@@ -1575,8 +1569,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
15751569
/** Pointer to data provider derived from the abastract base class QgsDataProvider */
15761570
QgsVectorDataProvider *mDataProvider;
15771571

1578-
QgsFeatureIterator mProviderIterator;
1579-
15801572
/** index of the primary label field */
15811573
QString mDisplayField;
15821574

@@ -1696,8 +1688,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
16961688
// Feature counts for each renderer symbol
16971689
QMap<QgsSymbolV2*, long> mSymbolFeatureCountMap;
16981690

1699-
QgsRenderContext* mCurrentRendererContext;
1700-
17011691
friend class QgsVectorLayerFeatureIterator;
17021692
};
17031693

‎src/plugins/georeferencer/qgsgeorefplugingui.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,6 @@ void QgsGeorefPluginGui::showGeorefConfigDialog()
633633
void QgsGeorefPluginGui::fullHistogramStretch()
634634
{
635635
mLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum );
636-
mLayer->setCacheImage( NULL );
637636
mCanvas->refresh();
638637
}
639638

@@ -642,7 +641,6 @@ void QgsGeorefPluginGui::localHistogramStretch()
642641
QgsRectangle rectangle = mIface->mapCanvas()->mapSettings().outputExtentToLayerExtent( mLayer, mIface->mapCanvas()->extent() );
643642

644643
mLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, QgsRaster::ContrastEnhancementMinMax, rectangle );
645-
mLayer->setCacheImage( NULL );
646644
mCanvas->refresh();
647645
}
648646

0 commit comments

Comments
 (0)
Please sign in to comment.