Skip to content

Commit

Permalink
Fix visibility presets in combination w/ offline editing
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Feb 28, 2017
1 parent dfe268f commit cfdb025
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/core/qgsofflineediting.cpp
Expand Up @@ -30,6 +30,7 @@
#include "qgsvectorlayereditbuffer.h"
#include "qgsvectorlayerjoinbuffer.h"
#include "qgsslconnect.h"
#include "qgsvisibilitypresetcollection.h"

#include <QDir>
#include <QDomDocument>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -632,6 +634,7 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
}

updateRelations( layer, newLayer );
updateVisibilityPresets( layer, newLayer );
// copy features
newLayer->startEditing();
QgsFeature f;
Expand Down Expand Up @@ -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 )
{
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsofflineediting.h
Expand Up @@ -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 );
Expand Down

1 comment on commit cfdb025

@3nids
Copy link
Member

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn port to master?

Please sign in to comment.