QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
6  email : [email protected]
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 
20 #include "qgsxmlutils.h"
21 
23 {
24  mGeometryChecks = settingsGeometryValidationDefaultChecks.value().split( ',' ) ;
25 }
26 
28 {
29  return mRemoveDuplicateNodes;
30 }
31 
33 {
34  mRemoveDuplicateNodes = value;
36 }
37 
39 {
40  return mGeometryPrecision;
41 }
42 
44 {
45  mGeometryPrecision = value;
47 }
48 
50 {
51  return mGeometryPrecision != 0.0 || mRemoveDuplicateNodes;
52 }
53 
54 void QgsGeometryOptions::apply( QgsGeometry &geometry ) const
55 {
56  if ( mGeometryPrecision != 0.0 )
57  geometry = geometry.snappedToGrid( mGeometryPrecision, mGeometryPrecision );
58 
59  if ( mRemoveDuplicateNodes )
60  geometry.removeDuplicateNodes( 4 * std::numeric_limits<double>::epsilon(), true );
61 }
62 
64 {
65  return mGeometryChecks;
66 }
67 
68 void QgsGeometryOptions::setGeometryChecks( const QStringList &geometryChecks )
69 {
70  mGeometryChecks = geometryChecks;
71  emit geometryChecksChanged();
72 }
73 
74 QVariantMap QgsGeometryOptions::checkConfiguration( const QString &checkId ) const
75 {
76  return mCheckConfiguration.value( checkId ).toMap();
77 }
78 
79 void QgsGeometryOptions::setCheckConfiguration( const QString &checkId, const QVariantMap &checkConfiguration )
80 {
81  mCheckConfiguration[checkId] = checkConfiguration;
83 }
84 
85 void QgsGeometryOptions::writeXml( QDomNode &node ) const
86 {
87  QDomDocument doc = node.ownerDocument();
88  QDomElement geometryOptionsElement = doc.createElement( QStringLiteral( "geometryOptions" ) );
89  node.appendChild( geometryOptionsElement );
90 
91  geometryOptionsElement.setAttribute( QStringLiteral( "removeDuplicateNodes" ), mRemoveDuplicateNodes ? 1 : 0 );
92  geometryOptionsElement.setAttribute( QStringLiteral( "geometryPrecision" ), mGeometryPrecision );
93 
94  QDomElement activeCheckListElement = QgsXmlUtils::writeVariant( mGeometryChecks, doc );
95  activeCheckListElement.setTagName( QStringLiteral( "activeChecks" ) );
96  geometryOptionsElement.appendChild( activeCheckListElement );
97  QDomElement checkConfigurationElement = QgsXmlUtils::writeVariant( mCheckConfiguration, doc );
98  checkConfigurationElement.setTagName( QStringLiteral( "checkConfiguration" ) );
99  geometryOptionsElement.appendChild( checkConfigurationElement );
100 }
101 
102 void QgsGeometryOptions::readXml( const QDomNode &node )
103 {
104  const QDomElement geometryOptionsElement = node.toElement();
105  setGeometryPrecision( geometryOptionsElement.attribute( QStringLiteral( "geometryPrecision" ), QStringLiteral( "0.0" ) ).toDouble() );
106  setRemoveDuplicateNodes( geometryOptionsElement.attribute( QStringLiteral( "removeDuplicateNodes" ), QStringLiteral( "0" ) ).toInt() == 1 );
107 
108  const QDomElement activeChecksElem = node.namedItem( QStringLiteral( "activeChecks" ) ).toElement();
109  const QVariant activeChecks = QgsXmlUtils::readVariant( activeChecksElem );
110  setGeometryChecks( activeChecks.toStringList() );
111 
112  const QDomElement checkConfigurationElem = node.namedItem( QStringLiteral( "checkConfiguration" ) ).toElement();
113  const QVariant checkConfiguration = QgsXmlUtils::readVariant( checkConfigurationElem );
114  mCheckConfiguration = checkConfiguration.toMap();
115 }
QgsGeometryOptions::checkConfigurationChanged
void checkConfigurationChanged()
Access the configuration for the check checkId.
QgsGeometryOptions::geometryPrecision
double geometryPrecision() const
The precision in which geometries on this layer should be saved.
Definition: qgsgeometryoptions.cpp:38
QgsGeometryOptions::removeDuplicateNodesChanged
void removeDuplicateNodesChanged()
Automatically remove duplicate nodes on all geometries which are edited on this layer.
QgsGeometry::removeDuplicateNodes
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...
Definition: qgsgeometry.cpp:1246
QgsGeometryOptions::geometryChecks
QStringList geometryChecks() const
A list of activated geometry checks.
Definition: qgsgeometryoptions.cpp:63
QgsGeometryOptions::setGeometryChecks
void setGeometryChecks(const QStringList &geometryChecks)
A list of activated geometry checks.
Definition: qgsgeometryoptions.cpp:68
QgsGeometryOptions::removeDuplicateNodes
bool removeDuplicateNodes() const
Automatically remove duplicate nodes on all geometries which are edited on this layer.
Definition: qgsgeometryoptions.cpp:27
QgsGeometryOptions::isActive
bool isActive() const
Determines if at least one fix is enabled.
Definition: qgsgeometryoptions.cpp:49
QgsXmlUtils::readVariant
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
Definition: qgsxmlutils.cpp:251
QgsGeometryOptions::apply
void apply(QgsGeometry &geometry) const
Apply any fixes configured on this class to geometry.
Definition: qgsgeometryoptions.cpp:54
QgsGeometryOptions::writeXml
void writeXml(QDomNode &node) const
Write the geometry options to the node.
Definition: qgsgeometryoptions.cpp:85
QgsGeometryOptions::settingsGeometryValidationDefaultChecks
static const QgsSettingsEntryString settingsGeometryValidationDefaultChecks
Settings entry search path for templates.
Definition: qgsgeometryoptions.h:150
QgsGeometryOptions::setGeometryPrecision
void setGeometryPrecision(double value)
The precision in which geometries on this layer should be saved.
Definition: qgsgeometryoptions.cpp:43
qgsxmlutils.h
QgsGeometryOptions::QgsGeometryOptions
QgsGeometryOptions()
Create a new QgsGeometryOptions object.
Definition: qgsgeometryoptions.cpp:22
QgsGeometryOptions::geometryPrecisionChanged
void geometryPrecisionChanged()
The precision in which geometries on this layer should be saved.
QgsGeometryOptions::setRemoveDuplicateNodes
void setRemoveDuplicateNodes(bool value)
Automatically remove duplicate nodes on all geometries which are edited on this layer.
Definition: qgsgeometryoptions.cpp:32
QgsSettingsEntryByReference::value
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
Definition: qgssettingsentry.h:379
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsGeometry::snappedToGrid
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.
Definition: qgsgeometry.cpp:1237
QgsGeometryOptions::setCheckConfiguration
void setCheckConfiguration(const QString &checkId, const QVariantMap &checkConfiguration)
Set the configuration for the check checkId.
Definition: qgsgeometryoptions.cpp:79
QgsGeometryOptions::geometryChecksChanged
void geometryChecksChanged()
A list of activated geometry checks.
qgsgeometryoptions.h
QgsXmlUtils::writeVariant
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
Definition: qgsxmlutils.cpp:106
QgsGeometryOptions::checkConfiguration
QVariantMap checkConfiguration(const QString &checkId) const
Access the configuration for the check checkId.
Definition: qgsgeometryoptions.cpp:74
QgsGeometryOptions::readXml
void readXml(const QDomNode &node)
Read the geometry options from node.
Definition: qgsgeometryoptions.cpp:102