Skip to content

Commit

Permalink
Merge pull request #7959 from m-kuhn/geometryOptions
Browse files Browse the repository at this point in the history
Add a new QML category "Geometry Options"
  • Loading branch information
m-kuhn committed Sep 19, 2018
2 parents 1390198 + 9b2dff6 commit 3cb82a5
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 71 deletions.
Original file line number Original file line Diff line number Diff line change
@@ -1,32 +1,32 @@
/************************************************************************ /************************************************************************
* This file has been generated automatically from * * This file has been generated automatically from *
* * * *
* src/core/qgsgeometryfixes.h * * src/core/qgsgeometryoptions.h *
* * * *
* Do not edit manually ! Edit header and run scripts/sipify.pl again * * Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/ ************************************************************************/








class QgsGeometryFixes class QgsGeometryOptions
{ {
%Docstring %Docstring


The QgsGeometryFixes class contains options to automatically adjust geometries to The QgsGeometryOptions class contains options to automatically adjust geometries to
constraints on a layer. constraints on a layer.


.. versionadded:: 3.4 .. versionadded:: 3.4
%End %End


%TypeHeaderCode %TypeHeaderCode
#include "qgsgeometryfixes.h" #include "qgsgeometryoptions.h"
%End %End
public: public:


QgsGeometryFixes(); QgsGeometryOptions();
%Docstring %Docstring
Create a new QgsGeometryFixes object. Create a new QgsGeometryOptions object.
%End %End


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


.. versionadded:: 3.4
%End

void writeXml( QDomNode &node ) const;
%Docstring
Write the geometry options to the ``node``.

.. versionadded:: 3.4
%End

void readXml( const QDomNode &node );
%Docstring
Read the geometry options from ``node``.

.. versionadded:: 3.4 .. versionadded:: 3.4
%End %End


Expand All @@ -80,7 +94,7 @@ Apply any fixes configured on this class to ``geometry``.
/************************************************************************ /************************************************************************
* This file has been generated automatically from * * This file has been generated automatically from *
* * * *
* src/core/qgsgeometryfixes.h * * src/core/qgsgeometryoptions.h *
* * * *
* Do not edit manually ! Edit header and run scripts/sipify.pl again * * Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/ ************************************************************************/
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsmaplayer.sip.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ This is the base class for all map layer types (vector, raster).
AttributeTable, AttributeTable,
Rendering, Rendering,
CustomProperties, CustomProperties,
GeometryOptions,
AllStyleCategories AllStyleCategories
}; };
typedef QFlags<QgsMapLayer::StyleCategory> StyleCategories; typedef QFlags<QgsMapLayer::StyleCategory> StyleCategories;
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsvectorlayer.sip.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2230,7 +2230,7 @@ Test if an edit command is active
.. versionadded:: 3.0 .. versionadded:: 3.0
%End %End


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


Expand Down
2 changes: 1 addition & 1 deletion python/core/core_auto.sip
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
%Include auto_generated/qgsfields.sip %Include auto_generated/qgsfields.sip
%Include auto_generated/qgsfileutils.sip %Include auto_generated/qgsfileutils.sip
%Include auto_generated/qgsfontutils.sip %Include auto_generated/qgsfontutils.sip
%Include auto_generated/qgsgeometryfixes.sip %Include auto_generated/qgsgeometryoptions.sip
%Include auto_generated/qgsgeometrysimplifier.sip %Include auto_generated/qgsgeometrysimplifier.sip
%Include auto_generated/qgshistogram.sip %Include auto_generated/qgshistogram.sip
%Include auto_generated/qgshstoreutils.sip %Include auto_generated/qgshstoreutils.sip
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgsmaplayerstylecategoriesmodel.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ QVariant QgsMapLayerStyleCategoriesModel::data( const QModelIndex &index, int ro
return QgsApplication::getThemeIcon( QStringLiteral( "/mActionOptions.svg" ) ); return QgsApplication::getThemeIcon( QStringLiteral( "/mActionOptions.svg" ) );
} }
break; break;
case QgsMapLayer::GeometryOptions:
switch ( role )
{
case Qt::DisplayRole:
return tr( "Geometry Options" );
case Qt::ToolTipRole:
return tr( "Geometry constraints and validity checks" );
case Qt::DecorationRole:
return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/digitizing.svg" ) );
}
break;
case QgsMapLayer::AllStyleCategories: case QgsMapLayer::AllStyleCategories:
switch ( role ) switch ( role )
{ {
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#include "qgsnewauxiliaryfielddialog.h" #include "qgsnewauxiliaryfielddialog.h"
#include "qgslabelinggui.h" #include "qgslabelinggui.h"
#include "qgssymbollayer.h" #include "qgssymbollayer.h"
#include "qgsgeometryfixes.h" #include "qgsgeometryoptions.h"
#include "qgsvectorlayersavestyledialog.h" #include "qgsvectorlayersavestyledialog.h"
#include "qgsvectorlayerloadstyledialog.h" #include "qgsvectorlayerloadstyledialog.h"


Expand Down Expand Up @@ -401,8 +401,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
mRemoveDuplicateNodesCheckbox->setEnabled( true ); mRemoveDuplicateNodesCheckbox->setEnabled( true );
mGeometryPrecisionSpinBox->setEnabled( true ); mGeometryPrecisionSpinBox->setEnabled( true );


mRemoveDuplicateNodesCheckbox->setChecked( mLayer->geometryFixes()->removeDuplicateNodes() ); mRemoveDuplicateNodesCheckbox->setChecked( mLayer->geometryOptions()->removeDuplicateNodes() );
mGeometryPrecisionSpinBox->setValue( mLayer->geometryFixes()->geometryPrecision() ); mGeometryPrecisionSpinBox->setValue( mLayer->geometryOptions()->geometryPrecision() );


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


mLayer->geometryFixes()->setRemoveDuplicateNodes( mRemoveDuplicateNodesCheckbox->isChecked() ); mLayer->geometryOptions()->setRemoveDuplicateNodes( mRemoveDuplicateNodesCheckbox->isChecked() );
mLayer->geometryFixes()->setGeometryPrecision( mGeometryPrecisionSpinBox->value() ); mLayer->geometryOptions()->setGeometryPrecision( mGeometryPrecisionSpinBox->value() );


// update symbology // update symbology
emit refreshLegend( mLayer->id() ); emit refreshLegend( mLayer->id() );
Expand Down
4 changes: 2 additions & 2 deletions src/core/CMakeLists.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ SET(QGIS_CORE_SRCS
qgsfontutils.cpp qgsfontutils.cpp
qgsgeometrysimplifier.cpp qgsgeometrysimplifier.cpp
qgsgeometryvalidator.cpp qgsgeometryvalidator.cpp
qgsgeometryfixes.cpp qgsgeometryoptions.cpp
qgsgml.cpp qgsgml.cpp
qgsgmlschema.cpp qgsgmlschema.cpp
qgshistogram.cpp qgshistogram.cpp
Expand Down Expand Up @@ -867,7 +867,7 @@ SET(QGIS_CORE_HDRS
qgsfields.h qgsfields.h
qgsfileutils.h qgsfileutils.h
qgsfontutils.h qgsfontutils.h
qgsgeometryfixes.h qgsgeometryoptions.h
qgsgeometrysimplifier.h qgsgeometrysimplifier.h
qgshistogram.h qgshistogram.h
qgshstoreutils.h qgshstoreutils.h
Expand Down
34 changes: 26 additions & 8 deletions src/core/qgsgeometryfixes.cpp → src/core/qgsgeometryoptions.cpp
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************** /***************************************************************************
qgsgeometryfixes.cpp qgsgeometryoptions.cpp
------------------- -------------------
begin : Aug 23, 2018 begin : Aug 23, 2018
copyright : (C) 2018 by Matthias Kuhn copyright : (C) 2018 by Matthias Kuhn
Expand All @@ -15,38 +15,56 @@
* * * *
***************************************************************************/ ***************************************************************************/


#include "qgsgeometryfixes.h" #include "qgsgeometryoptions.h"


bool QgsGeometryFixes::removeDuplicateNodes() const #include "qgsxmlutils.h"

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


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


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


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


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


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


if ( mRemoveDuplicateNodes ) if ( mRemoveDuplicateNodes )
geometry.removeDuplicateNodes(); geometry.removeDuplicateNodes();
} }

void QgsGeometryOptions::writeXml( QDomNode &node ) const
{
QDomElement geometryOptionsElement = node.ownerDocument().createElement( QStringLiteral( "geometryOptions" ) );
node.appendChild( geometryOptionsElement );

geometryOptionsElement.setAttribute( QStringLiteral( "removeDuplicateNodes" ), mRemoveDuplicateNodes ? 1 : 0 );
geometryOptionsElement.setAttribute( QStringLiteral( "geometryPrecision" ), mGeometryPrecision );
}

void QgsGeometryOptions::readXml( const QDomNode &node )
{
QDomElement geometryOptionsElement = node.toElement();
setGeometryPrecision( geometryOptionsElement.attribute( QStringLiteral( "geometryPrecision" ), QStringLiteral( "0.0" ) ).toDouble() );
setRemoveDuplicateNodes( geometryOptionsElement.attribute( QStringLiteral( "removeDuplicateNodes" ), QStringLiteral( "0" ) ).toInt() == 1 );
}
32 changes: 24 additions & 8 deletions src/core/qgsgeometryfixes.h → src/core/qgsgeometryoptions.h
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************** /***************************************************************************
qgsgeometryfixes.h qgsgeometryoptions.h
------------------- -------------------
begin : Aug 23, 2018 begin : Aug 23, 2018
copyright : (C) 2018 by Matthias Kuhn copyright : (C) 2018 by Matthias Kuhn
Expand All @@ -15,27 +15,29 @@
* * * *
***************************************************************************/ ***************************************************************************/


#ifndef QGSGEOMETRYFIXES_H #ifndef QGSGEOMETRYOPTIONS_H
#define QGSGEOMETRYFIXES_H #define QGSGEOMETRYOPTIONS_H


#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgsgeometry.h" #include "qgsgeometry.h"


/** /**
* \ingroup core * \ingroup core
* *
* The QgsGeometryFixes class contains options to automatically adjust geometries to * The QgsGeometryOptions class contains options to automatically adjust geometries to
* constraints on a layer. * constraints on a layer.
* *
* \since QGIS 3.4 * \since QGIS 3.4
*/ */
class CORE_EXPORT QgsGeometryFixes class CORE_EXPORT QgsGeometryOptions
{ {
public: public:


/** /**
* Create a new QgsGeometryFixes object. * Create a new QgsGeometryOptions object.
*/ */
QgsGeometryFixes() = default; QgsGeometryOptions() = default;


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


/**
* Write the geometry options to the \a node.
*
* \since QGIS 3.4
*/
void writeXml( QDomNode &node ) const;

/**
* Read the geometry options from \a node.
*
* \since QGIS 3.4
*/
void readXml( const QDomNode &node );

private: private:


/** /**
Expand All @@ -102,4 +118,4 @@ class CORE_EXPORT QgsGeometryFixes
double mGeometryPrecision = 0.0; double mGeometryPrecision = 0.0;
}; };


#endif // QGSGEOMETRYFIXES_H #endif // QGSGEOMETRYOPTIONS_H
3 changes: 2 additions & 1 deletion src/core/qgsmaplayer.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ class CORE_EXPORT QgsMapLayer : public QObject
AttributeTable = 1 << 9, //!< Attribute table settings: choice and order of columns, conditional styling AttributeTable = 1 << 9, //!< Attribute table settings: choice and order of columns, conditional styling
Rendering = 1 << 10, //!< Rendering: scale visibility, simplify method, opacity Rendering = 1 << 10, //!< Rendering: scale visibility, simplify method, opacity
CustomProperties = 1 << 11, //!< Custom properties (by plugins for instance) CustomProperties = 1 << 11, //!< Custom properties (by plugins for instance)
GeometryOptions = 1 << 12, //!< Geometry validation configuration
AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions | AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
MapTips | Diagrams | AttributeTable | Rendering | CustomProperties, MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions,
}; };
Q_ENUM( StyleCategory ) Q_ENUM( StyleCategory )
Q_DECLARE_FLAGS( StyleCategories, StyleCategory ) Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
Expand Down
Loading

0 comments on commit 3cb82a5

Please sign in to comment.