rubberband_rotation.patch

Sandro Santilli, 2014-12-30 08:07 AM

Download (3.29 KB)

View differences:

src/gui/qgsrubberband.cpp
425 425

  
426 426
  const QgsMapToPixel* transform = mMapCanvas->getCoordinateTransform();
427 427
  QgsPoint ll = transform->toMapCoordinates( rect.left(), rect.bottom() );
428
  QgsPoint lr = transform->toMapCoordinates( rect.right(), rect.bottom() );
429
  QgsPoint ul = transform->toMapCoordinates( rect.left(), rect.top() );
428 430
  QgsPoint ur = transform->toMapCoordinates( rect.right(), rect.top() );
429 431

  
430 432
  reset( QGis::Polygon );
431 433
  addPoint( ll, false );
432
  addPoint( QgsPoint( ur.x(), ll.y() ), false );
434
  addPoint( lr, false );
435
  //addPoint( QgsPoint( ur.x(), ll.y() ), false );
433 436
  addPoint( ur, false );
434
  addPoint( QgsPoint( ll.x(), ur.y() ), true );
437
  //addPoint( QgsPoint( ll.x(), ur.y() ), true );
438
  addPoint( ul, true );
435 439
}
436 440

  
437 441
/*!
......
518 522

  
519 523
void QgsRubberBand::updateRect()
520 524
{
521
  if ( mPoints.size() > 0 )
525
  if ( mPoints.empty() )
522 526
  {
523
    //initial point
524
    QList<QgsPoint>::const_iterator it = mPoints.at( 0 ).constBegin();
525
    if ( it == mPoints.at( 0 ).constEnd() )
526
    {
527
      return;
528
    }
527
    setRect( QgsRectangle() );
528
    setVisible( false );
529
    return;
530
  }
529 531

  
530
    qreal scale = mMapCanvas->mapUnitsPerPixel();
531
    qreal s = ( mIconSize - 1 ) / 2 * scale;
532
    qreal p = mPen.width() * scale;
532
  const QgsMapToPixel& m2p = *(mMapCanvas->getCoordinateTransform());
533 533

  
534
    QgsRectangle r( it->x() + mTranslationOffsetX - s - p, it->y() + mTranslationOffsetY - s - p,
535
                    it->x() + mTranslationOffsetX + s + p, it->y() + mTranslationOffsetY + s + p );
534
  qreal w = ( mIconSize - 1 ) / 2 + mPen.width();
536 535

  
537
    for ( int i = 0; i < mPoints.size(); ++i )
536
  QgsRectangle r;
537
  for ( int i = 0; i < mPoints.size(); ++i )
538
  {
539
    QList<QgsPoint>::const_iterator it = mPoints.at( i ).constBegin(),
540
                                    itE = mPoints.at( i ).constEnd();
541
    int j = 0;
542
    for ( ; it != itE; ++it )
538 543
    {
539
      QList<QgsPoint>::const_iterator it = mPoints.at( i ).constBegin();
540
      for ( ; it != mPoints.at( i ).constEnd(); ++it )
541
      {
542
        QgsRectangle rect = QgsRectangle( it->x() + mTranslationOffsetX - s - p, it->y() + mTranslationOffsetY - s - p,
543
                                          it->x() + mTranslationOffsetX + s + p, it->y() + mTranslationOffsetY + s + p );
544
        r.combineExtentWith( &rect );
545
      }
544
      QgsPoint p(it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY);
545
      p = m2p.transform(p);
546
      QgsRectangle rect(p.x() - w, p.y() - w, p.x() + w, p.y() + w);
547
      r.combineExtentWith( &rect );
546 548
    }
547
    setRect( r );
548
  }
549
  else
550
  {
551
    setRect( QgsRectangle() );
552 549
  }
553
  setVisible( mPoints.size() > 0 );
550

  
551
  // This is an hack to pass QgsMapCanvasItem::setRect what it
552
  // expects (encoding of position and size of the item)
553
  QgsPoint topLeft = m2p.toMapPoint( r.xMinimum(), r.yMinimum() );
554
  double res = m2p.mapUnitsPerPixel();
555
  QgsRectangle rect(topLeft.x(), topLeft.y(), topLeft.x() + r.width()*res, topLeft.y() - r.height()*res);
556

  
557
  setRect( rect );
558
  setVisible( true );
554 559
}
555 560

  
556 561
void QgsRubberBand::setTranslationOffset( double dx, double dy )