Skip to content

Commit

Permalink
Add debug capabilities to snapping utils
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jan 27, 2016
1 parent 19b18bc commit 86307ff
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 0 deletions.
15 changes: 15 additions & 0 deletions python/core/qgspointlocator.sip
Expand Up @@ -14,6 +14,16 @@ class QgsPointLocator : QObject

~QgsPointLocator();

//! Get associated layer
//! @note added in QGIS 2.14
QgsVectorLayer* layer() const;
//! Get destination CRS - may be null if not doing OTF reprojection
//! @note added in QGIS 2.14
const QgsCoordinateReferenceSystem* destCRS() const;
//! Get extent of the area point locator covers - if null then it caches the whole layer
//! @note added in QGIS 2.14
const QgsRectangle* extent() const;

enum Type { Invalid, Vertex, Edge, Area, All };

typedef QFlags<QgsPointLocator::Type> Types;
Expand Down Expand Up @@ -93,6 +103,11 @@ class QgsPointLocator : QObject
//! find out if the point is in any polygons
MatchList pointInPolygon( const QgsPoint& point );

//

//! Return how many geometries are cached in the index
//! @note added in QGIS 2.14
int cachedGeometryCount() const;

protected:
bool rebuildIndex( int maxFeaturesToIndex = -1 );
Expand Down
5 changes: 5 additions & 0 deletions python/core/qgssnappingutils.sip
Expand Up @@ -87,6 +87,11 @@ class QgsSnappingUtils : QObject
/** Query whether to consider intersections of nearby segments for snapping */
bool snapOnIntersections() const;

/** Get extra information about the instance
* @note added in QGIS 2.14
*/
QString dump();

public slots:
/** Read snapping configuration from the project */
void readConfigFromProject();
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgspointlocator.cpp
Expand Up @@ -621,6 +621,11 @@ QgsPointLocator::~QgsPointLocator()
delete mExtent;
}

const QgsCoordinateReferenceSystem* QgsPointLocator::destCRS() const
{
return mTransform ? &mTransform->destCRS() : nullptr;
}


bool QgsPointLocator::init( int maxFeaturesToIndex )
{
Expand Down
15 changes: 15 additions & 0 deletions src/core/qgspointlocator.h
Expand Up @@ -57,6 +57,16 @@ class CORE_EXPORT QgsPointLocator : public QObject

~QgsPointLocator();

//! Get associated layer
//! @note added in QGIS 2.14
QgsVectorLayer* layer() const { return mLayer; }
//! Get destination CRS - may be null if not doing OTF reprojection
//! @note added in QGIS 2.14
const QgsCoordinateReferenceSystem* destCRS() const;
//! Get extent of the area point locator covers - if null then it caches the whole layer
//! @note added in QGIS 2.14
const QgsRectangle* extent() const { return mExtent; }

enum Type
{
Invalid = 0,
Expand Down Expand Up @@ -163,6 +173,11 @@ class CORE_EXPORT QgsPointLocator : public QObject
//! find out if the point is in any polygons
MatchList pointInPolygon( const QgsPoint& point );

//

//! Return how many geometries are cached in the index
//! @note added in QGIS 2.14
int cachedGeometryCount() const { return mGeoms.count(); }

protected:
bool rebuildIndex( int maxFeaturesToIndex = -1 );
Expand Down
71 changes: 71 additions & 0 deletions src/core/qgssnappingutils.cpp
Expand Up @@ -426,6 +426,77 @@ void QgsSnappingUtils::setSnapOnIntersections( bool enabled )
emit configChanged();
}

QString QgsSnappingUtils::dump()
{
QString msg = "--- SNAPPING UTILS DUMP ---\n";

if ( !mMapSettings.hasValidSettings() )
{
msg += "invalid map settings!";
return msg;
}

QList<LayerConfig> layers;

if ( mSnapToMapMode == SnapCurrentLayer )
{
if ( mSnapToMapMode == SnapCurrentLayer && !mCurrentLayer )
{
msg += "no current layer!";
return msg;
}

layers << LayerConfig( mCurrentLayer, QgsPointLocator::Types( mDefaultType ), mDefaultTolerance, mDefaultUnit );
}
else if ( mSnapToMapMode == SnapAllLayers )
{
Q_FOREACH ( const QString& layerID, mMapSettings.layers() )
{
if ( QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerID ) ) )
layers << LayerConfig( vl, QgsPointLocator::Types( mDefaultType ), mDefaultTolerance, mDefaultUnit );
}
}
else if ( mSnapToMapMode == SnapAdvanced )
{
layers = mLayers;
}

Q_FOREACH ( const LayerConfig& layer, layers )
{
bool usingIndex = willUseIndex( layer.layer );

msg += QString( "layer : %1\n"
"config: %2 tolerance %3 %4\n" )
.arg( layer.layer->name() )
.arg( layer.type ).arg( layer.tolerance ).arg( layer.unit );

if ( usingIndex )
{
QgsPointLocator* loc = locatorForLayer( layer.layer );
if ( loc )
{
QString extentStr, cachedGeoms;
if ( const QgsRectangle* r = loc->extent() )
extentStr = " extent = " + r->toString();
else
extentStr = "full extent";
if ( loc->hasIndex() )
cachedGeoms = QString( "%1 feats" ).arg( loc->cachedGeometryCount() );
else
cachedGeoms = "not initialized";
msg += QString( "index : YES | %1 | %2\n" ).arg( cachedGeoms ).arg( extentStr );
}
else
msg += QString( "index : ???\n" ); // should not happen
}
else
msg += "index : NO\n";
msg += "-\n";
}

return msg;
}

const QgsCoordinateReferenceSystem* QgsSnappingUtils::destCRS()
{
return mMapSettings.hasCrsTransformEnabled() ? &mMapSettings.destinationCrs() : nullptr;
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgssnappingutils.h
Expand Up @@ -136,6 +136,11 @@ class CORE_EXPORT QgsSnappingUtils : public QObject
/** Query whether to consider intersections of nearby segments for snapping */
bool snapOnIntersections() const { return mSnapOnIntersection; }

/** Get extra information about the instance
* @note added in QGIS 2.14
*/
QString dump();

public slots:
/** Read snapping configuration from the project */
void readConfigFromProject();
Expand Down

0 comments on commit 86307ff

Please sign in to comment.