Merge pull request #33170 from elpaso/bugfix-gh33168-set-center-crash

Check for empty rect before calling setExtent
This commit is contained in:
Alessandro Pasotti 2019-11-30 18:57:29 +01:00 committed by GitHub
commit bc00621dfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -901,16 +901,20 @@ bool QgsMapCanvas::setReferencedExtent( const QgsReferencedRectangle &extent )
void QgsMapCanvas::setCenter( const QgsPointXY &center )
{
QgsRectangle r = mapSettings().extent();
double x = center.x();
double y = center.y();
setExtent(
QgsRectangle(
x - r.width() / 2.0, y - r.height() / 2.0,
x + r.width() / 2.0, y + r.height() / 2.0
),
true
const QgsRectangle r = mapSettings().extent();
const double x = center.x();
const double y = center.y();
const QgsRectangle rect(
x - r.width() / 2.0, y - r.height() / 2.0,
x + r.width() / 2.0, y + r.height() / 2.0
);
if ( ! rect.isEmpty() )
{
setExtent(
rect,
true
);
}
} // setCenter
QgsPointXY QgsMapCanvas::center() const