Skip to content

Commit be31574

Browse files
committedDec 27, 2012
Merge pull request #368 from tecoholic/6897
Fixes #6897. Handle import of old symbols.
2 parents ce4d03b + 8b98197 commit be31574

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed
 

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ i18n/*.qm
4848
.idea
4949
/python/plugins/sextante/resources_rc.py
5050
/python/plugins/sextante/about/ui_aboutdialogbase.py
51+
scripts/qgisstyle

‎src/core/symbology-ng/qgsstylev2.cpp

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#include <sqlite3.h>
3535

36-
#define STYLE_CURRENT_VERSION "0"
36+
#define STYLE_CURRENT_VERSION "1"
3737

3838
QgsStyleV2 *QgsStyleV2::mDefaultStyle = 0;
3939

@@ -1343,30 +1343,47 @@ bool QgsStyleV2::importXML( QString filename )
13431343
}
13441344

13451345
QString version = docEl.attribute( "version" );
1346-
if ( version != STYLE_CURRENT_VERSION )
1346+
if ( version != STYLE_CURRENT_VERSION && version != "0" )
13471347
{
13481348
mErrorString = "Unknown style file version: " + version;
13491349
return false;
13501350
}
13511351

1352-
// load symbols
1352+
QgsSymbolV2Map symbols;
1353+
13531354
QDomElement symbolsElement = docEl.firstChildElement( "symbols" );
13541355
QDomElement e = symbolsElement.firstChildElement();
1355-
while ( !e.isNull() )
1356+
1357+
if ( version == STYLE_CURRENT_VERSION )
13561358
{
1357-
if ( e.tagName() == "symbol" )
1359+
// For the new style, load symbols individualy
1360+
while ( !e.isNull() )
13581361
{
1359-
QgsSymbolV2* symbol = QgsSymbolLayerV2Utils::loadSymbol( e );
1360-
if ( symbol )
1362+
if ( e.tagName() == "symbol" )
13611363
{
1362-
addSymbol( e.attribute( "name" ), symbol );
1364+
QgsSymbolV2* symbol = QgsSymbolLayerV2Utils::loadSymbol( e );
1365+
if ( symbol )
1366+
{
1367+
symbols.insert( e.attribute( "name" ), symbol );
1368+
}
13631369
}
1370+
else
1371+
{
1372+
QgsDebugMsg( "unknown tag: " + e.tagName() );
1373+
}
1374+
e = e.nextSiblingElement();
13641375
}
1365-
else
1366-
{
1367-
QgsDebugMsg( "unknown tag: " + e.tagName() );
1368-
}
1369-
e = e.nextSiblingElement();
1376+
}
1377+
else
1378+
{
1379+
// for the old version, use the utility function to solve @symbol@layer subsymbols
1380+
symbols = QgsSymbolLayerV2Utils::loadSymbols( symbolsElement );
1381+
}
1382+
1383+
// save the symbols with proper name
1384+
for ( QMap<QString, QgsSymbolV2*>::iterator it = symbols.begin(); it != symbols.end(); it++ )
1385+
{
1386+
addSymbol( it.key(), it.value() );
13701387
}
13711388

13721389
// load color ramps

‎src/core/symbology-ng/qgssymbollayerv2utils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,6 @@ void QgsSymbolLayerV2Utils::saveProperties( QgsStringMap props, QDomDocument& do
23052305
}
23062306
}
23072307

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

0 commit comments

Comments
 (0)