Skip to content

Commit 778f223

Browse files
committed
more fixes to offlineediting - back to life
1 parent de7deb7 commit 778f223

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

src/core/qgsofflineediting.cpp

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <qgsofflineediting.h>
2626
#include <qgsproject.h>
2727
#include <qgsvectordataprovider.h>
28+
#include <qgsvectorlayereditbuffer.h>
2829

2930
#include <QDir>
3031
#include <QDomDocument>
@@ -50,7 +51,6 @@ extern "C"
5051

5152
QgsOfflineEditing::QgsOfflineEditing()
5253
{
53-
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( layerAdded( QgsMapLayer* ) ) );
5454
}
5555

5656
QgsOfflineEditing::~QgsOfflineEditing()
@@ -551,13 +551,14 @@ void QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, con
551551

552552
// NOTE: insert fids in this loop, as the db is locked during newLayer->nextFeature()
553553
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++ )
555556
{
556-
addFidLookup( db, layerId, offlineFeatureIds.at( i ), remoteFeatureIds.at( i ) );
557-
557+
addFidLookup( db, layerId, offlineFeatureIds.at( i ), remoteFeatureIds.at( remoteCount - (i+1) ) );
558558
emit progressUpdated( featureCount++ );
559559
}
560560
sqlExec( db, "COMMIT" );
561+
listenStartStopEdits( newLayer );
561562
}
562563
else
563564
{
@@ -1024,25 +1025,6 @@ QgsOfflineEditing::GeometryChanges QgsOfflineEditing::sqlQueryGeometryChanges( s
10241025
return values;
10251026
}
10261027

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-
10461028
void QgsOfflineEditing::committedAttributesAdded( const QString& qgisLayerId, const QList<QgsField>& addedAttributes )
10471029
{
10481030
sqlite3* db = openLoggingDb();
@@ -1204,3 +1186,41 @@ void QgsOfflineEditing::committedGeometriesChanges( const QString& qgisLayerId,
12041186
increaseCommitNo( db );
12051187
sqlite3_close( db );
12061188
}
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+
}

src/core/qgsofflineediting.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,16 @@ class CORE_EXPORT QgsOfflineEditing : public QObject
134134
};
135135
typedef QList<GeometryChange> GeometryChanges;
136136
GeometryChanges sqlQueryGeometryChanges( sqlite3* db, const QString& sql );
137+
void listenStartStopEdits( QgsVectorLayer* vLayer );
137138

138139
private slots:
139-
void layerAdded( QgsMapLayer* layer );
140140
void committedAttributesAdded( const QString& qgisLayerId, const QList<QgsField>& addedAttributes );
141141
void committedFeaturesAdded( const QString& qgisLayerId, const QgsFeatureList& addedFeatures );
142142
void committedFeaturesRemoved( const QString& qgisLayerId, const QgsFeatureIds& deletedFeatureIds );
143143
void committedAttributeValuesChanges( const QString& qgisLayerId, const QgsChangedAttributesMap& changedAttrsMap );
144144
void committedGeometriesChanges( const QString& qgisLayerId, const QgsGeometryMap& changedGeometries );
145+
void startListenFeatureChanges();
146+
void stopListenFeatureChanges();
145147
};
146148

147149
#endif // QGS_OFFLINE_EDITING_H

0 commit comments

Comments
 (0)