fix_node_tool.patch

Leyan Ouyang, 2012-02-19 11:53 AM

Download (10.4 KB)

View differences:

src/app/nodetool/qgsmaptoolnodetool.cpp
257 257
      QList<QgsSnappingResult> snapResults;
258 258
      QgsPoint firstCoords = mCanvas->getCoordinateTransform()->toMapPoint( mLastCoordinates->x(), mLastCoordinates->y() );
259 259
      QList<QgsPoint> excludePoints;
260
      excludePoints.append( mClosestVertex );
260
      excludePoints.append( mSnapResult.snappedVertex );
261 261
      mSnapper.snapToBackgroundLayers( e->pos(), snapResults, excludePoints );
262 262
      // get correct coordinates to move
263 263
      QgsPoint posMapCoord = snapPointFromResults( snapResults, e->pos() );
264 264
      if ( snapResults.size() > 0 )
265 265
      {
266
        firstCoords = toMapCoordinates( vlayer, mClosestVertex );
266
        firstCoords = toMapCoordinates( vlayer, mSnapResult.snappedVertex );
267 267
      }
268 268

  
269 269
      // special handling of points
......
348 348
  QList<QgsSnappingResult> snapResults;
349 349
  if ( !mSelectedFeature )
350 350
  {
351
    mSelectAnother = false;
351
    mSelectAnother = true;
352 352
    mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertexAndSegment, -1 );
353 353

  
354 354
    if ( snapResults.size() < 1 )
......
356 356
      displaySnapToleranceWarning();
357 357
      return;
358 358
    }
359

  
360
    mSelectedFeature = new QgsSelectedFeature( snapResults[0].snappedAtGeometry, vlayer, mCanvas );
359
    mAnother=snapResults[0].snappedAtGeometry;
360
    mSelectedFeature = new QgsSelectedFeature( mAnother, vlayer, mCanvas );
361 361
    connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) );
362 362
    mIsPoint = vlayer->geometryType() == QGis::Point;
363 363
  }
......
367 367
    QgsPoint mapCoordPoint = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
368 368
    double tol = QgsTolerance::vertexSearchRadius( vlayer, mCanvas->mapRenderer() );
369 369

  
370
    // get geometry and find if snapping is near it
371
    int atVertex, beforeVertex, afterVertex;
372
    double dist;
373
    mSelectedFeature->geometry()->closestVertex( toLayerCoordinates( vlayer, mapCoordPoint ), atVertex, beforeVertex, afterVertex, dist );
374
    dist = sqrt( dist );
370
    mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertexAndSegment, tol );
375 371

  
376
    mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertex, tol );
377
    if ( dist > tol )
372
    if ( snapResults.size() > 0 )
378 373
    {
379
      // for points only selecting another feature
380
      // no vertexes found (selecting or inverting selection) if move
381
      // or select another feature if clicked there
382
      mSnapper.snapToCurrentLayer( e->pos(), snapResults, mIsPoint ? QgsSnapper::SnapToVertex : QgsSnapper::SnapToSegment, tol );
383
      if ( snapResults.size() > 0 )
384
      {
385 374
        // need to check all if there is a point in my selected feature
386 375
        mAnother = snapResults.first().snappedAtGeometry;
376
        mSnapResult=snapResults[0];
387 377
        mSelectAnother = true;
388 378
        QList<QgsSnappingResult>::iterator it = snapResults.begin();
389
        QgsSnappingResult snapResult;
390 379
        for ( ; it != snapResults.end(); ++it )
391 380
        {
392 381
          if ( it->snappedAtGeometry == mSelectedFeature->featureId() )
393 382
          {
394
            snapResult = *it;
383
            mSnapResult = *it;
395 384
            mAnother = 0;
396 385
            mSelectAnother = false;
397 386
            break;
......
401 390
        if ( !mSelectAnother )
402 391
        {
403 392
          mMoving = true;
404
          QgsPoint point = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
405
          mClosestVertex = closestVertex( toLayerCoordinates( vlayer, point ) );
406 393

  
407
          if ( mIsPoint )
394
          if ( mSnapResult.snappedVertexNr!=-1 )
408 395
          {
409
            if ( !mCtrl )
396
            if ( !mSelectedFeature->isSelected( mSnapResult.snappedVertexNr ) )
410 397
            {
411
              mSelectedFeature->deselectAllVertexes();
412
              mSelectedFeature->selectVertex( snapResult.snappedVertexNr );
413
            }
414
            else
415
            {
416
              mSelectedFeature->invertVertexSelection( snapResult.snappedVertexNr );
398
              if ( !mCtrl )
399
              {
400
                mSelectedFeature->deselectAllVertexes();
401
              }
402
              mSelectedFeature->selectVertex( mSnapResult.snappedVertexNr );
417 403
            }
418 404
          }
419
          else if ( !mSelectedFeature->isSelected( snapResult.beforeVertexNr ) ||
420
                    !mSelectedFeature->isSelected( snapResult.afterVertexNr ) )
405
          else
421 406
          {
422
            if ( !mCtrl )
423
            {
424
              mSelectedFeature->deselectAllVertexes();
425
              mSelectedFeature->selectVertex( snapResult.afterVertexNr );
426
              mSelectedFeature->selectVertex( snapResult.beforeVertexNr );
427
            }
428
            else
407
            //Snapped to a segment
408
            if( !mSelectedFeature->isSelected( mSnapResult.beforeVertexNr ) ||
409
                !mSelectedFeature->isSelected( mSnapResult.afterVertexNr ) )
429 410
            {
430
              mSelectedFeature->invertVertexSelection( snapResult.afterVertexNr );
431
              mSelectedFeature->invertVertexSelection( snapResult.beforeVertexNr );
411
              if( !mCtrl )
412
              {
413
                mSelectedFeature->deselectAllVertexes();
414
              }
415
              mSelectedFeature->selectVertex( mSnapResult.afterVertexNr );
416
              mSelectedFeature->selectVertex( mSnapResult.beforeVertexNr );
432 417
            }
433 418
          }
434 419
        }
435
      }
436
      else if ( !mCtrl )
437
      {
438
        mSelectedFeature->deselectAllVertexes();
439
      }
440
    }
441
    else
442
    {
443
      // some vertex selected
444
      mMoving = true;
445
      QgsPoint point = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
446
      mClosestVertex = closestVertex( toLayerCoordinates( vlayer, point ) );
447
      if ( mMoving )
448
      {
449
        if ( mCtrl )
450
        {
451
          mSelectedFeature->invertVertexSelection( atVertex );
452
        }
420

  
453 421
        else
454 422
        {
455
          mSelectedFeature->deselectAllVertexes();
456
          mSelectedFeature->selectVertex( atVertex );
423
          // select another feature
424
          mAnother = snapResults.first().snappedAtGeometry;
425
          mSelectAnother = true;
457 426
        }
458 427
      }
459
      else
428
      else if ( !mCtrl )
460 429
      {
461
        // select another feature
462
        mAnother = snapResults.first().snappedAtGeometry;
463
        mSelectAnother = true;
430
        mSelectedFeature->deselectAllVertexes();
464 431
      }
465 432
    }
466
  }
467 433
  QgsDebugMsg( "Leaving." );
468 434
}
469 435

  
......
506 472
      mIsPoint = vlayer->geometryType() == QGis::Point;
507 473
      mSelectAnother = false;
508 474
    }
475
    else
476
    {
477
      if( !mCtrl )
478
      {
479
        if( mSnapResult.snappedVertexNr!=-1 )
480
        {
481
          bool selected=mSelectedFeature->isSelected( mSnapResult.snappedVertexNr );
482
          mSelectedFeature->deselectAllVertexes();
483
          if( selected )
484
          {
485
            mSelectedFeature->selectVertex( mSnapResult.snappedVertexNr );
486
          }
487
        }
488
        else
489
        {
490
          bool selected=mSelectedFeature->isSelected( mSnapResult.beforeVertexNr ) ||
491
            mSelectedFeature->isSelected( mSnapResult.afterVertexNr );
492
          mSelectedFeature->deselectAllVertexes();
493
          if( selected )
494
          {
495
            mSelectedFeature->selectVertex( mSnapResult.beforeVertexNr );
496
            mSelectedFeature->selectVertex( mSnapResult.afterVertexNr );
497
          }
498
        }
499
      }
500
    }
509 501
  }
510 502
  else
511 503
  {
......
544 536
      QList<QgsSnappingResult> snapResults;
545 537
      QgsPoint firstCoords = mCanvas->getCoordinateTransform()->toMapPoint( mLastCoordinates->x(), mLastCoordinates->y() );
546 538
      QList<QgsPoint> excludePoints;
547
      excludePoints.append( mClosestVertex );
539
      excludePoints.append( mSnapResult.snappedVertex );
548 540
      mSnapper.snapToBackgroundLayers( e->pos(), snapResults, excludePoints );
549 541
      coords = snapPointFromResults( snapResults, e->pos() );
550 542
      // coords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
551 543
      int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
552 544
      if ( snapResults.size() > 0 )
553 545
      {
554
        firstCoords = toMapCoordinates( vlayer, mClosestVertex );
546
        firstCoords = toMapCoordinates( vlayer, mSnapResult.snappedVertex );
555 547
        if ( topologicalEditing )
556 548
        {
557 549
          insertSegmentVerticesForSnap( snapResults, vlayer );
......
686 678
  mCanvas->refresh();
687 679
}
688 680

  
689
QgsPoint QgsMapToolNodeTool::closestVertex( QgsPoint point )
690
{
691
  int at;
692
  int before;
693
  int after;
694
  double dist;
695
  return mSelectedFeature->geometry()->closestVertex( point, at, before, after, dist );
696
}
697

  
698 681
void QgsMapToolNodeTool::keyPressEvent( QKeyEvent* e )
699 682
{
700 683
  if ( e->key() == Qt::Key_Control )
src/app/nodetool/qgsmaptoolnodetool.h
52 52
    //! called when map tool is being deactivated
53 53
    void deactivate();
54 54

  
55
    /**
56
     * Returns closest vertex to given point from selected feature
57
     */
58
    QgsPoint closestVertex( QgsPoint point );
59

  
60 55
  public slots:
61 56
    void selectedFeatureDestroyed();
62 57

  
......
134 129
    /** stored position of last press down action to count how much vertexes should be moved */
135 130
    QgsPoint* mLastCoordinates;
136 131

  
137
    /** closest vertex to click */
138
    QgsPoint mClosestVertex;
139

  
140 132
    /** backup of map coordinates to be able to count change between moves */
141 133
    QgsPoint mPosMapCoordBackup;
142 134

  
......
148 140

  
149 141
    /** flag to tell if edition points */
150 142
    bool mIsPoint;
143

  
144
    /** Snap result where user clicked */
145
    QgsSnappingResult mSnapResult;
146

  
151 147
};
152 148

  
153 149
#endif