Skip to content

Commit

Permalink
Merge pull request #8324 from elpaso/bugfix-unreported-ensure-qml-ext…
Browse files Browse the repository at this point in the history
…ention-on-save-style-to-file

Bugfix unreported ensure qml extention on save style to file
  • Loading branch information
elpaso committed Oct 25, 2018
2 parents 4acb12d + 6afb8de commit b0104a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -7398,6 +7398,11 @@ void QgisApp::saveStyleFile( QgsMapLayer *layer )
if ( filename.isEmpty() )
return;

if ( ! filename.endsWith( QStringLiteral( ".qml" ) ) )
{
filename += QStringLiteral( ".qml" );
}

bool defaultLoadedFlag;
layer->saveNamedStyle( filename, defaultLoadedFlag );

Expand Down
11 changes: 11 additions & 0 deletions tests/src/python/test_qgsmaplayer.py
Expand Up @@ -12,6 +12,7 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
import qgis # NOQA
import tempfile

Expand All @@ -20,6 +21,7 @@
QgsProject)
from qgis.testing import start_app, unittest
from qgis.PyQt.QtXml import QDomDocument
from qgis.PyQt.QtCore import QTemporaryDir

start_app()

Expand Down Expand Up @@ -105,6 +107,15 @@ def testReadWriteMetadata(self):
self.assertTrue(status)
self.assertTrue(layer2.metadata().abstract(), 'My abstract')

def testSaveNamedStyle(self):
layer = QgsVectorLayer("Point?field=fldtxt:string", "layer", "memory")
dir = QTemporaryDir()
dir_path = dir.path()
style_path = os.path.join(dir_path, 'my.qml')
_, result = layer.saveNamedStyle(style_path)
self.assertTrue(result)
self.assertTrue(os.path.exists(style_path))


if __name__ == '__main__':
unittest.main()

0 comments on commit b0104a2

Please sign in to comment.