Skip to content

Commit

Permalink
fix crash when moving layers
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@13063 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Mar 16, 2010
1 parent 74caf2f commit 72c7dd0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -540,7 +540,7 @@ void QgsLegend::addLayer( QgsMapLayer * layer )

void QgsLegend::setMapCanvas( QgsMapCanvas * canvas )
{
if( mMapCanvas )
if ( mMapCanvas )
{
disconnect( mMapCanvas, SIGNAL( layersChanged() ) );
}
Expand Down Expand Up @@ -699,12 +699,18 @@ bool QgsLegend::removeLayer( QgsMapLayer* ml, bool askCancelOnEditable )

void QgsLegend::moveLayer( QgsMapLayer * ml, int groupIndex )
{
if ( !ml )
return;

QgsLegendLayer *layer = findLegendLayer( ml->getLayerID() );
if ( !layer )
return;

QgsLegendGroup *group = dynamic_cast<QgsLegendGroup*>( topLevelItem( groupIndex ) );
if ( layer && group )
{
insertItem( layer, group );
}
if ( !group )
return;

insertItem( layer, group );
}

void QgsLegend::legendLayerShowProperties()
Expand Down Expand Up @@ -1760,16 +1766,16 @@ QTreeWidgetItem * QgsLegend::lastVisibleItem()

void QgsLegend::refreshCheckStates()
{
if( !mMapCanvas )
if ( !mMapCanvas )
{
return;
}

QList<QgsMapLayer*> lst = mMapCanvas->layers();
for ( QTreeWidgetItem* item = firstItem(); item; item = nextItem( item ) )
for ( QTreeWidgetItem* item = firstItem(); item; item = nextItem( item ) )
{
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( item );
if ( ll )
if ( ll )
{
ll->setCheckState( 0, ( lst.contains( ll->layer() ) ? Qt::Checked : Qt::Unchecked ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/legend/qgslegend.h
Expand Up @@ -244,7 +244,7 @@ class QgsLegend : public QTreeWidget
* Moves a layer to a group.
* @param ml the maplayer to move
* @param groupIndex index of group
* @return false if the group does not exist, false otherwise
* @note keep in mind that the group's index changes, if the moved layer is above the group.
*/
void moveLayer( QgsMapLayer* ml, int groupIndex );

Expand Down

0 comments on commit 72c7dd0

Please sign in to comment.