Skip to content

Commit

Permalink
Merge pull request #368 from tecoholic/6897
Browse files Browse the repository at this point in the history
Fixes #6897. Handle import of old symbols.
  • Loading branch information
NathanW2 committed Dec 27, 2012
2 parents ce4d03b + 8b98197 commit be31574
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ i18n/*.qm
.idea
/python/plugins/sextante/resources_rc.py
/python/plugins/sextante/about/ui_aboutdialogbase.py
scripts/qgisstyle
43 changes: 30 additions & 13 deletions src/core/symbology-ng/qgsstylev2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#include <sqlite3.h>

#define STYLE_CURRENT_VERSION "0"
#define STYLE_CURRENT_VERSION "1"

QgsStyleV2 *QgsStyleV2::mDefaultStyle = 0;

Expand Down Expand Up @@ -1343,30 +1343,47 @@ bool QgsStyleV2::importXML( QString filename )
}

QString version = docEl.attribute( "version" );
if ( version != STYLE_CURRENT_VERSION )
if ( version != STYLE_CURRENT_VERSION && version != "0" )
{
mErrorString = "Unknown style file version: " + version;
return false;
}

// load symbols
QgsSymbolV2Map symbols;

QDomElement symbolsElement = docEl.firstChildElement( "symbols" );
QDomElement e = symbolsElement.firstChildElement();
while ( !e.isNull() )

if ( version == STYLE_CURRENT_VERSION )
{
if ( e.tagName() == "symbol" )
// For the new style, load symbols individualy
while ( !e.isNull() )
{
QgsSymbolV2* symbol = QgsSymbolLayerV2Utils::loadSymbol( e );
if ( symbol )
if ( e.tagName() == "symbol" )
{
addSymbol( e.attribute( "name" ), symbol );
QgsSymbolV2* symbol = QgsSymbolLayerV2Utils::loadSymbol( e );
if ( symbol )
{
symbols.insert( e.attribute( "name" ), symbol );
}
}
else
{
QgsDebugMsg( "unknown tag: " + e.tagName() );
}
e = e.nextSiblingElement();
}
else
{
QgsDebugMsg( "unknown tag: " + e.tagName() );
}
e = e.nextSiblingElement();
}
else
{
// for the old version, use the utility function to solve @symbol@layer subsymbols
symbols = QgsSymbolLayerV2Utils::loadSymbols( symbolsElement );
}

// save the symbols with proper name
for ( QMap<QString, QgsSymbolV2*>::iterator it = symbols.begin(); it != symbols.end(); it++ )
{
addSymbol( it.key(), it.value() );
}

// load color ramps
Expand Down
1 change: 0 additions & 1 deletion src/core/symbology-ng/qgssymbollayerv2utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2305,7 +2305,6 @@ void QgsSymbolLayerV2Utils::saveProperties( QgsStringMap props, QDomDocument& do
}
}

// XXX Not used by QgStyleV2 anymore, But renderers use it still
QgsSymbolV2Map QgsSymbolLayerV2Utils::loadSymbols( QDomElement& element )
{
// go through symbols one-by-one and load them
Expand Down

0 comments on commit be31574

Please sign in to comment.