Skip to content

Commit

Permalink
allow limiting snapping to a given area
Browse files Browse the repository at this point in the history
(cherry picked from commit c6fb253)
  • Loading branch information
jef-n committed Jan 1, 2017
1 parent 84cdbff commit 9daa61b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
3 changes: 2 additions & 1 deletion python/core/qgssnappingutils.sip
Expand Up @@ -51,7 +51,8 @@ class QgsSnappingUtils : QObject
{
IndexAlwaysFull, //!< For all layers build index of full extent. Uses more memory, but queries are faster.
IndexNeverFull, //!< For all layers only create temporary indexes of small extent. Low memory usage, slower queries.
IndexHybrid //!< For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.
IndexHybrid, //!< For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.
IndexExtent //!< For all layer build index of extent given in map settings
};

/** Set a strategy for indexing geometry data - determines how fast and memory consuming the data structures will be */
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgspointlocator.cpp
Expand Up @@ -848,7 +848,7 @@ QgsPointLocator::Match QgsPointLocator::nearestVertex( const QgsPoint& point, do
QgsRectangle rect( point.x() - tolerance, point.y() - tolerance, point.x() + tolerance, point.y() + tolerance );
mRTree->intersectsWithQuery( rect2region( rect ), visitor );
if ( m.isValid() && m.distance() > tolerance )
return Match(); // // make sure that only match strictly within the tolerance is returned
return Match(); // make sure that only match strictly within the tolerance is returned
return m;
}

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

Expand Down
14 changes: 11 additions & 3 deletions src/core/qgssnappingutils.cpp
Expand Up @@ -99,7 +99,9 @@ bool QgsSnappingUtils::isIndexPrepared( QgsVectorLayer* vl, const QgsRectangle&
if ( mStrategy == IndexAlwaysFull && loc->hasIndex() )
return true;

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

return false; // the index - even if it exists - is not suitable
Expand Down Expand Up @@ -349,7 +351,13 @@ void QgsSnappingUtils::prepareIndex( const QList<LayerAndAreaOfInterest>& layers
QTime tt;
tt.start();
QgsPointLocator* loc = locatorForLayer( vl );
if ( mStrategy == IndexHybrid )
if ( mStrategy == IndexExtent )
{
QgsRectangle rect( mMapSettings.extent() );
loc->setExtent( &rect );
loc->init();
}
else if ( mStrategy == IndexHybrid )
{
// first time the layer is used? - let's set an initial guess about indexing
if ( !mHybridMaxAreaPerLayer.contains( vl->id() ) )
Expand Down Expand Up @@ -533,7 +541,7 @@ QString QgsSnappingUtils::dump()
.arg( layer.layer->name() )
.arg( layer.type ).arg( layer.tolerance ).arg( layer.unit );

if ( mStrategy == IndexAlwaysFull || mStrategy == IndexHybrid )
if ( mStrategy == IndexAlwaysFull || mStrategy == IndexHybrid || mStrategy == IndexExtent )
{
if ( QgsPointLocator* loc = locatorForLayer( layer.layer ) )
{
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgssnappingutils.h
Expand Up @@ -88,7 +88,8 @@ class CORE_EXPORT QgsSnappingUtils : public QObject
{
IndexAlwaysFull, //!< For all layers build index of full extent. Uses more memory, but queries are faster.
IndexNeverFull, //!< For all layers only create temporary indexes of small extent. Low memory usage, slower queries.
IndexHybrid //!< For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.
IndexHybrid, //!< For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.
IndexExtent //!< For all layer build index of extent given in map settings
};

/** Set a strategy for indexing geometry data - determines how fast and memory consuming the data structures will be */
Expand Down
14 changes: 8 additions & 6 deletions src/core/symbology-ng/qgscptcityarchive.cpp
Expand Up @@ -1084,13 +1084,15 @@ QMap< QString, QStringList > QgsCptCityDirectoryItem::rampsMap()
}

}
#if 0
//TODO what to do with other vars? e.g. schemeNames
// // add schemes to archive
// mSchemeMap[ path ] = schemeNames;
// schemeCount += schemeName.count();
// schemeNames.clear();
// listVariant.clear();
// prevName = "";
// add schemes to archive
mSchemeMap[ path ] = schemeNames;
schemeCount += schemeName.count();
schemeNames.clear();
listVariant.clear();
prevName = "";
#endif
return mRampsMap;
}

Expand Down
1 change: 0 additions & 1 deletion src/plugins/grass/qtermwidget/BlockArray.h
Expand Up @@ -40,7 +40,6 @@ struct Block {
size_t size;
};

// ///////////////////////////////////////////////////////

class BlockArray {
public:
Expand Down

0 comments on commit 9daa61b

Please sign in to comment.