From bca35539b630baf25d10d373a9c5aa09f1b67fd4 Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Mon, 9 Jun 2014 13:42:40 +0700 Subject: [PATCH] Fix #651 (zoom to layer with one point does not work) --- python/core/qgsrectangle.sip | 4 ++++ src/core/qgsmaprenderer.cpp | 2 +- src/core/qgsmapsettings.cpp | 2 +- src/core/qgsrectangle.cpp | 5 +++++ src/core/qgsrectangle.h | 6 +++++- src/gui/layertree/qgslayertreeviewdefaultactions.cpp | 5 ++++- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/python/core/qgsrectangle.sip b/python/core/qgsrectangle.sip index f15c59499ff..42454282ba5 100644 --- a/python/core/qgsrectangle.sip +++ b/python/core/qgsrectangle.sip @@ -77,7 +77,11 @@ class QgsRectangle //! expand the rectangle so that covers both the original rectangle and the given point void combineExtentWith( double x, double y ); //! test if rectangle is empty + //! Empty rectangle may still be non-null if it contains valid information (e.g. bounding box of a point) bool isEmpty() const; + //! test if the rectangle has all coordinates zero. Null rectangle is also an empty rectangle. + //! @note added in 2.4 + bool isNull() const; //! returns string representation in Wkt form QString asWktCoordinates() const; //! returns string representation as WKT Polygon diff --git a/src/core/qgsmaprenderer.cpp b/src/core/qgsmaprenderer.cpp index a29ec85a746..fcf3cb9554d 100644 --- a/src/core/qgsmaprenderer.cpp +++ b/src/core/qgsmaprenderer.cpp @@ -929,7 +929,7 @@ void QgsMapRenderer::updateFullExtent() QgsDebugMsg( "Updating extent using " + lyr->name() ); QgsDebugMsg( "Input extent: " + lyr->extent().toString() ); - if ( lyr->extent().isEmpty() ) + if ( lyr->extent().isNull() ) { ++it; continue; diff --git a/src/core/qgsmapsettings.cpp b/src/core/qgsmapsettings.cpp index 86dd21d8513..8d4c202aa19 100644 --- a/src/core/qgsmapsettings.cpp +++ b/src/core/qgsmapsettings.cpp @@ -430,7 +430,7 @@ QgsRectangle QgsMapSettings::fullExtent() const QgsDebugMsg( "Updating extent using " + lyr->name() ); QgsDebugMsg( "Input extent: " + lyr->extent().toString() ); - if ( lyr->extent().isEmpty() ) + if ( lyr->extent().isNull() ) { it++; continue; diff --git a/src/core/qgsrectangle.cpp b/src/core/qgsrectangle.cpp index 4d4e5b59b6f..65316ea8eb0 100644 --- a/src/core/qgsrectangle.cpp +++ b/src/core/qgsrectangle.cpp @@ -194,6 +194,11 @@ bool QgsRectangle::isEmpty() const return xmax <= xmin || ymax <= ymin; } +bool QgsRectangle::isNull() const +{ + return xmin == 0 && xmax == 0 && ymin == 0 && ymax == 0; +} + QString QgsRectangle::asWktCoordinates() const { QString rep = diff --git a/src/core/qgsrectangle.h b/src/core/qgsrectangle.h index 0ad6c2d2729..63688b3ee53 100644 --- a/src/core/qgsrectangle.h +++ b/src/core/qgsrectangle.h @@ -99,8 +99,12 @@ class CORE_EXPORT QgsRectangle void combineExtentWith( QgsRectangle *rect ); //! expand the rectangle so that covers both the original rectangle and the given point void combineExtentWith( double x, double y ); - //! test if rectangle is empty + //! test if rectangle is empty. + //! Empty rectangle may still be non-null if it contains valid information (e.g. bounding box of a point) bool isEmpty() const; + //! test if the rectangle has all coordinates zero. Null rectangle is also an empty rectangle. + //! @note added in 2.4 + bool isNull() const; //! returns string representation in Wkt form QString asWktCoordinates() const; //! returns string representation as WKT Polygon diff --git a/src/gui/layertree/qgslayertreeviewdefaultactions.cpp b/src/gui/layertree/qgslayertreeviewdefaultactions.cpp index 55ffced613b..dda3724f3e4 100644 --- a/src/gui/layertree/qgslayertreeviewdefaultactions.cpp +++ b/src/gui/layertree/qgslayertreeviewdefaultactions.cpp @@ -200,6 +200,9 @@ void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas* canvas, const Q QgsVectorLayer* vLayer = qobject_cast( layer ); + if ( vLayer->geometryType() == QGis::NoGeometry ) + continue; + if ( layerExtent.isEmpty() && layer->type() == QgsMapLayer::VectorLayer ) { qobject_cast( layer )->updateExtents(); @@ -216,7 +219,7 @@ void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas* canvas, const Q extent.combineExtentWith( &layerExtent ); } - if ( extent.isEmpty() ) + if ( extent.isNull() ) return; // Increase bounding box with 5%, so that layer is a bit inside the borders