Skip to content

Commit

Permalink
[FEATURE] load/save layer style (new symbology) from/to SLD document
Browse files Browse the repository at this point in the history
This is a huge commit, but it's mostly new functions. It changes only few lines on the existing code.
- add conversion between QgsExpression and OGC Filter Encoding 1.1
- add conversion between QgsRendererV2 and OGC Symbology Encoding 1.1

Work done for Regione Toscana-SIGTA
  • Loading branch information
brushtyler committed Mar 8, 2012
1 parent 7dc3096 commit 3906922
Show file tree
Hide file tree
Showing 39 changed files with 4,176 additions and 35 deletions.
39 changes: 31 additions & 8 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -950,14 +950,25 @@ void QgsVectorLayerProperties::on_pbnLoadStyle_clicked()
{
QSettings myQSettings; // where we keep last used filter in persistent state
QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", "." ).toString();
QString myFileName = QFileDialog::getOpenFileName( this, tr( "Load layer properties from style file (.qml)" ), myLastUsedDir, tr( "QGIS Layer Style File (*.qml)" ) );
QString myFileName = QFileDialog::getOpenFileName( this, tr( "Load layer properties from style file" ), myLastUsedDir,
tr( "QGIS Layer Style File (*.qml)" ) + ";;" + tr( "SLD File (*.sld)" ) );
if ( myFileName.isNull() )
{
return;
}

QString myMessage;
bool defaultLoadedFlag = false;
QString myMessage = layer->loadNamedStyle( myFileName, defaultLoadedFlag );

if ( myFileName.endsWith( ".sld", Qt::CaseInsensitive ) )
{
// load from SLD
myMessage = layer->loadSldStyle( myFileName, defaultLoadedFlag );
}
else
{
myMessage = layer->loadNamedStyle( myFileName, defaultLoadedFlag );
}
//reset if the default style was loaded ok only
if ( defaultLoadedFlag )
{
Expand All @@ -966,7 +977,7 @@ void QgsVectorLayerProperties::on_pbnLoadStyle_clicked()
else
{
//let the user know what went wrong
QMessageBox::information( this, tr( "Saved Style" ), myMessage );
QMessageBox::information( this, tr( "Load Style" ), myMessage );
}

QFileInfo myFI( myFileName );
Expand All @@ -979,22 +990,34 @@ void QgsVectorLayerProperties::on_pbnSaveStyleAs_clicked()
{
QSettings myQSettings; // where we keep last used filter in persistent state
QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", "." ).toString();
QString myOutputFileName = QFileDialog::getSaveFileName( this, tr( "Save layer properties as style file (.qml)" ), myLastUsedDir, tr( "QGIS Layer Style File (*.qml)" ) );
QString myOutputFileName = QFileDialog::getSaveFileName( this, tr( "Save layer properties as style file" ), myLastUsedDir,
tr( "QGIS Layer Style File (*.qml)" ) + ";;" + tr( "SLD File (*.sld)" ) );
if ( myOutputFileName.isNull() ) //dialog canceled
{
return;
}

apply(); // make sure the qml to save is uptodate

QString myMessage;
bool defaultLoadedFlag = false;

//ensure the user never omitted the extension from the file name
if ( !myOutputFileName.endsWith( ".qml", Qt::CaseInsensitive ) )
if ( myOutputFileName.endsWith( ".sld", Qt::CaseInsensitive ) )
{
// convert to SLD
myMessage = layer->saveSldStyle( myOutputFileName, defaultLoadedFlag );
}
else
{
myOutputFileName += ".qml";
if ( !myOutputFileName.endsWith( ".qml", Qt::CaseInsensitive ) )
{
myOutputFileName += ".qml";
}

myMessage = layer->saveNamedStyle( myOutputFileName, defaultLoadedFlag );
}

bool defaultLoadedFlag = false;
QString myMessage = layer->saveNamedStyle( myOutputFileName, defaultLoadedFlag );
//reset if the default style was loaded ok only
if ( defaultLoadedFlag )
{
Expand Down

0 comments on commit 3906922

Please sign in to comment.