Skip to content
Permalink
Browse files

Merge pull request #9402 from qgis/backport-8818-on-release-3_4

Backport #8818 on release-3_4
  • Loading branch information
m-kuhn committed Mar 6, 2019
2 parents b123b53 + bc4ec90 commit ee79ab29d8cfeef44f19a0e378f469ebd7c0d0fa
Showing with 37 additions and 0 deletions.
  1. +8 −0 src/core/qgsofflineediting.cpp
  2. +29 −0 tests/src/core/testqgsofflineediting.cpp
@@ -56,6 +56,7 @@ extern "C"
#define CUSTOM_PROPERTY_IS_OFFLINE_EDITABLE "isOfflineEditable"
#define CUSTOM_PROPERTY_REMOTE_SOURCE "remoteSource"
#define CUSTOM_PROPERTY_REMOTE_PROVIDER "remoteProvider"
#define CUSTOM_SHOW_FEATURE_COUNT "showFeatureCount"
#define PROJECT_ENTRY_SCOPE_OFFLINE "OfflineEditingPlugin"
#define PROJECT_ENTRY_KEY_OFFLINE_DB_PATH "/OfflineDbPath"

@@ -259,6 +260,11 @@ void QgsOfflineEditing::synchronize()
updateMapThemes( offlineLayer, remoteLayer );
updateLayerOrder( offlineLayer, remoteLayer );

//set QgsLayerTreeNode properties back
QgsLayerTreeLayer *layerTreeLayer = QgsProject::instance()->layerTreeRoot()->findLayer( offlineLayer->id() );
QgsLayerTreeLayer *newLayerTreeLayer = QgsProject::instance()->layerTreeRoot()->findLayer( remoteLayer->id() );
newLayerTreeLayer->setCustomProperty( CUSTOM_SHOW_FEATURE_COUNT, layerTreeLayer->customProperty( CUSTOM_SHOW_FEATURE_COUNT ) );

// apply layer edit log
QString qgisLayerId = layer->id();
QString sql = QStringLiteral( "SELECT \"id\" FROM 'log_layer_ids' WHERE \"qgis_id\" = '%1'" ).arg( qgisLayerId );
@@ -843,6 +849,8 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
if ( newLayerTreeLayer )
{
QgsLayerTreeNode *newLayerTreeLayerClone = newLayerTreeLayer->clone();
//copy the showFeatureCount property to the new node
newLayerTreeLayerClone->setCustomProperty( CUSTOM_SHOW_FEATURE_COUNT, layerTreeLayer->customProperty( CUSTOM_SHOW_FEATURE_COUNT ) );
QgsLayerTreeGroup *grp = qobject_cast<QgsLayerTreeGroup *>( newLayerTreeLayer->parent() );
parentTreeGroup->insertChildNode( index, newLayerTreeLayerClone );
if ( grp )
@@ -25,6 +25,7 @@
#include "qgsofflineediting.h"
#include "qgstest.h"
#include "qgsvectorlayerref.h"
#include "qgslayertree.h"

/**
* \ingroup UnitTests
@@ -107,12 +108,21 @@ void TestQgsOfflineEditing::createSpatialiteAndSynchronizeBack()
QCOMPARE( mpLayer->featureCount(), numberOfFeatures );
QCOMPARE( mpLayer->fields().size(), numberOfFields );

//set on LayerTreeNode showFeatureCount property
QgsLayerTreeLayer *layerTreelayer = QgsProject::instance()->layerTreeRoot()->findLayer( mpLayer->id() );
layerTreelayer->setCustomProperty( QStringLiteral( "showFeatureCount" ), 1 );

//convert
mOfflineEditing->convertToOfflineProject( offlineDataPath, offlineDbFile, layerIds, false, QgsOfflineEditing::SpatiaLite );

mpLayer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayers().first() );
QCOMPARE( mpLayer->name(), QStringLiteral( "points (offline)" ) );
QCOMPARE( mpLayer->featureCount(), numberOfFeatures );
//check LayerTreeNode showFeatureCount property
layerTreelayer = QgsProject::instance()->layerTreeRoot()->findLayer( mpLayer->id() );
QCOMPARE( layerTreelayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt(), 1 );
//unset on LayerTreeNode showFeatureCount property
layerTreelayer->setCustomProperty( QStringLiteral( "showFeatureCount" ), 0 );

//synchronize back
mOfflineEditing->synchronize();
@@ -121,6 +131,10 @@ void TestQgsOfflineEditing::createSpatialiteAndSynchronizeBack()
QCOMPARE( mpLayer->name(), QStringLiteral( "points" ) );
QCOMPARE( mpLayer->featureCount(), numberOfFeatures );
QCOMPARE( mpLayer->fields().size(), numberOfFields );

//check LayerTreeNode showFeatureCount property
layerTreelayer = QgsProject::instance()->layerTreeRoot()->findLayer( mpLayer->id() );
QCOMPARE( layerTreelayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt(), 0 );
}

void TestQgsOfflineEditing::createGeopackageAndSynchronizeBack()
@@ -134,6 +148,11 @@ void TestQgsOfflineEditing::createGeopackageAndSynchronizeBack()
it.nextFeature( firstFeatureBeforeAction );

connect( mOfflineEditing, &QgsOfflineEditing::warning, this, []( const QString & title, const QString & message ) { qDebug() << title << message; } );

//set on LayerTreeNode showFeatureCount property
QgsLayerTreeLayer *layerTreelayer = QgsProject::instance()->layerTreeRoot()->findLayer( mpLayer->id() );
layerTreelayer->setCustomProperty( QStringLiteral( "showFeatureCount" ), 1 );

//convert
mOfflineEditing->convertToOfflineProject( offlineDataPath, offlineDbFile, layerIds, false, QgsOfflineEditing::GPKG );

@@ -142,6 +161,9 @@ void TestQgsOfflineEditing::createGeopackageAndSynchronizeBack()
QCOMPARE( mpLayer->featureCount(), numberOfFeatures );
//comparing with the number +1 because GPKG created an fid
QCOMPARE( mpLayer->fields().size(), numberOfFields + 1 );
//check LayerTreeNode showFeatureCount property
layerTreelayer = QgsProject::instance()->layerTreeRoot()->findLayer( mpLayer->id() );
QCOMPARE( layerTreelayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt(), 1 );

QgsFeature firstFeatureInAction;
it = mpLayer->getFeatures();
@@ -159,13 +181,20 @@ void TestQgsOfflineEditing::createGeopackageAndSynchronizeBack()
mpLayer->commitChanges();
QCOMPARE( mpLayer->featureCount(), numberOfFeatures + 1 );

//unset on LayerTreeNode showFeatureCount property
layerTreelayer->setCustomProperty( QStringLiteral( "showFeatureCount" ), 0 );

//synchronize back
mOfflineEditing->synchronize();

mpLayer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayers().first() );
QCOMPARE( mpLayer->name(), QStringLiteral( "points" ) );
QCOMPARE( mpLayer->dataProvider()->featureCount(), numberOfFeatures + 1 );
QCOMPARE( mpLayer->fields().size(), numberOfFields );
//check LayerTreeNode showFeatureCount property
layerTreelayer = QgsProject::instance()->layerTreeRoot()->findLayer( mpLayer->id() );
QCOMPARE( layerTreelayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt(), 0 );

//get last feature
QgsFeature f = mpLayer->getFeature( mpLayer->dataProvider()->featureCount() - 1 );
qDebug() << "FID:" << f.id() << "Class:" << f.attribute( "Class" ).toString();

0 comments on commit ee79ab2

Please sign in to comment.
You can’t perform that action at this time.