Skip to content

Commit 21f9dcd

Browse files
committedJan 4, 2012
nodetool fixes (fixes #4523, #4737 & #4738)
1 parent a753fb0 commit 21f9dcd

File tree

2 files changed

+118
-117
lines changed

2 files changed

+118
-117
lines changed
 

‎src/app/qgsmaptoolnodetool.cpp

Lines changed: 115 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void VertexEntry::update()
112112

113113
QgsRubberBand* QgsMapToolNodeTool::createRubberBandMarker( QgsPoint center, QgsVectorLayer* vlayer )
114114
{
115-
//create rubber band marker for moving points
115+
// create rubberband marker for moving points
116116
QgsRubberBand* marker = new QgsRubberBand( mCanvas, true );
117117
marker->setColor( Qt::red );
118118
marker->setWidth( 2 );
@@ -143,14 +143,14 @@ QgsMapToolNodeTool::QgsMapToolNodeTool( QgsMapCanvas* canvas ): QgsMapToolVertex
143143
mClicked = false;
144144
mChangingGeometry = false;
145145
mIsPoint = false;
146-
//signal handling change of layer structure
146+
// signal handling change of layer structure
147147
connect( canvas, SIGNAL( layersChanged() ), this, SLOT( layersChanged() ) );
148-
//signal when destination srs changed to repaint coordinates
148+
// signal when destination srs changed to repaint coordinates
149149
connect( canvas->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( coordinatesChanged() ) );
150-
//signal changing of coordinate renderer changed to repaint markers
150+
// signal changing of coordinate renderer changed to repaint markers
151151
connect( canvas->mapRenderer(), SIGNAL( hasCrsTransformEnabled( bool ) ), this, SLOT( coordinatesChanged() ) );
152152
connect( canvas, SIGNAL( extentsChanged() ), this, SLOT( coordinatesChanged() ) );
153-
//signal changing of current layer
153+
// signal changing of current layer
154154
connect( QgisApp::instance()->legend(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ),
155155
this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
156156
}
@@ -162,7 +162,7 @@ QgsMapToolNodeTool::~QgsMapToolNodeTool()
162162

163163
void QgsMapToolNodeTool::layersChanged()
164164
{
165-
//deselection of feature when layer has changed
165+
// deselection of feature when layer has changed
166166
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
167167
if ( mSelectionFeature != NULL && mSelectionFeature->vlayer() != vlayer )
168168
{
@@ -173,7 +173,7 @@ void QgsMapToolNodeTool::layersChanged()
173173

174174
void QgsMapToolNodeTool::currentLayerChanged( QgsMapLayer* layer )
175175
{
176-
//deselection of feature when current layer has changed
176+
// deselection of feature when current layer has changed
177177
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer );
178178
if ( mSelectionFeature != NULL && mSelectionFeature->vlayer() != vlayer )
179179
{
@@ -185,10 +185,10 @@ void QgsMapToolNodeTool::currentLayerChanged( QgsMapLayer* layer )
185185

186186
void QgsMapToolNodeTool::featureDeleted( QgsFeatureId featureId )
187187
{
188-
//check if deleted feature is the one selected
188+
// check if deleted feature is the one selected
189189
if ( mSelectionFeature != NULL && featureId == mSelectionFeature->featureId() )
190190
{
191-
//if it's delete selection and disconnect signals since tool is not used anymore
191+
// if it's delete selection and disconnect signals since tool is not used anymore
192192
delete mSelectionFeature;
193193
mSelectionFeature = NULL;
194194
disconnect( mCanvas->currentLayer(), SIGNAL( featureDeleted( QgsFeatureId ) ) );
@@ -199,15 +199,15 @@ void QgsMapToolNodeTool::featureDeleted( QgsFeatureId featureId )
199199
void QgsMapToolNodeTool::layerModified( bool onlyGeometry )
200200
{
201201
Q_UNUSED( onlyGeometry );
202-
//handling modification of
202+
// handling modification of
203203
QgsFeature feat;
204204
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
205205
if ( mSelectionFeature && !mChangingGeometry && vlayer->featureAtId( mSelectionFeature->featureId(), feat, true, false ) )
206206
{
207207
if ( !feat.geometry()->isGeosEqual( *mSelectionFeature->feature()->geometry() ) )
208208
{
209209
mSelectionFeature->updateFromFeature();
210-
//throw error
210+
// throw error
211211
}
212212
}
213213
}
@@ -224,81 +224,83 @@ void QgsMapToolNodeTool::createMovingRubberBands()
224224
int vertex;
225225
for ( int i = 0; i < vertexMap.size(); i++ )
226226
{
227-
//create rubber band
227+
// create rubberband
228228
if ( vertexMap[i]->isSelected() && !vertexMap[i]->isInRubberBand() )
229229
{
230230
geometry->adjacentVertices( i, beforeVertex, afterVertex );
231231
vertex = i;
232232
while ( beforeVertex != -1 )
233-
{ //move forward NOTE: end if whole cycle is selected
234-
if ( vertexMap[beforeVertex]->isSelected() && beforeVertex != i ) //and take care of cycles
233+
{
234+
// move forward NOTE: end if whole cycle is selected
235+
if ( vertexMap[beforeVertex]->isSelected() && beforeVertex != i ) // and take care of cycles
235236
{
236237
vertex = beforeVertex;
237238
geometry->adjacentVertices( vertex, beforeVertex, afterVertex );
238239
}
239240
else
240-
{ //break if cycle is found
241+
{
242+
// break if cycle is found
241243
break;
242244
}
243245
}
244-
//we have first vertex of moving part
245-
//create rubber band and set default paramaters
246+
// we have first vertex of moving part
247+
// create rubberband and set default paramaters
246248
QgsRubberBand* rb = new QgsRubberBand( mCanvas, false );
247249
rb->setWidth( 2 );
248250
rb->setColor( Qt::blue );
249251
int index = 0;
250-
if ( beforeVertex != -1 ) //adding first point which is not moving
252+
if ( beforeVertex != -1 ) // adding first point which is not moving
251253
{
252254
rb->addPoint( toMapCoordinates( mCanvas->currentLayer(), vertexMap[beforeVertex]->point() ), false );
253255
vertexMap[beforeVertex]->setRubberBandValues( true, lastRubberBand, index );
254256
index++;
255257
}
256258
while ( vertex != -1 && vertexMap[vertex]->isSelected() && !vertexMap[vertex]->isInRubberBand() )
257259
{
258-
//topology rubber band creation if needed
260+
// topology rubberband creation if needed
259261
if ( topologicalEditing )
260262
{
261-
createTopologyRubbedBands( vlayer, vertexMap, vertex );
263+
createTopologyRubberBands( vlayer, vertexMap, vertex );
262264
}
263-
//adding point which will be moved
265+
// adding point which will be moved
264266
rb->addPoint( toMapCoordinates( mCanvas->currentLayer(), vertexMap[vertex]->point() ), false );
265-
//setting values about added vertex
267+
// setting values about added vertex
266268
vertexMap[vertex]->setRubberBandValues( true, lastRubberBand, index );
267269
index++;
268270
geometry->adjacentVertices( vertex, beforeVertex, vertex );
269271
}
270-
if ( vertex != -1 && !vertexMap[vertex]->isSelected() ) //add last point not moving if exists
272+
if ( vertex != -1 && !vertexMap[vertex]->isSelected() ) // add last point not moving if exists
271273
{
272274
rb->addPoint( toMapCoordinates( mCanvas->currentLayer(), vertexMap[vertex]->point() ), true );
273275
vertexMap[vertex]->setRubberBandValues( true, lastRubberBand, index );
274276
index++;
275277
}
276-
mQgsRubberBands.append( rb );
278+
mRubberBands.append( rb );
277279
lastRubberBand++;
278280
}
279281
}
280282
}
281283

282-
void QgsMapToolNodeTool::createTopologyRubbedBands( QgsVectorLayer* vlayer, const QList<VertexEntry*> &vertexMap, int vertex )
284+
void QgsMapToolNodeTool::createTopologyRubberBands( QgsVectorLayer* vlayer, const QList<VertexEntry*> &vertexMap, int vertex )
283285
{
284286
QMultiMap<double, QgsSnappingResult> currentResultList;
285287
QgsGeometry* geometry = mSelectionFeature->feature()->geometry();
286288

287-
//snapp from current vertex
289+
// snap from current vertex
288290
currentResultList.clear();
289291
vlayer->snapWithContext( vertexMap[vertex]->point(), ZERO_TOLERANCE, currentResultList, QgsSnapper::SnapToVertex );
290292
QMultiMap<double, QgsSnappingResult>::iterator resultIt = currentResultList.begin();
291293

292294
for ( ; resultIt != currentResultList.end(); ++resultIt )
293295
{
294-
//move all other
296+
// move all other
295297
if ( mSelectionFeature->featureId() != resultIt.value().snappedAtGeometry )
296298
{
297299
if ( mTopologyMovingVertexes.contains( resultIt.value().snappedAtGeometry ) )
298300
{
299301
if ( mTopologyMovingVertexes[resultIt.value().snappedAtGeometry]->contains( resultIt.value().snappedVertexNr ) )
300302
{
301-
//skip vertex already exists in some rubberband
303+
// skip vertex already exists in some rubberband
302304
continue;
303305
}
304306
}
@@ -310,26 +312,26 @@ void QgsMapToolNodeTool::createTopologyRubbedBands( QgsVectorLayer* vlayer, cons
310312

311313
int tVertex = resultIt.value().snappedVertexNr;
312314
int tVertexBackup = -1, tVertexAfter = -1;
313-
int tVertexFirst = tVertex;//vertex number to check for cycling
315+
int tVertexFirst = tVertex; // vertex number to check for cycling
314316
QgsFeature topolFeature;
315317

316318
vlayer->featureAtId( resultIt.value().snappedAtGeometry, topolFeature, true, false );
317319
QgsGeometry* topolGeometry = topolFeature.geometry();
318320

319-
while ( tVertex != -1 ) //looking for first vertex to rubber band
321+
while ( tVertex != -1 ) // looking for first vertex to rubberband
320322
{
321323
tVertexBackup = tVertex;
322324
topolGeometry->adjacentVertices( tVertex, tVertex, tVertexAfter );
323325
if ( tVertex == -1 || tVertex == tVertexFirst )
324-
break;//chceck if this is not first vertex of the feature or cycling error
325-
//if closest vertex is not from selected feature or is not selected end
326+
break; // check if this is not first vertex of the feature or cycling error
327+
// if closest vertex is not from selected feature or is not selected end
326328
double dist;
327329
QgsPoint point = topolGeometry->vertexAt( tVertex );
328330
int at, before, after;
329331
geometry->closestVertex( point, at, before, after, dist );
330-
if ( dist > ZERO_TOLERANCE || !vertexMap[at]->isSelected() ) //problem with double precision
332+
if ( dist > ZERO_TOLERANCE || !vertexMap[at]->isSelected() ) // problem with double precision
331333
{
332-
break; //found first vertex
334+
break; // found first vertex
333335
}
334336
}
335337

@@ -340,14 +342,14 @@ void QgsMapToolNodeTool::createTopologyRubbedBands( QgsVectorLayer* vlayer, cons
340342
{
341343
addedPoints = mTopologyMovingVertexes[ resultIt.value().snappedAtGeometry ];
342344
}
343-
if ( tVertex == -1 ) //adding first point if needed
345+
if ( tVertex == -1 ) // adding first point if needed
344346
{
345347
tVertex = tVertexBackup;
346348
}
347349
else
348350
{
349351
trb->addPoint( topolGeometry->vertexAt( tVertex ) );
350-
if ( tVertex == tVertexFirst ) //cycle first vertex need to be added also
352+
if ( tVertex == tVertexFirst ) // cycle first vertex need to be added also
351353
{
352354
movingPoints->insert( movingPointIndex );
353355
}
@@ -357,21 +359,21 @@ void QgsMapToolNodeTool::createTopologyRubbedBands( QgsVectorLayer* vlayer, cons
357359

358360
while ( tVertex != -1 )
359361
{
360-
//if closest vertex is not from selected feature or is not selected end
362+
// if closest vertex is not from selected feature or is not selected end
361363
double dist;
362364
QgsPoint point = topolGeometry->vertexAt( tVertex );
363365
int at, before, after;
364366
geometry->closestVertex( point, at, before, after, dist );
365367
// find first no matching vertex
366-
if ( dist > ZERO_TOLERANCE || !vertexMap[at]->isSelected() ) //problem with double precision
368+
if ( dist > ZERO_TOLERANCE || !vertexMap[at]->isSelected() ) // problem with double precision
367369
{
368370
trb->addPoint( topolGeometry->vertexAt( tVertex ) );
369-
break; //found first vertex
371+
break; // found first vertex
370372
}
371-
else //add moving point to rubber band
373+
else // add moving point to rubberband
372374
{
373375
if ( addedPoints->contains( tVertex ) )
374-
break; //just preventing to circle
376+
break; // just preventing to circle
375377
trb->addPoint( topolGeometry->vertexAt( tVertex ) );
376378
movingPoints->insert( movingPointIndex );
377379
movingPointIndex++;
@@ -387,7 +389,7 @@ void QgsMapToolNodeTool::createTopologyRubbedBands( QgsVectorLayer* vlayer, cons
387389

388390
void QgsMapToolNodeTool::coordinatesChanged()
389391
{
390-
//need to update vertex markers since coordinate systems have changed
392+
// need to update vertex markers since coordinate systems have changed
391393
if ( mSelectionFeature != NULL )
392394
{
393395
mSelectionFeature->updateVertexMarkersPosition();
@@ -412,8 +414,8 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
412414
mSelectAnother = false;
413415
if ( mMoving )
414416
{
415-
//create rubberband if none exists
416-
if ( mQgsRubberBands.empty() )
417+
// create rubberband if none exists
418+
if ( mRubberBands.empty() )
417419
{
418420
if ( mIsPoint )
419421
{
@@ -423,7 +425,7 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
423425
if ( vertexMap[i]->isSelected() )
424426
{
425427
QgsRubberBand* rb = createRubberBandMarker( vertexMap[i]->point(), vlayer );
426-
mQgsRubberBands.append( rb );
428+
mRubberBands.append( rb );
427429
}
428430
}
429431
}
@@ -434,32 +436,32 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
434436
}
435437
else
436438
{
437-
//move rubber band
439+
// move rubberband
438440
QList<QgsSnappingResult> snapResults;
439441
QgsPoint firstCoords = mCanvas->getCoordinateTransform()->toMapPoint( mLastCoordinates->x(), mLastCoordinates->y() );
440442
QList<QgsPoint> excludePoints;
441443
excludePoints.append( mClosestVertex );
442444
mSnapper.snapToBackgroundLayers( e->pos(), snapResults, excludePoints );
443-
//get correct coordinates to move
445+
// get correct coordinates to move
444446
QgsPoint posMapCoord = snapPointFromResults( snapResults, e->pos() );
445447
if ( snapResults.size() > 0 )
446448
{
447449
firstCoords = toMapCoordinates( vlayer, mClosestVertex );
448450
}
449451

450-
//special handling of points
452+
// special handling of points
451453
if ( mIsPoint )
452454
{
453455
double offsetX = posMapCoord.x() - firstCoords.x();
454456
double offsetY = posMapCoord.y() - firstCoords.y();
455-
for ( int i = 0; i < mQgsRubberBands.size(); i++ )
457+
for ( int i = 0; i < mRubberBands.size(); i++ )
456458
{
457-
mQgsRubberBands[i]->setTranslationOffset( offsetX, offsetY );
459+
mRubberBands[i]->setTranslationOffset( offsetX, offsetY );
458460
}
459461
return;
460462
}
461463

462-
//move points
464+
// move points
463465
QList<VertexEntry*> &vertexMap = mSelectionFeature->vertexMap();
464466
for ( int i = 0; i < vertexMap.size(); i++ )
465467
{
@@ -470,15 +472,15 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
470472
double x = mapCoords.x() + posMapCoord.x() - firstCoords.x();
471473
double y = mapCoords.y() + posMapCoord.y() - firstCoords.y();
472474

473-
mQgsRubberBands[vertexMap[i]->rubberBandNr()]->movePoint( vertexMap[i]->index(), QgsPoint( x, y ) );
475+
mRubberBands[vertexMap[i]->rubberBandNr()]->movePoint( vertexMap[i]->index(), QgsPoint( x, y ) );
474476
if ( vertexMap[i]->index() == 0 )
475477
{
476-
mQgsRubberBands[vertexMap[i]->rubberBandNr()]->movePoint( 0, QgsPoint( x, y ) );
478+
mRubberBands[vertexMap[i]->rubberBandNr()]->movePoint( 0, QgsPoint( x, y ) );
477479
}
478480
}
479481
}
480482

481-
//topological editing
483+
// topological editing
482484
double offsetX = posMapCoord.x() - mPosMapCoordBackup.x();
483485
double offsetY = posMapCoord.y() - mPosMapCoordBackup.y();
484486
for ( int i = 0; i < mTopologyRubberBand.size(); i++ )
@@ -546,7 +548,7 @@ bool QgsMapToolNodeTool::checkCorrectnessOfFeature( QgsVectorLayer *vlayer )
546548
{
547549
if ( !feat.geometry()->isGeosEqual( *mSelectionFeature->feature()->geometry() ) )
548550
{
549-
//update markers when geometries are not valid
551+
// update markers when geometries are not valid
550552
mSelectionFeature->updateFromFeature();
551553
}
552554
}
@@ -583,22 +585,22 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
583585
return;
584586
}
585587
mSelectionFeature = new SelectionFeature();
586-
mSelectionFeature->setSelectedFeature( snapResults[0].snappedAtGeometry, vlayer, NULL, mCanvas );
588+
mSelectionFeature->setSelectedFeature( snapResults[0].snappedAtGeometry, vlayer, NULL, mCanvas );
587589
mIsPoint = vlayer->dataProvider()->geometryType() == QGis::WKBPoint
588590
|| vlayer->dataProvider()->geometryType() == QGis::WKBMultiPoint;
589591
connectSignals( vlayer );
590592
}
591593
else
592594
{
593-
//check if feature is not modified from backgound and still exists
594-
//Note this code should never be reached signals should handle this error
595+
// check if feature is not modified from background and still exists
596+
// Note this code should never be reached signals should handle this error
595597
if ( !checkCorrectnessOfFeature( vlayer ) )
596598
return;
597599

598-
//some feature already selected
600+
// some feature already selected
599601
QgsPoint mapCoordPoint = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
600602
double tol = QgsTolerance::vertexSearchRadius( vlayer, mCanvas->mapRenderer() );
601-
//get geometry and find if snapping is near it
603+
// get geometry and find if snapping is near it
602604
QgsFeature f;
603605
vlayer->featureAtId( mSelectionFeature->featureId(), f, true, false );
604606
QgsGeometry* g = f.geometry();
@@ -608,12 +610,12 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
608610
dist = sqrt( dist );
609611

610612
mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertex, tol );
611-
//if (snapResults.size() < 1)
613+
// if (snapResults.size() < 1)
612614
if ( dist > tol )
613615
{
614-
//for points only selecting another feature
615-
//no vertexes found (selecting or inverting selection) if move
616-
//or select another feature if clicked there
616+
// for points only selecting another feature
617+
// no vertexes found (selecting or inverting selection) if move
618+
// or select another feature if clicked there
617619
QgsSnapper::SnappingType snapType = QgsSnapper::SnapToSegment;
618620
if ( mIsPoint )
619621
{
@@ -622,7 +624,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
622624
mSnapper.snapToCurrentLayer( e->pos(), snapResults, snapType, tol );
623625
if ( snapResults.size() > 0 )
624626
{
625-
//need to check all if there is a point in my selected feature
627+
// need to check all if there is a point in my selected feature
626628
mAnother = snapResults.first().snappedAtGeometry;
627629
mSelectAnother = true;
628630
QList<QgsSnappingResult>::iterator it = snapResults.begin();
@@ -661,7 +663,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
661663
}
662664
else
663665
{
664-
//some vertex selected
666+
// some vertex selected
665667
mMoving = true;
666668
QgsPoint point = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
667669
mClosestVertex = getClosestVertex( toLayerCoordinates( vlayer, point ) );
@@ -682,7 +684,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
682684
}
683685
else
684686
{
685-
//select another feature
687+
// select another feature
686688
mAnother = snapResults.first().snappedAtGeometry;
687689
mSelectAnother = true;
688690
}
@@ -709,8 +711,8 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
709711
mClicked = false;
710712
mSelectionRectangle = false;
711713
QgsPoint coords = toMapCoordinates( e->pos() );
712-
//QgsPoint coords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
713-
//QgsPoint firstCoords = toMapCoordinates( *mLastCoordinates );
714+
// QgsPoint coords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
715+
// QgsPoint firstCoords = toMapCoordinates( *mLastCoordinates );
714716
QgsPoint firstCoords = mCanvas->getCoordinateTransform()->toMapPoint( mLastCoordinates->x(), mLastCoordinates->y() );
715717
if ( mQRubberBand != NULL )
716718
{
@@ -722,7 +724,7 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
722724
{
723725
if ( mSelectAnother )
724726
{
725-
//select another feature (this should deselect current one ;-) )
727+
// select another feature (this should deselect current one ;-) )
726728
mSelectionFeature->setSelectedFeature( mAnother, vlayer, NULL, mCanvas );
727729
mIsPoint = vlayer->dataProvider()->geometryType() == QGis::WKBPoint ||
728730
vlayer->dataProvider()->geometryType() == QGis::WKBMultiPoint;
@@ -735,7 +737,7 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
735737
QgsPoint layerCoords = toLayerCoordinates( vlayer, coords );
736738
QgsPoint layerFirstCoords = toLayerCoordinates( vlayer, firstCoords );
737739

738-
//got correct coordinates
740+
// got correct coordinates
739741
double topX;
740742
double bottomX;
741743
if ( layerCoords.x() > layerFirstCoords.x() )
@@ -769,7 +771,7 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
769771
excludePoints.append( mClosestVertex );
770772
mSnapper.snapToBackgroundLayers( e->pos(), snapResults, excludePoints );
771773
coords = snapPointFromResults( snapResults, e->pos() );
772-
//coords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
774+
// coords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
773775
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
774776
if ( snapResults.size() > 0 )
775777
{
@@ -787,9 +789,9 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
787789
mSelectionFeature->moveSelectedVertexes( changeX, changeY );
788790
mCanvas->refresh();
789791
mChangingGeometry = false;
790-
//movingVertexes
792+
// movingVertexes
791793
}
792-
else //selecting vertexes by rubber band
794+
else // selecting vertexes by rubberband
793795
{
794796
QList<VertexEntry*> &vertexMap = mSelectionFeature->vertexMap();
795797
if ( !mCtrl )
@@ -801,7 +803,7 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
801803
if ( vertexMap[i]->point().x() < bottomX && vertexMap[i]->point().y() > leftY
802804
&& vertexMap[i]->point().x() > topX && vertexMap[i]->point().y() < rightY )
803805
{
804-
//inverting selection is enough because all were deselected if ctrl is not pressed
806+
// inverting selection is enough because all were deselected if ctrl is not pressed
805807
mSelectionFeature->invertVertexSelection( i, false );
806808
}
807809
}
@@ -835,25 +837,23 @@ void QgsMapToolNodeTool::deactivate()
835837

836838
void QgsMapToolNodeTool::removeRubberBands()
837839
{
838-
//cleanup rubber bands and list
839-
QList<QgsRubberBand*>::iterator rb_it = mQgsRubberBands.begin();
840-
for ( ; rb_it != mQgsRubberBands.end(); ++rb_it )
840+
// cleanup rubberbands and list
841+
foreach( QgsRubberBand *rb, mRubberBands )
841842
{
842-
delete *rb_it;
843+
delete rb;
843844
}
844-
mQgsRubberBands.clear();
845+
mRubberBands.clear();
845846

846-
rb_it = mTopologyRubberBand.begin();
847-
for ( ; rb_it != mTopologyRubberBand.end(); ++rb_it )
847+
foreach( QgsRubberBand *rb, mTopologyRubberBand )
848848
{
849-
delete *rb_it;
849+
delete rb;
850850
}
851851
mTopologyRubberBand.clear();
852852

853853
mTopologyMovingVertexes.clear();
854854
mTopologyRubberBandVertexes.clear();
855855

856-
//remove all data from selected feature (no change to rubber bands itself)
856+
// remove all data from selected feature (no change to rubberbands itself)
857857
if ( mSelectionFeature != NULL )
858858
mSelectionFeature->cleanRubberBandsData();
859859
}
@@ -876,11 +876,11 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QMouseEvent * e )
876876
mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToSegment, tol );
877877
if ( snapResults.size() < 1 )
878878
{
879-
//nowhere to pul vertex
879+
// nowhere to put vertex
880880
}
881881
else
882882
{
883-
//some segment selected
883+
// some segment selected
884884
if ( snapResults.first().snappedAtGeometry == mSelectionFeature->featureId() )
885885
{
886886
if ( snapResults.first().snappedVertexNr == -1 )
@@ -889,15 +889,15 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QMouseEvent * e )
889889
QgsPoint layerCoords = toLayerCoordinates( vlayer, coords );
890890
if ( topologicalEditing )
891891
{
892-
//snapp from adding position to this vertex when topological editing is enabled
892+
// snap from adding position to this vertex when topological editing is enabled
893893
currentResultList.clear();
894894
vlayer->snapWithContext( layerCoords, ZERO_TOLERANCE, currentResultList, QgsSnapper::SnapToSegment );
895895
}
896896

897897
vlayer->beginEditCommand( tr( "Inserted vertex" ) );
898898
mChangingGeometry = true;
899899

900-
//add vertex
900+
// add vertex
901901
vlayer->insertVertex( layerCoords.x(), layerCoords.y(), mSelectionFeature->featureId(), snapResults.first().afterVertexNr );
902902

903903
if ( topologicalEditing )
@@ -906,7 +906,7 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QMouseEvent * e )
906906

907907
for ( ; resultIt != currentResultList.end(); ++resultIt )
908908
{
909-
//create vertexes on same position when topological editing is enabled
909+
// create vertexes on same position when topological editing is enabled
910910
if ( mSelectionFeature->featureId() != resultIt.value().snappedAtGeometry )
911911
vlayer->insertVertex( layerCoords.x(), layerCoords.y(), resultIt.value().snappedAtGeometry, resultIt.value().afterVertexNr );
912912
}
@@ -958,8 +958,7 @@ void QgsMapToolNodeTool::keyReleaseEvent( QKeyEvent* e )
958958
}
959959

960960

961-
//selection object
962-
961+
// selection object
963962

964963
SelectionFeature::SelectionFeature()
965964
{
@@ -1027,7 +1026,6 @@ void SelectionFeature::setSelectedFeature( QgsFeatureId featureId,
10271026
mFeature = feature;
10281027
}
10291028

1030-
//createvertexmap
10311029
createVertexMap();
10321030

10331031
validateGeometry();
@@ -1107,13 +1105,13 @@ void SelectionFeature::deleteSelectedVertexes()
11071105
{
11081106
if ( mVertexMap[i]->equals() != -1 )
11091107
{
1110-
//to avoid try to delete some vertex twice
1108+
// to avoid try to delete some vertex twice
11111109
mVertexMap[ mVertexMap[i]->equals()]->setSelected( false );
11121110
}
11131111

11141112
if ( topologicalEditing )
11151113
{
1116-
//snapp from current vertex
1114+
// snap from current vertex
11171115
currentResultList.clear();
11181116
mVlayer->snapWithContext( mVertexMap[i]->point(), ZERO_TOLERANCE, currentResultList, QgsSnapper::SnapToVertex );
11191117
}
@@ -1131,7 +1129,7 @@ void SelectionFeature::deleteSelectedVertexes()
11311129

11321130
for ( ; resultIt != currentResultList.end(); ++resultIt )
11331131
{
1134-
//move all other
1132+
// move all other
11351133
if ( mFeatureId != resultIt.value().snappedAtGeometry )
11361134
mVlayer->deleteVertex( resultIt.value().snappedAtGeometry, resultIt.value().snappedVertexNr );
11371135
}
@@ -1176,7 +1174,7 @@ void SelectionFeature::moveSelectedVertexes( double changeX, double changeY )
11761174
{
11771175
if ( topologicalEditing )
11781176
{
1179-
//snapp from current vertex
1177+
// snap from current vertex
11801178
currentResultList.clear();
11811179
mVlayer->snapWithContext( mVertexMap[i]->point(), ZERO_TOLERANCE, currentResultList, QgsSnapper::SnapToVertex );
11821180
}
@@ -1191,7 +1189,7 @@ void SelectionFeature::moveSelectedVertexes( double changeX, double changeY )
11911189

11921190
for ( ; resultIt != currentResultList.end(); ++resultIt )
11931191
{
1194-
//move all other
1192+
// move all other
11951193
if ( mFeatureId != resultIt.value().snappedAtGeometry )
11961194
mVlayer->moveVertex( mVertexMap[i]->point().x(), mVertexMap[i]->point().y(),
11971195
resultIt.value().snappedAtGeometry, resultIt.value().snappedVertexNr );
@@ -1207,7 +1205,7 @@ void SelectionFeature::moveSelectedVertexes( double changeX, double changeY )
12071205
{
12081206
mVertexMap[ entry->equals()]->moveCenter( changeX, changeY );
12091207
mVertexMap[ entry->equals()]->update();
1210-
//for polygon delete both
1208+
// for polygon delete both
12111209
}
12121210
}
12131211
}
@@ -1222,7 +1220,7 @@ void SelectionFeature::moveSelectedVertexes( double changeX, double changeY )
12221220
tr( "Result geometry is invalid. Reverting last changes." ),
12231221
QMessageBox::Ok ,
12241222
QMessageBox::Ok );
1225-
//redo last operations
1223+
// redo last operations
12261224
mVlayer->destroyEditCommand();
12271225
updateFromFeature();
12281226
}
@@ -1236,10 +1234,10 @@ void SelectionFeature::moveSelectedVertexes( double changeX, double changeY )
12361234

12371235
void SelectionFeature::updateFromFeature()
12381236
{
1239-
//delete old map
1237+
// delete old map
12401238
deleteVertexMap();
12411239

1242-
//create new map
1240+
// create new map
12431241
createVertexMap();
12441242
}
12451243

@@ -1268,7 +1266,8 @@ void SelectionFeature::createVertexMapPolygon()
12681266
int y = 0;
12691267
QgsPolygon polygon = mFeature->geometry()->asPolygon();
12701268
if ( !polygon.empty() )
1271-
{ //polygon
1269+
{
1270+
// polygon
12721271
for ( int i2 = 0; i2 < polygon.size(); i2++ )
12731272
{
12741273
const QgsPolyline& poly = polygon[i2];
@@ -1282,14 +1281,16 @@ void SelectionFeature::createVertexMapPolygon()
12821281
y += poly.size();
12831282
}
12841283
}
1285-
else //multipolygon
1284+
else // multipolygon
12861285
{
12871286
QgsMultiPolygon multiPolygon = mFeature->geometry()->asMultiPolygon();
12881287
for ( int i2 = 0; i2 < multiPolygon.size(); i2++ )
1289-
{ //iterating through polygons
1288+
{
1289+
// iterating through polygons
12901290
const QgsPolygon& poly2 = multiPolygon[i2];
12911291
for ( int i3 = 0; i3 < poly2.size(); i3++ )
1292-
{ //iterating through polygon rings
1292+
{
1293+
// iterating through polygon rings
12931294
const QgsPolyline& poly = poly2[i3];
12941295
int i;
12951296
for ( i = 0; i < poly.size(); i++ )
@@ -1312,7 +1313,7 @@ void SelectionFeature::createVertexMapLine()
13121313
QgsMultiPolyline mLine = mFeature->geometry()->asMultiPolyline();
13131314
for ( int i2 = 0; i2 < mLine.size(); i2++ )
13141315
{
1315-
//iterating through polylines
1316+
// iterating through polylines
13161317
QgsPolyline poly = mLine[i2];
13171318
int i;
13181319
for ( i = 0; i < poly.size(); i++ )
@@ -1337,25 +1338,25 @@ void SelectionFeature::createVertexMapPoint()
13371338
{
13381339
if ( mFeature->geometry()->isMultipart() )
13391340
{
1340-
//multipoint
1341+
// multipoint
13411342
QgsMultiPoint poly = mFeature->geometry()->asMultiPoint();
13421343
int i;
13431344
for ( i = 0; i < poly.size(); i++ )
13441345
{
1345-
mVertexMap[i] = new VertexEntry( mCanvas, mVlayer, poly[i], 1, tr( "point %1" ).arg( i ) );
1346+
mVertexMap.insert( i, new VertexEntry( mCanvas, mVlayer, poly[i], 1, tr( "point %1" ).arg( i ) ) );
13461347
}
13471348
}
13481349
else
13491350
{
1350-
//single point
1351-
mVertexMap[ 1] = new VertexEntry( mCanvas, mVlayer, mFeature->geometry()->asPoint(), 1, tr( "single point" ) );
1351+
// single point
1352+
mVertexMap.insert( 1, new VertexEntry( mCanvas, mVlayer, mFeature->geometry()->asPoint(), 1, tr( "single point" ) ) );
13521353
}
13531354
}
13541355

13551356
void SelectionFeature::createVertexMap()
13561357
{
13571358
mVlayer->featureAtId( mFeatureId, *mFeature );
1358-
//createvertexmap for correct geometry type
1359+
// createvertexmap for correct geometry type
13591360
if ( mFeature->geometry()->type() == QGis::Polygon )
13601361
{
13611362
createVertexMapPolygon();
@@ -1413,22 +1414,22 @@ void SelectionFeature::invertVertexSelection( int vertexNr, bool invert )
14131414
{
14141415
VertexEntry *entry = mVertexMap[vertexNr];
14151416

1416-
bool selected = entry->isSelected();
1417+
bool selected = !entry->isSelected();
14171418

14181419
entry->setSelected( selected );
14191420
entry->update();
14201421

14211422
if ( entry->equals() != -1 && invert )
14221423
{
1423-
entry = mVertexMap[ mVertexMap[vertexNr]->equals()];
1424+
entry = mVertexMap[ entry->equals()];
14241425
entry->setSelected( selected );
14251426
entry->update();
14261427
}
14271428
}
14281429

14291430
void SelectionFeature::updateVertexMarkersPosition()
14301431
{
1431-
//function for on-line updating vertex markers without refresh of canvas
1432+
// function for on-line updating vertex markers without refresh of canvas
14321433
for ( int i = 0; i < mVertexMap.size(); i++ )
14331434
{
14341435
VertexEntry *entry = mVertexMap[i];

‎src/app/qgsmaptoolnodetool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class SelectionFeature: public QObject
9393
* @param canvas mapCanvas on which we are working
9494
* @param feature feature with which we work this parameter is not mandatory if it's not filled feature will be loaded
9595
*/
96-
void setSelectedFeature( QgsFeatureId featureId, QgsVectorLayer* vlayer, QgsRubberBand* rubberBand, QgsMapCanvas* canvas, QgsFeature* feature = NULL );
96+
void setSelectedFeature( QgsFeatureId featureId, QgsVectorLayer* vlayer, QgsRubberBand* rubberBand, QgsMapCanvas* canvas, QgsFeature* feature = NULL );
9797

9898
/**
9999
* Function to select vertex with number
@@ -330,13 +330,13 @@ class QgsMapToolNodeTool: public QgsMapToolVertexEdit
330330
* @param vertexMap map of vertexes
331331
* @param vertex currently processed vertex
332332
*/
333-
void createTopologyRubbedBands( QgsVectorLayer* vlayer, const QList<VertexEntry*> &vertexMap, int vertex );
333+
void createTopologyRubberBands( QgsVectorLayer* vlayer, const QList<VertexEntry*> &vertexMap, int vertex );
334334

335335
/** The position of the vertex to move (in map coordinates) to exclude later from snapping*/
336336
QList<QgsPoint> mExcludePoint;
337337

338338
/** rubber bands */
339-
QList<QgsRubberBand*> mQgsRubberBands;
339+
QList<QgsRubberBand*> mRubberBands;
340340

341341
/** list of topology rubber bands */
342342
QList<QgsRubberBand*> mTopologyRubberBand;

0 commit comments

Comments
 (0)
Please sign in to comment.