Skip to content

Commit

Permalink
Move geometry fixes to separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 23, 2018
1 parent d93d585 commit 063ccf4
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 155 deletions.
78 changes: 78 additions & 0 deletions python/core/auto_generated/qgsgeometryfixes.sip.in
@@ -0,0 +1,78 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsgeometryfixes.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsGeometryFixes
{
%Docstring
The QgsGeometryFixes class contains options to
%End

%TypeHeaderCode
#include "qgsgeometryfixes.h"
%End
public:
QgsGeometryFixes();

bool removeDuplicateNodes() const;
%Docstring
Automatically remove duplicate nodes on all geometries which are edited on this layer.

.. versionadded:: 3.4
%End

void setRemoveDuplicateNodes( bool value );
%Docstring
Automatically remove duplicate nodes on all geometries which are edited on this layer.

.. versionadded:: 3.4
%End

double geometryPrecision() const;
%Docstring
The precision in which geometries on this layer should be saved.
Geometries which are edited on this layer will be rounded to multiples of this value (snap to grid).
Set to 0.0 to disable.

.. versionadded:: 3.4
%End

void setGeometryPrecision( double value );
%Docstring
The precision in which geometries on this layer should be saved.
Geometries which are edited on this layer will be rounded to multiples of this value (snap to grid).
Set to 0.0 to disable.

.. versionadded:: 3.4
%End

bool isActive() const;
%Docstring
Determines if at least one fix is enabled.

.. versionadded:: 3.4
%End

void apply( QgsGeometry &geometry ) const;
%Docstring
Apply any fixes configured on this class to ``geometry``.

.. versionadded:: 3.4
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsgeometryfixes.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
46 changes: 3 additions & 43 deletions python/core/auto_generated/qgsvectorlayer.sip.in
Expand Up @@ -329,16 +329,6 @@ Constructor for LayerOptions.

};

struct GeometryOptions
{
explicit GeometryOptions( bool removeDuplicateNodes = false, double geometryPrecision = 0.0 );


bool removeDuplicateNodes;

double geometryPrecision;
};

explicit QgsVectorLayer( const QString &path = QString(), const QString &baseName = QString(),
const QString &providerLib = "ogr", const QgsVectorLayer::LayerOptions &options = QgsVectorLayer::LayerOptions() );
%Docstring
Expand Down Expand Up @@ -2235,39 +2225,9 @@ Test if an edit command is active
.. versionadded:: 3.0
%End

bool removeDuplicateNodes() const;
%Docstring
If the `removeDuplicateNodes` property is set on a layer, whenever a new feature enters
the edit buffer or the geometry of an existing feature is changed, duplicate nodes will
automatically be removed without any user intervention.

.. versionadded:: 3.4
%End

void setRemoveDuplicateNodes( bool removeDuplicateNodes );
%Docstring
If the `removeDuplicateNodes` property is set on a layer, whenever a new feature enters
the edit buffer or the geometry of an existing feature is changed, duplicate nodes will
automatically be removed without any user intervention.

.. versionadded:: 3.4
%End


double geometryPrecision() const;
%Docstring
The `geometryPrecision` property of a layer will enable an automatic snap to grid operation
on a layer whenever a new feature is added or the geometry of an existing feature is changed.
If it is set to 0.0, this feature is disabled.

.. versionadded:: 3.4
%End

void setGeometryPrecision( double geometryPrecision );
QgsGeometryFixes *geometryFixes() const;
%Docstring
The `geometryPrecision` property of a layer will enable an automatic snap to grid
on a layer whenever a new feature is added or the geometry of an existing feature is changed.
If it is set to 0.0, this feature is disabled.
Configuration and logic to apply automatically on any edit happening on this layer.

.. versionadded:: 3.4
%End
Expand Down Expand Up @@ -2637,7 +2597,7 @@ Emitted when the feature count for symbols on this layer has been recalculated.
Sets the extent
%End

private: // Private methods
private:
QgsVectorLayer( const QgsVectorLayer &rhs );
};

Expand Down
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -53,6 +53,7 @@
%Include auto_generated/qgsfields.sip
%Include auto_generated/qgsfileutils.sip
%Include auto_generated/qgsfontutils.sip
%Include auto_generated/qgsgeometryfixes.sip
%Include auto_generated/qgsgeometrysimplifier.sip
%Include auto_generated/qgshistogram.sip
%Include auto_generated/qgshtmlutils.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -203,6 +203,7 @@ SET(QGIS_CORE_SRCS
qgsfontutils.cpp
qgsgeometrysimplifier.cpp
qgsgeometryvalidator.cpp
qgsgeometryfixes.cpp
qgsgml.cpp
qgsgmlschema.cpp
qgshistogram.cpp
Expand Down Expand Up @@ -860,6 +861,7 @@ SET(QGIS_CORE_HDRS
qgsfields.h
qgsfileutils.h
qgsfontutils.h
qgsgeometryfixes.h
qgsgeometrysimplifier.h
qgshistogram.h
qgshtmlutils.h
Expand Down
52 changes: 52 additions & 0 deletions src/core/qgsgeometryfixes.cpp
@@ -0,0 +1,52 @@
/***************************************************************************
qgsgeometryfixes.cpp
-------------------
begin : Aug 23, 2018
copyright : (C) 2018 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsgeometryfixes.h"

bool QgsGeometryFixes::removeDuplicateNodes() const
{
return mRemoveDuplicateNodes;
}

void QgsGeometryFixes::setRemoveDuplicateNodes( bool value )
{
mRemoveDuplicateNodes = value;
}

double QgsGeometryFixes::geometryPrecision() const
{
return mGeometryPrecision;
}

void QgsGeometryFixes::setGeometryPrecision( double value )
{
mGeometryPrecision = value;
}

bool QgsGeometryFixes::isActive() const
{
return mGeometryPrecision != 0.0 || mRemoveDuplicateNodes;
}

void QgsGeometryFixes::apply( QgsGeometry &geometry ) const
{
if ( mGeometryPrecision != 0.0 )
geometry = geometry.snappedToGrid( mGeometryPrecision, mGeometryPrecision );

if ( mRemoveDuplicateNodes )
geometry.removeDuplicateNodes();
}
96 changes: 96 additions & 0 deletions src/core/qgsgeometryfixes.h
@@ -0,0 +1,96 @@
/***************************************************************************
qgsgeometryfixes.h
-------------------
begin : Aug 23, 2018
copyright : (C) 2018 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSGEOMETRYFIXES_H
#define QGSGEOMETRYFIXES_H

#include "qgsgeometry.h"

/**
* The QgsGeometryFixes class contains options to

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Aug 26, 2018

Collaborator

?

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Aug 26, 2018

Author Member

Weird. I was really sure I had that fixed... Lost in transmission, thanks.

*/
class CORE_EXPORT QgsGeometryFixes
{
public:
QgsGeometryFixes() = default;

/**
* Automatically remove duplicate nodes on all geometries which are edited on this layer.
*
* \since QGIS 3.4
*/
bool removeDuplicateNodes() const;

/**
* Automatically remove duplicate nodes on all geometries which are edited on this layer.
*
* \since QGIS 3.4
*/
void setRemoveDuplicateNodes( bool value );

/**
* The precision in which geometries on this layer should be saved.
* Geometries which are edited on this layer will be rounded to multiples of this value (snap to grid).
* Set to 0.0 to disable.
*
* \since QGIS 3.4
*/
double geometryPrecision() const;

/**
* The precision in which geometries on this layer should be saved.
* Geometries which are edited on this layer will be rounded to multiples of this value (snap to grid).
* Set to 0.0 to disable.
*
* \since QGIS 3.4
*/
void setGeometryPrecision( double value );

/**
* Determines if at least one fix is enabled.
*
* \since QGIS 3.4
*/
bool isActive() const;

/**
* Apply any fixes configured on this class to \a geometry.
*
* \since QGIS 3.4
*/
void apply( QgsGeometry &geometry ) const;

private:

/**
* Automatically remove duplicate nodes on all geometries which are edited on this layer.
*
* \since QGIS 3.4
*/
bool mRemoveDuplicateNodes = false;

/**
* The precision in which geometries on this layer should be saved.
* Geometries which are edited on this layer will be rounded to multiples of this value (snap to grid).
* Set to 0.0 to disable.
*
* \since QGIS 3.4
*/
double mGeometryPrecision = 0.0;
};

#endif // QGSGEOMETRYFIXES_H

0 comments on commit 063ccf4

Please sign in to comment.