Skip to content
Permalink
Browse files

use selected filter to determine style type (QML or SLD) (fix #35944)

(cherry picked from commit f2ea6e8)
  • Loading branch information
alexbruy authored and nyalldawson committed Jun 19, 2020
1 parent a9fbe6a commit bfed9b81f989a336a08420e5dd91a18d93c17d43
Showing with 14 additions and 7 deletions.
  1. +14 −7 src/app/qgsrasterlayerproperties.cpp
@@ -1882,21 +1882,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 uptodate

0 comments on commit bfed9b8

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