QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsgeometryoptions.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometryoptions.cpp
3 -------------------
4 begin : Aug 23, 2018
5 copyright : (C) 2018 by Matthias Kuhn
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgsgeometryoptions.h"
19#include "moc_qgsgeometryoptions.cpp"
20#include "qgsxmlutils.h"
22#include "qgssettingstree.h"
23
25
30
32{
33 return mRemoveDuplicateNodes;
34}
35
37{
38 mRemoveDuplicateNodes = value;
40}
41
43{
44 return mGeometryPrecision;
45}
46
48{
49 mGeometryPrecision = value;
51}
52
54{
55 return mGeometryPrecision != 0.0 || mRemoveDuplicateNodes;
56}
57
59{
60 if ( mGeometryPrecision != 0.0 )
61 geometry = geometry.snappedToGrid( mGeometryPrecision, mGeometryPrecision );
62
63 if ( mRemoveDuplicateNodes )
64 geometry.removeDuplicateNodes( 4 * std::numeric_limits<double>::epsilon(), true );
65}
66
68{
69 return mGeometryChecks;
70}
71
72void QgsGeometryOptions::setGeometryChecks( const QStringList &geometryChecks )
73{
74 mGeometryChecks = geometryChecks;
76}
77
78QVariantMap QgsGeometryOptions::checkConfiguration( const QString &checkId ) const
79{
80 return mCheckConfiguration.value( checkId ).toMap();
81}
82
83void QgsGeometryOptions::setCheckConfiguration( const QString &checkId, const QVariantMap &checkConfiguration )
84{
85 mCheckConfiguration[checkId] = checkConfiguration;
87}
88
89void QgsGeometryOptions::writeXml( QDomNode &node ) const
90{
91 QDomDocument doc = node.ownerDocument();
92 QDomElement geometryOptionsElement = doc.createElement( QStringLiteral( "geometryOptions" ) );
93 node.appendChild( geometryOptionsElement );
94
95 geometryOptionsElement.setAttribute( QStringLiteral( "removeDuplicateNodes" ), mRemoveDuplicateNodes ? 1 : 0 );
96 geometryOptionsElement.setAttribute( QStringLiteral( "geometryPrecision" ), mGeometryPrecision );
97
98 QDomElement activeCheckListElement = QgsXmlUtils::writeVariant( mGeometryChecks, doc );
99 activeCheckListElement.setTagName( QStringLiteral( "activeChecks" ) );
100 geometryOptionsElement.appendChild( activeCheckListElement );
101 QDomElement checkConfigurationElement = QgsXmlUtils::writeVariant( mCheckConfiguration, doc );
102 checkConfigurationElement.setTagName( QStringLiteral( "checkConfiguration" ) );
103 geometryOptionsElement.appendChild( checkConfigurationElement );
104}
105
106void QgsGeometryOptions::readXml( const QDomNode &node )
107{
108 const QDomElement geometryOptionsElement = node.toElement();
109 setGeometryPrecision( geometryOptionsElement.attribute( QStringLiteral( "geometryPrecision" ), QStringLiteral( "0.0" ) ).toDouble() );
110 setRemoveDuplicateNodes( geometryOptionsElement.attribute( QStringLiteral( "removeDuplicateNodes" ), QStringLiteral( "0" ) ).toInt() == 1 );
111
112 const QDomElement activeChecksElem = node.namedItem( QStringLiteral( "activeChecks" ) ).toElement();
113 const QVariant activeChecks = QgsXmlUtils::readVariant( activeChecksElem );
114 setGeometryChecks( activeChecks.toStringList() );
115
116 const QDomElement checkConfigurationElem = node.namedItem( QStringLiteral( "checkConfiguration" ) ).toElement();
117 const QVariant checkConfiguration = QgsXmlUtils::readVariant( checkConfigurationElem );
118 mCheckConfiguration = checkConfiguration.toMap();
119}
bool isActive() const
Determines if at least one fix is enabled.
void removeDuplicateNodesChanged()
Automatically remove duplicate nodes on all geometries which are edited on this layer.
void geometryChecksChanged()
A list of activated geometry checks.
double geometryPrecision() const
The precision in which geometries on this layer should be saved.
bool removeDuplicateNodes() const
Automatically remove duplicate nodes on all geometries which are edited on this layer.
void setGeometryPrecision(double value)
The precision in which geometries on this layer should be saved.
void setRemoveDuplicateNodes(bool value)
Automatically remove duplicate nodes on all geometries which are edited on this layer.
void readXml(const QDomNode &node)
Read the geometry options from node.
QgsGeometryOptions()
Create a new QgsGeometryOptions object.
void setCheckConfiguration(const QString &checkId, const QVariantMap &checkConfiguration)
Set the configuration for the check checkId.
static const QgsSettingsEntryString * settingsGeometryValidationDefaultChecks
Settings entry search path for templates.
QStringList geometryChecks() const
A list of activated geometry checks.
void checkConfigurationChanged()
Access the configuration for the check checkId.
void apply(QgsGeometry &geometry) const
Apply any fixes configured on this class to geometry.
void geometryPrecisionChanged()
The precision in which geometries on this layer should be saved.
void writeXml(QDomNode &node) const
Write the geometry options to the node.
void setGeometryChecks(const QStringList &geometryChecks)
A list of activated geometry checks.
QVariantMap checkConfiguration(const QString &checkId) const
Access the configuration for the check checkId.
A geometry is the spatial representation of a feature.
QgsGeometry snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0) const
Returns a new geometry with all points or vertices snapped to the closest point of the grid.
bool removeDuplicateNodes(double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false)
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
A string settings entry.
static QgsSettingsTreeNode * sTreeGeometryValidation
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.