QGIS API Documentation 3.99.0-Master (d270888f95f)
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
21#include "qgssettingstree.h"
22#include "qgsxmlutils.h"
23
24#include <QString>
25
26#include "moc_qgsgeometryoptions.cpp"
27
28using namespace Qt::StringLiterals;
29
31
33{
34 mGeometryChecks = settingsGeometryValidationDefaultChecks->value().split( ',' ) ;
35}
36
38{
39 return mRemoveDuplicateNodes;
40}
41
43{
44 mRemoveDuplicateNodes = value;
46}
47
49{
50 return mGeometryPrecision;
51}
52
54{
55 mGeometryPrecision = value;
57}
58
60{
61 return mGeometryPrecision != 0.0 || mRemoveDuplicateNodes;
62}
63
65{
66 if ( mGeometryPrecision != 0.0 )
67 geometry = geometry.snappedToGrid( mGeometryPrecision, mGeometryPrecision );
68
69 if ( mRemoveDuplicateNodes )
70 geometry.removeDuplicateNodes( 4 * std::numeric_limits<double>::epsilon(), true );
71}
72
74{
75 return mGeometryChecks;
76}
77
79{
80 mGeometryChecks = geometryChecks;
82}
83
84QVariantMap QgsGeometryOptions::checkConfiguration( const QString &checkId ) const
85{
86 return mCheckConfiguration.value( checkId ).toMap();
87}
88
89void QgsGeometryOptions::setCheckConfiguration( const QString &checkId, const QVariantMap &checkConfiguration )
90{
91 mCheckConfiguration[checkId] = checkConfiguration;
93}
94
95void QgsGeometryOptions::writeXml( QDomNode &node ) const
96{
97 QDomDocument doc = node.ownerDocument();
98 QDomElement geometryOptionsElement = doc.createElement( u"geometryOptions"_s );
99 node.appendChild( geometryOptionsElement );
100
101 geometryOptionsElement.setAttribute( u"removeDuplicateNodes"_s, mRemoveDuplicateNodes ? 1 : 0 );
102 geometryOptionsElement.setAttribute( u"geometryPrecision"_s, mGeometryPrecision );
103
104 QDomElement activeCheckListElement = QgsXmlUtils::writeVariant( mGeometryChecks, doc );
105 activeCheckListElement.setTagName( u"activeChecks"_s );
106 geometryOptionsElement.appendChild( activeCheckListElement );
107 QDomElement checkConfigurationElement = QgsXmlUtils::writeVariant( mCheckConfiguration, doc );
108 checkConfigurationElement.setTagName( u"checkConfiguration"_s );
109 geometryOptionsElement.appendChild( checkConfigurationElement );
110}
111
112void QgsGeometryOptions::readXml( const QDomNode &node )
113{
114 const QDomElement geometryOptionsElement = node.toElement();
115 setGeometryPrecision( geometryOptionsElement.attribute( u"geometryPrecision"_s, u"0.0"_s ).toDouble() );
116 setRemoveDuplicateNodes( geometryOptionsElement.attribute( u"removeDuplicateNodes"_s, u"0"_s ).toInt() == 1 );
117
118 const QDomElement activeChecksElem = node.namedItem( u"activeChecks"_s ).toElement();
119 const QVariant activeChecks = QgsXmlUtils::readVariant( activeChecksElem );
120 setGeometryChecks( activeChecks.toStringList() );
121
122 const QDomElement checkConfigurationElem = node.namedItem( u"checkConfiguration"_s ).toElement();
123 const QVariant checkConfiguration = QgsXmlUtils::readVariant( checkConfigurationElem );
124 mCheckConfiguration = checkConfiguration.toMap();
125}
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...
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.