@@ -80,7 +80,7 @@ void QgsStyleV2::clear()
80
80
sqlite3_close ( mCurrentDB );
81
81
}
82
82
83
- bool QgsStyleV2::addSymbol ( QString name, QgsSymbolV2* symbol )
83
+ bool QgsStyleV2::addSymbol ( QString name, QgsSymbolV2* symbol, bool update )
84
84
{
85
85
if ( !symbol || name.isEmpty () )
86
86
return false ;
@@ -89,6 +89,9 @@ bool QgsStyleV2::addSymbol( QString name, QgsSymbolV2* symbol )
89
89
90
90
mSymbols .insert ( name, symbol );
91
91
92
+ if ( update )
93
+ updateSymbol ( SymbolEntity, name );
94
+
92
95
return true ;
93
96
}
94
97
@@ -108,7 +111,7 @@ bool QgsStyleV2::saveSymbol( QString name, QgsSymbolV2* symbol, int groupid, QSt
108
111
QByteArray xmlArray;
109
112
QTextStream stream ( &xmlArray );
110
113
symEl.save ( stream, 4 );
111
- char *query = sqlite3_mprintf ( " INSERT INTO symbol VALUES (NULL, '%q', '%q', %d)" ,
114
+ char *query = sqlite3_mprintf ( " INSERT INTO symbol VALUES (NULL, '%q', '%q', %d); " ,
112
115
name.toUtf8 ().constData (), xmlArray.constData (), groupid );
113
116
114
117
if ( !runEmptyQuery ( query ) )
@@ -170,17 +173,19 @@ QStringList QgsStyleV2::symbolNames()
170
173
}
171
174
172
175
173
- bool QgsStyleV2::addColorRamp ( QString name, QgsVectorColorRampV2* colorRamp )
176
+ bool QgsStyleV2::addColorRamp ( QString name, QgsVectorColorRampV2* colorRamp, bool update )
174
177
{
175
178
if ( !colorRamp || name.isEmpty () )
176
179
return false ;
177
180
178
181
// delete previous symbol (if any)
179
182
delete mColorRamps .value ( name );
180
183
181
- QgsDebugMsg ( " Inserted " + name );
182
184
mColorRamps .insert ( name, colorRamp );
183
185
186
+ if ( update )
187
+ updateSymbol ( ColorrampEntity, name );
188
+
184
189
return true ;
185
190
}
186
191
@@ -201,7 +206,7 @@ bool QgsStyleV2::saveColorRamp( QString name, QgsVectorColorRampV2* ramp, int gr
201
206
QByteArray xmlArray;
202
207
QTextStream stream ( &xmlArray );
203
208
rampEl.save ( stream, 4 );
204
- char *query = sqlite3_mprintf ( " INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d)" ,
209
+ char *query = sqlite3_mprintf ( " INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d); " ,
205
210
name.toUtf8 ().constData (), xmlArray.constData (), groupid );
206
211
207
212
if ( !runEmptyQuery ( query ) )
@@ -1378,3 +1383,64 @@ bool QgsStyleV2::importXML( QString filename )
1378
1383
mFileName = filename;
1379
1384
return true ;
1380
1385
}
1386
+
1387
+ bool QgsStyleV2::updateSymbol ( StyleEntity type, QString name )
1388
+ {
1389
+ QDomDocument doc ( " dummy" );
1390
+ QDomElement symEl;
1391
+ QByteArray xmlArray;
1392
+ QTextStream stream ( &xmlArray );
1393
+
1394
+ char *query;
1395
+
1396
+ if ( type == SymbolEntity )
1397
+ {
1398
+ // check if it is an existing symbol
1399
+ if ( !symbolNames ().contains ( name ) )
1400
+ {
1401
+ QgsDebugMsg ( " Update request recieved for unavailable symbol" );
1402
+ return false ;
1403
+ }
1404
+
1405
+ symEl = QgsSymbolLayerV2Utils::saveSymbol ( name, symbol ( name ), doc );
1406
+ if ( symEl.isNull () )
1407
+ {
1408
+ QgsDebugMsg ( " Couldn't convert symbol to valid XML!" );
1409
+ return false ;
1410
+ }
1411
+ symEl.save ( stream, 4 );
1412
+ query = sqlite3_mprintf ( " UPDATE symbol SET xml='%q' WHERE name='%q';" ,
1413
+ xmlArray.constData (), name.toUtf8 ().constData () );
1414
+ }
1415
+ else if ( type == ColorrampEntity )
1416
+ {
1417
+ if ( !colorRampNames ().contains ( name ) )
1418
+ {
1419
+ QgsDebugMsg ( " Update requested for unavailable color ramp." );
1420
+ return false ;
1421
+ }
1422
+
1423
+ symEl = QgsSymbolLayerV2Utils::saveColorRamp ( name, colorRamp ( name ), doc );
1424
+ if ( symEl.isNull () )
1425
+ {
1426
+ QgsDebugMsg ( " Couldn't convert color ramp to valid XML!" );
1427
+ return false ;
1428
+ }
1429
+ symEl.save ( stream, 4 );
1430
+ query = sqlite3_mprintf ( " UPDATE colorramp SET xml='%q' WHERE name='%q';" ,
1431
+ xmlArray.constData (), name.toUtf8 ().constData () );
1432
+ }
1433
+ else
1434
+ {
1435
+ QgsDebugMsg ( " Updating the unsupported StyleEntity" );
1436
+ return false ;
1437
+ }
1438
+
1439
+
1440
+ if ( !runEmptyQuery ( query ) )
1441
+ {
1442
+ QgsDebugMsg ( " Couldn't insert symbol into the database!" );
1443
+ return false ;
1444
+ }
1445
+ return true ;
1446
+ }
0 commit comments