Skip to content

Commit

Permalink
Avoid re-querying vector layers for sublayers when loading them
Browse files Browse the repository at this point in the history
into QGIS

In all paths leading to this function we have already resolved
the list of sub layers, so no need to call this potentially expensive
function immediately again...

(cherry picked from commit 117d21a)
  • Loading branch information
nyalldawson committed Aug 8, 2020
1 parent 1464b0c commit fc5b6e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -5455,7 +5455,7 @@ bool QgisApp::addVectorLayersPrivate( const QStringList &layerQStringList, const
// sublayers selection dialog so the user can select the sublayers to actually load.
if ( sublayers.count() > 1 )
{
addedLayers.append( askUserForOGRSublayers( layer ) );
addedLayers.append( askUserForOGRSublayers( layer, sublayers ) );

// The first layer loaded is not useful in that case. The user can select it in
// the list if he wants to load it.
Expand Down Expand Up @@ -5948,7 +5948,7 @@ QList< QgsMapLayer * > QgisApp::loadGDALSublayers( const QString &uri, const QSt

// This method is the method that does the real job. If the layer given in
// parameter is nullptr, then the method tries to act on the activeLayer.
QList<QgsMapLayer *> QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
QList<QgsMapLayer *> QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer, const QStringList &sublayers )
{
QList<QgsMapLayer *> result;
if ( !layer )
Expand All @@ -5958,8 +5958,6 @@ QList<QgsMapLayer *> QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
return result;
}

QStringList sublayers = layer->dataProvider()->subLayers();

QgsSublayersDialog::LayerDefinitionList list;
QMap< QString, int > mapLayerNameToCount;
bool uniqueNames = true;
Expand Down Expand Up @@ -12433,7 +12431,7 @@ QgsVectorLayer *QgisApp::addVectorLayerPrivate( const QString &vectorLayerPath,
! vectorLayerPath.contains( QStringLiteral( "layerid=" ) ) &&
! vectorLayerPath.contains( QStringLiteral( "layername=" ) ) )
{
QList< QgsMapLayer * > addedLayers = askUserForOGRSublayers( layer );
QList< QgsMapLayer * > addedLayers = askUserForOGRSublayers( layer, sublayers );

// The first layer loaded is not useful in that case. The user can select it in
// the list if he wants to load it.
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.h
Expand Up @@ -1950,7 +1950,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
* This method will open a dialog so the user can select OGR sublayers to load,
* and then returns a list of these layers.
*/
QList< QgsMapLayer * > askUserForOGRSublayers( QgsVectorLayer *layer );
QList< QgsMapLayer * > askUserForOGRSublayers( QgsVectorLayer *layer, const QStringList &subLayers );

/**
* Add a raster layer to the map (passed in as a ptr).
Expand Down

0 comments on commit fc5b6e1

Please sign in to comment.