diff --git a/python/gui/auto_generated/qgsrasterlayersaveasdialog.sip.in b/python/gui/auto_generated/qgsrasterlayersaveasdialog.sip.in index 8c68677d3ea..16f8f9abc70 100644 --- a/python/gui/auto_generated/qgsrasterlayersaveasdialog.sip.in +++ b/python/gui/auto_generated/qgsrasterlayersaveasdialog.sip.in @@ -54,7 +54,13 @@ Constructor for QgsRasterLayerSaveAsDialog bool tileMode() const; bool addToCanvas() const; QString outputFileName() const; + QString outputLayerName() const; +%Docstring +Name of the output layer within GeoPackage file + +.. versionadded:: 3.4 +%End QString outputFormat() const; QgsCoordinateReferenceSystem outputCrs(); QStringList createOptions() const; diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index d40269227ba..6e3cee871c7 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -12825,7 +12825,7 @@ bool QgisApp::addRasterLayers( QStringList const &fileNameQStringList, bool guiW QString layerName = myFileInfo.completeBaseName(); // ...unless the layer uri matches "GPKG:filePath:layerName" and layerName differs from the file base name - QStringList layerUriSegments = myIterator->split( QLatin1String( ":" ) ); + const QStringList layerUriSegments = myIterator->split( QLatin1String( ":" ) ); if ( layerUriSegments.count() == 3 && layerUriSegments[ 0 ] == QLatin1String( "GPKG" ) && layerUriSegments[ 2 ] != layerName ) { layerName = QStringLiteral( "%1 %2" ).arg( layerName, layerUriSegments[ 2 ] ); diff --git a/src/gui/qgsrasterlayersaveasdialog.cpp b/src/gui/qgsrasterlayersaveasdialog.cpp index e197e4cf117..711114ef11d 100644 --- a/src/gui/qgsrasterlayersaveasdialog.cpp +++ b/src/gui/qgsrasterlayersaveasdialog.cpp @@ -425,7 +425,7 @@ QStringList QgsRasterLayerSaveAsDialog::createOptions() const if ( outputFormat() == QStringLiteral( "GPKG" ) ) { // Overwrite the GPKG table options - int indx = options.indexOf( QRegExp( "^RASTER_TABLE=.*" ) ); + int indx = options.indexOf( QRegularExpression( "^RASTER_TABLE=.*", QRegularExpression::CaseInsensitiveOption | QRegularExpression::MultilineOption ) ); if ( indx > -1 ) { options.replace( indx, QStringLiteral( "RASTER_TABLE=%1" ).arg( outputLayerName() ) ); @@ -436,9 +436,9 @@ QStringList QgsRasterLayerSaveAsDialog::createOptions() const } // Only enable the append mode if the layer doesn't exist yet. For existing layers a 'confirm overwrite' dialog will be shown. - if ( !outputLayerExistsInGpkg() ) + if ( !outputLayerExists() ) { - indx = options.indexOf( QRegExp( "^APPEND_SUBDATASET=.*", Qt::CaseInsensitive ) ); + indx = options.indexOf( QRegularExpression( "^APPEND_SUBDATASET=.*", QRegularExpression::CaseInsensitiveOption | QRegularExpression::MultilineOption ) ); if ( indx > -1 ) { options.replace( indx, QStringLiteral( "APPEND_SUBDATASET=YES" ) ); @@ -907,10 +907,19 @@ bool QgsRasterLayerSaveAsDialog::validate() const return true; } -bool QgsRasterLayerSaveAsDialog::outputLayerExistsInGpkg() const +bool QgsRasterLayerSaveAsDialog::outputLayerExists() const { - QgsRasterLayer *layer = nullptr; - layer = new QgsRasterLayer( QStringLiteral( "GPKG:%1:%2" ).arg( outputFileName(), outputLayerName() ), "", QStringLiteral( "gdal" ) ); + QString uri; + if ( outputFormat() == QStringLiteral( "GPKG" ) ) + { + uri = QStringLiteral( "GPKG:%1:%2" ).arg( outputFileName(), outputLayerName() ); + } + else + { + uri = outputFileName(); + } + + std::unique_ptr< QgsRasterLayer > layer( new QgsRasterLayer( uri, "", QStringLiteral( "gdal" ) ) ); return layer->isValid(); } @@ -921,7 +930,7 @@ void QgsRasterLayerSaveAsDialog::accept() return; } - if ( outputFormat() == QStringLiteral( "GPKG" ) && outputLayerExistsInGpkg() && + if ( outputFormat() == QStringLiteral( "GPKG" ) && outputLayerExists() && QMessageBox::warning( this, tr( "Save Raster Layer" ), tr( "The layer %1 already exists in the target file, and overwriting layers in GeoPackage is not supported. " "Do you want to overwrite the whole file?" ).arg( outputLayerName() ), diff --git a/src/gui/qgsrasterlayersaveasdialog.h b/src/gui/qgsrasterlayersaveasdialog.h index 5275a86ac0b..ac83c0033b3 100644 --- a/src/gui/qgsrasterlayersaveasdialog.h +++ b/src/gui/qgsrasterlayersaveasdialog.h @@ -71,8 +71,9 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast bool tileMode() const; bool addToCanvas() const; QString outputFileName() const; + /** - * Name of the output layer within GeoPackage file. + * Name of the output layer within GeoPackage file * \since QGIS 3.4 */ QString outputLayerName() const; @@ -143,8 +144,8 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast double noDataCellValue( int row, int column ) const; void adjustNoDataCellWidth( int row, int column ); bool validate() const; - // Returns true if the output layer already exists in the GeoPackage file. - bool outputLayerExistsInGpkg() const; + // Returns true if the output layer already exists. + bool outputLayerExists() const; void insertAvailableOutputFormats(); };