Skip to content
Permalink
Browse files

Implement QgsProject::snapSettingsForLayer as a convenient way to acc…

…ess snap properties for a layer
  • Loading branch information
mhugent committed Jun 19, 2012
1 parent 1d6943d commit 654924d276a3e1356333263288bb899b723040bf
Showing with 92 additions and 0 deletions.
  1. +5 −0 python/core/qgsproject.sip
  2. +74 −0 src/core/qgsproject.cpp
  3. +13 −0 src/core/qgsproject.h
@@ -240,6 +240,11 @@ public:
@note added in 1.4 */
void setBadLayerHandler( QgsProjectBadLayerHandler* handler );

void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType, double tolerance );

bool snapSettingsForLayer( const QString& layerId, bool& enabled /Out/, QgsSnapper::SnappingType& type /Out/, QgsTolerance::UnitType& units /Out/, double& tolerance /Out/,
bool& avoidIntersection /Out/ );

protected:

/** Set error message from read/write operation
@@ -1621,7 +1621,81 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
return false;
}

void QgsProject::setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType, double tolerance )
{
//soon...
}

bool QgsProject::snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType &type, QgsTolerance::UnitType& units, double& tolerance,
bool& avoidIntersection )
{
QStringList layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList;
snapSettings( layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList );
int idx = layerIdList.indexOf( layerId );
if ( idx == -1 )
{
return false;
}

//make sure all lists are long enough
int minListEntries = idx + 1;
if ( layerIdList.size() < minListEntries || enabledList.size() < minListEntries || snapTypeList.size() < minListEntries ||
toleranceUnitList.size() < minListEntries || toleranceList.size() < minListEntries )
{
return false;
}

//enabled
enabled = enabledList.at( idx ) == "enabled";

//snap type
QString snapType = snapTypeList.at( idx );
if ( snapType == "to_segment" )
{
type = QgsSnapper::SnapToSegment;
}
else if ( snapType == "to_vertex_and_segment" )
{
type = QgsSnapper::SnapToVertexAndSegment;
}
else //to vertex
{
type = QgsSnapper::SnapToVertex;
}

//units
if ( toleranceUnitList.at( idx ) == "1" )
{
units = QgsTolerance::Pixels;
}
else
{
units = QgsTolerance::MapUnits;
}

//tolerance
tolerance = toleranceList.at( idx ).toDouble();

//avoid intersection
avoidIntersection = ( avoidIntersectionList.indexOf( layerId ) != -1 );

return true;
}

void QgsProject::snapSettings( QStringList& layerIdList, QStringList& enabledList, QStringList& snapTypeList, QStringList& toleranceUnitList, QStringList& toleranceList,
QStringList& avoidIntersectionList )
{
layerIdList = readListEntry( "Digitizing", "/LayerSnappingList" );
enabledList = readListEntry( "Digitizing", "/LayerSnappingEnabledList" );
toleranceList = readListEntry( "Digitizing", "/LayerSnappingToleranceList" );
toleranceUnitList = readListEntry( "Digitizing", "/LayerSnappingToleranceUnitList" );
snapTypeList = readListEntry( "Digitizing", "/LayerSnapToList" );
avoidIntersectionList = readListEntry( "Digitizing", "/AvoidIntersectionsList" );
}

void QgsProjectBadLayerDefaultHandler::handleBadLayers( QList<QDomNode> /*layers*/, QDomDocument /*projectDom*/ )
{
// just ignore any bad layers
}


@@ -28,6 +28,10 @@
#include <QObject>
#include <QPair>

//for the snap settings
#include "qgssnapper.h"
#include "qgstolerance.h"

//#include <QDomDocument>

class QFileInfo;
@@ -286,6 +290,12 @@ class CORE_EXPORT QgsProject : public QObject
bool createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes,
QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag = true );

//convenience interface for querying / modifying the project snap settings per layer
void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType, double tolerance );

bool snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType& type, QgsTolerance::UnitType& units, double& tolerance,
bool& avoidIntersection );

protected:

/** Set error message from read/write operation
@@ -339,6 +349,9 @@ class CORE_EXPORT QgsProject : public QObject
If the project file path is empty, QgsProject is going to ignore the layer for saving (e.g. because it is part and managed by an embedded group)*/
QHash< QString, QPair< QString, bool> > mEmbeddedLayers;

void snapSettings( QStringList& layerIdList, QStringList& enabledList, QStringList& snapTypeList, QStringList& snapUnitList, QStringList& toleranceUnitList,
QStringList& avoidIntersectionList );

}; // QgsProject


0 comments on commit 654924d

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