Ensure layer tree indicator icons are repainted on changes

This commit is contained in:
Nyall Dawson 2019-07-16 09:11:22 +10:00
parent bd44f53236
commit 33ee00f3f6
3 changed files with 19 additions and 1 deletions

View File

@ -52,6 +52,13 @@ Sets tool tip text
void clicked( const QModelIndex &index );
%Docstring
Emitted when user clicks on the indicator
%End
void changed();
%Docstring
Emitted when the indicator changes state (e.g. icon).
.. versionadded:: 3.10
%End
};

View File

@ -398,12 +398,17 @@ QList<QgsMapLayer *> QgsLayerTreeView::selectedLayersRecursive() const
void QgsLayerTreeView::addIndicator( QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator )
{
if ( !mIndicators[node].contains( indicator ) )
{
mIndicators[node].append( indicator );
connect( indicator, &QgsLayerTreeViewIndicator::changed, this, [ = ] { update(); } );
update();
}
}
void QgsLayerTreeView::removeIndicator( QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator )
{
mIndicators[node].removeOne( indicator );
update();
}
QList<QgsLayerTreeViewIndicator *> QgsLayerTreeView::indicators( QgsLayerTreeNode *node ) const

View File

@ -42,7 +42,7 @@ class GUI_EXPORT QgsLayerTreeViewIndicator : public QObject
//! Indicator icon that will be displayed in the layer tree view
QIcon icon() const { return mIcon; }
//! Sets indicator icon that will be displayed in the layer tree view
void setIcon( const QIcon &icon ) { mIcon = icon; }
void setIcon( const QIcon &icon ) { mIcon = icon; emit changed(); }
//! Returns tool tip text that will be shown when user hovers mouse over the indicator
QString toolTip() const { return mToolTip; }
@ -53,6 +53,12 @@ class GUI_EXPORT QgsLayerTreeViewIndicator : public QObject
//! Emitted when user clicks on the indicator
void clicked( const QModelIndex &index );
/**
* Emitted when the indicator changes state (e.g. icon).
* \since QGIS 3.10
*/
void changed();
private:
QIcon mIcon;
QString mToolTip;