Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevents a crash when online features are gone
Fixes an unreported segfault when converting an online layer to offline if features cannot be (completely) fetched. Funded by Boundless
- Loading branch information
Showing
1 changed file
with
13 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,9 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath, | |
if ( newLayer ) | ||
{ | ||
layerIdMapping.insert( origLayerId, newLayer ); | ||
// remove remote layer | ||
QgsMapLayerRegistry::instance()->removeMapLayers( | ||
QStringList() << origLayerId ); | ||
} | ||
} | ||
|
||
|
@@ -645,7 +648,16 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit | |
int remoteCount = remoteFeatureIds.size(); | ||
for ( int i = 0; i < remoteCount; i++ ) | ||
{ | ||
addFidLookup( db, layerId, offlineFeatureIds.at( i ), remoteFeatureIds.at( remoteCount - ( i + 1 ) ) ); | ||
// Check if the online feature has been fetched (WFS download aborted for some reason) | ||
if ( i < offlineFeatureIds.count() ) | ||
{ | ||
addFidLookup( db, layerId, offlineFeatureIds.at( i ), remoteFeatureIds.at( remoteCount - ( i + 1 ) ) ); | ||
} | ||
else | ||
{ | ||
showWarning( QString( "Feature cannot be copied to the offline layer, please check if the online layer '%1' is sill accessible." ).arg( layer->name() ) ); | ||
return nullptr; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
elpaso
Author
Contributor
|
||
} | ||
emit progressUpdated( featureCount++ ); | ||
} | ||
sqlExec( db, "COMMIT" ); | ||
|
@@ -654,10 +666,6 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit | |
{ | ||
showWarning( newLayer->commitErrors().join( "\n" ) ); | ||
} | ||
|
||
// remove remote layer | ||
QgsMapLayerRegistry::instance()->removeMapLayers( | ||
QStringList() << layer->id() ); | ||
} | ||
return newLayer; | ||
} | ||
|
@elpaso
shouldn't the transaction be rolled back here?
Sidenote; I normally prefer not to return in the middle of a function to avoid having skipped cleanup steps at the end of a function.