Skip to content

Commit 30b757b

Browse files
committed
More in-place support tweaks, add tests
1 parent 8951e15 commit 30b757b

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

src/analysis/processing/qgsalgorithmsplitwithlines.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ bool QgsSplitWithLinesAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) cons
7878
if ( !layer )
7979
return false;
8080

81+
if ( layer->geometryType() != QgsWkbTypes::LineGeometry && layer->geometryType() != QgsWkbTypes::PolygonGeometry )
82+
return false;
83+
8184
return true;
8285
}
8386

src/analysis/processing/qgsalgorithmswapxy.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
***************************************************************************/
1717

1818
#include "qgsalgorithmswapxy.h"
19+
#include "qgsvectorlayer.h"
1920

2021
///@cond PRIVATE
2122

@@ -60,6 +61,18 @@ QgsSwapXYAlgorithm *QgsSwapXYAlgorithm::createInstance() const
6061
return new QgsSwapXYAlgorithm();
6162
}
6263

64+
bool QgsSwapXYAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
65+
{
66+
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
67+
if ( !layer )
68+
return false;
69+
70+
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
71+
return false;
72+
73+
return layer->isSpatial();
74+
}
75+
6376
QgsProcessingFeatureSource::Flag QgsSwapXYAlgorithm::sourceFlags() const
6477
{
6578
// this algorithm doesn't care about invalid geometries

src/analysis/processing/qgsalgorithmswapxy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class QgsSwapXYAlgorithm : public QgsProcessingFeatureBasedAlgorithm
4141
QString groupId() const override;
4242
QString shortHelpString() const override;
4343
QgsSwapXYAlgorithm *createInstance() const override SIP_FACTORY;
44+
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
4445

4546
protected:
4647

tests/src/python/test_qgsprocessinginplace.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def _all_true():
5151
types = _add_multi(types)
5252
types = _add_z(types)
5353
types = _add_m(types)
54+
types.append('NoGeometry')
5455
return {t: True for t in types}
5556

5657

@@ -124,11 +125,12 @@ def _support_inplace_edit_tester(self, alg_name, expected):
124125
def test_support_in_place_edit(self):
125126

126127
ALL = _all_true()
128+
GEOMETRY_ONLY = {t: t != 'NoGeometry' for t in _all_true().keys()}
127129
NONE = _all_false()
128130
LINESTRING_ONLY = {t: t.find('LineString') >= 0 for t in _all_true().keys()}
129131
Z_ONLY = {t: t.find('Z') > 0 for t in _all_true().keys()}
130132
M_ONLY = {t: t.rfind('M') > 0 for t in _all_true().keys()}
131-
NOT_M = {t: t.rfind('M') < 1 for t in _all_true().keys()}
133+
NOT_M = {t: t.rfind('M') < 1 and t != 'NoGeometry' for t in _all_true().keys()}
132134
POLYGON_ONLY = {t: t in ('Polygon', 'MultiPolygon') for t in _all_true().keys()}
133135
MULTI_ONLY = {t: t.find('Multi') == 0 for t in _all_true().keys()}
134136
SINGLE_ONLY = {t: t.find('Multi') == -1 for t in _all_true().keys()}
@@ -138,8 +140,8 @@ def test_support_in_place_edit(self):
138140

139141
self._support_inplace_edit_tester('native:smoothgeometry', LINESTRING_AND_POLYGON_ONLY)
140142
self._support_inplace_edit_tester('native:parallellines', LINESTRING_ONLY)
141-
self._support_inplace_edit_tester('native:arrayfeatures', ALL)
142-
self._support_inplace_edit_tester('native:reprojectlayer', ALL)
143+
self._support_inplace_edit_tester('native:arrayfeatures', GEOMETRY_ONLY)
144+
self._support_inplace_edit_tester('native:reprojectlayer', GEOMETRY_ONLY)
143145
self._support_inplace_edit_tester('qgis:densifygeometries', LINESTRING_AND_POLYGON_ONLY)
144146
self._support_inplace_edit_tester('qgis:densifygeometriesgivenaninterval', LINESTRING_AND_POLYGON_ONLY)
145147
self._support_inplace_edit_tester('native:setzfromraster', Z_ONLY)
@@ -150,18 +152,25 @@ def test_support_in_place_edit(self):
150152
self._support_inplace_edit_tester('native:multiringconstantbuffer', POLYGON_ONLY)
151153
self._support_inplace_edit_tester('native:orientedminimumboundingbox', POLYGON_ONLY)
152154
self._support_inplace_edit_tester('qgis:orthogonalize', LINESTRING_AND_POLYGON_ONLY)
153-
self._support_inplace_edit_tester('native:removeduplicatevertices', ALL)
154-
self._support_inplace_edit_tester('native:rotatefeatures', ALL)
155+
self._support_inplace_edit_tester('native:removeduplicatevertices', GEOMETRY_ONLY)
156+
self._support_inplace_edit_tester('native:rotatefeatures', GEOMETRY_ONLY)
155157
self._support_inplace_edit_tester('native:segmentizebymaxangle', NONE)
156158
self._support_inplace_edit_tester('native:segmentizebymaxdistance', NONE)
157159
self._support_inplace_edit_tester('native:setmfromraster', M_ONLY)
158160
self._support_inplace_edit_tester('native:simplifygeometries', LINESTRING_AND_POLYGON_ONLY)
159-
self._support_inplace_edit_tester('native:snappointstogrid', ALL)
160-
self._support_inplace_edit_tester('native:multiparttosingleparts', ALL)
161+
self._support_inplace_edit_tester('native:snappointstogrid', GEOMETRY_ONLY)
162+
self._support_inplace_edit_tester('native:multiparttosingleparts', GEOMETRY_ONLY)
161163
self._support_inplace_edit_tester('native:promotetomulti', MULTI_ONLY)
162-
self._support_inplace_edit_tester('native:subdivide', ALL)
163-
self._support_inplace_edit_tester('native:translategeometry', ALL)
164-
self._support_inplace_edit_tester('native:swapxy', ALL)
164+
self._support_inplace_edit_tester('native:subdivide', GEOMETRY_ONLY)
165+
self._support_inplace_edit_tester('native:translategeometry', GEOMETRY_ONLY)
166+
self._support_inplace_edit_tester('native:swapxy', GEOMETRY_ONLY)
167+
self._support_inplace_edit_tester('qgis:linestopolygons', NONE)
168+
self._support_inplace_edit_tester('qgis:polygonstolines', NONE)
169+
self._support_inplace_edit_tester('native:boundary', GEOMETRY_ONLY)
170+
self._support_inplace_edit_tester('native:clip', GEOMETRY_ONLY)
171+
self._support_inplace_edit_tester('native:difference', GEOMETRY_ONLY)
172+
self._support_inplace_edit_tester('native:dropgeometries', ALL)
173+
self._support_inplace_edit_tester('native:splitwithlines', LINESTRING_AND_POLYGON_ONLY)
165174

166175
def _make_compatible_tester(self, feature_wkt, layer_wkb_name, attrs=[1]):
167176
layer = self._make_layer(layer_wkb_name)

0 commit comments

Comments
 (0)