Follow up 60fa8eae07389 - implement Nyall's suggestions

This commit is contained in:
Borys Jurgiel 2018-09-13 11:52:35 +02:00
parent c01f56ce5b
commit b08ad825f1
4 changed files with 27 additions and 11 deletions

View File

@ -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;

View File

@ -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 ] );

View File

@ -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() ),

View File

@ -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();
};