Fix #651 (zoom to layer with one point does not work)

This commit is contained in:
Martin Dobias 2014-06-09 13:42:40 +07:00
parent 48b099c8b6
commit bca35539b6
6 changed files with 20 additions and 4 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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 =

View File

@ -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

View File

@ -200,6 +200,9 @@ void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas* canvas, const Q
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( layer );
if ( vLayer->geometryType() == QGis::NoGeometry )
continue;
if ( layerExtent.isEmpty() && layer->type() == QgsMapLayer::VectorLayer )
{
qobject_cast<QgsVectorLayer*>( 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