Skip to content

Commit cfdb025

Browse files
committed
Fix visibility presets in combination w/ offline editing
1 parent dfe268f commit cfdb025

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/core/qgsofflineediting.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "qgsvectorlayereditbuffer.h"
3131
#include "qgsvectorlayerjoinbuffer.h"
3232
#include "qgsslconnect.h"
33+
#include "qgsvisibilitypresetcollection.h"
3334

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

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

634636
updateRelations( layer, newLayer );
637+
updateVisibilityPresets( layer, newLayer );
635638
// copy features
636639
newLayer->startEditing();
637640
QgsFeature f;
@@ -970,6 +973,36 @@ void QgsOfflineEditing::updateRelations( QgsVectorLayer* sourceLayer, QgsVectorL
970973
}
971974
}
972975

976+
void QgsOfflineEditing::updateVisibilityPresets( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer )
977+
{
978+
QgsVisibilityPresetCollection* presetCollection = QgsProject::instance()->visibilityPresetCollection();
979+
QStringList visibilityPresets = presetCollection->presets();
980+
981+
Q_FOREACH ( const QString& preset, visibilityPresets )
982+
{
983+
QgsVisibilityPresetCollection::PresetRecord record = presetCollection->presetState( preset );
984+
985+
if ( record.mVisibleLayerIDs.removeOne( sourceLayer->id() ) )
986+
record.mVisibleLayerIDs.append( targetLayer->id() );
987+
988+
QString style = record.mPerLayerCurrentStyle.value( sourceLayer->id() );
989+
if ( !style.isNull() )
990+
{
991+
record.mPerLayerCurrentStyle.remove( sourceLayer->id() );
992+
record.mPerLayerCurrentStyle.insert( targetLayer->id(), style );
993+
}
994+
995+
if ( !record.mPerLayerCheckedLegendSymbols.contains( sourceLayer->id() ) )
996+
{
997+
QSet<QString> checkedSymbols = record.mPerLayerCheckedLegendSymbols.value( sourceLayer->id() );
998+
record.mPerLayerCheckedLegendSymbols.remove( sourceLayer->id() );
999+
record.mPerLayerCheckedLegendSymbols.insert( targetLayer->id(), checkedSymbols );
1000+
}
1001+
1002+
QgsProject::instance()->visibilityPresetCollection()->update( preset, record );
1003+
}
1004+
}
1005+
9731006
// NOTE: use this to map column indices in case the remote geometry column is not last
9741007
QMap<int, int> QgsOfflineEditing::attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer )
9751008
{

src/core/qgsofflineediting.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ class CORE_EXPORT QgsOfflineEditing : public QObject
112112
* Updates all relations that reference or are referenced by the source layer to the targetLayer.
113113
*/
114114
void updateRelations( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );
115+
/**
116+
* Update all visibility presets that affect the source layer.
117+
*/
118+
void updateVisibilityPresets( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );
119+
115120
QMap<int, int> attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer );
116121

117122
void showWarning( const QString& message );

0 commit comments

Comments
 (0)