Skip to content

Commit

Permalink
reading of all the custom properties to e.g. copy them to the offline…
Browse files Browse the repository at this point in the history
… project
  • Loading branch information
signedav authored and nyalldawson committed Mar 18, 2020
1 parent ac40ed4 commit 8131799
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions python/core/auto_generated/qgsmaplayer.sip.in
Expand Up @@ -608,6 +608,15 @@ Read a custom property from layer. Properties are stored in a map and saved in p
Set custom properties for layer. Current properties are dropped.

.. versionadded:: 3.0
%End

const QgsObjectCustomProperties &customProperties() const;
%Docstring
Read all custom properties from layer. Properties are stored in a map and saved in project file.

.. seealso:: :py:func:`setCustomProperties`

.. versionadded:: 3.14
%End

void removeCustomProperty( const QString &key );
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -1699,6 +1699,11 @@ void QgsMapLayer::setCustomProperties( const QgsObjectCustomProperties &properti
mCustomProperties = properties;
}

const QgsObjectCustomProperties &QgsMapLayer::customProperties() const
{
return mCustomProperties;
}

QVariant QgsMapLayer::customProperty( const QString &value, const QVariant &defaultValue ) const
{
return mCustomProperties.value( value, defaultValue );
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsmaplayer.h
Expand Up @@ -614,6 +614,13 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
void setCustomProperties( const QgsObjectCustomProperties &properties );

/**
* Read all custom properties from layer. Properties are stored in a map and saved in project file.
* \see setCustomProperties
* \since QGIS 3.14
*/
const QgsObjectCustomProperties &customProperties() const;

/**
* Remove a custom property from layer. Properties are stored in a map and saved in project file.
* \see setCustomProperty()
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsofflineediting.cpp
Expand Up @@ -848,6 +848,9 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
showWarning( newLayer->commitErrors().join( QStringLiteral( "\n" ) ) );
}

// copy the custom properties from original layer
newLayer->setCustomProperties( layer->customProperties() );

// mark as offline layer
newLayer->setCustomProperty( CUSTOM_PROPERTY_IS_OFFLINE_EDITABLE, true );

Expand Down

0 comments on commit 8131799

Please sign in to comment.