Skip to content
Permalink
Browse files

Add optional recursive = false to findGroups

  • Loading branch information
jgrocha authored and nyalldawson committed Mar 23, 2021
1 parent 2eb7781 commit 01806b1dea9b471502dde5ae29fd58bccf446df4
@@ -129,14 +129,9 @@ Find layer IDs used in all layer nodes. Searches recursively the whole sub-tree.
Find group node with specified name. Searches recursively the whole sub-tree.
%End

QList<QgsLayerTreeGroup *> findGroups() const;
QList<QgsLayerTreeGroup *> findGroups( bool recursive = false ) const;
%Docstring
Find child group layer nodes. Does not search recursively the whole sub-tree.
%End

QList<QgsLayerTreeGroup *> findAllGroups() const;
%Docstring
Find all group layer nodes. Searches recursively the whole sub-tree.
Find group layer nodes. Searches recursively the whole sub-tree, is recursive is set.
%End

static QgsLayerTreeGroup *readXml( QDomElement &element, const QgsReadWriteContext &context ) /Factory/;
@@ -253,29 +253,18 @@ QgsLayerTreeGroup *QgsLayerTreeGroup::findGroup( const QString &name )
return nullptr;
}

QList<QgsLayerTreeGroup *> QgsLayerTreeGroup::findGroups() const
QList<QgsLayerTreeGroup *> QgsLayerTreeGroup::findGroups( bool recursive ) const
{
QList<QgsLayerTreeGroup *> list;

for ( QgsLayerTreeNode *child : mChildren )
{
if ( QgsLayerTree::isGroup( child ) )
list << QgsLayerTree::toGroup( child );
}
return list;
}

QList<QgsLayerTreeGroup *> QgsLayerTreeGroup::findAllGroups() const
{
QList<QgsLayerTreeGroup *> list;

for ( QgsLayerTreeNode *child : std::as_const( mChildren ) )
{
if ( QgsLayerTree::isGroup( child ) )
{
QgsLayerTreeGroup *childGroup = QgsLayerTree::toGroup( child );
list << childGroup;
list << childGroup->findAllGroups( );
if ( recursive )
list << childGroup->findGroups( recursive );
}
}
return list;
@@ -142,14 +142,9 @@ class CORE_EXPORT QgsLayerTreeGroup : public QgsLayerTreeNode
QgsLayerTreeGroup *findGroup( const QString &name );

/**
* Find child group layer nodes. Does not search recursively the whole sub-tree.
* Find group layer nodes. Searches recursively the whole sub-tree, is recursive is set.
*/
QList<QgsLayerTreeGroup *> findGroups() const;

/**
* Find all group layer nodes. Searches recursively the whole sub-tree.
*/
QList<QgsLayerTreeGroup *> findAllGroups() const;
QList<QgsLayerTreeGroup *> findGroups( bool recursive = false ) const;

/**
* Read group (tree) from XML element <layer-tree-group> and return the newly created group (or NULLPTR on error).
@@ -732,7 +732,7 @@ void TestQgsLayerTree::testFindNestedGroups()
QVERIFY( groups.contains( group2 ) == 0 );
QVERIFY( groups.contains( group3 ) == 0 );

QList<QgsLayerTreeGroup *> all = project.layerTreeRoot()->findAllGroups();
QList<QgsLayerTreeGroup *> all = project.layerTreeRoot()->findGroups( true );

QVERIFY( all.contains( group1 ) );
QVERIFY( all.contains( group2 ) );

0 comments on commit 01806b1

Please sign in to comment.