Skip to content

Commit

Permalink
more robust fix for #2762 as suggested by Martin
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15727 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
alexbruy committed Apr 16, 2011
1 parent f861f8b commit 9ef6503
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
13 changes: 1 addition & 12 deletions src/app/legend/qgsapplegendinterface.cpp
Expand Up @@ -119,18 +119,7 @@ bool QgsAppLegendInterface::isLayerVisible( QgsMapLayer * ml )

QList< QgsMapLayer * > QgsAppLegendInterface::layers() const
{
QList< QgsMapLayer * > items;
QTreeWidgetItemIterator it( mLegend );
while ( *it )
{
QgsLegendLayer *llayer = dynamic_cast<QgsLegendLayer *>( *it );
if ( llayer )
items.append( llayer->layer() );

++it;
}

return items;
return mLegend->layers();
}

void QgsAppLegendInterface::refreshLayerSymbology( QgsMapLayer *ml )
Expand Down
18 changes: 17 additions & 1 deletion src/app/legend/qgslegend.cpp
Expand Up @@ -649,7 +649,7 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
updateMapCanvasLayerSet();

// first layer?
if ( QgsMapLayerRegistry::instance()->count() == 1 )
if ( layers().count() == 1 )
{
mMapCanvas->zoomToFullExtent();
mMapCanvas->clearExtentHistory();
Expand Down Expand Up @@ -716,6 +716,22 @@ QList<QgsMapLayer *> QgsLegend::selectedLayers()
return layers;
}

QList<QgsMapLayer *> QgsLegend::layers()
{
QList< QgsMapLayer * > items;
QTreeWidgetItemIterator it( this );
while ( *it )
{
QgsLegendLayer *llayer = dynamic_cast<QgsLegendLayer *>( *it );
if ( llayer )
items.append( llayer->layer() );

++it;
}

return items;
}

bool QgsLegend::setCurrentLayer( QgsMapLayer *layer )
{
QgsLegendLayer *ll = findLegendLayer( layer );
Expand Down
6 changes: 5 additions & 1 deletion src/app/legend/qgslegend.h
Expand Up @@ -112,6 +112,10 @@ class QgsLegend : public QTreeWidget
Else, an empty list is returned.*/
QList<QgsMapLayer *> selectedLayers();

/*!Returns all layers loaded in QgsMapCanvas.
Else, an empty list is returned.*/
QList<QgsMapLayer *> layers();

/*!set the current layer
returns true if the layer exists, false otherwise*/
bool setCurrentLayer( QgsMapLayer *layer );
Expand Down Expand Up @@ -410,7 +414,7 @@ class QgsLegend : public QTreeWidget

/**Pointer to the main canvas. Used for requiring repaints in case of legend changes*/
QgsMapCanvas* mMapCanvas;

/**Stores the width values of the LegendSymbologyItem pixmaps. The purpose of this is that the legend may automatically change
the global IconWidth when items are added or removed*/
std::multiset<int> mPixmapWidthValues;
Expand Down

0 comments on commit 9ef6503

Please sign in to comment.