Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Consider rotation in pre-rendering display of map items
  • Loading branch information
Sandro Santilli committed Jan 3, 2015
1 parent 4d449f1 commit 888a9f0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/gui/qgsmapcanvasitem.sip
Expand Up @@ -45,7 +45,7 @@ class QgsMapCanvasItem : QGraphicsItem
QgsRectangle rect() const;

//! sets canvas item rectangle in map units
void setRect( const QgsRectangle& r );
void setRect( const QgsRectangle& r, bool resetRotation = true );

//! transformation from screen coordinates to map coordinates
QgsPoint toMapCoordinates( const QPoint& point ) const;
Expand Down
11 changes: 9 additions & 2 deletions src/gui/qgsmapcanvasitem.cpp
Expand Up @@ -73,7 +73,7 @@ QgsRectangle QgsMapCanvasItem::rect() const
}


void QgsMapCanvasItem::setRect( const QgsRectangle& rect )
void QgsMapCanvasItem::setRect( const QgsRectangle& rect, bool resetRotation )
{
mRect = rect;
//updatePosition();
Expand All @@ -94,6 +94,12 @@ void QgsMapCanvasItem::setRect( const QgsRectangle& rect )
setPos( r.topLeft() );
mItemSize = QSizeF( r.width() + 2, r.height() + 2 );

if ( resetRotation )
{
mRectRotation = mMapCanvas->rotation();
setRotation( 0 );
}

// QgsDebugMsg(QString("[%1,%2]-[%3x%4]").arg((int) r.left()).arg((int) r.top()).arg((int) r.width()).arg((int) r.height()));

update();
Expand Down Expand Up @@ -132,7 +138,8 @@ bool QgsMapCanvasItem::setRenderContextVariables( QPainter* p, QgsRenderContext&
void QgsMapCanvasItem::updatePosition()
{
// default implementation: recalculate position of the item
setRect( mRect );
setRect( mRect, false );
setRotation( mMapCanvas->rotation() - mRectRotation );
}


Expand Down
4 changes: 3 additions & 1 deletion src/gui/qgsmapcanvasitem.h
Expand Up @@ -69,7 +69,7 @@ class GUI_EXPORT QgsMapCanvasItem : public QGraphicsItem
QgsRectangle rect() const;

//! sets canvas item rectangle in map units
void setRect( const QgsRectangle& r );
void setRect( const QgsRectangle& r, bool resetRotation = true );

//! transformation from screen coordinates to map coordinates
QgsPoint toMapCoordinates( const QPoint& point ) const;
Expand All @@ -92,6 +92,8 @@ class GUI_EXPORT QgsMapCanvasItem : public QGraphicsItem
//! on rotation change
QgsRectangle mRect;

double mRectRotation;

//! offset from normal position due current panning operation,
//! used when converting map coordinates to move map canvas items
//! @deprecated since v2.4
Expand Down

0 comments on commit 888a9f0

Please sign in to comment.