@@ -697,6 +697,8 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
697
697
{
698
698
// Destroy all cached geometries and clear the references to them
699
699
deleteCachedGeometries ();
700
+
701
+ mCachedGeometriesRect = rendererContext.extent ();
700
702
}
701
703
702
704
updateFeatureCount ();
@@ -783,13 +785,19 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
783
785
QgsLogger::warning ( " QgsRenderer is null in QgsVectorLayer::draw()" );
784
786
}
785
787
788
+ if ( mEditable )
789
+ {
790
+ QgsDebugMsg (QString (" Cached %1 geometries." ).arg (mCachedGeometries .count ()));
791
+ }
792
+
786
793
return TRUE ; // Assume success always
787
794
}
788
795
789
796
void QgsVectorLayer::deleteCachedGeometries ()
790
797
{
791
798
// Destroy any cached geometries
792
799
mCachedGeometries .clear ();
800
+ mCachedGeometriesRect = QgsRectangle ();
793
801
}
794
802
795
803
void QgsVectorLayer::drawVertexMarker ( int x, int y, QPainter& p, QgsVectorLayer::VertexMarkerType type )
@@ -3135,15 +3143,36 @@ int QgsVectorLayer::snapWithContext( const QgsPoint& startPoint, double snapping
3135
3143
QgsRectangle searchRect ( startPoint.x () - snappingTolerance, startPoint.y () - snappingTolerance,
3136
3144
startPoint.x () + snappingTolerance, startPoint.y () + snappingTolerance );
3137
3145
double sqrSnappingTolerance = snappingTolerance * snappingTolerance;
3138
-
3139
- select ( QgsAttributeList (), searchRect, true , true );
3140
-
3146
+
3141
3147
int n = 0 ;
3142
3148
QgsFeature f;
3143
- while ( nextFeature ( f ) )
3149
+
3150
+ if (mCachedGeometriesRect .contains (searchRect))
3151
+ {
3152
+ QgsDebugMsg (" Using cached geometries for snapping." );
3153
+
3154
+ QgsGeometryMap::iterator it = mCachedGeometries .begin ();
3155
+ for ( ; it != mCachedGeometries .end () ; ++it)
3156
+ {
3157
+ QgsGeometry* g = &(it.value ());
3158
+ if (g->boundingBox ().intersects (searchRect))
3159
+ {
3160
+ snapToGeometry ( startPoint, it.key (), g, sqrSnappingTolerance, snappingResults, snap_to );
3161
+ ++n;
3162
+ }
3163
+ }
3164
+ }
3165
+ else
3144
3166
{
3145
- snapToGeometry ( startPoint, f.id (), f.geometry (), sqrSnappingTolerance, snappingResults, snap_to );
3146
- ++n;
3167
+ // snapping outside cached area
3168
+
3169
+ select ( QgsAttributeList (), searchRect, true , true );
3170
+
3171
+ while ( nextFeature ( f ) )
3172
+ {
3173
+ snapToGeometry ( startPoint, f.id (), f.geometry (), sqrSnappingTolerance, snappingResults, snap_to );
3174
+ ++n;
3175
+ }
3147
3176
}
3148
3177
3149
3178
return n == 0 ? 2 : 0 ;
0 commit comments