Skip to content

Commit

Permalink
Fix for bug report #19174 - hide newly added layer(s) when in group
Browse files Browse the repository at this point in the history
When loading a single layer QGIS will set it as invisible if the user have chosen so (new_layers_visible=false) in the settings. When a data set contains more than one layer and the user
chooses "Add layers to a group" the layers are added as visible no matter what.

This commit is fixing that problem for both GDAL and OGR data sets by setting both the group and its layers as invisible/unchecked.

Fixes #19174
  • Loading branch information
chau-intl committed Dec 4, 2018
1 parent ee25bb4 commit 651b656
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4934,6 +4934,7 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )

QgsLayerTreeGroup *group = nullptr;
bool addToGroup = settings.value( QStringLiteral( "/qgis/openSublayersInGroup" ), true ).toBool();
bool newLayersVisible = settings.value( QStringLiteral( "/qgis/new_layers_visible" ), true ).toBool();
if ( addToGroup )
{
group = QgsProject::instance()->layerTreeRoot()->insertGroup( 0, layer->name() );
Expand Down Expand Up @@ -4967,6 +4968,10 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
}
}
}

// Respect if user don't want the new group of layers visible.
if ( addToGroup && ! newLayersVisible )
group->setItemVisibilityCheckedRecursive( newLayersVisible );
}
}

Expand Down Expand Up @@ -5131,6 +5136,7 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
{
QgsSettings settings;
bool addToGroup = settings.value( QStringLiteral( "/qgis/openSublayersInGroup" ), true ).toBool();
bool newLayersVisible = settings.value( QStringLiteral( "/qgis/new_layers_visible" ), true ).toBool();
QgsLayerTreeGroup *group = nullptr;
if ( addToGroup )
group = QgsProject::instance()->layerTreeRoot()->insertGroup( 0, name );
Expand All @@ -5144,6 +5150,10 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
if ( addToGroup )
group->addLayer( l );
}

// Respect if user don't want the new group of layers visible.
if ( addToGroup && ! newLayersVisible )
group->setItemVisibilityCheckedRecursive( newLayersVisible );
}
}

Expand Down

0 comments on commit 651b656

Please sign in to comment.