@@ -76,32 +76,15 @@ void QgsMapToolSimplify::updateSimplificationPreview()
76
76
{
77
77
// create a copy of selected feature and do the simplification
78
78
QgsFeature f = mSelectedFeature ;
79
- if ( mTolerance > 0 )
80
- {
81
- if ( mSelectedFeature .geometry ()->type () == QGis::Line )
82
- {
83
- QgsSimplifyFeature::simplifyLine ( f, mTolerance );
84
- }
85
- else
86
- {
87
- QgsSimplifyFeature::simplifyPolygon ( f, mTolerance );
88
- }
89
- }
90
- mRubberBand ->setToGeometry ( f.geometry (), 0 );
79
+ QgsSimplifyFeature::simplify ( f, mTolerance );
80
+ mRubberBand ->setToGeometry ( f.geometry (), currentVectorLayer () );
91
81
}
92
82
93
83
94
84
void QgsMapToolSimplify::storeSimplified ()
95
85
{
96
86
QgsVectorLayer * vlayer = currentVectorLayer ();
97
- if ( mSelectedFeature .geometry ()->type () == QGis::Line )
98
- {
99
- QgsSimplifyFeature::simplifyLine ( mSelectedFeature , mTolerance );
100
- }
101
- else
102
- {
103
- QgsSimplifyFeature::simplifyPolygon ( mSelectedFeature , mTolerance );
104
- }
87
+ QgsSimplifyFeature::simplify ( mSelectedFeature , mTolerance );
105
88
106
89
vlayer->beginEditCommand ( tr ( " Geometry simplified" ) );
107
90
vlayer->changeGeometry ( mSelectedFeature .id (), mSelectedFeature .geometry () );
@@ -223,7 +206,7 @@ void QgsMapToolSimplify::canvasPressEvent( QMouseEvent * e )
223
206
return ;
224
207
}
225
208
226
- QgsPoint layerCoords = mCanvas -> getCoordinateTransform ()-> toMapPoint ( e-> pos (). x () , e->pos (). y () );
209
+ QgsPoint layerCoords = toLayerCoordinates ( vlayer , e->pos () );
227
210
228
211
double r = QgsTolerance::vertexSearchRadius ( vlayer, mCanvas ->mapSettings () );
229
212
QgsRectangle selectRect = QgsRectangle ( layerCoords.x () - r, layerCoords.y () - r,
@@ -259,10 +242,10 @@ void QgsMapToolSimplify::canvasPressEvent( QMouseEvent * e )
259
242
}
260
243
261
244
mRubberBand = new QgsRubberBand ( mCanvas );
262
- mRubberBand ->setToGeometry ( mSelectedFeature .geometry (), 0 );
263
245
mRubberBand ->setColor ( QColor ( 255 , 0 , 0 , 65 ) );
264
246
mRubberBand ->setWidth ( 2 );
265
247
mRubberBand ->show ();
248
+ updateSimplificationPreview ();
266
249
267
250
// show dialog as a non-modal window
268
251
mSimplifyDialog ->show ();
@@ -309,6 +292,21 @@ QVector<QgsPoint> QgsMapToolSimplify::getPointList( QgsFeature& f )
309
292
// //////////////////////////////////////////////////////////////////////////
310
293
311
294
295
+ bool QgsSimplifyFeature::simplify ( QgsFeature& feature, double tolerance )
296
+ {
297
+ if ( tolerance <= 0 )
298
+ return false ;
299
+
300
+ if ( feature.geometry ()->type () == QGis::Line )
301
+ {
302
+ return QgsSimplifyFeature::simplifyLine ( feature, tolerance );
303
+ }
304
+ else
305
+ {
306
+ return QgsSimplifyFeature::simplifyPolygon ( feature, tolerance );
307
+ }
308
+ }
309
+
312
310
bool QgsSimplifyFeature::simplifyLine ( QgsFeature& lineFeature, double tolerance )
313
311
{
314
312
QgsGeometry* line = lineFeature.geometry ();
@@ -331,7 +329,6 @@ bool QgsSimplifyFeature::simplifyPolygon( QgsFeature& polygonFeature, double tol
331
329
}
332
330
333
331
QVector<QgsPoint> resultPoints = simplifyPoints ( polygon->asPolygon ()[0 ], tolerance );
334
- // resultPoints.push_back(resultPoints[0]);
335
332
QVector<QgsPolyline> poly;
336
333
poly.append ( resultPoints );
337
334
polygonFeature.setGeometry ( QgsGeometry::fromPolygon ( poly ) );
0 commit comments