Don't mark project dirty when legend nodes are expanded/collapsed

This commit is contained in:
Nyall Dawson 2018-03-10 12:25:55 +10:00
parent 773ec220ba
commit 40ceb7bdce
4 changed files with 28 additions and 1 deletions

View File

@ -148,6 +148,8 @@ Returns list of indicators associated with a particular layer tree node.
.. versionadded:: 3.2
%End
public slots:
void refreshLayerSymbology( const QString &layerId );
%Docstring

View File

@ -3238,7 +3238,12 @@ void QgisApp::setupConnections()
connect( mLayerTreeView->layerTreeModel()->rootGroup(), &QgsLayerTreeNode::visibilityChanged,
this, &QgisApp::markDirty );
connect( mLayerTreeView->layerTreeModel()->rootGroup(), &QgsLayerTreeNode::customPropertyChanged,
this, &QgisApp::markDirty );
this, [ = ]( QgsLayerTreeNode *, const QString & key )
{
// only mark dirty for non-view only changes
if ( !QgsLayerTreeView::viewOnlyCustomProperties().contains( key ) )
QgisApp::markDirty();
} );
// connect map layer registry
connect( QgsProject::instance(), &QgsProject::layersAdded,

View File

@ -355,6 +355,12 @@ QList<QgsLayerTreeViewIndicator *> QgsLayerTreeView::indicators( QgsLayerTreeNod
return mIndicators.value( node );
}
///@cond PRIVATE
QStringList QgsLayerTreeView::viewOnlyCustomProperties()
{
return QStringList() << QStringLiteral( "expandedLegendNodes" );
}
///@endcond
void QgsLayerTreeView::refreshLayerSymbology( const QString &layerId )
{

View File

@ -135,6 +135,20 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
*/
QList<QgsLayerTreeViewIndicator *> indicators( QgsLayerTreeNode *node ) const;
///@cond PRIVATE
/**
* Returns a list of custom property keys which are considered as related to view operations
* only. E.g. node expanded state.
*
* Changes to these keys will not mark a project as "dirty" and trigger unsaved changes
* warnings.
*
* \since QGIS 3.2
*/
static QStringList viewOnlyCustomProperties() SIP_SKIP;
///@endcond
public slots:
//! Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model
void refreshLayerSymbology( const QString &layerId );