@@ -59,11 +59,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
59
59
layerWKBType == QGis::WKBMultiLineString25D || layerWKBType == QGis::WKBPoint25D || layerWKBType == QGis::WKBMultiPoint25D )
60
60
{
61
61
QMessageBox::critical ( 0 , tr ( " 2.5D shape type not supported" ), tr ( " Adding features to 2.5D shapetypes is not supported yet" ) );
62
- delete mRubberBand ;
63
- mRubberBand = NULL ;
64
- mCapturing = FALSE ;
65
- mCaptureList .clear ();
66
- mCanvas ->refresh ();
62
+ stopCapturing ();
67
63
return ;
68
64
}
69
65
@@ -85,7 +81,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
85
81
}
86
82
87
83
// POINT CAPTURING
88
- if ( mCaptureMode == CapturePoint )
84
+ if ( mode () == CapturePoint )
89
85
{
90
86
// check we only use this tool for point/multipoint layers
91
87
if ( vlayer->geometryType () != QGis::Point )
@@ -129,7 +125,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
129
125
QgsFeature* f = new QgsFeature ( 0 , " WKBPoint" );
130
126
131
127
int size = 0 ;
132
- char end = QgsApplication::endian ();
128
+ char endian = QgsApplication::endian ();
133
129
unsigned char *wkb = NULL ;
134
130
int wkbtype = 0 ;
135
131
double x = savePoint.x ();
@@ -140,7 +136,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
140
136
size = 1 + sizeof ( int ) + 2 * sizeof ( double );
141
137
wkb = new unsigned char [size];
142
138
wkbtype = QGis::WKBPoint;
143
- memcpy ( &wkb[0 ], &end , 1 );
139
+ memcpy ( &wkb[0 ], &endian , 1 );
144
140
memcpy ( &wkb[1 ], &wkbtype, sizeof ( int ) );
145
141
memcpy ( &wkb[5 ], &x, sizeof ( double ) );
146
142
memcpy ( &wkb[5 ] + sizeof ( double ), &y, sizeof ( double ) );
@@ -151,14 +147,14 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
151
147
wkb = new unsigned char [size];
152
148
wkbtype = QGis::WKBMultiPoint;
153
149
int position = 0 ;
154
- memcpy ( &wkb[position], &end , 1 );
150
+ memcpy ( &wkb[position], &endian , 1 );
155
151
position += 1 ;
156
152
memcpy ( &wkb[position], &wkbtype, sizeof ( int ) );
157
153
position += sizeof ( int );
158
154
int npoint = 1 ;
159
155
memcpy ( &wkb[position], &npoint, sizeof ( int ) );
160
156
position += sizeof ( int );
161
- memcpy ( &wkb[position], &end , 1 );
157
+ memcpy ( &wkb[position], &endian , 1 );
162
158
position += 1 ;
163
159
int pointtype = QGis::WKBPoint;
164
160
memcpy ( &wkb[position], &pointtype, sizeof ( int ) );
@@ -209,18 +205,18 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
209
205
}
210
206
211
207
}
212
- else if ( mCaptureMode == CaptureLine || mCaptureMode == CapturePolygon )
208
+ else if ( mode () == CaptureLine || mode () == CapturePolygon )
213
209
{
214
210
// check we only use the line tool for line/multiline layers
215
- if ( mCaptureMode == CaptureLine && vlayer->geometryType () != QGis::Line )
211
+ if ( mode () == CaptureLine && vlayer->geometryType () != QGis::Line )
216
212
{
217
213
QMessageBox::information ( 0 , tr ( " Wrong editing tool" ),
218
214
tr ( " Cannot apply the 'capture line' tool on this vector layer" ) );
219
215
return ;
220
216
}
221
217
222
218
// check we only use the polygon tool for polygon/multipolygon layers
223
- if ( mCaptureMode == CapturePolygon && vlayer->geometryType () != QGis::Polygon )
219
+ if ( mode () == CapturePolygon && vlayer->geometryType () != QGis::Polygon )
224
220
{
225
221
QMessageBox::information ( 0 , tr ( " Wrong editing tool" ),
226
222
tr ( " Cannot apply the 'capture polygon' tool on this vector layer" ) );
@@ -244,52 +240,46 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
244
240
245
241
if ( e->button () == Qt::LeftButton )
246
242
{
247
- mCapturing = TRUE ;
243
+ startCapturing () ;
248
244
}
249
245
else if ( e->button () == Qt::RightButton )
250
246
{
251
247
// End of string
252
248
253
- mCapturing = FALSE ;
254
-
255
249
// lines: bail out if there are not at least two vertices
256
- if ( mCaptureMode == CaptureLine && mCaptureList . size () < 2 )
250
+ if ( mode () == CaptureLine && size () < 2 )
257
251
{
258
- delete mRubberBand ;
259
- mRubberBand = NULL ;
260
- mCaptureList .clear ();
252
+ stopCapturing ();
261
253
return ;
262
254
}
263
255
264
256
// polygons: bail out if there are not at least two vertices
265
- if ( mCaptureMode == CapturePolygon && mCaptureList . size () < 3 )
257
+ if ( mode () == CapturePolygon && size () < 3 )
266
258
{
267
- delete mRubberBand ;
268
- mRubberBand = NULL ;
269
- mCaptureList .clear ();
259
+ stopCapturing ();
270
260
return ;
271
261
}
272
262
273
263
// create QgsFeature with wkb representation
274
264
QgsFeature* f = new QgsFeature ( 0 , " WKBLineString" );
275
265
unsigned char * wkb;
276
- int size ;
277
- char end = QgsApplication::endian ();
266
+ int wkbsize ;
267
+ char endian = QgsApplication::endian ();
278
268
279
- if ( mCaptureMode == CaptureLine )
269
+ if ( mode () == CaptureLine )
280
270
{
281
271
if ( layerWKBType == QGis::WKBLineString )
282
272
{
283
- size = 1 + 2 * sizeof ( int ) + 2 * mCaptureList . size () * sizeof ( double );
284
- wkb = new unsigned char [size ];
273
+ wkbsize = 1 + 2 * sizeof ( int ) + 2 * size () * sizeof ( double );
274
+ wkb = new unsigned char [wkbsize ];
285
275
int wkbtype = QGis::WKBLineString;
286
- int length = mCaptureList . size ();
287
- memcpy ( &wkb[0 ], &end , 1 );
276
+ int length = size ();
277
+ memcpy ( &wkb[0 ], &endian , 1 );
288
278
memcpy ( &wkb[1 ], &wkbtype, sizeof ( int ) );
289
279
memcpy ( &wkb[1 +sizeof ( int )], &length, sizeof ( int ) );
290
280
int position = 1 + 2 * sizeof ( int );
291
281
double x, y;
292
- for ( QList<QgsPoint>::iterator it = mCaptureList . begin (); it != mCaptureList . end (); ++it )
282
+ for ( QList<QgsPoint>::iterator it = begin (); it != end (); ++it )
293
283
{
294
284
QgsPoint savePoint = *it;
295
285
x = savePoint.x ();
@@ -304,27 +294,27 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
304
294
}
305
295
else if ( layerWKBType == QGis::WKBMultiLineString )
306
296
{
307
- size = 1 + 2 * sizeof ( int ) + 1 + 2 * sizeof ( int ) + 2 * mCaptureList . size () * sizeof ( double );
308
- wkb = new unsigned char [size ];
297
+ wkbsize = 1 + 2 * sizeof ( int ) + 1 + 2 * sizeof ( int ) + 2 * size () * sizeof ( double );
298
+ wkb = new unsigned char [wkbsize ];
309
299
int position = 0 ;
310
300
int wkbtype = QGis::WKBMultiLineString;
311
- memcpy ( &wkb[position], &end , 1 );
301
+ memcpy ( &wkb[position], &endian , 1 );
312
302
position += 1 ;
313
303
memcpy ( &wkb[position], &wkbtype, sizeof ( int ) );
314
304
position += sizeof ( int );
315
305
int nlines = 1 ;
316
306
memcpy ( &wkb[position], &nlines, sizeof ( int ) );
317
307
position += sizeof ( int );
318
- memcpy ( &wkb[position], &end , 1 );
308
+ memcpy ( &wkb[position], &endian , 1 );
319
309
position += 1 ;
320
310
int linewkbtype = QGis::WKBLineString;
321
311
memcpy ( &wkb[position], &linewkbtype, sizeof ( int ) );
322
312
position += sizeof ( int );
323
- int length = mCaptureList . size ();
313
+ int length = size ();
324
314
memcpy ( &wkb[position], &length, sizeof ( int ) );
325
315
position += sizeof ( int );
326
316
double x, y;
327
- for ( QList<QgsPoint>::iterator it = mCaptureList . begin (); it != mCaptureList . end (); ++it )
317
+ for ( QList<QgsPoint>::iterator it = begin (); it != end (); ++it )
328
318
{
329
319
QgsPoint savePoint = *it;
330
320
x = savePoint.x ();
@@ -340,30 +330,28 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
340
330
else
341
331
{
342
332
QMessageBox::critical ( 0 , tr ( " Error" ), tr ( " Cannot add feature. Unknown WKB type" ) );
343
- delete mRubberBand ;
344
- mRubberBand = NULL ;
345
- mCaptureList .clear ();
333
+ stopCapturing ();
346
334
return ; // unknown wkbtype
347
335
}
348
- f->setGeometryAndOwnership ( &wkb[0 ], size );
336
+ f->setGeometryAndOwnership ( &wkb[0 ], wkbsize );
349
337
}
350
338
else // polygon
351
339
{
352
340
if ( layerWKBType == QGis::WKBPolygon )
353
341
{
354
- size = 1 + 3 * sizeof ( int ) + 2 * ( mCaptureList . size () + 1 ) * sizeof ( double );
355
- wkb = new unsigned char [size ];
342
+ wkbsize = 1 + 3 * sizeof ( int ) + 2 * ( size () + 1 ) * sizeof ( double );
343
+ wkb = new unsigned char [wkbsize ];
356
344
int wkbtype = QGis::WKBPolygon;
357
- int length = mCaptureList . size () + 1 ;// +1 because the first point is needed twice
345
+ int length = size () + 1 ;// +1 because the first point is needed twice
358
346
int numrings = 1 ;
359
- memcpy ( &wkb[0 ], &end , 1 );
347
+ memcpy ( &wkb[0 ], &endian , 1 );
360
348
memcpy ( &wkb[1 ], &wkbtype, sizeof ( int ) );
361
349
memcpy ( &wkb[1 +sizeof ( int )], &numrings, sizeof ( int ) );
362
350
memcpy ( &wkb[1 +2 *sizeof ( int )], &length, sizeof ( int ) );
363
351
int position = 1 + 3 * sizeof ( int );
364
352
double x, y;
365
353
QList<QgsPoint>::iterator it;
366
- for ( it = mCaptureList . begin (); it != mCaptureList . end (); ++it )
354
+ for ( it = begin (); it != end (); ++it )
367
355
{
368
356
QgsPoint savePoint = *it;
369
357
x = savePoint.x ();
@@ -376,7 +364,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
376
364
position += sizeof ( double );
377
365
}
378
366
// close the polygon
379
- it = mCaptureList . begin ();
367
+ it = begin ();
380
368
QgsPoint savePoint = *it;
381
369
x = savePoint.x ();
382
370
y = savePoint.y ();
@@ -388,21 +376,21 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
388
376
}
389
377
else if ( layerWKBType == QGis::WKBMultiPolygon )
390
378
{
391
- size = 2 + 5 * sizeof ( int ) + 2 * ( mCaptureList . size () + 1 ) * sizeof ( double );
392
- wkb = new unsigned char [size ];
379
+ wkbsize = 2 + 5 * sizeof ( int ) + 2 * ( size () + 1 ) * sizeof ( double );
380
+ wkb = new unsigned char [wkbsize ];
393
381
int wkbtype = QGis::WKBMultiPolygon;
394
382
int polygontype = QGis::WKBPolygon;
395
- int length = mCaptureList . size () + 1 ;// +1 because the first point is needed twice
383
+ int length = size () + 1 ;// +1 because the first point is needed twice
396
384
int numrings = 1 ;
397
385
int numpolygons = 1 ;
398
386
int position = 0 ; // pointer position relative to &wkb[0]
399
- memcpy ( &wkb[position], &end , 1 );
387
+ memcpy ( &wkb[position], &endian , 1 );
400
388
position += 1 ;
401
389
memcpy ( &wkb[position], &wkbtype, sizeof ( int ) );
402
390
position += sizeof ( int );
403
391
memcpy ( &wkb[position], &numpolygons, sizeof ( int ) );
404
392
position += sizeof ( int );
405
- memcpy ( &wkb[position], &end , 1 );
393
+ memcpy ( &wkb[position], &endian , 1 );
406
394
position += 1 ;
407
395
memcpy ( &wkb[position], &polygontype, sizeof ( int ) );
408
396
position += sizeof ( int );
@@ -412,7 +400,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
412
400
position += sizeof ( int );
413
401
double x, y;
414
402
QList<QgsPoint>::iterator it;
415
- for ( it = mCaptureList . begin (); it != mCaptureList . end (); ++it )// add the captured points to the polygon
403
+ for ( it = begin (); it != end (); ++it )// add the captured points to the polygon
416
404
{
417
405
QgsPoint savePoint = *it;
418
406
x = savePoint.x ();
@@ -425,7 +413,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
425
413
position += sizeof ( double );
426
414
}
427
415
// close the polygon
428
- it = mCaptureList . begin ();
416
+ it = begin ();
429
417
QgsPoint savePoint = *it;
430
418
x = savePoint.x ();
431
419
y = savePoint.y ();
@@ -436,12 +424,10 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
436
424
else
437
425
{
438
426
QMessageBox::critical ( 0 , tr ( " Error" ), tr ( " Cannot add feature. Unknown WKB type" ) );
439
- delete mRubberBand ;
440
- mRubberBand = NULL ;
441
- mCaptureList .clear ();
427
+ stopCapturing ();
442
428
return ; // unknown wkbtype
443
429
}
444
- f->setGeometryAndOwnership ( &wkb[0 ], size );
430
+ f->setGeometryAndOwnership ( &wkb[0 ], wkbsize );
445
431
446
432
int avoidIntersectionsReturn = f->geometry ()->avoidIntersections ();
447
433
if ( avoidIntersectionsReturn == 1 )
@@ -453,9 +439,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
453
439
// bail out...
454
440
QMessageBox::critical ( 0 , tr ( " Error" ), tr ( " The feature could not be added because removing the polygon intersections would change the geometry type" ) );
455
441
delete f;
456
- delete mRubberBand ;
457
- mRubberBand = 0 ;
458
- mCaptureList .clear ();
442
+ stopCapturing ();
459
443
return ;
460
444
}
461
445
else if ( avoidIntersectionsReturn == 3 )
@@ -510,12 +494,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
510
494
}
511
495
delete f;
512
496
513
- delete mRubberBand ;
514
- mRubberBand = NULL ;
515
-
516
- // delete the elements of mCaptureList
517
- mCaptureList .clear ();
518
- mCanvas ->refresh ();
497
+ stopCapturing ();
519
498
}
520
499
}
521
500
}
0 commit comments