Skip to content

Commit 8a33a14

Browse files
committedOct 21, 2020
customPropertyChanged signal in map layers to handle things like e.g. the offline layer indicator in the legend tree accordingly
1 parent cdff8ba commit 8a33a14

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed
 

‎python/core/auto_generated/qgsmaplayer.sip.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,12 @@ Emitted when the validity of this layer changed.
15931593
.. versionadded:: 3.16
15941594
%End
15951595

1596+
void customPropertyChanged( QgsMapLayer *layer, const QString &key );
1597+
%Docstring
1598+
Emitted when a custom property of a node within the tree has been changed or removed
1599+
1600+
.. versionadded:: 3.16
1601+
%End
15961602

15971603
protected:
15981604

‎src/app/qgslayertreeviewofflineindicator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ void QgsLayerTreeViewOfflineIndicatorProvider::connectSignals( QgsMapLayer *laye
3030
if ( !layer )
3131
return;
3232

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

3736
bool QgsLayerTreeViewOfflineIndicatorProvider::acceptLayer( QgsMapLayer *layer )

‎src/core/qgsmaplayer.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,11 @@ QStringList QgsMapLayer::customPropertyKeys() const
17071707

17081708
void QgsMapLayer::setCustomProperty( const QString &key, const QVariant &value )
17091709
{
1710-
mCustomProperties.setValue( key, value );
1710+
if ( !mCustomProperties.contains( key ) || mCustomProperties.value( key ) != value )
1711+
{
1712+
mCustomProperties.setValue( key, value );
1713+
emit customPropertyChanged( this, key );
1714+
}
17111715
}
17121716

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

17281732
void QgsMapLayer::removeCustomProperty( const QString &key )
17291733
{
1730-
mCustomProperties.remove( key );
1734+
1735+
if ( mCustomProperties.contains( key ) )
1736+
{
1737+
mCustomProperties.remove( key );
1738+
emit customPropertyChanged( this, key );
1739+
}
17311740
}
17321741

17331742
QgsError QgsMapLayer::error() const

‎src/core/qgsmaplayer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,12 @@ class CORE_EXPORT QgsMapLayer : public QObject
14241424
*/
14251425
void isValidChanged();
14261426

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

14281434
private slots:
14291435

0 commit comments

Comments
 (0)
Please sign in to comment.