Skip to content
Permalink
Browse files

[FEATURE] load/save layer style (new symbology) from/to SLD document

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 authored and alexbruy committed Mar 8, 2012
1 parent 64d7eb4 commit 84be523ba7722b540c9af0a18930ae905c65cd98
Showing with 4,176 additions and 35 deletions.
  1. +31 −8 src/app/qgsvectorlayerproperties.cpp
  2. +585 −0 src/core/qgsexpression.cpp
  3. +39 −0 src/core/qgsexpression.h
  4. +139 −0 src/core/qgsmaplayer.cpp
  5. +7 −0 src/core/qgsmaplayer.h
  6. +47 −0 src/core/qgsvectorlayer.cpp
  7. +2 −0 src/core/qgsvectorlayer.h
  8. +48 −0 src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
  9. +5 −0 src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
  10. +113 −0 src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
  11. +4 −0 src/core/symbology-ng/qgsellipsesymbollayerv2.h
  12. +291 −0 src/core/symbology-ng/qgsfillsymbollayerv2.cpp
  13. +16 −0 src/core/symbology-ng/qgsfillsymbollayerv2.h
  14. +49 −0 src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
  15. +5 −0 src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
  16. +253 −0 src/core/symbology-ng/qgslinesymbollayerv2.cpp
  17. +9 −0 src/core/symbology-ng/qgslinesymbollayerv2.h
  18. +201 −2 src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
  19. +9 −0 src/core/symbology-ng/qgsmarkersymbollayerv2.h
  20. +8 −0 src/core/symbology-ng/qgspointdisplacementrenderer.cpp
  21. +2 −0 src/core/symbology-ng/qgspointdisplacementrenderer.h
  22. +104 −0 src/core/symbology-ng/qgsrendererv2.cpp
  23. +27 −4 src/core/symbology-ng/qgsrendererv2.h
  24. +6 −2 src/core/symbology-ng/qgsrendererv2registry.cpp
  25. +23 −1 src/core/symbology-ng/qgsrendererv2registry.h
  26. +230 −1 src/core/symbology-ng/qgsrulebasedrendererv2.cpp
  27. +8 −0 src/core/symbology-ng/qgsrulebasedrendererv2.h
  28. +83 −0 src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
  29. +4 −0 src/core/symbology-ng/qgssinglesymbolrendererv2.h
  30. +13 −0 src/core/symbology-ng/qgssymbollayerv2.cpp
  31. +10 −2 src/core/symbology-ng/qgssymbollayerv2.h
  32. +19 −11 src/core/symbology-ng/qgssymbollayerv2registry.cpp
  33. +20 −1 src/core/symbology-ng/qgssymbollayerv2registry.h
  34. +1,625 −1 src/core/symbology-ng/qgssymbollayerv2utils.cpp
  35. +108 −2 src/core/symbology-ng/qgssymbollayerv2utils.h
  36. +13 −0 src/core/symbology-ng/qgssymbolv2.cpp
  37. +5 −0 src/core/symbology-ng/qgssymbolv2.h
  38. +12 −0 src/core/symbology-ng/qgsvectorfieldsymbollayer.cpp
  39. +3 −0 src/core/symbology-ng/qgsvectorfieldsymbollayer.h
@@ -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 )
{
@@ -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 );
@@ -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 )
{

0 comments on commit 84be523

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