Skip to content
Permalink
Browse files

Revert to specific setters and getters

  • Loading branch information
m-kuhn committed Aug 23, 2018
1 parent 4b6421c commit f69e58f261c7f29bd4fbebfa539ed2766a6cf7d0
@@ -2235,18 +2235,39 @@ Test if an edit command is active
.. versionadded:: 3.0
%End

GeometryOptions geometryOptions() const;
bool removeDuplicateNodes() const;
%Docstring
The geometry options applied to this layer contain information about
how geometries should be preprocessed when added to or edited on this layer.
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 setGeometryOptions( const GeometryOptions &geometryOptions );
void setRemoveDuplicateNodes( bool removeDuplicateNodes );
%Docstring
The geometry options applied to this layer contain information about
how geometries should be preprocessed when added to or edited on this layer.
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 );
%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.

.. versionadded:: 3.4
%End
@@ -423,14 +423,13 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(

updateAuxiliaryStoragePage();

QgsVectorLayer::GeometryOptions geomOps = mLayer->geometryOptions();
if ( mLayer->isSpatial() )
{
mRemoveDuplicateVerticeCheckbox->setEnabled( true );
mGeometryPrecisionSpinBox->setEnabled( true );

mRemoveDuplicateVerticeCheckbox->setChecked( geomOps.removeDuplicateNodes );
mGeometryPrecisionSpinBox->setValue( geomOps.geometryPrecision );
mRemoveDuplicateVerticeCheckbox->setChecked( mLayer->removeDuplicateNodes() );
mGeometryPrecisionSpinBox->setValue( mLayer->geometryPrecision() );

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

QgsVectorLayer::GeometryOptions geomOps;
geomOps.removeDuplicateNodes = mRemoveDuplicateVerticeCheckbox->isChecked();
geomOps.geometryPrecision = mGeometryPrecisionSpinBox->value();
mLayer->setGeometryOptions( geomOps );
mLayer->setRemoveDuplicateNodes( mRemoveDuplicateVerticeCheckbox->isChecked() );
mLayer->setGeometryPrecision( mGeometryPrecisionSpinBox->value() );

// update symbology
emit refreshLegend( mLayer->id() );
@@ -4790,14 +4790,24 @@ QgsAbstractVectorLayerLabeling *QgsVectorLayer::readLabelingFromCustomProperties
return labeling;
}

QgsVectorLayer::GeometryOptions QgsVectorLayer::geometryOptions() const
double QgsVectorLayer::geometryPrecision() const
{
return mGeometryOptions;
return mGeometryOptions.geometryPrecision;
}

void QgsVectorLayer::setGeometryOptions( const GeometryOptions &geometryOptions )
void QgsVectorLayer::setGeometryPrecision( double geometryPrecision )
{
mGeometryOptions = geometryOptions;
mGeometryOptions.geometryPrecision = geometryPrecision;
}

bool QgsVectorLayer::removeDuplicateNodes() const
{
return mGeometryOptions.removeDuplicateNodes;
}

void QgsVectorLayer::setRemoveDuplicateNodes( bool removeDuplicateNodes )
{
mGeometryOptions.removeDuplicateNodes = removeDuplicateNodes;
}

void QgsVectorLayer::setReadExtentFromXml( bool readExtentFromXml )
@@ -2019,20 +2019,41 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
bool isEditCommandActive() const { return mEditCommandActive; }

/**
* The geometry options applied to this layer contain information about
* how geometries should be preprocessed when added to or edited on this layer.
* 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.
*
* \since QGIS 3.4
*/
GeometryOptions geometryOptions() const;
bool removeDuplicateNodes() const;

/**
* The geometry options applied to this layer contain information about
* how geometries should be preprocessed when added to or edited on this layer.
* 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.
*
* \since QGIS 3.4
*/
void setGeometryOptions( const GeometryOptions &geometryOptions );
void setRemoveDuplicateNodes( bool removeDuplicateNodes );


/**
* 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.
*
* \since QGIS 3.4
*/
double geometryPrecision() const;

/**
* 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.
*
* \since QGIS 3.4
*/
void setGeometryPrecision( double geometryPrecision );

public slots:

@@ -2758,44 +2758,36 @@ def testFeatureRequestWithReprojectionAndVirtualFields(self):

def testPrecision(self):
layer = QgsVectorLayer("Polygon?crs=epsg:2056&field=pk:int", "vl", "memory")
geomOps = QgsVectorLayer.GeometryOptions()
geomOps.geometryPrecision = 10
layer.setGeometryOptions(geomOps)
layer.setGeometryPrecision(10)
geom = QgsGeometry.fromWkt('Polygon ((2596411 1224654, 2596400 1224652, 2596405 1224640, 2596410 1224641, 2596411 1224654))')
feature = QgsFeature(layer.fields())
feature.setGeometry(geom)
layer.startEditing()
layer.addFeature(feature)
self.assertGeometriesEqual(QgsGeometry.fromWkt('Polygon ((2596410 1224650, 2596400 1224650, 2596410 1224640, 2596410 1224650))'), feature.geometry(), 'geometry with unsnapped nodes', 'fixed geometry')
geomOps.geometryPrecision = 0.0
layer.setGeometryOptions(geomOps)
layer.setGeometryPrecision(0.0)
feature.setGeometry(QgsGeometry.fromWkt('Polygon ((2596411 1224654, 2596400 1224652, 2596405 1224640, 2596410 1224641, 2596411 1224654))'))
layer.addFeature(feature)
self.assertGeometriesEqual(QgsGeometry.fromWkt('Polygon ((2596411 1224654, 2596400 1224652, 2596405 1224640, 2596410 1224641, 2596411 1224654))'), feature.geometry(), 'geometry with duplicates', 'unchanged geometry')

def testRemoveDuplicateNodes(self):
layer = QgsVectorLayer("Polygon?crs=epsg:2056&field=pk:int", "vl", "memory")
geomOps = QgsVectorLayer.GeometryOptions()
geomOps.removeDuplicateNodes = True
layer.setGeometryOptions(geomOps)
layer.setRemoveDuplicateNodes(True)
geom = QgsGeometry.fromWkt('Polygon ((70 80, 80 90, 80 90, 60 50, 70 80))')
feature = QgsFeature(layer.fields())
feature.setGeometry(geom)
layer.startEditing()
layer.addFeature(feature)
self.assertGeometriesEqual(feature.geometry(), QgsGeometry.fromWkt('Polygon ((70 80, 80 90, 60 50, 70 80))'), 'fixed geometry', 'geometry with duplicates')
geomOps.removeDuplicateNodes = False
layer.setGeometryOptions(geomOps)
layer.setRemoveDuplicateNodes(False)
feature.setGeometry(QgsGeometry.fromWkt('Polygon ((70 80, 80 90, 80 90, 60 50, 70 80))'))
layer.addFeature(feature)
self.assertGeometriesEqual(feature.geometry(), QgsGeometry.fromWkt('Polygon ((70 80, 80 90, 80 90, 60 50, 70 80))'), 'unchanged geometry', 'geometry with duplicates')

def testPrecisionAndDuplicateNodes(self):
layer = QgsVectorLayer("Polygon?crs=epsg:2056&field=pk:int", "vl", "memory")
geomOps = QgsVectorLayer.GeometryOptions()
geomOps.removeDuplicateNodes = True
geomOps.geometryPrecision = 10
layer.setGeometryOptions(geomOps)
layer.setGeometryPrecision(10)
layer.setRemoveDuplicateNodes(True)
geom = QgsGeometry.fromWkt('Polygon ((2596411 1224654, 2596400 1224652, 2596402 1224653, 2596405 1224640, 2596410 1224641, 2596411 1224654))')
feature = QgsFeature(layer.fields())
feature.setGeometry(geom)

0 comments on commit f69e58f

Please sign in to comment.
You can’t perform that action at this time.