Skip to content
Permalink
Browse files
Consider rotation in rubberband placement
Fixes artifacts on zoom by rectangle (#11910) and placement of
measure tool rubberband.
  • Loading branch information
Sandro Santilli committed Jan 3, 2015
1 parent 888a9f0 commit d7269595e12cba8b7e3b45dcd3a7b63b1712d8ad
Showing with 38 additions and 28 deletions.
  1. +36 −28 src/gui/qgsrubberband.cpp
  2. +2 −0 src/gui/qgsrubberband.h
@@ -425,13 +425,15 @@ void QgsRubberBand::setToCanvasRectangle( const QRect& rect )

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

reset( QGis::Polygon );
addPoint( ll, false );
addPoint( QgsPoint( ur.x(), ll.y() ), false );
addPoint( lr, false );
addPoint( ur, false );
addPoint( QgsPoint( ll.x(), ur.y() ), true );
addPoint( ul, true );
}

/*!
@@ -518,39 +520,45 @@ void QgsRubberBand::paint( QPainter* p )

void QgsRubberBand::updateRect()
{
if ( mPoints.size() > 0 )
if ( mPoints.empty() )
{
//initial point
QList<QgsPoint>::const_iterator it = mPoints.at( 0 ).constBegin();
if ( it == mPoints.at( 0 ).constEnd() )
{
return;
}
setRect( QgsRectangle() );
setVisible( false );
return;
}

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

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

for ( int i = 0; i < mPoints.size(); ++i )
QgsRectangle r;
for ( int i = 0; i < mPoints.size(); ++i )
{
QList<QgsPoint>::const_iterator it = mPoints.at( i ).constBegin(),
itE = mPoints.at( i ).constEnd();
int j = 0;
for ( ; it != itE; ++it )
{
QList<QgsPoint>::const_iterator it = mPoints.at( i ).constBegin();
for ( ; it != mPoints.at( i ).constEnd(); ++it )
{
QgsRectangle rect = QgsRectangle( it->x() + mTranslationOffsetX - s - p, it->y() + mTranslationOffsetY - s - p,
it->x() + mTranslationOffsetX + s + p, it->y() + mTranslationOffsetY + s + p );
r.combineExtentWith( &rect );
}
QgsPoint p( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY );
p = m2p.transform( p );
QgsRectangle rect( p.x() - w, p.y() - w, p.x() + w, p.y() + w );
r.combineExtentWith( &rect );
}
setRect( r );
}
else
{
setRect( QgsRectangle() );
}
setVisible( mPoints.size() > 0 );

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

setRect( rect );
setVisible( true );
}

void QgsRubberBand::updatePosition( )
{
// nothing to do here...
}

void QgsRubberBand::setTranslationOffset( double dx, double dy )
@@ -242,6 +242,8 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
*/
QgsGeometry* asGeometry();

virtual void updatePosition();

protected:
virtual void paint( QPainter* p );

0 comments on commit d726959

Please sign in to comment.