Skip to content
Permalink
Browse files
Preserve custom layer order in offline editing
  • Loading branch information
m-kuhn committed Mar 23, 2017
1 parent 8cecf23 commit e5aaceacbe968280eac9a919c6731306e65eab7e
Showing with 34 additions and 0 deletions.
  1. +29 −0 src/core/qgsofflineediting.cpp
  2. +5 −0 src/core/qgsofflineediting.h
@@ -34,6 +34,7 @@
#include "qgsvectorlayerutils.h"
#include "qgsrelationmanager.h"
#include "qgsmapthemecollection.h"
#include "qgslayertree.h"

#include <QDir>
#include <QDomDocument>
@@ -258,6 +259,7 @@ void QgsOfflineEditing::synchronize()
copySymbology( offlineLayer, remoteLayer );
updateRelations( offlineLayer, remoteLayer );
updateMapThemes( offlineLayer, remoteLayer );
updateLayerOrder( offlineLayer, remoteLayer );

// apply layer edit log
QString qgisLayerId = layer->id();
@@ -617,6 +619,7 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit

updateRelations( layer, newLayer );
updateMapThemes( layer, newLayer );
updateLayerOrder( layer, newLayer );
// copy features
newLayer->startEditing();
QgsFeature f;
@@ -950,6 +953,32 @@ void QgsOfflineEditing::updateMapThemes( QgsVectorLayer *sourceLayer, QgsVectorL
}
}

void QgsOfflineEditing::updateLayerOrder( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer )
{
QList<QgsMapLayer *> layerOrder = QgsProject::instance()->layerTreeRoot()->customLayerOrder();

auto iterator = layerOrder.begin();

while ( iterator != layerOrder.end() )
{
if ( *iterator == targetLayer )
{
iterator = layerOrder.erase( iterator );
if ( iterator == layerOrder.end() )
break;
}

if ( *iterator == sourceLayer )
{
*iterator = targetLayer;
}

++iterator;
}

QgsProject::instance()->layerTreeRoot()->setCustomLayerOrder( layerOrder );
}

// NOTE: use this to map column indices in case the remote geometry column is not last
QMap<int, int> QgsOfflineEditing::attributeLookup( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer )
{
@@ -119,6 +119,11 @@ class CORE_EXPORT QgsOfflineEditing : public QObject
*/
void updateMapThemes( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );

/**
* Preserve the layer order
*/
void updateLayerOrder( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );

QMap<int, int> attributeLookup( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer );

void showWarning( const QString &message );

0 comments on commit e5aacea

Please sign in to comment.