@@ -287,11 +287,14 @@ void QgsOfflineEditing::synchronize()
287
287
showWarning ( remoteLayer->commitErrors ().join ( " \n " ) );
288
288
}
289
289
}
290
-
290
+ // Invalidate the connection to force a reload if the project is put offline
291
+ // again with the same path
292
+ offlineLayer->dataProvider ()->invalidateConnections ( QgsDataSourceURI ( offlineLayer->source () ).database () );
291
293
// remove offline layer
292
294
QgsMapLayerRegistry::instance ()->removeMapLayers (
293
295
( QStringList () << qgisLayerId ) );
294
296
297
+
295
298
// disable offline project
296
299
QString projectTitle = QgsProject::instance ()->title ();
297
300
projectTitle.remove ( QRegExp ( " \\ (offline\\ )$" ) );
@@ -459,6 +462,7 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
459
462
return nullptr ;
460
463
461
464
QString tableName = layer->id ();
465
+ QgsDebugMsg ( QString ( " Creating offline table %1 ..." ).arg ( tableName ) );
462
466
463
467
// create table
464
468
QString sql = QString ( " CREATE TABLE '%1' (" ).arg ( tableName );
@@ -541,9 +545,10 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
541
545
if ( rc == SQLITE_OK )
542
546
{
543
547
// add new layer
544
- QgsVectorLayer* newLayer = new QgsVectorLayer ( QString ( " dbname='%1' table='%2'%3 sql=" )
545
- .arg ( offlineDbPath,
546
- tableName, layer->hasGeometryType () ? " (Geometry)" : " " ),
548
+ QString connectionString = QString ( " dbname='%1' table='%2'%3 sql=" )
549
+ .arg ( offlineDbPath,
550
+ tableName, layer->hasGeometryType () ? " (Geometry)" : " " );
551
+ QgsVectorLayer* newLayer = new QgsVectorLayer ( connectionString,
547
552
layer->name () + " (offline)" , " spatialite" );
548
553
if ( newLayer->isValid () )
549
554
{
@@ -1296,33 +1301,39 @@ void QgsOfflineEditing::committedGeometriesChanges( const QString& qgisLayerId,
1296
1301
void QgsOfflineEditing::startListenFeatureChanges ()
1297
1302
{
1298
1303
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( sender () );
1299
- // enable logging
1300
- connect ( vLayer->editBuffer (), SIGNAL ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ),
1301
- this , SLOT ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ) );
1304
+ // enable logging, check if editBuffer is not null
1305
+ if ( vLayer->editBuffer () )
1306
+ {
1307
+ connect ( vLayer->editBuffer (), SIGNAL ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ),
1308
+ this , SLOT ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ) );
1309
+ connect ( vLayer->editBuffer (), SIGNAL ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ),
1310
+ this , SLOT ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ) );
1311
+ connect ( vLayer->editBuffer (), SIGNAL ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ),
1312
+ this , SLOT ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ) );
1313
+ }
1302
1314
connect ( vLayer, SIGNAL ( committedFeaturesAdded ( const QString&, const QgsFeatureList& ) ),
1303
1315
this , SLOT ( committedFeaturesAdded ( const QString&, const QgsFeatureList& ) ) );
1304
1316
connect ( vLayer, SIGNAL ( committedFeaturesRemoved ( const QString&, const QgsFeatureIds& ) ),
1305
1317
this , SLOT ( committedFeaturesRemoved ( const QString&, const QgsFeatureIds& ) ) );
1306
- connect ( vLayer->editBuffer (), SIGNAL ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ),
1307
- this , SLOT ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ) );
1308
- connect ( vLayer->editBuffer (), SIGNAL ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ),
1309
- this , SLOT ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ) );
1310
1318
}
1311
1319
1312
1320
void QgsOfflineEditing::stopListenFeatureChanges ()
1313
1321
{
1314
1322
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( sender () );
1315
- // disable logging
1316
- disconnect ( vLayer->editBuffer (), SIGNAL ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ),
1317
- this , SLOT ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ) );
1323
+ // disable logging, check if editBuffer is not null
1324
+ if ( vLayer->editBuffer () )
1325
+ {
1326
+ disconnect ( vLayer->editBuffer (), SIGNAL ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ),
1327
+ this , SLOT ( committedAttributesAdded ( const QString&, const QList<QgsField>& ) ) );
1328
+ disconnect ( vLayer->editBuffer (), SIGNAL ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ),
1329
+ this , SLOT ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ) );
1330
+ disconnect ( vLayer->editBuffer (), SIGNAL ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ),
1331
+ this , SLOT ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ) );
1332
+ }
1318
1333
disconnect ( vLayer, SIGNAL ( committedFeaturesAdded ( const QString&, const QgsFeatureList& ) ),
1319
1334
this , SLOT ( committedFeaturesAdded ( const QString&, const QgsFeatureList& ) ) );
1320
1335
disconnect ( vLayer, SIGNAL ( committedFeaturesRemoved ( const QString&, const QgsFeatureIds& ) ),
1321
1336
this , SLOT ( committedFeaturesRemoved ( const QString&, const QgsFeatureIds& ) ) );
1322
- disconnect ( vLayer->editBuffer (), SIGNAL ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ),
1323
- this , SLOT ( committedAttributeValuesChanges ( const QString&, const QgsChangedAttributesMap& ) ) );
1324
- disconnect ( vLayer->editBuffer (), SIGNAL ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ),
1325
- this , SLOT ( committedGeometriesChanges ( const QString&, const QgsGeometryMap& ) ) );
1326
1337
}
1327
1338
1328
1339
void QgsOfflineEditing::layerAdded ( QgsMapLayer* layer )
0 commit comments