Skip to content

Commit 9e15906

Browse files
committed
Fix check/unchek of groups in TOC (ticket #5013)
1 parent 9154e4e commit 9e15906

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/app/legend/qgslegend.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,22 @@ void QgsLegend::updateGroupCheckStates( QTreeWidgetItem *item )
521521

522522
void QgsLegend::mouseReleaseEvent( QMouseEvent * e )
523523
{
524+
QStringList layersPriorToEvent = layerIDs();
524525
QTreeWidget::mouseReleaseEvent( e );
525526
mMousePressedFlag = false;
526527

527528
if ( mItemsBeingMoved.isEmpty() )
529+
{
530+
//Trigger refresh because of check states on layers.
531+
//If it comes from a check action on a group, it is not covered in handleItemChanges(),
532+
//so we do it here
533+
QgsLegendGroup *lg = dynamic_cast<QgsLegendGroup *>( currentItem() );
534+
if ( lg && ( layersPriorToEvent != layerIDs() ) )
535+
{
536+
mMapCanvas->refresh();
537+
}
528538
return;
539+
}
529540

530541
setCursor( QCursor( Qt::ArrowCursor ) );
531542
hideLine();
@@ -1907,8 +1918,11 @@ QStringList QgsLegend::layerIDs()
19071918
QgsLegendLayer* ll = qobject_cast<QgsLegendLayer *>( li );
19081919
if ( ll )
19091920
{
1910-
QgsMapLayer *lyr = ll->layer();
1911-
layers.push_front( lyr->id() );
1921+
if ( ll->checkState( 0 ) == Qt::Checked )
1922+
{
1923+
QgsMapLayer *lyr = ll->layer();
1924+
layers.push_front( lyr->id() );
1925+
}
19121926
}
19131927
}
19141928

src/app/legend/qgslegend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class QgsLegend : public QTreeWidget
169169
/**Removes an item from the legend. This is e.g. necessary before shifting it to another place*/
170170
void removeItem( QTreeWidgetItem* item );
171171

172-
/**Returns the ids of the layers contained in this legend. The order is bottom->top*/
172+
/**Returns the ids of the visible layers contained in this legend. The order is bottom->top*/
173173
QStringList layerIDs();
174174

175175
/**Updates layer set of map canvas*/

0 commit comments

Comments
 (0)