|
30 | 30 | #include "qgsvectorlayereditbuffer.h"
|
31 | 31 | #include "qgsvectorlayerjoinbuffer.h"
|
32 | 32 | #include "qgsslconnect.h"
|
| 33 | +#include "qgsvisibilitypresetcollection.h" |
33 | 34 |
|
34 | 35 | #include <QDir>
|
35 | 36 | #include <QDomDocument>
|
@@ -257,6 +258,7 @@ void QgsOfflineEditing::synchronize()
|
257 | 258 | // copy style
|
258 | 259 | copySymbology( offlineLayer, remoteLayer );
|
259 | 260 | updateRelations( offlineLayer, remoteLayer );
|
| 261 | + updateVisibilityPresets( offlineLayer, remoteLayer ); |
260 | 262 |
|
261 | 263 | // apply layer edit log
|
262 | 264 | QString qgisLayerId = layer->id();
|
@@ -632,6 +634,7 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
|
632 | 634 | }
|
633 | 635 |
|
634 | 636 | updateRelations( layer, newLayer );
|
| 637 | + updateVisibilityPresets( layer, newLayer ); |
635 | 638 | // copy features
|
636 | 639 | newLayer->startEditing();
|
637 | 640 | QgsFeature f;
|
@@ -970,6 +973,36 @@ void QgsOfflineEditing::updateRelations( QgsVectorLayer* sourceLayer, QgsVectorL
|
970 | 973 | }
|
971 | 974 | }
|
972 | 975 |
|
| 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 | + |
973 | 1006 | // NOTE: use this to map column indices in case the remote geometry column is not last
|
974 | 1007 | QMap<int, int> QgsOfflineEditing::attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer )
|
975 | 1008 | {
|
|
0 commit comments