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,7 @@ extern "C"
50
51
51
52
QgsOfflineEditing::QgsOfflineEditing ()
52
53
{
53
- connect ( QgsMapLayerRegistry::instance (), SIGNAL ( layerWasAdded ( QgsMapLayer* ) ), this , SLOT ( layerAdded ( QgsMapLayer* ) ) );
54
+ connect ( QgsMapLayerRegistry::instance (), SIGNAL ( layerWasAdded ( QgsMapLayer* ) ), this , SLOT ( layerAdded ( QgsMapLayer* ) ) );
54
55
}
55
56
56
57
QgsOfflineEditing::~QgsOfflineEditing ()
@@ -522,8 +523,8 @@ void QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, con
522
523
// NOTE: Spatialite provider ignores position of geometry column
523
524
// fill gap in QgsAttributeMap if geometry column is not last (WORKAROUND)
524
525
int column = 0 ;
525
- QgsAttributes newAttrs;
526
526
QgsAttributes attrs = f.attributes ();
527
+ QgsAttributes newAttrs (attrs.count ());
527
528
for ( int it = 0 ; it < attrs.count (); ++it )
528
529
{
529
530
newAttrs[column++] = attrs[it];
@@ -551,10 +552,10 @@ void QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, con
551
552
552
553
// NOTE: insert fids in this loop, as the db is locked during newLayer->nextFeature()
553
554
sqlExec ( db, " BEGIN" );
554
- for ( int i = 0 ; i < remoteFeatureIds.size (); i++ )
555
+ int remoteCount = remoteFeatureIds.size ();
556
+ for ( int i = 0 ; i < remoteCount; i++ )
555
557
{
556
- addFidLookup ( db, layerId, offlineFeatureIds.at ( i ), remoteFeatureIds.at ( i ) );
557
-
558
+ addFidLookup ( db, layerId, offlineFeatureIds.at ( i ), remoteFeatureIds.at ( remoteCount - (i+1 ) ) );
558
559
emit progressUpdated ( featureCount++ );
559
560
}
560
561
sqlExec ( db, " COMMIT" );
@@ -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,48 @@ 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::layerAdded ( QgsMapLayer* layer )
1223
+ {
1224
+ // detect offline layer
1225
+ if ( layer->customProperty ( CUSTOM_PROPERTY_IS_OFFLINE_EDITABLE, false ).toBool () )
1226
+ {
1227
+ QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( layer );
1228
+ connect ( vLayer, SIGNAL ( editingStarted () ), this , SLOT ( startListenFeatureChanges () ) );
1229
+ connect ( vLayer, SIGNAL ( editingStopped () ), this , SLOT ( stopListenFeatureChanges () ) );
1230
+ }
1231
+ }
1232
+
1233
+
0 commit comments