@@ -272,7 +272,7 @@ QgsVectorLayerImport::ImportError QgsOgrProvider::createEmptyLayer(
272
272
QgsOgrProvider::QgsOgrProvider( QString const & uri )
273
273
: QgsVectorDataProvider( uri )
274
274
, ogrDataSource( nullptr )
275
- , extent_ ( nullptr )
275
+ , mExtent ( nullptr )
276
276
, ogrLayer( nullptr )
277
277
, ogrOrigLayer( nullptr )
278
278
, mLayerIndex( 0 )
@@ -456,11 +456,7 @@ bool QgsOgrProvider::setSubsetString( const QString& theSQL, bool updateFeatureC
456
456
loadFields ();
457
457
QgsDebugMsg ( " Done checking validity" );
458
458
459
- if ( extent_ )
460
- {
461
- free ( extent_ );
462
- extent_ = nullptr ;
463
- }
459
+ updateExtents ();
464
460
465
461
emit dataChanged ();
466
462
@@ -846,26 +842,24 @@ unsigned char * QgsOgrProvider::getGeometryPointer( OGRFeatureH fet )
846
842
847
843
QgsRectangle QgsOgrProvider::extent ()
848
844
{
849
- if ( !extent_ )
845
+ if ( !mExtent )
850
846
{
851
- extent_ = calloc ( sizeof ( OGREnvelope ), 1 );
847
+ mExtent = new OGREnvelope ( );
852
848
853
849
// get the extent_ (envelope) of the layer
854
850
QgsDebugMsg ( " Starting get extent" );
855
851
856
852
// TODO: This can be expensive, do we really need it!
857
853
if ( ogrLayer == ogrOrigLayer )
858
854
{
859
- OGR_L_GetExtent ( ogrLayer, ( OGREnvelope * ) extent_ , true );
855
+ OGR_L_GetExtent ( ogrLayer, mExtent , true );
860
856
}
861
857
else
862
858
{
863
- OGREnvelope *bb = static_cast <OGREnvelope*>( extent_ );
864
-
865
- bb->MinX = std::numeric_limits<double >::max ();
866
- bb->MinY = std::numeric_limits<double >::max ();
867
- bb->MaxX = -std::numeric_limits<double >::max ();
868
- bb->MaxY = -std::numeric_limits<double >::max ();
859
+ mExtent ->MinX = std::numeric_limits<double >::max ();
860
+ mExtent ->MinY = std::numeric_limits<double >::max ();
861
+ mExtent ->MaxX = -std::numeric_limits<double >::max ();
862
+ mExtent ->MaxY = -std::numeric_limits<double >::max ();
869
863
870
864
OGRFeatureH f;
871
865
@@ -878,10 +872,10 @@ QgsRectangle QgsOgrProvider::extent()
878
872
OGREnvelope env;
879
873
OGR_G_GetEnvelope ( g, &env );
880
874
881
- if ( env. MinX < bb ->MinX ) bb ->MinX = env.MinX ;
882
- if ( env. MinY < bb ->MinY ) bb ->MinY = env.MinY ;
883
- if ( env. MaxX > bb ->MaxX ) bb ->MaxX = env.MaxX ;
884
- if ( env. MaxY > bb ->MaxY ) bb ->MaxY = env.MaxY ;
875
+ mExtent ->MinX = qMin ( mExtent ->MinX , env.MinX ) ;
876
+ mExtent ->MinY = qMin ( mExtent ->MinY , env.MinY ) ;
877
+ mExtent ->MaxX = qMin ( mExtent ->MaxX , env.MaxX ) ;
878
+ mExtent ->MaxY = qMin ( mExtent ->MaxY , env.MaxY ) ;
885
879
}
886
880
887
881
OGR_F_Destroy ( f );
@@ -892,18 +886,14 @@ QgsRectangle QgsOgrProvider::extent()
892
886
QgsDebugMsg ( " Finished get extent" );
893
887
}
894
888
895
- OGREnvelope *ext = static_cast <OGREnvelope *>( extent_ );
896
- mExtentRect .set ( ext->MinX , ext->MinY , ext->MaxX , ext->MaxY );
889
+ mExtentRect .set ( mExtent ->MinX , mExtent ->MinY , mExtent ->MaxX , mExtent ->MaxY );
897
890
return mExtentRect ;
898
891
}
899
892
900
893
void QgsOgrProvider::updateExtents ()
901
894
{
902
- if ( extent_ )
903
- {
904
- free ( extent_ );
905
- extent_ = nullptr ;
906
- }
895
+ delete mExtent ;
896
+ mExtent = nullptr ;
907
897
}
908
898
909
899
size_t QgsOgrProvider::layerCount () const
@@ -1409,11 +1399,7 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )
1409
1399
1410
1400
clearMinMaxCache ();
1411
1401
1412
- if ( extent_ )
1413
- {
1414
- free ( extent_ );
1415
- extent_ = nullptr ;
1416
- }
1402
+ updateExtents ();
1417
1403
1418
1404
return returnvalue;
1419
1405
}
@@ -2846,11 +2832,7 @@ void QgsOgrProvider::close()
2846
2832
}
2847
2833
ogrDataSource = nullptr ;
2848
2834
2849
- if ( extent_ )
2850
- {
2851
- free ( extent_ );
2852
- extent_ = nullptr ;
2853
- }
2835
+ updateExtents ();
2854
2836
2855
2837
QgsOgrConnPool::unrefS ( mFilePath );
2856
2838
}
0 commit comments