Skip to content

Commit 3cb82a5

Browse files
authored
Merge pull request #7959 from m-kuhn/geometryOptions
Add a new QML category "Geometry Options"
2 parents 1390198 + 9b2dff6 commit 3cb82a5

14 files changed

+124
-71
lines changed

python/core/auto_generated/qgsgeometryfixes.sip.in python/core/auto_generated/qgsgeometryoptions.sip.in

+21-7
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
/************************************************************************
22
* This file has been generated automatically from *
33
* *
4-
* src/core/qgsgeometryfixes.h *
4+
* src/core/qgsgeometryoptions.h *
55
* *
66
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
77
************************************************************************/
88

99

1010

1111

12-
class QgsGeometryFixes
12+
class QgsGeometryOptions
1313
{
1414
%Docstring
1515

16-
The QgsGeometryFixes class contains options to automatically adjust geometries to
16+
The QgsGeometryOptions class contains options to automatically adjust geometries to
1717
constraints on a layer.
1818

1919
.. versionadded:: 3.4
2020
%End
2121

2222
%TypeHeaderCode
23-
#include "qgsgeometryfixes.h"
23+
#include "qgsgeometryoptions.h"
2424
%End
2525
public:
2626

27-
QgsGeometryFixes();
27+
QgsGeometryOptions();
2828
%Docstring
29-
Create a new QgsGeometryFixes object.
29+
Create a new QgsGeometryOptions object.
3030
%End
3131

3232
bool removeDuplicateNodes() const;
@@ -72,6 +72,20 @@ Determines if at least one fix is enabled.
7272
%Docstring
7373
Apply any fixes configured on this class to ``geometry``.
7474

75+
.. versionadded:: 3.4
76+
%End
77+
78+
void writeXml( QDomNode &node ) const;
79+
%Docstring
80+
Write the geometry options to the ``node``.
81+
82+
.. versionadded:: 3.4
83+
%End
84+
85+
void readXml( const QDomNode &node );
86+
%Docstring
87+
Read the geometry options from ``node``.
88+
7589
.. versionadded:: 3.4
7690
%End
7791

@@ -80,7 +94,7 @@ Apply any fixes configured on this class to ``geometry``.
8094
/************************************************************************
8195
* This file has been generated automatically from *
8296
* *
83-
* src/core/qgsgeometryfixes.h *
97+
* src/core/qgsgeometryoptions.h *
8498
* *
8599
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
86100
************************************************************************/

python/core/auto_generated/qgsmaplayer.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ This is the base class for all map layer types (vector, raster).
8989
AttributeTable,
9090
Rendering,
9191
CustomProperties,
92+
GeometryOptions,
9293
AllStyleCategories
9394
};
9495
typedef QFlags<QgsMapLayer::StyleCategory> StyleCategories;

python/core/auto_generated/qgsvectorlayer.sip.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -2230,7 +2230,7 @@ Test if an edit command is active
22302230
.. versionadded:: 3.0
22312231
%End
22322232

2233-
QgsGeometryFixes *geometryFixes() const;
2233+
QgsGeometryOptions *geometryOptions() const;
22342234
%Docstring
22352235
Configuration and logic to apply automatically on any edit happening on this layer.
22362236

python/core/core_auto.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
%Include auto_generated/qgsfields.sip
5555
%Include auto_generated/qgsfileutils.sip
5656
%Include auto_generated/qgsfontutils.sip
57-
%Include auto_generated/qgsgeometryfixes.sip
57+
%Include auto_generated/qgsgeometryoptions.sip
5858
%Include auto_generated/qgsgeometrysimplifier.sip
5959
%Include auto_generated/qgshistogram.sip
6060
%Include auto_generated/qgshstoreutils.sip

src/app/qgsmaplayerstylecategoriesmodel.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@ QVariant QgsMapLayerStyleCategoriesModel::data( const QModelIndex &index, int ro
208208
return QgsApplication::getThemeIcon( QStringLiteral( "/mActionOptions.svg" ) );
209209
}
210210
break;
211+
case QgsMapLayer::GeometryOptions:
212+
switch ( role )
213+
{
214+
case Qt::DisplayRole:
215+
return tr( "Geometry Options" );
216+
case Qt::ToolTipRole:
217+
return tr( "Geometry constraints and validity checks" );
218+
case Qt::DecorationRole:
219+
return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/digitizing.svg" ) );
220+
}
221+
break;
211222
case QgsMapLayer::AllStyleCategories:
212223
switch ( role )
213224
{

src/app/qgsvectorlayerproperties.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#include "qgsnewauxiliaryfielddialog.h"
6161
#include "qgslabelinggui.h"
6262
#include "qgssymbollayer.h"
63-
#include "qgsgeometryfixes.h"
63+
#include "qgsgeometryoptions.h"
6464
#include "qgsvectorlayersavestyledialog.h"
6565
#include "qgsvectorlayerloadstyledialog.h"
6666

@@ -401,8 +401,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
401401
mRemoveDuplicateNodesCheckbox->setEnabled( true );
402402
mGeometryPrecisionSpinBox->setEnabled( true );
403403

404-
mRemoveDuplicateNodesCheckbox->setChecked( mLayer->geometryFixes()->removeDuplicateNodes() );
405-
mGeometryPrecisionSpinBox->setValue( mLayer->geometryFixes()->geometryPrecision() );
404+
mRemoveDuplicateNodesCheckbox->setChecked( mLayer->geometryOptions()->removeDuplicateNodes() );
405+
mGeometryPrecisionSpinBox->setValue( mLayer->geometryOptions()->geometryPrecision() );
406406

407407
mGeometryPrecisionSpinBox->setSuffix( QStringLiteral( " [%1]" ).arg( QgsUnitTypes::toAbbreviatedString( mLayer->crs().mapUnits() ) ) );
408408
}
@@ -751,8 +751,8 @@ void QgsVectorLayerProperties::apply()
751751
mVector3DWidget->apply();
752752
#endif
753753

754-
mLayer->geometryFixes()->setRemoveDuplicateNodes( mRemoveDuplicateNodesCheckbox->isChecked() );
755-
mLayer->geometryFixes()->setGeometryPrecision( mGeometryPrecisionSpinBox->value() );
754+
mLayer->geometryOptions()->setRemoveDuplicateNodes( mRemoveDuplicateNodesCheckbox->isChecked() );
755+
mLayer->geometryOptions()->setGeometryPrecision( mGeometryPrecisionSpinBox->value() );
756756

757757
// update symbology
758758
emit refreshLegend( mLayer->id() );

src/core/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ SET(QGIS_CORE_SRCS
204204
qgsfontutils.cpp
205205
qgsgeometrysimplifier.cpp
206206
qgsgeometryvalidator.cpp
207-
qgsgeometryfixes.cpp
207+
qgsgeometryoptions.cpp
208208
qgsgml.cpp
209209
qgsgmlschema.cpp
210210
qgshistogram.cpp
@@ -867,7 +867,7 @@ SET(QGIS_CORE_HDRS
867867
qgsfields.h
868868
qgsfileutils.h
869869
qgsfontutils.h
870-
qgsgeometryfixes.h
870+
qgsgeometryoptions.h
871871
qgsgeometrysimplifier.h
872872
qgshistogram.h
873873
qgshstoreutils.h
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***************************************************************************
2-
qgsgeometryfixes.cpp
2+
qgsgeometryoptions.cpp
33
-------------------
44
begin : Aug 23, 2018
55
copyright : (C) 2018 by Matthias Kuhn
@@ -15,38 +15,56 @@
1515
* *
1616
***************************************************************************/
1717

18-
#include "qgsgeometryfixes.h"
18+
#include "qgsgeometryoptions.h"
1919

20-
bool QgsGeometryFixes::removeDuplicateNodes() const
20+
#include "qgsxmlutils.h"
21+
22+
bool QgsGeometryOptions::removeDuplicateNodes() const
2123
{
2224
return mRemoveDuplicateNodes;
2325
}
2426

25-
void QgsGeometryFixes::setRemoveDuplicateNodes( bool value )
27+
void QgsGeometryOptions::setRemoveDuplicateNodes( bool value )
2628
{
2729
mRemoveDuplicateNodes = value;
2830
}
2931

30-
double QgsGeometryFixes::geometryPrecision() const
32+
double QgsGeometryOptions::geometryPrecision() const
3133
{
3234
return mGeometryPrecision;
3335
}
3436

35-
void QgsGeometryFixes::setGeometryPrecision( double value )
37+
void QgsGeometryOptions::setGeometryPrecision( double value )
3638
{
3739
mGeometryPrecision = value;
3840
}
3941

40-
bool QgsGeometryFixes::isActive() const
42+
bool QgsGeometryOptions::isActive() const
4143
{
4244
return mGeometryPrecision != 0.0 || mRemoveDuplicateNodes;
4345
}
4446

45-
void QgsGeometryFixes::apply( QgsGeometry &geometry ) const
47+
void QgsGeometryOptions::apply( QgsGeometry &geometry ) const
4648
{
4749
if ( mGeometryPrecision != 0.0 )
4850
geometry = geometry.snappedToGrid( mGeometryPrecision, mGeometryPrecision );
4951

5052
if ( mRemoveDuplicateNodes )
5153
geometry.removeDuplicateNodes();
5254
}
55+
56+
void QgsGeometryOptions::writeXml( QDomNode &node ) const
57+
{
58+
QDomElement geometryOptionsElement = node.ownerDocument().createElement( QStringLiteral( "geometryOptions" ) );
59+
node.appendChild( geometryOptionsElement );
60+
61+
geometryOptionsElement.setAttribute( QStringLiteral( "removeDuplicateNodes" ), mRemoveDuplicateNodes ? 1 : 0 );
62+
geometryOptionsElement.setAttribute( QStringLiteral( "geometryPrecision" ), mGeometryPrecision );
63+
}
64+
65+
void QgsGeometryOptions::readXml( const QDomNode &node )
66+
{
67+
QDomElement geometryOptionsElement = node.toElement();
68+
setGeometryPrecision( geometryOptionsElement.attribute( QStringLiteral( "geometryPrecision" ), QStringLiteral( "0.0" ) ).toDouble() );
69+
setRemoveDuplicateNodes( geometryOptionsElement.attribute( QStringLiteral( "removeDuplicateNodes" ), QStringLiteral( "0" ) ).toInt() == 1 );
70+
}

src/core/qgsgeometryfixes.h src/core/qgsgeometryoptions.h

+24-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***************************************************************************
2-
qgsgeometryfixes.h
2+
qgsgeometryoptions.h
33
-------------------
44
begin : Aug 23, 2018
55
copyright : (C) 2018 by Matthias Kuhn
@@ -15,27 +15,29 @@
1515
* *
1616
***************************************************************************/
1717

18-
#ifndef QGSGEOMETRYFIXES_H
19-
#define QGSGEOMETRYFIXES_H
18+
#ifndef QGSGEOMETRYOPTIONS_H
19+
#define QGSGEOMETRYOPTIONS_H
2020

21+
#include "qgis_core.h"
22+
#include "qgis_sip.h"
2123
#include "qgsgeometry.h"
2224

2325
/**
2426
* \ingroup core
2527
*
26-
* The QgsGeometryFixes class contains options to automatically adjust geometries to
28+
* The QgsGeometryOptions class contains options to automatically adjust geometries to
2729
* constraints on a layer.
2830
*
2931
* \since QGIS 3.4
3032
*/
31-
class CORE_EXPORT QgsGeometryFixes
33+
class CORE_EXPORT QgsGeometryOptions
3234
{
3335
public:
3436

3537
/**
36-
* Create a new QgsGeometryFixes object.
38+
* Create a new QgsGeometryOptions object.
3739
*/
38-
QgsGeometryFixes() = default;
40+
QgsGeometryOptions() = default;
3941

4042
/**
4143
* Automatically remove duplicate nodes on all geometries which are edited on this layer.
@@ -83,6 +85,20 @@ class CORE_EXPORT QgsGeometryFixes
8385
*/
8486
void apply( QgsGeometry &geometry ) const;
8587

88+
/**
89+
* Write the geometry options to the \a node.
90+
*
91+
* \since QGIS 3.4
92+
*/
93+
void writeXml( QDomNode &node ) const;
94+
95+
/**
96+
* Read the geometry options from \a node.
97+
*
98+
* \since QGIS 3.4
99+
*/
100+
void readXml( const QDomNode &node );
101+
86102
private:
87103

88104
/**
@@ -102,4 +118,4 @@ class CORE_EXPORT QgsGeometryFixes
102118
double mGeometryPrecision = 0.0;
103119
};
104120

105-
#endif // QGSGEOMETRYFIXES_H
121+
#endif // QGSGEOMETRYOPTIONS_H

src/core/qgsmaplayer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ class CORE_EXPORT QgsMapLayer : public QObject
153153
AttributeTable = 1 << 9, //!< Attribute table settings: choice and order of columns, conditional styling
154154
Rendering = 1 << 10, //!< Rendering: scale visibility, simplify method, opacity
155155
CustomProperties = 1 << 11, //!< Custom properties (by plugins for instance)
156+
GeometryOptions = 1 << 12, //!< Geometry validation configuration
156157
AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
157-
MapTips | Diagrams | AttributeTable | Rendering | CustomProperties,
158+
MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions,
158159
};
159160
Q_ENUM( StyleCategory )
160161
Q_DECLARE_FLAGS( StyleCategories, StyleCategory )

0 commit comments

Comments
 (0)