Skip to content

Commit eb725f3

Browse files
committed
Do not update extent by default if trust project option is activated
1 parent b55c134 commit eb725f3

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

python/core/qgsvectorlayer.sip

+3-1
Original file line numberDiff line numberDiff line change
@@ -1793,10 +1793,12 @@ Returns the current blending mode for features
17931793
.. seealso:: selectByIds()
17941794
%End
17951795

1796-
virtual void updateExtents();
1796+
virtual void updateExtents( bool force = false );
17971797
%Docstring
17981798
Update the extents for the layer. This is necessary if features are
17991799
added/deleted or the layer has been subsetted.
1800+
1801+
\param force true to update layer extent even if it's read from xml by default, false otherwise
18001802
%End
18011803

18021804
bool startEditing();

src/app/qgsvectorlayerproperties.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ void QgsVectorLayerProperties::setPbnQueryBuilderEnabled()
13871387

13881388
void QgsVectorLayerProperties::on_pbnUpdateExtents_clicked()
13891389
{
1390-
mLayer->updateExtents();
1390+
mLayer->updateExtents( true ); // force update whatever options activated
13911391
mMetadataFilled = false;
13921392
}
13931393

src/core/qgsvectorlayer.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,11 @@ bool QgsVectorLayer::countSymbolFeatures()
782782
return true;
783783
}
784784

785-
void QgsVectorLayer::updateExtents()
785+
void QgsVectorLayer::updateExtents( bool force )
786786
{
787-
mValidExtent = false;
787+
// do not update extent by default when trust project option is activated
788+
if ( force || !mReadExtent || ( mReadExtent && mXmlExtent.isNull() ) )
789+
mValidExtent = false;
788790
}
789791

790792
void QgsVectorLayer::setExtent( const QgsRectangle &r )
@@ -801,16 +803,17 @@ QgsRectangle QgsVectorLayer::extent() const
801803
if ( !isSpatial() )
802804
return rect;
803805

806+
if ( !mValidExtent && mDataProvider && mReadExtent && !mXmlExtent.isNull() )
807+
{
808+
mExtent = mXmlExtent;
809+
mValidExtent = true;
810+
mLazyExtent = false;
811+
}
812+
804813
if ( !mValidExtent && mLazyExtent && mDataProvider )
805814
{
806815
QgsRectangle mbr;
807816

808-
// get the extent from xml
809-
if ( mReadExtent && !mXmlExtent.isNull() && !mDataProvider->hasMetadata() )
810-
{
811-
mbr = mXmlExtent;
812-
}
813-
814817
// get the extent data provider if not yet defined
815818
if ( mbr.isNull() )
816819
{
@@ -1524,7 +1527,7 @@ bool QgsVectorLayer::setDataProvider( QString const &provider )
15241527
}
15251528

15261529
// TODO: Check if the provider has the capability to send fullExtentCalculated
1527-
connect( mDataProvider, &QgsVectorDataProvider::fullExtentCalculated, this, &QgsVectorLayer::updateExtents );
1530+
connect( mDataProvider, &QgsVectorDataProvider::fullExtentCalculated, this, [ = ] { updateExtents(); } );
15281531

15291532
// get and store the feature type
15301533
mWkbType = mDataProvider->wkbType();

src/core/qgsvectorlayer.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1671,8 +1671,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
16711671

16721672
/** Update the extents for the layer. This is necessary if features are
16731673
* added/deleted or the layer has been subsetted.
1674+
*
1675+
* \param force true to update layer extent even if it's read from xml by default, false otherwise
16741676
*/
1675-
virtual void updateExtents();
1677+
virtual void updateExtents( bool force = false );
16761678

16771679
/**
16781680
* Make layer editable.

0 commit comments

Comments
 (0)