mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Implement QgsProject::snapSettingsForLayer as a convenient way to access snap properties for a layer
This commit is contained in:
parent
1d6943d067
commit
654924d276
@ -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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user