Skip to content
Permalink
Browse files

Add debug capabilities to snapping utils

  • Loading branch information
wonder-sk committed Jan 27, 2016
1 parent 19b18bc commit 86307ffc7c678ef34a0e45429e406855e8c1f614
@@ -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;
@@ -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 );
@@ -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();
@@ -621,6 +621,11 @@ QgsPointLocator::~QgsPointLocator()
delete mExtent;
}

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


bool QgsPointLocator::init( int maxFeaturesToIndex )
{
@@ -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,
@@ -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 );
@@ -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;
@@ -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();

0 comments on commit 86307ff

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