Skip to content

Commit

Permalink
Also add API to determine if group layers should be expanded when cal…
Browse files Browse the repository at this point in the history
…ling QgsMapCanvas::layers()
  • Loading branch information
nyalldawson committed Nov 23, 2021
1 parent a5b9c7b commit b063d47
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 5 additions & 2 deletions python/gui/auto_generated/qgsmapcanvas.sip.in
Expand Up @@ -460,13 +460,16 @@ layers which may be visible in the canvas, but not associated with a :py:class:`

int layerCount() const;
%Docstring
Returns number of layers on the map
Returns number of layers on the map.
%End

QList<QgsMapLayer *> layers() const;
QList<QgsMapLayer *> layers( bool expandGroupLayers = false ) const;
%Docstring
Returns the list of layers shown within the map canvas.

Since QGIS 3.24, if the ``expandGroupLayers`` option is ``True`` then group layers will be converted to
all their child layers.

.. seealso:: :py:func:`setLayers`
%End

Expand Down
7 changes: 3 additions & 4 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -2430,12 +2430,11 @@ QColor QgsMapCanvas::selectionColor() const
int QgsMapCanvas::layerCount() const
{
return mapSettings().layers().size();
} // layerCount

}

QList<QgsMapLayer *> QgsMapCanvas::layers() const
QList<QgsMapLayer *> QgsMapCanvas::layers( bool expandGroupLayers ) const
{
return mapSettings().layers();
return mapSettings().layers( expandGroupLayers );
}

void QgsMapCanvas::layerStateChange()
Expand Down
10 changes: 8 additions & 2 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -471,14 +471,20 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView, public QgsExpressionContex
*/
QgsMapLayer *layer( const QString &id );

//! Returns number of layers on the map
/**
* Returns number of layers on the map.
*/
int layerCount() const;

/**
* Returns the list of layers shown within the map canvas.
*
* Since QGIS 3.24, if the \a expandGroupLayers option is TRUE then group layers will be converted to
* all their child layers.
*
* \see setLayers()
*/
QList<QgsMapLayer *> layers() const;
QList<QgsMapLayer *> layers( bool expandGroupLayers = false ) const;

/**
* Freeze/thaw the map canvas. This is used to prevent the canvas from
Expand Down

0 comments on commit b063d47

Please sign in to comment.