@@ -117,6 +117,12 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
117
117
actionDialog = new QgsAttributeActionDialog ( layer->actions (), fields, actionOptionsFrame );
118
118
actionLayout->addWidget ( actionDialog );
119
119
120
+ // Create the menu for the save style button to choose the output format
121
+ mSaveAsMenu = new QMenu ( pbnSaveStyleAs );
122
+ mSaveAsMenu ->addAction ( tr ( " QGIS Layer Style File" ) );
123
+ mSaveAsMenu ->addAction ( tr ( " SLD File" ) );
124
+ QObject::connect ( mSaveAsMenu , SIGNAL ( triggered ( QAction * ) ), this , SLOT ( saveStyleAsMenuTriggered ( QAction * ) ) );
125
+
120
126
reset ();
121
127
122
128
if ( layer->dataProvider () )// enable spatial index button group if supported by provider
@@ -950,6 +956,7 @@ void QgsVectorLayerProperties::on_pbnLoadStyle_clicked()
950
956
{
951
957
QSettings myQSettings; // where we keep last used filter in persistent state
952
958
QString myLastUsedDir = myQSettings.value ( " style/lastStyleDir" , " ." ).toString ();
959
+
953
960
QString myFileName = QFileDialog::getOpenFileName ( this , tr ( " Load layer properties from style file" ), myLastUsedDir,
954
961
tr ( " QGIS Layer Style File" ) + " (*.qml);;" + tr ( " SLD File" ) + " (*.sld)" );
955
962
if ( myFileName.isNull () )
@@ -987,34 +994,65 @@ void QgsVectorLayerProperties::on_pbnLoadStyle_clicked()
987
994
988
995
989
996
void QgsVectorLayerProperties::on_pbnSaveStyleAs_clicked ()
997
+ {
998
+ saveStyleAs ( QML );
999
+ }
1000
+
1001
+ void QgsVectorLayerProperties::saveStyleAsMenuTriggered ( QAction *action )
1002
+ {
1003
+ QMenu *menu = qobject_cast<QMenu *>( sender () );
1004
+ if ( !menu )
1005
+ return ;
1006
+
1007
+ int index = mSaveAsMenu ->actions ().indexOf ( action );
1008
+ if ( index < 0 )
1009
+ return ;
1010
+
1011
+ saveStyleAs ( (StyleType) index );
1012
+ }
1013
+
1014
+ void QgsVectorLayerProperties::saveStyleAs ( StyleType styleType )
990
1015
{
991
1016
QSettings myQSettings; // where we keep last used filter in persistent state
992
1017
QString myLastUsedDir = myQSettings.value ( " style/lastStyleDir" , " ." ).toString ();
993
- QString myOutputFileName = QFileDialog::getSaveFileName ( this , tr ( " Save layer properties as style file" ), myLastUsedDir,
994
- tr ( " QGIS Layer Style File" ) + " (*.qml);;" + tr ( " SLD File" ) + " (*.sld)" );
1018
+
1019
+ QString format, extension;
1020
+ if ( styleType == SLD )
1021
+ {
1022
+ format = tr ( " SLD File" ) + " (*.sld)" ;
1023
+ extension = " .sld" ;
1024
+ }
1025
+ else
1026
+ {
1027
+ format = tr ( " QGIS Layer Style File" ) + " (*.qml)" ;
1028
+ extension = " .qml" ;
1029
+ }
1030
+
1031
+ QString myOutputFileName = QFileDialog::getSaveFileName ( this , tr ( " Save layer properties as style file" ),
1032
+ myLastUsedDir, format );
995
1033
if ( myOutputFileName.isNull () ) // dialog canceled
996
1034
{
997
1035
return ;
998
1036
}
999
1037
1000
- apply (); // make sure the qml to save is uptodate
1038
+ apply (); // make sure the style to save is uptodate
1001
1039
1002
1040
QString myMessage;
1003
1041
bool defaultLoadedFlag = false ;
1004
1042
1005
1043
// ensure the user never omitted the extension from the file name
1006
- if ( myOutputFileName.endsWith ( " .sld" , Qt::CaseInsensitive ) )
1044
+ if ( myOutputFileName.endsWith ( extension, Qt::CaseInsensitive ) )
1045
+ {
1046
+ myOutputFileName += extension;
1047
+ }
1048
+
1049
+ if ( styleType == SLD )
1007
1050
{
1008
1051
// convert to SLD
1009
1052
myMessage = layer->saveSldStyle ( myOutputFileName, defaultLoadedFlag );
1010
1053
}
1011
1054
else
1012
1055
{
1013
- if ( !myOutputFileName.endsWith ( " .qml" , Qt::CaseInsensitive ) )
1014
- {
1015
- myOutputFileName += " .qml" ;
1016
- }
1017
-
1018
1056
myMessage = layer->saveNamedStyle ( myOutputFileName, defaultLoadedFlag );
1019
1057
}
1020
1058
@@ -1234,6 +1272,11 @@ void QgsVectorLayerProperties::updateSymbologyPage()
1234
1272
mRendererDialog = new QgsRendererV2PropertiesDialog ( layer, QgsStyleV2::defaultStyle (), true );
1235
1273
1236
1274
connect ( mRendererDialog , SIGNAL ( useNewSymbology ( bool ) ), this , SLOT ( setUsingNewSymbology ( bool ) ) );
1275
+
1276
+ // display the menu to choose the output format (fix #5136)
1277
+ pbnSaveStyleAs->setText ( tr ( " Save Style" ) );
1278
+ pbnSaveStyleAs->setMenu ( mSaveAsMenu );
1279
+ QObject::disconnect ( pbnSaveStyleAs, SIGNAL ( clicked () ), this , SLOT ( on_pbnSaveStyleAs_clicked () ) );
1237
1280
}
1238
1281
else if ( layer->renderer () )
1239
1282
{
@@ -1261,6 +1304,10 @@ void QgsVectorLayerProperties::updateSymbologyPage()
1261
1304
1262
1305
QObject::connect ( legendtypecombobox, SIGNAL ( activated ( const QString & ) ), this ,
1263
1306
SLOT ( alterLayerDialog ( const QString & ) ) );
1307
+
1308
+ pbnSaveStyleAs->setText ( tr ( " Save Style..." ) );
1309
+ pbnSaveStyleAs->setMenu ( NULL );
1310
+ QObject::connect ( pbnSaveStyleAs, SIGNAL ( clicked () ), this , SLOT ( on_pbnSaveStyleAs_clicked () ) );
1264
1311
}
1265
1312
else
1266
1313
{
0 commit comments