Skip to content

Commit

Permalink
Remove QgsGeometryCache class
Browse files Browse the repository at this point in the history
The geometry cache was only used for few geometry editing operations anyway. In earlier versions
of QGIS the geometry cache was also used by old snapping classes which have been replaced
by QgsPointLocator that also keeps a spatial index of geometries and it is not rebuilt on every re-render.

Reasons for removal:
- geometry cache was repopulated on every redraw of layers in editing mode, slowing down rendering
- data structure for the cache was a simple map with features accessed by their ID (no spatial index)
- the cache was only getting refreshed for the current view of the main map canvas (not a generic cache)
- not used for snapping anymore where caching was important to avoid roundtrips to data provider
  • Loading branch information
wonder-sk committed May 6, 2017
1 parent 5e3c6e5 commit 0a0c33d
Show file tree
Hide file tree
Showing 22 changed files with 47 additions and 344 deletions.
4 changes: 4 additions & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat
- QgsHtmlAnnotationItem. Use QgsHtmlAnnotation instead.
- QgsHttpTransaction. This class was outdated and code should be ported to native Qt or Python implementations.
- QgsGenericProjectionSelector. Use QgsProjectionSelectionTreeWidget instead.
- QgsGeometryCache. It got redundant after removal of old snapping classes (QgsSnapper + friends).
- QgsLabel and QgsLabelAttributes. Replaced by labeling based on PAL library, see QgsLabelingEngine.
- QgsLabelingEngineInterface. Replaced by QgsLabelingEngine.
- QgsLegendInterface was removed. It was replaced by layer tree API (QgsLayerTreeNode class and others).
Expand Down Expand Up @@ -1446,6 +1447,7 @@ and subclasses are not designed to be subclassed in PyQGIS.
be used instead of a null pointer if no transformation is required.
- prepareJobs() and drawLabeling() (neither available in PyQGIS) do not take QgsPalLabeling parameter anymore. All drawing of labels is done by QgsLabelingEngine.
- drawOldLabeling(), drawNewLabeling() were removed. The method drawLabeling() should be used instead.
- setRequestedGeometryCacheForLayers() was removed. There is no extra caching done during rendering job.


QgsMapTool {#qgis_api_break_3_0_QgsMapTool}
Expand Down Expand Up @@ -2146,6 +2148,7 @@ QgsVectorLayerEditUtils {#qgis_api_break_3_0_QgsVectorLayerEditUtils}

- addTopologicalPoints() now accepts a geometry reference, not a pointer.
- insertSegmentVerticesForSnap() has been removed.
- cache() has been removed.


QgsVectorLayerImport {#qgis_api_break_3_0_QgsVectorLayerImport}
Expand All @@ -2168,6 +2171,7 @@ QgsVectorLayerUndoCommand {#qgis_api_break_3_0_QgsVectorLayerUndoCommand}
-------------------------

- QgsVectorLayerUndoCommandChangeGeometry constructor now accepts a geometry reference, not a pointer.
- cache() has been removed.


QgsVisibilityPresetCollection {#qgis_api_break_3_0_QgsVisibilityPresetCollection}
Expand Down
1 change: 0 additions & 1 deletion python/core/core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@
%Include qgscacheindex.sip
%Include qgscacheindexfeatureid.sip
%Include qgsfeaturestore.sip
%Include qgsgeometrycache.sip
%Include qgslayerdefinition.sip
%Include qgsprojectfiletransform.sip
%Include qgsvectorlayereditutils.sip
Expand Down
26 changes: 0 additions & 26 deletions python/core/qgsgeometrycache.sip

This file was deleted.

4 changes: 0 additions & 4 deletions python/core/qgsmaprendererjob.sip
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ class QgsMapRendererJob : QObject
//! Does not take ownership of the object.
void setCache( QgsMapRendererCache *cache );

//! Set which vector layers should be cached while rendering
//! @note The way how geometries are cached is really suboptimal - this method may be removed in future releases
void setRequestedGeometryCacheForLayers( const QStringList &layerIds );

//! Find out how long it took to finish the job (in milliseconds)
int renderingTime() const;

Expand Down
1 change: 0 additions & 1 deletion python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,6 @@ Returns the current transparency for the vector layer
virtual QString htmlMetadata() const;



void setSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod );
%Docstring
Set the simplification settings for fast rendering of features
Expand Down
3 changes: 0 additions & 3 deletions python/core/qgsvectorlayereditutils.sip
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ class QgsVectorLayerEditUtils
public:
QgsVectorLayerEditUtils( QgsVectorLayer *layer );

QgsGeometryCache *cache();


/** Insert a new vertex before the given vertex number,
* in the given ring, item (first number is index 0), and feature
* Not meaningful for Point geometries
Expand Down
1 change: 0 additions & 1 deletion python/core/qgsvectorlayerundocommand.sip
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class QgsVectorLayerUndoCommand : QUndoCommand

//! Returns the layer associated with the undo command
QgsVectorLayer *layer();
QgsGeometryCache *cache();

virtual int id() const;
virtual bool mergeWith( QUndoCommand * );
Expand Down
2 changes: 0 additions & 2 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ SET(QGIS_CORE_SRCS
qgsfieldproxymodel.cpp
qgsfields.cpp
qgsfontutils.cpp
qgsgeometrycache.cpp
qgsgeometrysimplifier.cpp
qgsgeometryvalidator.cpp
qgsgml.cpp
Expand Down Expand Up @@ -735,7 +734,6 @@ SET(QGIS_CORE_HDRS
qgsfield_p.h
qgsfields.h
qgsfontutils.h
qgsgeometrycache.h
qgshistogram.h
qgsindexedfeature.h
qgsinterval.h
Expand Down
46 changes: 0 additions & 46 deletions src/core/qgsgeometrycache.cpp

This file was deleted.

60 changes: 0 additions & 60 deletions src/core/qgsgeometrycache.h

This file was deleted.

13 changes: 0 additions & 13 deletions src/core/qgsmaprenderercustompainterjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,6 @@ void QgsMapRendererJob::drawLabeling( const QgsMapSettings &settings, QgsRenderC
}


void QgsMapRendererJob::updateLayerGeometryCaches()
{
QMap<QString, QgsGeometryCache>::const_iterator it = mGeometryCaches.constBegin();
for ( ; it != mGeometryCaches.constEnd(); ++it )
{
const QgsGeometryCache &cache = it.value();
if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( it.key() ) ) )
* vl->cache() = cache;
}
mGeometryCaches.clear();
}


bool QgsMapRendererJob::needTemporaryImage( QgsMapLayer *ml )
{
if ( ml->type() == QgsMapLayer::VectorLayer )
Expand Down
12 changes: 0 additions & 12 deletions src/core/qgsmaprendererjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ LayerRenderJobs QgsMapRendererJob::prepareJobs( QPainter *painter, QgsLabelingEn

bool requiresLabelRedraw = !( mCache && mCache->hasCacheImage( LABEL_CACHE_ID ) );

mGeometryCaches.clear();

while ( li.hasPrevious() )
{
QgsMapLayer *ml = li.previous();
Expand Down Expand Up @@ -341,14 +339,6 @@ LayerRenderJobs QgsMapRendererJob::prepareJobs( QPainter *painter, QgsLabelingEn
if ( hasStyleOverride )
ml->styleManager()->restoreOverrideStyle();

if ( mRequestedGeomCacheForLayers.contains( ml->id() ) )
{
if ( QgsVectorLayerRenderer *vlr = dynamic_cast<QgsVectorLayerRenderer *>( job.renderer ) )
{
vlr->setGeometryCachePointer( &mGeometryCaches[ ml->id()] );
}
}

} // while (li.hasPrevious())

return layerJobs;
Expand Down Expand Up @@ -428,8 +418,6 @@ void QgsMapRendererJob::cleanupJobs( LayerRenderJobs &jobs )


jobs.clear();

updateLayerGeometryCaches();
}

void QgsMapRendererJob::cleanupLabelJob( LabelRenderJob &job )
Expand Down
13 changes: 0 additions & 13 deletions src/core/qgsmaprendererjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#include "qgsmapsettings.h"

#include "qgsgeometrycache.h"

class QgsLabelingEngine;
class QgsLabelingResults;
Expand Down Expand Up @@ -186,10 +185,6 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
//! Does not take ownership of the object.
void setCache( QgsMapRendererCache *cache );

//! Set which vector layers should be cached while rendering
//! \note The way how geometries are cached is really suboptimal - this method may be removed in future releases
void setRequestedGeometryCacheForLayers( const QStringList &layerIds ) { mRequestedGeomCacheForLayers = layerIds; }

//! Find out how long it took to finish the job (in milliseconds)
int renderingTime() const { return mRenderingTime; }

Expand Down Expand Up @@ -279,14 +274,6 @@ class CORE_EXPORT QgsMapRendererJob : public QObject

bool needTemporaryImage( QgsMapLayer *ml );

//! called when rendering has finished to update all layers' geometry caches
void updateLayerGeometryCaches();

//! list of layer IDs for which the geometry cache should be updated
QStringList mRequestedGeomCacheForLayers;
//! map of geometry caches
QMap<QString, QgsGeometryCache> mGeometryCaches;

const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
};

Expand Down
13 changes: 0 additions & 13 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#include "qgsfeature.h"
#include "qgsfeaturerequest.h"
#include "qgsfields.h"
#include "qgsgeometrycache.h"
#include "qgsgeometry.h"
#include "qgslogger.h"
#include "qgsmaplayerlegend.h"
Expand Down Expand Up @@ -142,7 +141,6 @@ QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath,
, mFeatureBlendMode( QPainter::CompositionMode_SourceOver ) // Default to normal feature blending
, mLayerTransparency( 0 )
, mVertexMarkerOnlyForSelection( false )
, mCache( new QgsGeometryCache() )
, mEditBuffer( nullptr )
, mJoinBuffer( nullptr )
, mExpressionFieldBuffer( nullptr )
Expand Down Expand Up @@ -190,7 +188,6 @@ QgsVectorLayer::~QgsVectorLayer()
delete mEditBuffer;
delete mJoinBuffer;
delete mExpressionFieldBuffer;
delete mCache;
delete mLabeling;
delete mDiagramLayerSettings;
delete mDiagramRenderer;
Expand Down Expand Up @@ -2438,11 +2435,6 @@ bool QgsVectorLayer::commitChanges()
QgsMessageLog::logMessage( tr( "Commit errors:\n %1" ).arg( mCommitErrors.join( QStringLiteral( "\n " ) ) ) );
}

if ( mCache )
{
mCache->deleteCachedGeometries();
}

updateFields();
mDataProvider->updateExtents();

Expand Down Expand Up @@ -2490,11 +2482,6 @@ bool QgsVectorLayer::rollBack( bool deleteBuffer )
}
emit editingStopped();

if ( mCache )
{
mCache->deleteCachedGeometries();
}

if ( rollbackExtent )
updateExtents();

Expand Down
7 changes: 0 additions & 7 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class QgsEditorWidgetWrapper;
class QgsExpressionFieldBuffer;
class QgsFeatureRenderer;
class QgsGeometry;
class QgsGeometryCache;
class QgsGeometryVertexIndex;
class QgsMapToPixel;
class QgsRectangle;
Expand Down Expand Up @@ -1487,9 +1486,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte

QString htmlMetadata() const override;

//! \note not available in Python bindings
inline QgsGeometryCache *cache() SIP_SKIP { return mCache; }

/** Set the simplification settings for fast rendering of features
* \since QGIS 2.2
*/
Expand Down Expand Up @@ -1971,9 +1967,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! Annotation form for this layer
QString mAnnotationForm;

//! cache for some vector layer data - currently only geometries for faster editing
QgsGeometryCache *mCache = nullptr;

//! stores information about uncommitted changes to layer
QgsVectorLayerEditBuffer *mEditBuffer = nullptr;
friend class QgsVectorLayerEditBuffer;
Expand Down
Loading

0 comments on commit 0a0c33d

Please sign in to comment.