Skip to content
Permalink
Browse files

Fix visibility presets in combination w/ offline editing

  • Loading branch information
m-kuhn committed Feb 28, 2017
1 parent dfe268f commit cfdb02585fcd7a65f0ab12a52b752e53390074db
Showing with 38 additions and 0 deletions.
  1. +33 −0 src/core/qgsofflineediting.cpp
  2. +5 −0 src/core/qgsofflineediting.h
@@ -30,6 +30,7 @@
#include "qgsvectorlayereditbuffer.h"
#include "qgsvectorlayerjoinbuffer.h"
#include "qgsslconnect.h"
#include "qgsvisibilitypresetcollection.h"

#include <QDir>
#include <QDomDocument>
@@ -257,6 +258,7 @@ void QgsOfflineEditing::synchronize()
// copy style
copySymbology( offlineLayer, remoteLayer );
updateRelations( offlineLayer, remoteLayer );
updateVisibilityPresets( offlineLayer, remoteLayer );

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

updateRelations( layer, newLayer );
updateVisibilityPresets( layer, newLayer );
// copy features
newLayer->startEditing();
QgsFeature f;
@@ -970,6 +973,36 @@ void QgsOfflineEditing::updateRelations( QgsVectorLayer* sourceLayer, QgsVectorL
}
}

void QgsOfflineEditing::updateVisibilityPresets( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer )
{
QgsVisibilityPresetCollection* presetCollection = QgsProject::instance()->visibilityPresetCollection();
QStringList visibilityPresets = presetCollection->presets();

Q_FOREACH ( const QString& preset, visibilityPresets )
{
QgsVisibilityPresetCollection::PresetRecord record = presetCollection->presetState( preset );

if ( record.mVisibleLayerIDs.removeOne( sourceLayer->id() ) )
record.mVisibleLayerIDs.append( targetLayer->id() );

QString style = record.mPerLayerCurrentStyle.value( sourceLayer->id() );
if ( !style.isNull() )
{
record.mPerLayerCurrentStyle.remove( sourceLayer->id() );
record.mPerLayerCurrentStyle.insert( targetLayer->id(), style );
}

if ( !record.mPerLayerCheckedLegendSymbols.contains( sourceLayer->id() ) )
{
QSet<QString> checkedSymbols = record.mPerLayerCheckedLegendSymbols.value( sourceLayer->id() );
record.mPerLayerCheckedLegendSymbols.remove( sourceLayer->id() );
record.mPerLayerCheckedLegendSymbols.insert( targetLayer->id(), checkedSymbols );
}

QgsProject::instance()->visibilityPresetCollection()->update( preset, record );
}
}

// 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 )
{
@@ -112,6 +112,11 @@ class CORE_EXPORT QgsOfflineEditing : public QObject
* Updates all relations that reference or are referenced by the source layer to the targetLayer.
*/
void updateRelations( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );
/**
* Update all visibility presets that affect the source layer.
*/
void updateVisibilityPresets( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );

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

void showWarning( const QString& message );

1 comment on commit cfdb025

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids commented on cfdb025 Mar 1, 2017

@m-kuhn port to master?

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