Skip to content
Permalink
Browse files

Merge pull request #36774 from alexbruy/raster-sld

improve logic for choosing style type when exporting raster style (fix #35944)
  • Loading branch information
alexbruy committed May 28, 2020
2 parents c1dd894 + f2ea6e8 commit 0496ce52fc568f2aa8e3ca3ece6528a9f601559b
Showing with 14 additions and 7 deletions.
  1. +14 −7 src/gui/raster/qgsrasterlayerproperties.cpp
@@ -2169,21 +2169,28 @@ void QgsRasterLayerProperties::saveStyleAs_clicked()
QgsSettings settings;
QString lastUsedDir = settings.value( QStringLiteral( "style/lastStyleDir" ), QDir::homePath() ).toString();

QString selectedFilter;
QString outputFileName = QFileDialog::getSaveFileName(
this,
tr( "Save layer properties as style file" ),
lastUsedDir,
tr( "QGIS Layer Style File" ) + " (*.qml)" + ";;" + tr( "Styled Layer Descriptor" ) + " (*.sld)" );
tr( "QGIS Layer Style File" ) + " (*.qml)" + ";;" + tr( "Styled Layer Descriptor" ) + " (*.sld)",
&selectedFilter );
if ( outputFileName.isEmpty() )
return;

// set style type depending on extension
StyleType type = StyleType::QML;
if ( outputFileName.endsWith( QLatin1String( ".sld" ), Qt::CaseInsensitive ) )
type = StyleType::SLD;
else
// ensure the user never omits the extension from the file name
StyleType type;
// use selectedFilter to set style type
if ( selectedFilter.contains( QStringLiteral( ".qml" ), Qt::CaseInsensitive ) )
{
outputFileName = QgsFileUtils::ensureFileNameHasExtension( outputFileName, QStringList() << QStringLiteral( "qml" ) );
type = StyleType::QML;
}
else
{
outputFileName = QgsFileUtils::ensureFileNameHasExtension( outputFileName, QStringList() << QStringLiteral( "sld" ) );
type = StyleType::SLD;
}

apply(); // make sure the style to save is up-to-date

0 comments on commit 0496ce5

Please sign in to comment.
You can’t perform that action at this time.