mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
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
This commit is contained in:
parent
a697e0f456
commit
e00cfa7bc2
@ -666,9 +666,12 @@ bool QgsOgrProvider::addFeatures( QgsFeatureList & flist )
|
||||
}
|
||||
}
|
||||
|
||||
// flush features
|
||||
OGR_L_SyncToDisk( ogrLayer );
|
||||
if ( !syncToDisc() )
|
||||
{
|
||||
returnvalue = false;
|
||||
}
|
||||
featuresCounted = OGR_L_GetFeatureCount( ogrLayer, TRUE ); //new feature count
|
||||
|
||||
return returnvalue;
|
||||
}
|
||||
|
||||
@ -774,7 +777,6 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
|
||||
}
|
||||
|
||||
OGR_L_SyncToDisk( ogrLayer );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -831,8 +833,7 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
|
||||
|
||||
OGR_F_Destroy( theOGRFeature );
|
||||
}
|
||||
OGR_L_SyncToDisk( ogrLayer );
|
||||
return true;
|
||||
return syncToDisc();
|
||||
}
|
||||
|
||||
bool QgsOgrProvider::createSpatialIndex()
|
||||
@ -863,7 +864,11 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )
|
||||
}
|
||||
}
|
||||
|
||||
OGR_L_SyncToDisk( ogrLayer );
|
||||
if ( !syncToDisc() )
|
||||
{
|
||||
returnvalue = false;
|
||||
}
|
||||
|
||||
QFileInfo fi( dataSourceUri() ); // to get the base name
|
||||
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
|
||||
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, NULL );
|
||||
@ -1599,3 +1604,28 @@ QString QgsOgrProvider::quotedIdentifier( QString field )
|
||||
field.replace( "'", "\\'" );
|
||||
return field.prepend( "\"" ).append( "\"" );
|
||||
}
|
||||
|
||||
bool QgsOgrProvider::syncToDisc()
|
||||
{
|
||||
OGR_L_SyncToDisk( ogrLayer );
|
||||
|
||||
//for shapefiles: is there already a spatial index?
|
||||
QFileInfo fi( dataSourceUri() );
|
||||
QString filePath = fi.filePath();
|
||||
|
||||
//remove the suffix and add .qix
|
||||
int suffixLength = fi.suffix().length();
|
||||
if ( suffixLength > 0 )
|
||||
{
|
||||
QString indexFilePath = filePath;
|
||||
indexFilePath.chop( suffixLength );
|
||||
indexFilePath.append( "qix" );
|
||||
QFile indexFile( indexFilePath );
|
||||
if ( indexFile.exists() ) //there is already a spatial index file
|
||||
{
|
||||
//the already existing spatial index is removed automatically by OGR
|
||||
return createSpatialIndex();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -263,4 +263,7 @@ class QgsOgrProvider : public QgsVectorDataProvider
|
||||
bool deleteFeature( int id );
|
||||
|
||||
QString quotedIdentifier( QString field );
|
||||
|
||||
/**Calls OGR_L_SyncToDisk and recreates the spatial index if present*/
|
||||
bool syncToDisc();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user