Skip to content

Commit

Permalink
customPropertyChanged signal in map layers to handle things like e.g.…
Browse files Browse the repository at this point in the history
… the offline layer indicator in the legend tree accordingly
  • Loading branch information
signedav committed Oct 21, 2020
1 parent cdff8ba commit 8a33a14
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions python/core/auto_generated/qgsmaplayer.sip.in
Expand Up @@ -1593,6 +1593,12 @@ Emitted when the validity of this layer changed.
.. versionadded:: 3.16
%End

void customPropertyChanged( QgsMapLayer *layer, const QString &key );
%Docstring
Emitted when a custom property of a node within the tree has been changed or removed

.. versionadded:: 3.16
%End

protected:

Expand Down
3 changes: 1 addition & 2 deletions src/app/qgslayertreeviewofflineindicator.cpp
Expand Up @@ -30,8 +30,7 @@ void QgsLayerTreeViewOfflineIndicatorProvider::connectSignals( QgsMapLayer *laye
if ( !layer )
return;

//this has to be solved different
connect( mLayerTreeView->layerTreeModel()->rootGroup(), &QgsLayerTreeNode::customPropertyChanged, this, [ this, layer ]( ) { this->onLayerChanged( layer ); } );
connect( layer, &QgsMapLayer::customPropertyChanged, this, [ this, layer ]( ) { this->onLayerChanged( layer ); } );
}

bool QgsLayerTreeViewOfflineIndicatorProvider::acceptLayer( QgsMapLayer *layer )
Expand Down
13 changes: 11 additions & 2 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -1707,7 +1707,11 @@ QStringList QgsMapLayer::customPropertyKeys() const

void QgsMapLayer::setCustomProperty( const QString &key, const QVariant &value )
{
mCustomProperties.setValue( key, value );
if ( !mCustomProperties.contains( key ) || mCustomProperties.value( key ) != value )
{
mCustomProperties.setValue( key, value );
emit customPropertyChanged( this, key );
}
}

void QgsMapLayer::setCustomProperties( const QgsObjectCustomProperties &properties )
Expand All @@ -1727,7 +1731,12 @@ QVariant QgsMapLayer::customProperty( const QString &value, const QVariant &defa

void QgsMapLayer::removeCustomProperty( const QString &key )
{
mCustomProperties.remove( key );

if ( mCustomProperties.contains( key ) )
{
mCustomProperties.remove( key );
emit customPropertyChanged( this, key );
}
}

QgsError QgsMapLayer::error() const
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsmaplayer.h
Expand Up @@ -1424,6 +1424,12 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
void isValidChanged();

/**
* Emitted when a custom property of a node within the tree has been changed or removed
*
* \since QGIS 3.16
*/
void customPropertyChanged( QgsMapLayer *layer, const QString &key );

private slots:

Expand Down

0 comments on commit 8a33a14

Please sign in to comment.