Skip to content
Permalink
Browse files

Fix #11143 (remove visibility groups after removal of a layer)

  • Loading branch information
wonder-sk committed Sep 5, 2014
1 parent 0abcf6e commit fd5669cf8372916fb9be14988a4f35a22200363f
Showing with 23 additions and 4 deletions.
  1. +20 −4 src/app/qgsvisibilitygroups.cpp
  2. +3 −0 src/app/qgsvisibilitygroups.h
@@ -47,6 +47,9 @@ QgsVisibilityGroups::QgsVisibilityGroups()

connect( mMenu, SIGNAL( aboutToShow() ), this, SLOT( menuAboutToShow() ) );

connect( QgsMapLayerRegistry::instance(), SIGNAL( layersRemoved( QStringList ) ),
this, SLOT( registryLayersRemoved( QStringList ) ) );

connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ),
this, SLOT( readProject( const QDomDocument & ) ) );
connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ),
@@ -226,8 +229,8 @@ void QgsVisibilityGroups::applyStateToLayerTreeGroup( QgsLayerTreeGroup* parent,
foreach ( QgsLayerTreeModelLegendNode* legendNode, model->layerLegendNodes( nodeLayer ) )
{
Qt::CheckState shouldHaveState = checkedNodes.contains( legendNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString() ) ? Qt::Checked : Qt::Unchecked;
if ( ( legendNode->flags() & Qt::ItemIsUserCheckable ) &&
legendNode->data( Qt::CheckStateRole ).toInt() != shouldHaveState )
if (( legendNode->flags() & Qt::ItemIsUserCheckable ) &&
legendNode->data( Qt::CheckStateRole ).toInt() != shouldHaveState )
legendNode->setData( shouldHaveState, Qt::CheckStateRole );
}
}
@@ -236,8 +239,8 @@ void QgsVisibilityGroups::applyStateToLayerTreeGroup( QgsLayerTreeGroup* parent,
// all nodes should be checked
foreach ( QgsLayerTreeModelLegendNode* legendNode, model->layerLegendNodes( nodeLayer ) )
{
if ( ( legendNode->flags() & Qt::ItemIsUserCheckable ) &&
legendNode->data( Qt::CheckStateRole ).toInt() != Qt::Checked )
if (( legendNode->flags() & Qt::ItemIsUserCheckable ) &&
legendNode->data( Qt::CheckStateRole ).toInt() != Qt::Checked )
legendNode->setData( Qt::Checked, Qt::CheckStateRole );
}
}
@@ -370,3 +373,16 @@ void QgsVisibilityGroups::writeProject( QDomDocument& doc )

doc.firstChildElement( "qgis" ).appendChild( visGroupsElem );
}

void QgsVisibilityGroups::registryLayersRemoved( QStringList layerIDs )
{
foreach ( QString layerID, layerIDs )
{
foreach ( QString groupName, mGroups.keys() )
{
GroupRecord& rec = mGroups[groupName];
rec.mVisibleLayerIDs.remove( layerID );
rec.mPerLayerCheckedLegendSymbols.remove( layerID );
}
}
}
@@ -19,6 +19,7 @@
#include <QMap>
#include <QObject>
#include <QSet>
#include <QStringList>

class QAction;
class QDomDocument;
@@ -72,6 +73,8 @@ class QgsVisibilityGroups : public QObject
void readProject( const QDomDocument& doc );
void writeProject( QDomDocument& doc );

void registryLayersRemoved( QStringList layerIDs );

protected:
QgsVisibilityGroups(); // singleton

0 comments on commit fd5669c

Please sign in to comment.
You can’t perform that action at this time.