@@ -133,7 +133,8 @@ typedef bool deleteStyleById_t(
133
133
QgsVectorLayer::QgsVectorLayer ( const QString &vectorLayerPath,
134
134
const QString &baseName,
135
135
const QString &providerKey,
136
- bool loadDefaultStyleFlag )
136
+ bool loadDefaultStyleFlag,
137
+ bool readExtent )
137
138
: QgsMapLayer( VectorLayer, baseName, vectorLayerPath )
138
139
, mDataProvider( nullptr )
139
140
, mProviderKey( providerKey )
@@ -153,6 +154,7 @@ QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath,
153
154
, mLazyExtent( true )
154
155
, mSymbolFeatureCounted( false )
155
156
, mEditCommandActive( false )
157
+ , mReadExtent( readExtent )
156
158
157
159
{
158
160
mActions = new QgsActionManager ( this );
@@ -222,6 +224,7 @@ QgsVectorLayer *QgsVectorLayer::clone() const
222
224
layer->setAttributeTableConfig ( attributeTableConfig () );
223
225
layer->setFeatureBlendMode ( featureBlendMode () );
224
226
layer->setOpacity ( opacity () );
227
+ layer->setReadExtent ( readExtent () );
225
228
226
229
Q_FOREACH ( const QgsAction &action, actions ()->actions () )
227
230
{
@@ -800,8 +803,19 @@ QgsRectangle QgsVectorLayer::extent() const
800
803
801
804
if ( !mValidExtent && mLazyExtent && mDataProvider )
802
805
{
803
- // get the extent
804
- QgsRectangle mbr = mDataProvider ->extent ();
806
+ QgsRectangle mbr;
807
+
808
+ // get the extent from xml
809
+ if ( mReadExtent && !mXmlExtent .isNull () && !mDataProvider ->hasMetadata () )
810
+ {
811
+ mbr = mXmlExtent ;
812
+ }
813
+
814
+ // get the extent data provider if not yet defined
815
+ if ( mbr.isNull () )
816
+ {
817
+ mbr = mDataProvider ->extent ();
818
+ }
805
819
806
820
// show the extent
807
821
QgsDebugMsg ( " Extent of layer: " + mbr.toString () );
@@ -1428,6 +1442,16 @@ bool QgsVectorLayer::readXml( const QDomNode &layer_node, const QgsReadWriteCont
1428
1442
1429
1443
setLegend ( QgsMapLayerLegend::defaultVectorLegend ( this ) );
1430
1444
1445
+ // read extent
1446
+ if ( mReadExtent )
1447
+ {
1448
+ QDomNode extentNode = layer_node.namedItem ( QStringLiteral ( " extent" ) );
1449
+ if ( !extentNode.isNull () )
1450
+ {
1451
+ mXmlExtent = QgsXmlUtils::readRectangle ( extentNode.toElement () );
1452
+ }
1453
+ }
1454
+
1431
1455
return mValid ; // should be true if read successfully
1432
1456
1433
1457
} // void QgsVectorLayer::readXml
@@ -4418,3 +4442,13 @@ QgsAbstractVectorLayerLabeling *QgsVectorLayer::readLabelingFromCustomProperties
4418
4442
4419
4443
return labeling;
4420
4444
}
4445
+
4446
+ void QgsVectorLayer::setReadExtent ( bool readExtent )
4447
+ {
4448
+ mReadExtent = readExtent;
4449
+ }
4450
+
4451
+ bool QgsVectorLayer::readExtent () const
4452
+ {
4453
+ return mReadExtent ;
4454
+ }
0 commit comments