Skip to content
Permalink
Browse files

allow limiting snapping to a given area

(cherry picked from commit c6fb253)
  • Loading branch information
jef-n committed Jan 1, 2017
1 parent 84cdbff commit 9daa61b47d4eefff3c0dff47cc50cc60b97b7af7
@@ -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 */
@@ -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;
}

@@ -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;
}

@@ -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
@@ -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() ) )
@@ -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 ) )
{
@@ -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 */
@@ -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;
}

@@ -40,7 +40,6 @@ struct Block {
size_t size;
};

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

class BlockArray {
public:

0 comments on commit 9daa61b

Please sign in to comment.
You can’t perform that action at this time.