Skip to content
Permalink
Browse files
Ensure that correct layer type filtering is applied when requerying s…
…ublayers
  • Loading branch information
nyalldawson committed Jul 12, 2021
1 parent ec4b97b commit 28e8b4d811cb0b5f05c983593a45bd7f0414537a
Showing with 31 additions and 6 deletions.
  1. +22 −4 src/app/qgisapp.cpp
  2. +8 −2 src/app/qgsprovidersublayersdialog.cpp
  3. +1 −0 src/app/qgsprovidersublayersdialog.h
@@ -5517,7 +5517,7 @@ bool QgisApp::addVectorLayersPrivate( const QStringList &layers, const QString &
case SublayerHandling::AskUser:
{
// prompt user for sublayers
QgsProviderSublayersDialog dlg( uri, path, sublayers, this );
QgsProviderSublayersDialog dlg( uri, path, sublayers, {QgsMapLayerType::VectorLayer}, this );

if ( dlg.exec() )
sublayers = dlg.selectedLayers();
@@ -5533,6 +5533,11 @@ bool QgisApp::addVectorLayersPrivate( const QStringList &layers, const QString &
{
// requery sublayers, resolving geometry types
sublayers = QgsProviderRegistry::instance()->querySublayers( uri, Qgis::SublayerQueryFlag::ResolveGeometryType );
// filter out non-vector sublayers
sublayers.erase( std::remove_if( sublayers.begin(), sublayers.end(), []( const QgsProviderSublayerDetails & sublayer )
{
return sublayer.type() != QgsMapLayerType::VectorLayer;
} ), sublayers.end() );
}
break;
}
@@ -5546,6 +5551,11 @@ bool QgisApp::addVectorLayersPrivate( const QStringList &layers, const QString &
{
// requery sublayers, resolving geometry types
sublayers = QgsProviderRegistry::instance()->querySublayers( uri, Qgis::SublayerQueryFlag::ResolveGeometryType );
// filter out non-vector sublayers
sublayers.erase( std::remove_if( sublayers.begin(), sublayers.end(), []( const QgsProviderSublayerDetails & sublayer )
{
return sublayer.type() != QgsMapLayerType::VectorLayer;
} ), sublayers.end() );
}

// now add sublayers
@@ -5887,7 +5897,7 @@ bool QgisApp::askUserForZipItemLayers( const QString &path, const QList< QgsMapL
case SublayerHandling::AskUser:
{
// prompt user for sublayers
QgsProviderSublayersDialog dlg( path, path, sublayers, this );
QgsProviderSublayersDialog dlg( path, path, sublayers, acceptableTypes, this );

if ( dlg.exec() )
sublayers = dlg.selectedLayers();
@@ -5903,6 +5913,10 @@ bool QgisApp::askUserForZipItemLayers( const QString &path, const QList< QgsMapL
{
// requery sublayers, resolving geometry types
sublayers = QgsProviderRegistry::instance()->querySublayers( path, Qgis::SublayerQueryFlag::ResolveGeometryType );
sublayers.erase( std::remove_if( sublayers.begin(), sublayers.end(), [acceptableTypes]( const QgsProviderSublayerDetails & sublayer )
{
return !acceptableTypes.empty() && !acceptableTypes.contains( sublayer.type() );
} ), sublayers.end() );
}
break;
}
@@ -5916,6 +5930,10 @@ bool QgisApp::askUserForZipItemLayers( const QString &path, const QList< QgsMapL
{
// requery sublayers, resolving geometry types
sublayers = QgsProviderRegistry::instance()->querySublayers( path, Qgis::SublayerQueryFlag::ResolveGeometryType );
sublayers.erase( std::remove_if( sublayers.begin(), sublayers.end(), [acceptableTypes]( const QgsProviderSublayerDetails & sublayer )
{
return !acceptableTypes.empty() && !acceptableTypes.contains( sublayer.type() );
} ), sublayers.end() );
}

// now add sublayers
@@ -7334,7 +7352,7 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )
case SublayerHandling::AskUser:
{
// prompt user for sublayers
QgsProviderSublayersDialog dlg( fileName, fileName, sublayers, this );
QgsProviderSublayersDialog dlg( fileName, fileName, sublayers, {}, this );

if ( dlg.exec() )
sublayers = dlg.selectedLayers();
@@ -13059,7 +13077,7 @@ T *QgisApp::addLayerPrivate( QgsMapLayerType type, const QString &uri, const QSt
{
case SublayerHandling::AskUser:
{
QgsProviderSublayersDialog dlg( updatedUri, path, sublayers, this );
QgsProviderSublayersDialog dlg( updatedUri, path, sublayers, {type}, this );
if ( dlg.exec() )
{
const QList< QgsProviderSublayerDetails > selectedLayers = dlg.selectedLayers();
@@ -91,7 +91,7 @@ Qt::ItemFlags QgsProviderSublayerDialogModel::flags( const QModelIndex &index )
return QgsProviderSublayerModel::flags( index );
}

QgsProviderSublayersDialog::QgsProviderSublayersDialog( const QString &uri, const QString &filePath, const QList<QgsProviderSublayerDetails> initialDetails, QWidget *parent, Qt::WindowFlags fl )
QgsProviderSublayersDialog::QgsProviderSublayersDialog( const QString &uri, const QString &filePath, const QList<QgsProviderSublayerDetails> initialDetails, const QList<QgsMapLayerType> &acceptableTypes, QWidget *parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
{
setupUi( this );
@@ -147,7 +147,13 @@ QgsProviderSublayersDialog::QgsProviderSublayersDialog( const QString &uri, cons
mTask = new QgsProviderSublayerTask( uri );
connect( mTask.data(), &QgsProviderSublayerTask::taskCompleted, this, [ = ]
{
mModel->setSublayerDetails( mTask->results() );
QList< QgsProviderSublayerDetails > res = mTask->results();
res.erase( std::remove_if( res.begin(), res.end(), [acceptableTypes]( const QgsProviderSublayerDetails & sublayer )
{
return !acceptableTypes.empty() && !acceptableTypes.contains( sublayer.type() );
} ), res.end() );

mModel->setSublayerDetails( res );
mTask = nullptr;
} );
QgsApplication::taskManager()->addTask( mTask.data() );
@@ -50,6 +50,7 @@ class QgsProviderSublayersDialog : public QDialog, private Ui::QgsProviderSublay
QgsProviderSublayersDialog( const QString &uri,
const QString &filePath,
const QList< QgsProviderSublayerDetails> initialDetails = QList< QgsProviderSublayerDetails>(),
const QList< QgsMapLayerType > &acceptableTypes = QList< QgsMapLayerType >(),
QWidget *parent SIP_TRANSFERTHIS = nullptr,
Qt::WindowFlags fl = Qt::WindowFlags() );

0 comments on commit 28e8b4d

Please sign in to comment.