Skip to content
Permalink
Browse files
Address review
  • Loading branch information
suricactus committed Aug 17, 2021
1 parent e073877 commit a5968fa7ade95d3a327ef396d31545a71d57c33f
@@ -53,9 +53,12 @@ Convert current project for offline editing
Returns ``True`` if current project is offline
%End


void synchronize( bool useTransaction = false );
%Docstring
Synchronize to remote layers

:param useTransaction: enforce the remote layer modifications with the same source to be in a transaction group
%End

signals:
@@ -175,7 +175,7 @@ void QgsOfflineEditing::synchronize( bool useTransaction )

if ( !offlineLayer || !offlineLayer->isValid() )
{
QgsDebugMsgLevel( QStringLiteral( "Skipping offline layer %1 because it is an invalid layer" ).arg( offlineLayer->id() ), 4 );
QgsDebugMsgLevel( QStringLiteral( "Skipping offline layer %1 because it is an invalid layer" ).arg( layer_it.key() ), 4 );
continue;
}

@@ -228,14 +228,14 @@ void QgsOfflineEditing::synchronize( bool useTransaction )
QMap<QPair<QString, QString>, std::shared_ptr<QgsTransactionGroup>> transactionGroups;
if ( useTransaction )
{
for ( std::shared_ptr<QgsVectorLayer> &remoteLayer : remoteLayersByOfflineId )
for ( const std::shared_ptr<QgsVectorLayer> &remoteLayer : std::as_const( remoteLayersByOfflineId ) )
{
const QString connectionString = QgsTransaction::connectionString( remoteLayer->source() );
const QPair pair( remoteLayer->providerType(), connectionString );
std::shared_ptr<QgsTransactionGroup> transactionGroup = transactionGroups.value( pair );

if ( !transactionGroup.get() )
transactionGroup = std::make_shared<QgsTransactionGroup>( this );
transactionGroup = std::make_shared<QgsTransactionGroup>();

if ( !transactionGroup->addLayer( remoteLayer.get() ) )
{
@@ -249,7 +249,8 @@ void QgsOfflineEditing::synchronize( bool useTransaction )
QgsDebugMsgLevel( QStringLiteral( "Created %1 transaction groups" ).arg( transactionGroups.count() ), 4 );
}

for ( int offlineLayerId : remoteLayersByOfflineId.keys() )
const QList<int> offlineIds = remoteLayersByOfflineId.keys();
for ( int offlineLayerId : offlineIds )
{
std::shared_ptr<QgsVectorLayer> remoteLayer = remoteLayersByOfflineId.value( offlineLayerId );
QgsVectorLayer *offlineLayer = offlineLayersByOfflineId.value( offlineLayerId );
@@ -279,7 +280,7 @@ void QgsOfflineEditing::synchronize( bool useTransaction )
}


for ( int offlineLayerId : remoteLayersByOfflineId.keys() )
for ( int offlineLayerId : offlineIds )
{
std::shared_ptr<QgsVectorLayer> remoteLayer = remoteLayersByOfflineId[offlineLayerId];
QgsVectorLayer *offlineLayer = offlineLayersByOfflineId[offlineLayerId];
@@ -1244,7 +1245,7 @@ void QgsOfflineEditing::increaseCommitNo( sqlite3 *db )
sqlExec( db, sql );
}

void QgsOfflineEditing::addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid, QString remotePk )
void QgsOfflineEditing::addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid, const QString &remotePk )
{
const QString sql = QStringLiteral( "INSERT INTO 'log_fids' VALUES ( %1, %2, %3, %4 )" ).arg( layerId ).arg( offlineFid ).arg( remoteFid ).arg( sqlEscape( remotePk ) );
sqlExec( db, sql );
@@ -1715,7 +1716,7 @@ int QgsOfflineEditing::getLayerPkIdx( const QgsVectorLayer *layer ) const
QString QgsOfflineEditing::sqlEscape( QString value ) const
{
if ( value.isNull() )
return QString( "NULL" );
return QStringLiteral( "NULL" );

value.replace( "'", "''" );

@@ -71,7 +71,11 @@ class CORE_EXPORT QgsOfflineEditing : public QObject
//! Returns TRUE if current project is offline
bool isOfflineProject() const;

//! Synchronize to remote layers

/**
* Synchronize to remote layers
* \param useTransaction enforce the remote layer modifications with the same source to be in a transaction group
*/
void synchronize( bool useTransaction = false );

signals:
@@ -140,7 +144,7 @@ class CORE_EXPORT QgsOfflineEditing : public QObject
int getOrCreateLayerId( sqlite3 *db, const QString &qgisLayerId );
int getCommitNo( sqlite3 *db );
void increaseCommitNo( sqlite3 *db );
void addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid, QString remotePk );
void addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid, const QString &remotePk );
QgsFeatureId remoteFid( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsVectorLayer *remoteLayer );
QgsFeatureId offlineFid( sqlite3 *db, int layerId, QgsFeatureId remoteFid );
bool isAddedFeature( sqlite3 *db, int layerId, QgsFeatureId fid );

0 comments on commit a5968fa

Please sign in to comment.