@@ -105,6 +105,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
105
105
, mJoinBuffer( 0 )
106
106
, mDiagramRenderer( 0 )
107
107
, mDiagramLayerSettings( 0 )
108
+ , mValidExtent( false )
108
109
{
109
110
mActions = new QgsAttributeAction ( this );
110
111
@@ -1461,10 +1462,24 @@ long QgsVectorLayer::updateFeatureCount() const
1461
1462
1462
1463
void QgsVectorLayer::updateExtents ()
1463
1464
{
1464
- if ( !hasGeometryType () )
1465
- return ;
1465
+ mValidExtent = false ;
1466
+ }
1467
+
1468
+ void QgsVectorLayer::setExtent ( const QgsRectangle &r )
1469
+ {
1470
+ QgsMapLayer::setExtent ( r );
1471
+ mValidExtent = true ;
1472
+ }
1466
1473
1467
- mLayerExtent .setMinimal ();
1474
+ QgsRectangle QgsVectorLayer::extent ()
1475
+ {
1476
+ if ( mValidExtent )
1477
+ return QgsMapLayer::extent ();
1478
+
1479
+ QgsRectangle rect;
1480
+
1481
+ if ( !hasGeometryType () )
1482
+ return rect;
1468
1483
1469
1484
if ( !mDataProvider )
1470
1485
{
@@ -1480,13 +1495,13 @@ void QgsVectorLayer::updateExtents()
1480
1495
if ( mDataProvider ->featureCount () != 0 )
1481
1496
{
1482
1497
QgsRectangle r = mDataProvider ->extent ();
1483
- mLayerExtent .combineExtentWith ( &r );
1498
+ rect .combineExtentWith ( &r );
1484
1499
}
1485
1500
1486
1501
for ( QgsFeatureList::iterator it = mAddedFeatures .begin (); it != mAddedFeatures .end (); it++ )
1487
1502
{
1488
1503
QgsRectangle r = it->geometry ()->boundingBox ();
1489
- mLayerExtent .combineExtentWith ( &r );
1504
+ rect .combineExtentWith ( &r );
1490
1505
}
1491
1506
}
1492
1507
else
@@ -1499,19 +1514,23 @@ void QgsVectorLayer::updateExtents()
1499
1514
if ( fet.geometry () )
1500
1515
{
1501
1516
QgsRectangle bb = fet.geometry ()->boundingBox ();
1502
- mLayerExtent .combineExtentWith ( &bb );
1517
+ rect .combineExtentWith ( &bb );
1503
1518
}
1504
1519
}
1505
1520
}
1506
1521
1507
- if ( mLayerExtent .xMinimum () > mLayerExtent .xMaximum () && mLayerExtent .yMinimum () > mLayerExtent .yMaximum () )
1522
+ if ( rect .xMinimum () > rect .xMaximum () && rect .yMinimum () > rect .yMaximum () )
1508
1523
{
1509
1524
// special case when there are no features in provider nor any added
1510
- mLayerExtent = QgsRectangle (); // use rectangle with zero coordinates
1525
+ rect = QgsRectangle (); // use rectangle with zero coordinates
1511
1526
}
1512
1527
1528
+ setExtent ( rect );
1529
+
1513
1530
// Send this (hopefully) up the chain to the map canvas
1514
1531
emit recalculateExtents ();
1532
+
1533
+ return rect;
1515
1534
}
1516
1535
1517
1536
QString QgsVectorLayer::subsetString ()
@@ -2819,10 +2838,7 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )
2819
2838
QString s = mbr.toString ();
2820
2839
QgsDebugMsg ( " Extent of layer: " + s );
2821
2840
// store the extent
2822
- mLayerExtent .setXMaximum ( mbr.xMaximum () );
2823
- mLayerExtent .setXMinimum ( mbr.xMinimum () );
2824
- mLayerExtent .setYMaximum ( mbr.yMaximum () );
2825
- mLayerExtent .setYMinimum ( mbr.yMinimum () );
2841
+ setExtent ( mbr );
2826
2842
2827
2843
// get and store the feature type
2828
2844
mWkbType = mDataProvider ->geometryType ();
0 commit comments