Skip to content

Commit c6fb253

Browse files
committed
allow limiting snapping to a given area
1 parent 4d6a535 commit c6fb253

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

python/core/qgssnappingutils.sip

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class QgsSnappingUtils : QObject
4747
{
4848
IndexAlwaysFull, //!< For all layers build index of full extent. Uses more memory, but queries are faster.
4949
IndexNeverFull, //!< For all layers only create temporary indexes of small extent. Low memory usage, slower queries.
50-
IndexHybrid //!< For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.
50+
IndexHybrid, //!< For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.
51+
IndexExtent //!< For all layer build index of extent given in map settings
5152
};
5253

5354
/** Set a strategy for indexing geometry data - determines how fast and memory consuming the data structures will be */

src/core/qgspointlocator.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ QgsPointLocator::Match QgsPointLocator::nearestVertex( const QgsPoint& point, do
849849
QgsRectangle rect( point.x() - tolerance, point.y() - tolerance, point.x() + tolerance, point.y() + tolerance );
850850
mRTree->intersectsWithQuery( rect2region( rect ), visitor );
851851
if ( m.isValid() && m.distance() > tolerance )
852-
return Match(); // // make sure that only match strictly within the tolerance is returned
852+
return Match(); // make sure that only match strictly within the tolerance is returned
853853
return m;
854854
}
855855

@@ -871,7 +871,7 @@ QgsPointLocator::Match QgsPointLocator::nearestEdge( const QgsPoint& point, doub
871871
QgsRectangle rect( point.x() - tolerance, point.y() - tolerance, point.x() + tolerance, point.y() + tolerance );
872872
mRTree->intersectsWithQuery( rect2region( rect ), visitor );
873873
if ( m.isValid() && m.distance() > tolerance )
874-
return Match(); // // make sure that only match strictly within the tolerance is returned
874+
return Match(); // make sure that only match strictly within the tolerance is returned
875875
return m;
876876
}
877877

src/core/qgssnappingutils.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ bool QgsSnappingUtils::isIndexPrepared( QgsVectorLayer* vl, const QgsRectangle&
9191
if ( mStrategy == IndexAlwaysFull && loc->hasIndex() )
9292
return true;
9393

94-
if ( mStrategy == IndexHybrid && loc->hasIndex() && ( !loc->extent() || loc->extent()->contains( areaOfInterest ) ) )
94+
QgsRectangle aoi( areaOfInterest );
95+
aoi.scale( 0.999 );
96+
if (( mStrategy == IndexHybrid || mStrategy == IndexExtent ) && loc->hasIndex() && ( !loc->extent() || loc->extent()->contains( aoi ) ) )
9597
return true;
9698

9799
return false; // the index - even if it exists - is not suitable
@@ -339,7 +341,13 @@ void QgsSnappingUtils::prepareIndex( const QList<LayerAndAreaOfInterest>& layers
339341
QTime tt;
340342
tt.start();
341343
QgsPointLocator* loc = locatorForLayer( vl );
342-
if ( mStrategy == IndexHybrid )
344+
if ( mStrategy == IndexExtent )
345+
{
346+
QgsRectangle rect( mMapSettings.extent() );
347+
loc->setExtent( &rect );
348+
loc->init();
349+
}
350+
else if ( mStrategy == IndexHybrid )
343351
{
344352
// first time the layer is used? - let's set an initial guess about indexing
345353
if ( !mHybridMaxAreaPerLayer.contains( vl->id() ) )
@@ -487,7 +495,7 @@ QString QgsSnappingUtils::dump()
487495
.arg( layer.layer->name() )
488496
.arg( layer.type ).arg( layer.tolerance ).arg( layer.unit );
489497

490-
if ( mStrategy == IndexAlwaysFull || mStrategy == IndexHybrid )
498+
if ( mStrategy == IndexAlwaysFull || mStrategy == IndexHybrid || mStrategy == IndexExtent )
491499
{
492500
if ( QgsPointLocator* loc = locatorForLayer( layer.layer ) )
493501
{

src/core/qgssnappingutils.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ class CORE_EXPORT QgsSnappingUtils : public QObject
8989
{
9090
IndexAlwaysFull, //!< For all layers build index of full extent. Uses more memory, but queries are faster.
9191
IndexNeverFull, //!< For all layers only create temporary indexes of small extent. Low memory usage, slower queries.
92-
IndexHybrid //!< For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.
92+
IndexHybrid, //!< For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.
93+
IndexExtent //!< For all layer build index of extent given in map settings
9394
};
9495

9596
//! Set a strategy for indexing geometry data - determines how fast and memory consuming the data structures will be

src/core/symbology-ng/qgscptcityarchive.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -1048,13 +1048,15 @@ QMap< QString, QStringList > QgsCptCityDirectoryItem::rampsMap()
10481048
}
10491049

10501050
}
1051+
#if 0
10511052
//TODO what to do with other vars? e.g. schemeNames
1052-
// // add schemes to archive
1053-
// mSchemeMap[ path ] = schemeNames;
1054-
// schemeCount += schemeName.count();
1055-
// schemeNames.clear();
1056-
// listVariant.clear();
1057-
// prevName = "";
1053+
// add schemes to archive
1054+
mSchemeMap[ path ] = schemeNames;
1055+
schemeCount += schemeName.count();
1056+
schemeNames.clear();
1057+
listVariant.clear();
1058+
prevName = "";
1059+
#endif
10581060
return mRampsMap;
10591061
}
10601062

src/plugins/grass/qtermwidget/BlockArray.h

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ struct Block {
4040
size_t size;
4141
};
4242

43-
// ///////////////////////////////////////////////////////
4443

4544
class BlockArray {
4645
public:

0 commit comments

Comments
 (0)