Skip to content

Commit

Permalink
Fix #11143 (remove visibility groups after removal of a layer)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Sep 5, 2014
1 parent 0abcf6e commit fd5669c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/app/qgsvisibilitygroups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 & ) ),
Expand Down Expand Up @@ -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 );
}
}
Expand All @@ -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 );
}
}
Expand Down Expand Up @@ -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 );
}
}
}
3 changes: 3 additions & 0 deletions src/app/qgsvisibilitygroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <QMap>
#include <QObject>
#include <QSet>
#include <QStringList>

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

void registryLayersRemoved( QStringList layerIDs );

protected:
QgsVisibilityGroups(); // singleton

Expand Down

0 comments on commit fd5669c

Please sign in to comment.