Skip to content

Commit

Permalink
Fix feature highlight in presence of rotation (#11815)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Santilli committed Jan 3, 2015
1 parent df49538 commit dee9c46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/gui/qgshighlight.cpp
Expand Up @@ -268,6 +268,11 @@ void QgsHighlight::paintPolygon( QPainter *p, QgsPolygon polygon )
p->drawPath( path );
}

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

/*!
Draw the shape in response to an update event.
*/
Expand Down Expand Up @@ -357,12 +362,6 @@ void QgsHighlight::paint( QPainter* p )
QgsFeatureRendererV2 *renderer = getRenderer( context, tmpColor, tmpFillColor );
if ( layer && renderer )
{
QgsRectangle extent = mMapCanvas->extent();
if ( extent != rect() ) // catches also canvas resize as it is causing extent change
{
updateRect();
return; // it will be repainted after updateRect()
}

QSize imageSize( mMapCanvas->mapSettings().outputSize() );
QImage image = QImage( imageSize.width(), imageSize.height(), QImage::Format_ARGB32 );
Expand Down Expand Up @@ -429,7 +428,16 @@ void QgsHighlight::updateRect()
// 1) currently there is no method in QgsFeatureRendererV2 to get rendered feature
// bounding box
// 2) using different extent would result in shifted fill patterns
setRect( mMapCanvas->extent() );

// This is an hack to pass QgsMapCanvasItem::setRect what it
// expects (encoding of position and size of the item)
const QgsMapToPixel& m2p = mMapCanvas->mapSettings().mapToPixel();
QgsPoint topLeft = m2p.toMapPoint( 0, 0 );
double res = m2p.mapUnitsPerPixel();
QSizeF imageSize = mMapCanvas->mapSettings().outputSize();
QgsRectangle rect( topLeft.x(), topLeft.y(), topLeft.x() + imageSize.width()*res, topLeft.y() - imageSize.height()*res );
setRect( rect );

setVisible( true );
}
else
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgshighlight.h
Expand Up @@ -68,6 +68,8 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem

const QgsMapLayer *layer() const { return mLayer; }

virtual void updatePosition();

protected:
virtual void paint( QPainter* p );

Expand Down

0 comments on commit dee9c46

Please sign in to comment.