Skip to content

Commit dee9c46

Browse files
author
Sandro Santilli
committed
Fix feature highlight in presence of rotation (#11815)
1 parent df49538 commit dee9c46

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/gui/qgshighlight.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ void QgsHighlight::paintPolygon( QPainter *p, QgsPolygon polygon )
268268
p->drawPath( path );
269269
}
270270

271+
void QgsHighlight::updatePosition( )
272+
{
273+
// nothing to do here...
274+
}
275+
271276
/*!
272277
Draw the shape in response to an update event.
273278
*/
@@ -357,12 +362,6 @@ void QgsHighlight::paint( QPainter* p )
357362
QgsFeatureRendererV2 *renderer = getRenderer( context, tmpColor, tmpFillColor );
358363
if ( layer && renderer )
359364
{
360-
QgsRectangle extent = mMapCanvas->extent();
361-
if ( extent != rect() ) // catches also canvas resize as it is causing extent change
362-
{
363-
updateRect();
364-
return; // it will be repainted after updateRect()
365-
}
366365

367366
QSize imageSize( mMapCanvas->mapSettings().outputSize() );
368367
QImage image = QImage( imageSize.width(), imageSize.height(), QImage::Format_ARGB32 );
@@ -429,7 +428,16 @@ void QgsHighlight::updateRect()
429428
// 1) currently there is no method in QgsFeatureRendererV2 to get rendered feature
430429
// bounding box
431430
// 2) using different extent would result in shifted fill patterns
432-
setRect( mMapCanvas->extent() );
431+
432+
// This is an hack to pass QgsMapCanvasItem::setRect what it
433+
// expects (encoding of position and size of the item)
434+
const QgsMapToPixel& m2p = mMapCanvas->mapSettings().mapToPixel();
435+
QgsPoint topLeft = m2p.toMapPoint( 0, 0 );
436+
double res = m2p.mapUnitsPerPixel();
437+
QSizeF imageSize = mMapCanvas->mapSettings().outputSize();
438+
QgsRectangle rect( topLeft.x(), topLeft.y(), topLeft.x() + imageSize.width()*res, topLeft.y() - imageSize.height()*res );
439+
setRect( rect );
440+
433441
setVisible( true );
434442
}
435443
else

src/gui/qgshighlight.h

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
6868

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

71+
virtual void updatePosition();
72+
7173
protected:
7274
virtual void paint( QPainter* p );
7375

0 commit comments

Comments
 (0)