Skip to content

Commit

Permalink
append style name to the output file name when saving multiple styles
Browse files Browse the repository at this point in the history
(fix #46597)
  • Loading branch information
alexbruy authored and nyalldawson committed Sep 29, 2023
1 parent dce0a07 commit 3aba951
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/gui/vector/qgsvectorlayerproperties.cpp
Expand Up @@ -68,6 +68,7 @@
#include "qgsnative.h"
#include "qgssubsetstringeditorproviderregistry.h"
#include "qgsprovidersourcewidgetproviderregistry.h"
#include "qgsfileutils.h"
#include "qgswebview.h"
#include "qgswebframe.h"
#if WITH_QTWEBKIT
Expand Down Expand Up @@ -1286,14 +1287,16 @@ void QgsVectorLayerProperties::saveMultipleStylesAs()
{
QString message;
const QString filePath { dlg.outputFilePath() };
QString safePath { filePath };
const QFileInfo fi { filePath };
QString safePath { QString( filePath ).replace( fi.baseName(),
QStringLiteral( "%1_%2" ).arg( fi.baseName(), QgsFileUtils::stringToSafeFilename( styleName ) ) ) };
if ( styleIndex > 0 && stylesSelected.count( ) > 1 )
{
int i = 1;
while ( QFile::exists( safePath ) )
{
const QFileInfo fi { filePath };
safePath = QString( filePath ).replace( '.' + fi.completeSuffix(),
const QFileInfo fi { safePath };
safePath = QString( safePath ).replace( '.' + fi.completeSuffix(),
QStringLiteral( "_%1.%2" ).arg( QString::number( i ), fi.completeSuffix() ) );
i++;
}
Expand Down Expand Up @@ -1332,6 +1335,7 @@ void QgsVectorLayerProperties::saveMultipleStylesAs()
}
else
{
name += QStringLiteral( "_%1" ).arg( styleName );
QStringList ids, names, descriptions;
mLayer->listStylesInDatabase( ids, names, descriptions, msgError );
int i = 1;
Expand Down

0 comments on commit 3aba951

Please sign in to comment.