From 7dc51d93d56445a01fee98ff2f8ffd105695d580 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 22 Jul 2021 13:44:03 +1000 Subject: [PATCH] Use querySublayers in QgsVectorLayerSaveAsDialog to determine sublayers of an existing file ...instead of older deprecated sublayers handling --- src/gui/ogr/qgsvectorlayersaveasdialog.cpp | 43 +++++++++------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/src/gui/ogr/qgsvectorlayersaveasdialog.cpp b/src/gui/ogr/qgsvectorlayersaveasdialog.cpp index 4bef8e085c7..b258e071276 100644 --- a/src/gui/ogr/qgsvectorlayersaveasdialog.cpp +++ b/src/gui/ogr/qgsvectorlayersaveasdialog.cpp @@ -26,7 +26,6 @@ #include "qgsmapcanvas.h" #include "qgsgui.h" #include "qgsapplication.h" -#include "qgsogrdataitems.h" #include #include #include @@ -35,6 +34,8 @@ #include "gdal.h" #include "qgsdatums.h" #include "qgsiconutils.h" +#include "qgsproviderregistry.h" +#include "qgsprovidersublayerdetails.h" static const int COLUMN_IDX_NAME = 0; static const int COLUMN_IDX_TYPE = 1; @@ -387,34 +388,24 @@ void QgsVectorLayerSaveAsDialog::accept() } else if ( mActionOnExistingFile == QgsVectorFileWriter::CreateOrOverwriteFile && QFile::exists( filename() ) ) { - try + const QList sublayers = QgsProviderRegistry::instance()->querySublayers( filename() ); + QStringList layerList; + layerList.reserve( sublayers.size() ); + for ( const QgsProviderSublayerDetails &sublayer : sublayers ) { - const QList subLayers = QgsOgrLayerItem::subLayers( filename(), format() ); - QStringList layerList; - for ( const QgsOgrDbLayerInfo *layer : subLayers ) - { - layerList.append( layer->name() ); - } - qDeleteAll( subLayers ); - if ( layerList.length() > 1 ) - { - layerList.sort( Qt::CaseInsensitive ); - QMessageBox msgBox; - msgBox.setIcon( QMessageBox::Warning ); - msgBox.setWindowTitle( tr( "Overwrite File" ) ); - msgBox.setText( tr( "This file contains %1 layers that will be lost!\n" ).arg( QLocale().toString( layerList.length() ) ) ); - msgBox.setDetailedText( tr( "The following layers will be permanently lost:\n\n%1" ).arg( layerList.join( "\n" ) ) ); - msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel ); - if ( msgBox.exec() == QMessageBox::Cancel ) - return; - } + layerList.append( sublayer.name() ); } - catch ( QgsOgrLayerNotValidException &ex ) + if ( layerList.length() > 1 ) { - QMessageBox::critical( this, - tr( "Save Vector Layer As" ), - tr( "Error opening destination file: %1" ).arg( ex.what() ) ); - return; + layerList.sort( Qt::CaseInsensitive ); + QMessageBox msgBox; + msgBox.setIcon( QMessageBox::Warning ); + msgBox.setWindowTitle( tr( "Overwrite File" ) ); + msgBox.setText( tr( "This file contains %1 layers that will be lost!\n" ).arg( QLocale().toString( layerList.length() ) ) ); + msgBox.setDetailedText( tr( "The following layers will be permanently lost:\n\n%1" ).arg( layerList.join( "\n" ) ) ); + msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel ); + if ( msgBox.exec() == QMessageBox::Cancel ) + return; } }