Skip to content
Permalink
Browse files

Fix map themes in combination w/ offline editing

  • Loading branch information
m-kuhn committed Mar 2, 2017
1 parent e84829e commit 9c3fa187fa0406923305ad7cf03ba5cd0e6f052a
@@ -27,16 +27,18 @@ class QgsMapThemeCollection : QObject
bool operator==( const QgsMapThemeCollection::MapThemeLayerRecord& other ) const;
bool operator!=( const QgsMapThemeCollection::MapThemeLayerRecord& other ) const;

//! Returns map layer or null if the layer does not exist anymore
QgsMapLayer* layer() const;

//! Whether current style is valid and should be applied

void setLayer( QgsMapLayer* layer );


bool usingCurrentStyle;
//! Name of the current style of the layer

QString currentStyle;
//! Whether checkedLegendItems should be applied

bool usingLegendItems;
//! Rule keys of check legend items in layer tree model

QSet<QString> checkedLegendItems;
};

@@ -55,6 +57,10 @@ class QgsMapThemeCollection : QObject

//! Sets layer records for the theme.
void setLayerRecords( const QList<QgsMapThemeCollection::MapThemeLayerRecord>& records );
void removeLayerRecord( QgsMapLayer* layer );


void addLayerRecord( const QgsMapThemeCollection::MapThemeLayerRecord& record );

//! Return set with only records for valid layers
//! @note not available in python bindings
@@ -465,6 +465,20 @@ void QgsMapThemeCollection::layerStyleRenamed( const QString& oldName, const QSt
emit mapThemesChanged();
}

void QgsMapThemeCollection::MapThemeRecord::removeLayerRecord( QgsMapLayer* layer )
{
for ( int i = 0; i < mLayerRecords.length(); ++i )
{
if ( mLayerRecords.at( i ).layer() == layer )
mLayerRecords.removeAt( i );
}
}

void QgsMapThemeCollection::MapThemeRecord::addLayerRecord( const QgsMapThemeCollection::MapThemeLayerRecord& record )
{
mLayerRecords.append( record );
}

QHash<QgsMapLayer*, QgsMapThemeCollection::MapThemeLayerRecord> QgsMapThemeCollection::MapThemeRecord::validLayerRecords() const
{
QHash<QgsMapLayer*, MapThemeLayerRecord> validSet;
@@ -475,3 +489,8 @@ QHash<QgsMapLayer*, QgsMapThemeCollection::MapThemeLayerRecord> QgsMapThemeColle
}
return validSet;
}

void QgsMapThemeCollection::MapThemeLayerRecord::setLayer( QgsMapLayer* layer )
{
mLayer = layer;
}
@@ -74,6 +74,9 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject
//! Returns map layer or null if the layer does not exist anymore
QgsMapLayer* layer() const { return mLayer; }

//! Set the map layer for this record
void setLayer( QgsMapLayer* layer );

//! Whether current style is valid and should be applied
bool usingCurrentStyle;
//! Name of the current style of the layer
@@ -112,6 +115,12 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject
//! Sets layer records for the theme.
void setLayerRecords( const QList<MapThemeLayerRecord>& records ) { mLayerRecords = records; }

//! Removes a record for \a layer if present.
void removeLayerRecord( QgsMapLayer* layer );

//! Add a new record for a layer.
void addLayerRecord( const MapThemeLayerRecord& record );

//! Return set with only records for valid layers
//! @note not available in python bindings
QHash<QgsMapLayer*, MapThemeLayerRecord> validLayerRecords() const;
@@ -33,6 +33,7 @@
#include "qgslogger.h"
#include "qgsvectorlayerutils.h"
#include "qgsrelationmanager.h"
#include "qgsmapthemecollection.h"

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

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

updateRelations( layer, newLayer );
updateMapThemes( layer, newLayer );
// copy features
newLayer->startEditing();
QgsFeature f;
@@ -924,6 +927,29 @@ void QgsOfflineEditing::updateRelations( QgsVectorLayer* sourceLayer, QgsVectorL
}
}

void QgsOfflineEditing::updateMapThemes( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer )
{
QgsMapThemeCollection* mapThemeCollection = QgsProject::instance()->mapThemeCollection();
QStringList mapThemeNames = mapThemeCollection->mapThemes();

Q_FOREACH ( const QString& mapThemeName, mapThemeNames )
{
QgsMapThemeCollection::MapThemeRecord record = mapThemeCollection->mapThemeState( mapThemeName );

Q_FOREACH ( QgsMapThemeCollection::MapThemeLayerRecord layerRecord, record.layerRecords() )
{
if ( layerRecord.layer() == sourceLayer )
{
layerRecord.setLayer( targetLayer );
record.removeLayerRecord( sourceLayer );
record.addLayerRecord( layerRecord );
}
}

QgsProject::instance()->mapThemeCollection()->update( mapThemeName, 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 )
{
@@ -113,6 +113,12 @@ 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 map themes that affect the source layer.
*/
void updateMapThemes( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );

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

void showWarning( const QString& message );

0 comments on commit 9c3fa18

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