Skip to content

Commit

Permalink
Don't mark project dirty when legend nodes are expanded/collapsed
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 12, 2018
1 parent 773ec22 commit 40ceb7b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions python/gui/layertree/qgslayertreeview.sip.in
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/gui/layertree/qgslayertreeview.cpp
Expand Up @@ -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 )
{
Expand Down
14 changes: 14 additions & 0 deletions src/gui/layertree/qgslayertreeview.h
Expand Up @@ -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 );
Expand Down

0 comments on commit 40ceb7b

Please sign in to comment.