25
25
#include < qgsofflineediting.h>
26
26
#include < qgsproject.h>
27
27
#include < qgsvectordataprovider.h>
28
+ #include < qgsvectorlayereditbuffer.h>
28
29
29
30
#include < QDir>
30
31
#include < QDomDocument>
@@ -50,7 +51,6 @@ extern "C"
50
51
51
52
QgsOfflineEditing::QgsOfflineEditing ()
52
53
{
53
- connect ( QgsMapLayerRegistry::instance (), SIGNAL ( layerWasAdded ( QgsMapLayer* ) ), this , SLOT ( layerAdded ( QgsMapLayer* ) ) );
54
54
}
55
55
56
56
QgsOfflineEditing::~QgsOfflineEditing ()
@@ -551,13 +551,14 @@ void QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, con
551
551
552
552
// NOTE: insert fids in this loop, as the db is locked during newLayer->nextFeature()
553
553
sqlExec ( db, " BEGIN" );
554
- for ( int i = 0 ; i < remoteFeatureIds.size (); i++ )
554
+ int remoteCount = remoteFeatureIds.size ();
555
+ for ( int i = 0 ; i < remoteCount; i++ )
555
556
{
556
- addFidLookup ( db, layerId, offlineFeatureIds.at ( i ), remoteFeatureIds.at ( i ) );
557
-
557
+ addFidLookup ( db, layerId, offlineFeatureIds.at ( i ), remoteFeatureIds.at ( remoteCount - (i+1 ) ) );
558
558
emit progressUpdated ( featureCount++ );
559
559
}
560
560
sqlExec ( db, " COMMIT" );
561
+ listenStartStopEdits ( newLayer );
561
562
}
562
563
else
563
564
{
@@ -1024,25 +1025,6 @@ QgsOfflineEditing::GeometryChanges QgsOfflineEditing::sqlQueryGeometryChanges( s
1024
1025
return values;
1025
1026
}
1026
1027
1027
- void QgsOfflineEditing::layerAdded ( QgsMapLayer* layer )
1028
- {
1029
- // detect offline layer
1030
- if ( layer->customProperty ( CUSTOM_PROPERTY_IS_OFFLINE_EDITABLE, false ).toBool () )
1031
- {
1032
- // enable logging
1033
- connect ( layer, SIGNAL ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ),
1034
- this , SLOT ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ) );
1035
- connect ( layer, SIGNAL ( committedFeaturesAdded ( const QString&, const QgsFeatureList& ) ),
1036
- this , SLOT ( committedFeaturesAdded ( const QString&, const QgsFeatureList& ) ) );
1037
- connect ( layer, SIGNAL ( committedFeaturesRemoved ( const QString&, const QgsFeatureIds& ) ),
1038
- this , SLOT ( committedFeaturesRemoved ( const QString&, const QgsFeatureIds& ) ) );
1039
- connect ( layer, SIGNAL ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ),
1040
- this , SLOT ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ) );
1041
- connect ( layer, SIGNAL ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ),
1042
- this , SLOT ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ) );
1043
- }
1044
- }
1045
-
1046
1028
void QgsOfflineEditing::committedAttributesAdded ( const QString& qgisLayerId, const QList<QgsField>& addedAttributes )
1047
1029
{
1048
1030
sqlite3* db = openLoggingDb ();
@@ -1204,3 +1186,41 @@ void QgsOfflineEditing::committedGeometriesChanges( const QString& qgisLayerId,
1204
1186
increaseCommitNo ( db );
1205
1187
sqlite3_close ( db );
1206
1188
}
1189
+
1190
+ void QgsOfflineEditing::startListenFeatureChanges ()
1191
+ {
1192
+ QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( sender () );
1193
+ // enable logging
1194
+ connect ( vLayer->editBuffer (), SIGNAL ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ),
1195
+ this , SLOT ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ) );
1196
+ connect ( vLayer, SIGNAL ( committedFeaturesAdded ( const QString&, const QgsFeatureList& ) ),
1197
+ this , SLOT ( committedFeaturesAdded ( const QString&, const QgsFeatureList& ) ) );
1198
+ connect ( vLayer, SIGNAL ( committedFeaturesRemoved ( const QString&, const QgsFeatureIds& ) ),
1199
+ this , SLOT ( committedFeaturesRemoved ( const QString&, const QgsFeatureIds& ) ) );
1200
+ connect ( vLayer->editBuffer (), SIGNAL ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ),
1201
+ this , SLOT ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ) );
1202
+ connect ( vLayer->editBuffer (), SIGNAL ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ),
1203
+ this , SLOT ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ) );
1204
+ }
1205
+
1206
+ void QgsOfflineEditing::stopListenFeatureChanges ()
1207
+ {
1208
+ QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( sender () );
1209
+ // disable logging
1210
+ disconnect ( vLayer->editBuffer (), SIGNAL ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ),
1211
+ this , SLOT ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ) );
1212
+ disconnect ( vLayer, SIGNAL ( committedFeaturesAdded ( const QString&, const QgsFeatureList& ) ),
1213
+ this , SLOT ( committedFeaturesAdded ( const QString&, const QgsFeatureList& ) ) );
1214
+ disconnect ( vLayer, SIGNAL ( committedFeaturesRemoved ( const QString&, const QgsFeatureIds& ) ),
1215
+ this , SLOT ( committedFeaturesRemoved ( const QString&, const QgsFeatureIds& ) ) );
1216
+ disconnect ( vLayer->editBuffer (), SIGNAL ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ),
1217
+ this , SLOT ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ) );
1218
+ disconnect ( vLayer->editBuffer (), SIGNAL ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ),
1219
+ this , SLOT ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ) );
1220
+ }
1221
+
1222
+ void QgsOfflineEditing::listenStartStopEdits ( QgsVectorLayer *vLayer )
1223
+ {
1224
+ connect ( vLayer, SIGNAL ( editingStarted () ), this , SLOT ( startListenFeatureChanges () ) );
1225
+ connect ( vLayer, SIGNAL ( editingStopped () ), this , SLOT ( stopListenFeatureChanges () ) );
1226
+ }
0 commit comments