@@ -289,6 +289,42 @@ bool QgsStyle::openDB( const QString& filename )
289
289
return true ;
290
290
}
291
291
292
+ bool QgsStyle::createMemoryDB ()
293
+ {
294
+ mErrorString .clear ();
295
+ if ( !openDB ( QStringLiteral ( " :memory:" ) ) )
296
+ {
297
+ mErrorString = QStringLiteral ( " Unable to create temporary memory database" );
298
+ QgsDebugMsg ( mErrorString );
299
+ return false ;
300
+ }
301
+ char *query = sqlite3_mprintf ( " CREATE TABLE symbol(" \
302
+ " id INTEGER PRIMARY KEY," \
303
+ " name TEXT UNIQUE," \
304
+ " xml TEXT," \
305
+ " favorite INTEGER);" \
306
+ " CREATE TABLE colorramp(" \
307
+ " id INTEGER PRIMARY KEY," \
308
+ " name TEXT UNIQUE," \
309
+ " xml TEXT," \
310
+ " favorite INTEGER);" \
311
+ " CREATE TABLE tag(" \
312
+ " id INTEGER PRIMARY KEY," \
313
+ " name TEXT);" \
314
+ " CREATE TABLE tagmap(" \
315
+ " tag_id INTEGER NOT NULL," \
316
+ " symbol_id INTEGER);" \
317
+ " CREATE TABLE ctagmap(" \
318
+ " tag_id INTEGER NOT NULL," \
319
+ " colorramp_id INTEGER);" \
320
+ " CREATE TABLE smartgroup(" \
321
+ " id INTEGER PRIMARY KEY," \
322
+ " name TEXT," \
323
+ " xml TEXT);" );
324
+ runEmptyQuery ( query );
325
+ return true ;
326
+ }
327
+
292
328
bool QgsStyle::load ( const QString& filename )
293
329
{
294
330
mErrorString .clear ();
@@ -1391,14 +1427,42 @@ bool QgsStyle::exportXml( const QString& filename )
1391
1427
root.setAttribute ( QStringLiteral ( " version" ), STYLE_CURRENT_VERSION );
1392
1428
doc.appendChild ( root );
1393
1429
1394
- // TODO work on the groups and tags
1430
+ QStringList favoriteSymbols = symbolsOfFavorite ( SymbolEntity );
1431
+ QStringList favoriteColorramps = symbolsOfFavorite ( ColorrampEntity );
1432
+
1433
+ // save symbols and attach tags
1395
1434
QDomElement symbolsElem = QgsSymbolLayerUtils::saveSymbols ( mSymbols , QStringLiteral ( " symbols" ), doc );
1396
- QDomElement rampsElem = doc.createElement ( QStringLiteral ( " colorramps" ) );
1435
+ QDomNodeList symbolsList = symbolsElem.elementsByTagName ( QStringLiteral ( " symbol" ) );
1436
+ int nbSymbols = symbolsList.count ();
1437
+ for ( int i = 0 ; i < nbSymbols; ++i )
1438
+ {
1439
+ QDomElement symbol = symbolsList.at ( i ).toElement ();
1440
+ QString name = symbol.attribute ( QStringLiteral ( " name" ) );
1441
+ QStringList tags = tagsOfSymbol ( SymbolEntity, name );
1442
+ if ( tags.count () > 0 )
1443
+ {
1444
+ symbol.setAttribute ( QStringLiteral ( " tags" ), tags.join ( " ," ) );
1445
+ }
1446
+ if ( favoriteSymbols.contains ( name ) )
1447
+ {
1448
+ symbol.setAttribute ( QStringLiteral ( " favorite" ), " 1" );
1449
+ }
1450
+ }
1397
1451
1398
1452
// save color ramps
1453
+ QDomElement rampsElem = doc.createElement ( QStringLiteral ( " colorramps" ) );
1399
1454
for ( QMap<QString, QgsColorRamp*>::const_iterator itr = mColorRamps .constBegin (); itr != mColorRamps .constEnd (); ++itr )
1400
1455
{
1401
1456
QDomElement rampEl = QgsSymbolLayerUtils::saveColorRamp ( itr.key (), itr.value (), doc );
1457
+ QStringList tags = tagsOfSymbol ( ColorrampEntity, itr.key () );
1458
+ if ( tags.count () > 0 )
1459
+ {
1460
+ rampEl.setAttribute ( QStringLiteral ( " tags" ), tags.join ( " ," ) );
1461
+ }
1462
+ if ( favoriteColorramps.contains ( itr.key () ) )
1463
+ {
1464
+ rampEl.setAttribute ( QStringLiteral ( " favorite" ), " 1" );
1465
+ }
1402
1466
rampsElem.appendChild ( rampEl );
1403
1467
}
1404
1468
0 commit comments