Skip to content

Commit e00cfa7

Browse files
author
mhugent
committed
Fix for bug #1572: new features will not display before spatial index is recreated/QGIS restarted
git-svn-id: http://svn.osgeo.org/qgis/trunk@11225 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a697e0f commit e00cfa7

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

src/providers/ogr/qgsogrprovider.cpp

+36-6
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,12 @@ bool QgsOgrProvider::addFeatures( QgsFeatureList & flist )
666666
}
667667
}
668668

669-
// flush features
670-
OGR_L_SyncToDisk( ogrLayer );
669+
if ( !syncToDisc() )
670+
{
671+
returnvalue = false;
672+
}
671673
featuresCounted = OGR_L_GetFeatureCount( ogrLayer, TRUE ); //new feature count
674+
672675
return returnvalue;
673676
}
674677

@@ -774,7 +777,6 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
774777
}
775778

776779
OGR_L_SyncToDisk( ogrLayer );
777-
778780
return true;
779781
}
780782

@@ -831,8 +833,7 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
831833

832834
OGR_F_Destroy( theOGRFeature );
833835
}
834-
OGR_L_SyncToDisk( ogrLayer );
835-
return true;
836+
return syncToDisc();
836837
}
837838

838839
bool QgsOgrProvider::createSpatialIndex()
@@ -863,7 +864,11 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )
863864
}
864865
}
865866

866-
OGR_L_SyncToDisk( ogrLayer );
867+
if ( !syncToDisc() )
868+
{
869+
returnvalue = false;
870+
}
871+
867872
QFileInfo fi( dataSourceUri() ); // to get the base name
868873
QString sql = QString( "REPACK %1" ).arg( fi.completeBaseName() ); // don't quote the layer name as it works with spaces in the name and won't work if the name is quoted
869874
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, NULL );
@@ -1599,3 +1604,28 @@ QString QgsOgrProvider::quotedIdentifier( QString field )
15991604
field.replace( "'", "\\'" );
16001605
return field.prepend( "\"" ).append( "\"" );
16011606
}
1607+
1608+
bool QgsOgrProvider::syncToDisc()
1609+
{
1610+
OGR_L_SyncToDisk( ogrLayer );
1611+
1612+
//for shapefiles: is there already a spatial index?
1613+
QFileInfo fi( dataSourceUri() );
1614+
QString filePath = fi.filePath();
1615+
1616+
//remove the suffix and add .qix
1617+
int suffixLength = fi.suffix().length();
1618+
if ( suffixLength > 0 )
1619+
{
1620+
QString indexFilePath = filePath;
1621+
indexFilePath.chop( suffixLength );
1622+
indexFilePath.append( "qix" );
1623+
QFile indexFile( indexFilePath );
1624+
if ( indexFile.exists() ) //there is already a spatial index file
1625+
{
1626+
//the already existing spatial index is removed automatically by OGR
1627+
return createSpatialIndex();
1628+
}
1629+
}
1630+
return true;
1631+
}

src/providers/ogr/qgsogrprovider.h

+3
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,7 @@ class QgsOgrProvider : public QgsVectorDataProvider
263263
bool deleteFeature( int id );
264264

265265
QString quotedIdentifier( QString field );
266+
267+
/**Calls OGR_L_SyncToDisk and recreates the spatial index if present*/
268+
bool syncToDisc();
266269
};

0 commit comments

Comments
 (0)