Skip to content

Commit

Permalink
Follow up 60fa8ea - implement Nyall's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
borysiasty committed Sep 13, 2018
1 parent c01f56c commit b08ad82
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
6 changes: 6 additions & 0 deletions python/gui/auto_generated/qgsrasterlayersaveasdialog.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
Expand Down
23 changes: 16 additions & 7 deletions src/gui/qgsrasterlayersaveasdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand All @@ -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" ) );
Expand Down Expand Up @@ -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();
}

Expand All @@ -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() ),
Expand Down
7 changes: 4 additions & 3 deletions src/gui/qgsrasterlayersaveasdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
};
Expand Down

0 comments on commit b08ad82

Please sign in to comment.