From 778f223598b3ad488562c9f6af97f32a54d0c6ff Mon Sep 17 00:00:00 2001 From: vinayan Date: Mon, 13 May 2013 11:17:57 +0530 Subject: [PATCH] more fixes to offlineediting - back to life --- src/core/qgsofflineediting.cpp | 66 ++++++++++++++++++++++------------ src/core/qgsofflineediting.h | 4 ++- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/src/core/qgsofflineediting.cpp b/src/core/qgsofflineediting.cpp index 748f4d854e33..5512200083dd 100644 --- a/src/core/qgsofflineediting.cpp +++ b/src/core/qgsofflineediting.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -50,7 +51,6 @@ extern "C" QgsOfflineEditing::QgsOfflineEditing() { - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( layerAdded( QgsMapLayer* ) ) ); } QgsOfflineEditing::~QgsOfflineEditing() @@ -551,13 +551,14 @@ void QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, con // NOTE: insert fids in this loop, as the db is locked during newLayer->nextFeature() sqlExec( db, "BEGIN" ); - for ( int i = 0; i < remoteFeatureIds.size(); i++ ) + int remoteCount = remoteFeatureIds.size(); + for ( int i = 0; i < remoteCount; i++ ) { - addFidLookup( db, layerId, offlineFeatureIds.at( i ), remoteFeatureIds.at( i ) ); - + addFidLookup( db, layerId, offlineFeatureIds.at( i ), remoteFeatureIds.at( remoteCount - (i+1) ) ); emit progressUpdated( featureCount++ ); } sqlExec( db, "COMMIT" ); + listenStartStopEdits( newLayer ); } else { @@ -1024,25 +1025,6 @@ QgsOfflineEditing::GeometryChanges QgsOfflineEditing::sqlQueryGeometryChanges( s return values; } -void QgsOfflineEditing::layerAdded( QgsMapLayer* layer ) -{ - // detect offline layer - if ( layer->customProperty( CUSTOM_PROPERTY_IS_OFFLINE_EDITABLE, false ).toBool() ) - { - // enable logging - connect( layer, SIGNAL( committedAttributesAdded( const QString&, const QList& ) ), - this, SLOT( committedAttributesAdded( const QString&, const QList& ) ) ); - connect( layer, SIGNAL( committedFeaturesAdded( const QString&, const QgsFeatureList& ) ), - this, SLOT( committedFeaturesAdded( const QString&, const QgsFeatureList& ) ) ); - connect( layer, SIGNAL( committedFeaturesRemoved( const QString&, const QgsFeatureIds& ) ), - this, SLOT( committedFeaturesRemoved( const QString&, const QgsFeatureIds& ) ) ); - connect( layer, SIGNAL( committedAttributeValuesChanges( const QString&, const QgsChangedAttributesMap& ) ), - this, SLOT( committedAttributeValuesChanges( const QString&, const QgsChangedAttributesMap& ) ) ); - connect( layer, SIGNAL( committedGeometriesChanges( const QString&, const QgsGeometryMap& ) ), - this, SLOT( committedGeometriesChanges( const QString&, const QgsGeometryMap& ) ) ); - } -} - void QgsOfflineEditing::committedAttributesAdded( const QString& qgisLayerId, const QList& addedAttributes ) { sqlite3* db = openLoggingDb(); @@ -1204,3 +1186,41 @@ void QgsOfflineEditing::committedGeometriesChanges( const QString& qgisLayerId, increaseCommitNo( db ); sqlite3_close( db ); } + +void QgsOfflineEditing::startListenFeatureChanges() +{ + QgsVectorLayer* vLayer = qobject_cast( sender() ); + // enable logging + connect( vLayer->editBuffer(), SIGNAL( committedAttributesAdded( const QString&, const QList& ) ), + this, SLOT( committedAttributesAdded( const QString&, const QList& ) ) ); + connect( vLayer, SIGNAL( committedFeaturesAdded( const QString&, const QgsFeatureList& ) ), + this, SLOT( committedFeaturesAdded( const QString&, const QgsFeatureList& ) ) ); + connect( vLayer, SIGNAL( committedFeaturesRemoved( const QString&, const QgsFeatureIds& ) ), + this, SLOT( committedFeaturesRemoved( const QString&, const QgsFeatureIds& ) ) ); + connect( vLayer->editBuffer(), SIGNAL( committedAttributeValuesChanges( const QString&, const QgsChangedAttributesMap& ) ), + this, SLOT( committedAttributeValuesChanges( const QString&, const QgsChangedAttributesMap& ) ) ); + connect( vLayer->editBuffer(), SIGNAL( committedGeometriesChanges( const QString&, const QgsGeometryMap& ) ), + this, SLOT( committedGeometriesChanges( const QString&, const QgsGeometryMap& ) ) ); +} + +void QgsOfflineEditing::stopListenFeatureChanges() +{ + QgsVectorLayer* vLayer = qobject_cast( sender() ); + // disable logging + disconnect( vLayer->editBuffer(), SIGNAL( committedAttributesAdded( const QString&, const QList& ) ), + this, SLOT( committedAttributesAdded( const QString&, const QList& ) ) ); + disconnect( vLayer, SIGNAL( committedFeaturesAdded( const QString&, const QgsFeatureList& ) ), + this, SLOT( committedFeaturesAdded( const QString&, const QgsFeatureList& ) ) ); + disconnect( vLayer, SIGNAL( committedFeaturesRemoved( const QString&, const QgsFeatureIds& ) ), + this, SLOT( committedFeaturesRemoved( const QString&, const QgsFeatureIds& ) ) ); + disconnect( vLayer->editBuffer(), SIGNAL( committedAttributeValuesChanges( const QString&, const QgsChangedAttributesMap& ) ), + this, SLOT( committedAttributeValuesChanges( const QString&, const QgsChangedAttributesMap& ) ) ); + disconnect( vLayer->editBuffer(), SIGNAL( committedGeometriesChanges( const QString&, const QgsGeometryMap& ) ), + this, SLOT( committedGeometriesChanges( const QString&, const QgsGeometryMap& ) ) ); +} + +void QgsOfflineEditing::listenStartStopEdits( QgsVectorLayer *vLayer ) +{ + connect( vLayer, SIGNAL( editingStarted() ), this, SLOT( startListenFeatureChanges() ) ); + connect( vLayer, SIGNAL( editingStopped() ), this, SLOT( stopListenFeatureChanges() ) ); +} diff --git a/src/core/qgsofflineediting.h b/src/core/qgsofflineediting.h index cb408b7b7041..6534855c9811 100644 --- a/src/core/qgsofflineediting.h +++ b/src/core/qgsofflineediting.h @@ -134,14 +134,16 @@ class CORE_EXPORT QgsOfflineEditing : public QObject }; typedef QList GeometryChanges; GeometryChanges sqlQueryGeometryChanges( sqlite3* db, const QString& sql ); + void listenStartStopEdits( QgsVectorLayer* vLayer ); private slots: - void layerAdded( QgsMapLayer* layer ); void committedAttributesAdded( const QString& qgisLayerId, const QList& addedAttributes ); void committedFeaturesAdded( const QString& qgisLayerId, const QgsFeatureList& addedFeatures ); void committedFeaturesRemoved( const QString& qgisLayerId, const QgsFeatureIds& deletedFeatureIds ); void committedAttributeValuesChanges( const QString& qgisLayerId, const QgsChangedAttributesMap& changedAttrsMap ); void committedGeometriesChanges( const QString& qgisLayerId, const QgsGeometryMap& changedGeometries ); + void startListenFeatureChanges(); + void stopListenFeatureChanges(); }; #endif // QGS_OFFLINE_EDITING_H