Skip to content
Permalink
Browse files
Fix handling of rotation in partial-rendering of map (#11909)
  • Loading branch information
Sandro Santilli committed Jan 4, 2015
1 parent 2418ec7 commit 41da5c35f833a4d03d6f97c4dcbe4a246f75f943
Showing with 16 additions and 9 deletions.
  1. +14 −9 src/gui/qgsmapcanvas.cpp
  2. +2 −0 src/gui/qgsmapcanvas.h
@@ -723,14 +723,7 @@ void QgsMapCanvas::rendererJobFinished()

p.end();

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

mMap->setContent( img, rect );
mMap->setContent( img, imageRect( img ) );
}

// now we are in a slot called from mJob - do not delete it immediately
@@ -741,9 +734,21 @@ void QgsMapCanvas::rendererJobFinished()
emit mapCanvasRefreshed();
}

QgsRectangle QgsMapCanvas::imageRect( const QImage& img )
{
// This is an hack to pass QgsMapCanvasItem::setRect what it
// expects (encoding of position and size of the item)
const QgsMapToPixel& m2p = mSettings.mapToPixel();
QgsPoint topLeft = m2p.toMapPoint( 0, 0 );
double res = m2p.mapUnitsPerPixel();
QgsRectangle rect( topLeft.x(), topLeft.y(), topLeft.x() + img.width()*res, topLeft.y() - img.height()*res );
return rect;
}

void QgsMapCanvas::mapUpdateTimeout()
{
mMap->setContent( mJob->renderedImage(), mJob->mapSettings().visibleExtent() );
const QImage& img = mJob->renderedImage();
mMap->setContent( img, imageRect( img ) );

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Feb 15, 2015

Member

Is mJob->mapSettings().visibleExtent() not ok?
That would be more appropriate as it uses the extent at which the current image is rendered and not the extent of the mapcanvas (which may have changed since the job was scheduled).
Maybe specifying the QgsMapSettings object as parameter to the imageRect method so it can perform the rotation logic on that one instead?

This comment has been minimized.

Copy link
@strk

strk Feb 16, 2015

Contributor

Read the "hack" comment in imageRect. The QgsMapCanvasItem doesn't know how to handle rotated extents, so uses the passed-in rectangle just to encode position and size. If we pass visibleExtent the side would be larger than the actual one when the image is rotated. This has been tested manually/visually, you can try yourself to see what the effects of passing visibleExtent is.

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Feb 16, 2015

Member

The problem is that it conflicts with a fix I implemented in December because upon repeated quick changing of the map extent (like pinch-zooming) the rendered map extent will be shown at the wrong position.
Currently testing if it works if m2p from the jobs QgsMapSettings is used instead of the one from the map canvas within imageRect.

This comment has been minimized.

Copy link
@strk

strk Feb 16, 2015

Contributor

since you're at it, it would be great to have an automated testcase for that. It was too hard for me to figure out the best way to do it.

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Feb 16, 2015

Member

#1901

Can you check if that works for you?

}

void QgsMapCanvas::stopRendering()
@@ -643,6 +643,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView

QgsPreviewEffect* mPreviewEffect;

QgsRectangle imageRect( const QImage& img );

}; // class QgsMapCanvas


0 comments on commit 41da5c3

Please sign in to comment.