Skip to content

Commit 6bf56e8

Browse files
committed
Merge branch 'style-docs' of https://github.com/tecoholic/Quantum-GIS
2 parents b6760ce + 447c0d1 commit 6bf56e8

File tree

3 files changed

+249
-51
lines changed

3 files changed

+249
-51
lines changed

src/core/symbology-ng/qgsstylev2.cpp

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void QgsStyleV2::clear()
8080
sqlite3_close( mCurrentDB );
8181
}
8282

83-
bool QgsStyleV2::addSymbol( QString name, QgsSymbolV2* symbol )
83+
bool QgsStyleV2::addSymbol( QString name, QgsSymbolV2* symbol, bool update )
8484
{
8585
if ( !symbol || name.isEmpty() )
8686
return false;
@@ -89,6 +89,9 @@ bool QgsStyleV2::addSymbol( QString name, QgsSymbolV2* symbol )
8989

9090
mSymbols.insert( name, symbol );
9191

92+
if ( update )
93+
updateSymbol( SymbolEntity, name );
94+
9295
return true;
9396
}
9497

@@ -108,7 +111,7 @@ bool QgsStyleV2::saveSymbol( QString name, QgsSymbolV2* symbol, int groupid, QSt
108111
QByteArray xmlArray;
109112
QTextStream stream( &xmlArray );
110113
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);",
112115
name.toUtf8().constData(), xmlArray.constData(), groupid );
113116

114117
if ( !runEmptyQuery( query ) )
@@ -170,17 +173,19 @@ QStringList QgsStyleV2::symbolNames()
170173
}
171174

172175

173-
bool QgsStyleV2::addColorRamp( QString name, QgsVectorColorRampV2* colorRamp )
176+
bool QgsStyleV2::addColorRamp( QString name, QgsVectorColorRampV2* colorRamp, bool update )
174177
{
175178
if ( !colorRamp || name.isEmpty() )
176179
return false;
177180

178181
// delete previous symbol (if any)
179182
delete mColorRamps.value( name );
180183

181-
QgsDebugMsg( "Inserted " + name );
182184
mColorRamps.insert( name, colorRamp );
183185

186+
if ( update )
187+
updateSymbol( ColorrampEntity, name );
188+
184189
return true;
185190
}
186191

@@ -201,7 +206,7 @@ bool QgsStyleV2::saveColorRamp( QString name, QgsVectorColorRampV2* ramp, int gr
201206
QByteArray xmlArray;
202207
QTextStream stream( &xmlArray );
203208
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);",
205210
name.toUtf8().constData(), xmlArray.constData(), groupid );
206211

207212
if ( !runEmptyQuery( query ) )
@@ -1378,3 +1383,64 @@ bool QgsStyleV2::importXML( QString filename )
13781383
mFileName = filename;
13791384
return true;
13801385
}
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

Comments
 (0)