void QgsOfflineEditing::updateFidLookup( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId ) { // update fid lookup for added features // get remote added fids // NOTE: use QMap for sorted fids QMap < QgsFeatureId, bool /*dummy*/ > newRemoteFids; QgsFeature f; QgsFeatureIterator fit = remoteLayer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( QgsAttributeList() ) ); emit progressModeSet( QgsOfflineEditing::ProcessFeatures, remoteLayer->featureCount() ); int i = 1; while ( fit.nextFeature( f ) ) { if ( offlineFid( db, layerId, f.id() ) == -1 ) { newRemoteFids[ f.id()] = true; } emit progressUpdated( i++ ); } // get local added fids // NOTE: fids are sorted QString sql = QString( "SELECT \"fid\" FROM 'log_added_features' WHERE \"layer_id\" = %1" ).arg( layerId ); QList<int> newOfflineFids = sqlQueryInts( db, sql ); if ( newRemoteFids.size() != newOfflineFids.size() ) { //showWarning( QString( "Different number of new features on offline layer (%1) and remote layer (%2)" ).arg(newOfflineFids.size()).arg(newRemoteFids.size()) ); } else { // add new fid lookups i = 0; sqlExec( db, "BEGIN" ); for ( QMap<QgsFeatureId, bool>::const_iterator it = newRemoteFids.begin(); it != newRemoteFids.end(); ++it ) { addFidLookup( db, layerId, newOfflineFids.at( i++ ), it.key() ); } sqlExec( db, "COMMIT" ); } }
void QgsOfflineEditing::updateFidLookup( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId ) { // update fid lookup for added features // get remote added fids // NOTE: use QMap for sorted fids QMap < int, bool /*dummy*/ > newRemoteFids; QgsFeature f; remoteLayer->select( QgsAttributeList(), QgsRectangle(), false, false ); mProgressDialog->setupProgressBar( tr( "%v / %m features processed" ), remoteLayer->featureCount() ); int i = 1; while ( remoteLayer->nextFeature( f ) ) { if ( offlineFid( db, layerId, f.id() ) == -1 ) { newRemoteFids[ f.id()] = true; } mProgressDialog->setProgressValue( i++ ); } // get local added fids // NOTE: fids are sorted QString sql = QString( "SELECT \"fid\" FROM 'log_added_features' WHERE \"layer_id\" = %1" ).arg( layerId ); QList<int> newOfflineFids = sqlQueryInts( db, sql ); if ( newRemoteFids.size() != newOfflineFids.size() ) { //showWarning( QString( "Different number of new features on offline layer (%1) and remote layer (%2)" ).arg(newOfflineFids.size()).arg(newRemoteFids.size()) ); } else { // add new fid lookups i = 0; sqlExec( db, "BEGIN" ); for ( QMap<int, bool>::const_iterator it = newRemoteFids.begin(); it != newRemoteFids.end(); ++it ) { addFidLookup( db, layerId, newOfflineFids.at( i++ ), it.key() ); } sqlExec( db, "COMMIT" ); } }