Skip to content

Commit

Permalink
Fix handling of rotation in partial-rendering of map (#11909)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Santilli committed Jan 4, 2015
1 parent 2418ec7 commit 41da5c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -643,6 +643,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView

QgsPreviewEffect* mPreviewEffect;

QgsRectangle imageRect( const QImage& img );

}; // class QgsMapCanvas


Expand Down

0 comments on commit 41da5c3

Please sign in to comment.