26 #include <QDomDocument>    27 #include <QDomElement>    29 #include <QDomNodeList>    31 #include <QTextStream>    36 #define STYLE_CURRENT_VERSION  "1"    83   if ( !symbol || name.
isEmpty() )
   112     QgsDebugMsg( 
"Couldn't convert symbol to valid XML!" );
   119   symEl.
save( stream, 4 );
   120   char *query = sqlite3_mprintf( 
"INSERT INTO symbol VALUES (NULL, '%q', '%q', %d);",
   125     QgsDebugMsg( 
"Couldn't insert symbol into the database!" );
   149     QgsDebugMsg( 
"Sorry! Cannot open database to tag." );
   156     QgsDebugMsg( 
"No such symbol for deleting in database: " + name + 
". Cheers." );
   167   return symbol ? symbol->
clone() : 
nullptr;
   188   if ( !colorRamp || name.
isEmpty() )
   217     QgsDebugMsg( 
"Couldn't convert color ramp to valid XML!" );
   224   rampEl.
save( stream, 4 );
   225   char *query = sqlite3_mprintf( 
"INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
   230     QgsDebugMsg( 
"Couldn't insert colorramp into the database!" );
   245   char *query = sqlite3_mprintf( 
"DELETE FROM colorramp WHERE name='%q'", name.
toUtf8().
constData() );
   248     QgsDebugMsg( 
"Couldn't remove color ramp from the database." );
   260   return ramp ? ramp->
clone() : 
nullptr;
   296   if ( !
openDB( filename ) )
   298     mErrorString = 
"Unable to open database file specified";
   304   char *query = sqlite3_mprintf( 
"UPDATE symbol SET groupid=0 WHERE groupid IS NULL;"   305                                  "UPDATE colorramp SET groupid=0 WHERE groupid IS NULL;"   306                                  "UPDATE symgroup SET parent=0 WHERE parent IS NULL;" );
   310   query = sqlite3_mprintf( 
"SELECT * FROM symbol" );
   312   sqlite3_stmt *ppStmt;
   313   int nError = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   314   while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   321       QgsDebugMsg( 
"Cannot open symbol " + symbol_name );
   331   sqlite3_finalize( ppStmt );
   333   query = sqlite3_mprintf( 
"SELECT * FROM colorramp" );
   334   nError = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   335   while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   388   if ( !f.
open( QFile::WriteOnly ) )
   390     mErrorString = 
"Couldn't open file for writing: " + filename;
   407     QgsDebugMsg( 
"Symbol of new name already exists" );
   419     QgsDebugMsg( 
"Sorry! Cannot open database to tag." );
   426     QgsDebugMsg( 
"No such symbol for tagging in database: " + oldName );
   439     QgsDebugMsg( 
"Color ramp of new name already exists." );
   450   sqlite3_stmt *ppStmt;
   451   char *query = sqlite3_mprintf( 
"SELECT id FROM colorramp WHERE name='%q'", oldName.
toUtf8().
constData() );
   452   int nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   453   if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   455     rampid = sqlite3_column_int( ppStmt, 0 );
   457   sqlite3_finalize( ppStmt );
   466   sqlite3_stmt *ppStmt;
   467   const char *query = 
"SELECT * FROM symgroup";
   468   int nError = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   469   while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   471     groupNames << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 
SymgroupName ) ) );
   473   sqlite3_finalize( ppStmt );
   480   sqlite3_stmt *ppStmt;
   481   const char *query = 
"SELECT * FROM symgroup";
   482   int nError = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   483   while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   485     groupIds << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 
SymgroupId ) ) ).toInt();
   487   sqlite3_finalize( ppStmt );
   496     QgsDebugMsg( 
"Cannot open database for listing groups" );
   500   char *query = 
nullptr;
   502   sqlite3_stmt *ppStmt;
   505   if ( parent == 
"" || parent == 
QString() )
   507     query = sqlite3_mprintf( 
"SELECT * FROM symgroup WHERE parent=0" );
   511     char *subquery = sqlite3_mprintf( 
"SELECT * FROM symgroup WHERE name='%q'", parent.
toUtf8().
constData() );
   512     nError = sqlite3_prepare_v2( 
mCurrentDB, subquery, -1, &ppStmt, 
nullptr );
   513     if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   515       query = sqlite3_mprintf( 
"SELECT * FROM symgroup WHERE parent=%d", sqlite3_column_int( ppStmt, 
SymgroupId ) );
   517     sqlite3_finalize( ppStmt );
   526   nError = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   527   while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   533   sqlite3_finalize( ppStmt );
   542     QgsDebugMsg( 
QString( 
"Cannot Open database for getting group symbols of groupid: %1" ).arg( groupid ) );
   549     query = sqlite3_mprintf( 
"SELECT name FROM symbol WHERE groupid=%d", groupid );
   553     query = sqlite3_mprintf( 
"SELECT name FROM colorramp WHERE groupid=%d", groupid );
   561   sqlite3_stmt *ppStmt;
   562   int nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   565   while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   567     symbols << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 0 ) ) );
   570   sqlite3_finalize( ppStmt );
   579     QgsDebugMsg( 
QString( 
"Cannot open database to get symbols of tagid %1" ).arg( tagid ) );
   586     subquery = sqlite3_mprintf( 
"SELECT symbol_id FROM tagmap WHERE tag_id=%d", tagid );
   590     subquery = sqlite3_mprintf( 
"SELECT symbol_id FROM ctagmap WHERE tag_id=%d", tagid );
   598   sqlite3_stmt *ppStmt;
   599   int nErr = sqlite3_prepare_v2( 
mCurrentDB, subquery, -1, &ppStmt, 
nullptr );
   603   while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   605     int symbolId = sqlite3_column_int( ppStmt, 0 );
   608                   ? sqlite3_mprintf( 
"SELECT name FROM symbol WHERE id=%d", symbolId )
   609                   : sqlite3_mprintf( 
"SELECT name FROM colorramp WHERE id=%d", symbolId );
   611     sqlite3_stmt *ppStmt2;
   612     int sErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt2, 
nullptr );
   613     while ( sErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
   615       symbols << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt2, 0 ) ) );
   617     sqlite3_finalize( ppStmt2 );
   619   sqlite3_finalize( ppStmt );
   629   char *query = sqlite3_mprintf( 
"INSERT INTO symgroup VALUES (NULL, '%q', %d)", groupName.
toUtf8().
constData(), parentid );
   631   sqlite3_stmt *ppStmt;
   632   int nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   633   if ( nErr == SQLITE_OK )
   634     ( void )sqlite3_step( ppStmt );
   636   sqlite3_finalize( ppStmt );
   638   return static_cast< int >( sqlite3_last_insert_rowid( 
mCurrentDB ) );
   645   sqlite3_stmt *ppStmt;
   647   char *query = sqlite3_mprintf( 
"INSERT INTO tag VALUES (NULL, '%q')", tagname.
toUtf8().
constData() );
   648   int nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   649   if ( nErr == SQLITE_OK )
   650     ( void )sqlite3_step( ppStmt );
   651   sqlite3_finalize( ppStmt );
   653   return static_cast< int >( sqlite3_last_insert_rowid( 
mCurrentDB ) );
   661   sqlite3_stmt *ppStmt;
   663   char *query = sqlite3_mprintf( 
"SELECT name FROM tag" );
   664   int nError = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   667   while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   669     tagList << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 0 ) ) );
   672   sqlite3_finalize( ppStmt );
   683       query = sqlite3_mprintf( 
"UPDATE symbol SET name='%q' WHERE id=%d", newName.
toUtf8().
constData(), id );
   686       query = sqlite3_mprintf( 
"UPDATE symgroup SET name='%q' WHERE id=%d", newName.
toUtf8().
constData(), id );
   689       query = sqlite3_mprintf( 
"UPDATE tag SET name='%q' WHERE id=%d", newName.
toUtf8().
constData(), id );
   692       query = sqlite3_mprintf( 
"UPDATE colorramp SET name='%q' WHERE id=%d", newName.
toUtf8().
constData(), id );
   695       query = sqlite3_mprintf( 
"UPDATE smartgroup SET name='%q' WHERE id=%d", newName.
toUtf8().
constData(), id );
   707   char *query = sqlite3_mprintf( 
"SELECT parent FROM symgroup WHERE id=%d", 
id );
   709   sqlite3_stmt *ppStmt;
   710   int err = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   713   if ( err == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   714     parentid = sqlite3_column_int( ppStmt, 0 );
   716   sqlite3_finalize( ppStmt );
   718   return sqlite3_mprintf( 
"UPDATE symbol SET groupid=%d WHERE groupid=%d;"   719                           "UPDATE symgroup SET parent=%d WHERE parent=%d;"   720                           "DELETE FROM symgroup WHERE id=%d", parentid, 
id, parentid, 
id, 
id );
   729       query = sqlite3_mprintf( 
"DELETE FROM symbol WHERE id=%d; DELETE FROM tagmap WHERE symbol_id=%d", 
id, 
id );
   735       query = sqlite3_mprintf( 
"DELETE FROM tag WHERE id=%d; DELETE FROM tagmap WHERE tag_id=%d", 
id, 
id );
   738       query = sqlite3_mprintf( 
"DELETE FROM colorramp WHERE id=%d", 
id );
   741       query = sqlite3_mprintf( 
"DELETE FROM smartgroup WHERE id=%d", 
id );
   759   char *zErr = 
nullptr;
   760   int nErr = sqlite3_exec( 
mCurrentDB, query, 
nullptr, 
nullptr, &zErr );
   764     sqlite3_free( query );
   767   if ( nErr != SQLITE_OK )
   772   return zErr == SQLITE_OK;
   782       query = sqlite3_mprintf( 
"UPDATE symbol SET groupid=%d WHERE name='%q'", groupid, name.
toUtf8().
constData() );
   785       query = sqlite3_mprintf( 
"UPDATE colorramp SET groupid=%d WHERE name='%q'", groupid, name.
toUtf8().
constData() );
   789       QgsDebugMsg( 
"Wrong entity value. cannot apply group" );
   800     QgsDebugMsg( 
"Sorry! Cannot open database to search" );
   806   char *query = sqlite3_mprintf( 
"SELECT name FROM %q WHERE name LIKE '%%%q%%'",
   809   sqlite3_stmt *ppStmt;
   810   int nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   813   while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   815     symbols << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 0 ) ) );
   818   sqlite3_finalize( ppStmt );
   821   query = sqlite3_mprintf( 
"SELECT id FROM tag WHERE name LIKE '%%%q%%'", qword.
toUtf8().
constData() );
   822   nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, NULL );
   825   while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   830   sqlite3_finalize( ppStmt );
   837     query = sqlite3_mprintf( 
"SELECT symbol_id FROM tagmap WHERE tag_id IN (%q)",
   842     query = sqlite3_mprintf( 
"SELECT colorramp_id FROM ctagmap WHERE tag_id IN (%q)",
   845   nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, NULL );
   848   while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   850     symbolids << 
QString::fromUtf8(( 
const char * ) sqlite3_column_text( ppStmt, 0 ) );
   853   sqlite3_finalize( ppStmt );
   856   dummy = symbolids.
join( 
", " );
   857   query = sqlite3_mprintf( 
"SELECT name FROM %q  WHERE id IN (%q)",
   859   nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, NULL );
   860   while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   862     symbols << 
QString::fromUtf8(( 
const char * ) sqlite3_column_text( ppStmt, 0 ) );
   865   sqlite3_finalize( ppStmt );
   874     QgsDebugMsg( 
"Sorry! Cannot open database to tag." );
   881     QgsDebugMsg( 
"No such symbol for tagging in database: " + symbol );
   886   Q_FOREACH ( 
const QString &tag, tags )
   889     char *query = sqlite3_mprintf( 
"SELECT id FROM tag WHERE name='%q'", tag.
toUtf8().
constData() );
   891     sqlite3_stmt *ppStmt;
   892     int nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   895     if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   897       tagid = sqlite3_column_int( ppStmt, 0 );
   904     sqlite3_finalize( ppStmt );
   908             ? sqlite3_mprintf( 
"INSERT INTO tagmap VALUES (%d,%d)", tagid, symbolid )
   909             : sqlite3_mprintf( 
"INSERT INTO ctagmap VALUES (%d,%d)", tagid, symbolid );
   911     char *zErr = 
nullptr;
   912     nErr = sqlite3_exec( 
mCurrentDB, query, 
nullptr, 
nullptr, &zErr );
   926     QgsDebugMsg( 
"Sorry! Cannot open database for detgging." );
   931                 ? sqlite3_mprintf( 
"SELECT id FROM symbol WHERE name='%q'", symbol.
toUtf8().
constData() )
   932                 : sqlite3_mprintf( 
"SELECT id FROM colorramp WHERE name='%q'", symbol.
toUtf8().
constData() );
   933   sqlite3_stmt *ppStmt;
   934   int nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
   937   if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
   939     symbolid = sqlite3_column_int( ppStmt, 0 );
   943     sqlite3_finalize( ppStmt );
   947   sqlite3_finalize( ppStmt );
   949   Q_FOREACH ( 
const QString &tag, tags )
   951     query = sqlite3_mprintf( 
"SELECT id FROM tag WHERE name='%q'", tag.
toUtf8().
constData() );
   953     sqlite3_stmt *ppStmt2;
   954     nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt2, 
nullptr );
   957     if ( nErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
   959       tagid = sqlite3_column_int( ppStmt2, 0 );
   962     sqlite3_finalize( ppStmt2 );
   968               ? sqlite3_mprintf( 
"DELETE FROM tagmap WHERE tag_id=%d AND symbol_id=%d", tagid, symbolid )
   969               : sqlite3_mprintf( 
"DELETE FROM ctagmap WHERE tag_id=%d AND colorramp_id=%d", tagid, symbolid );
   984     QgsDebugMsg( 
"Sorry! Cannot open database for getting the tags." );
   994                 ? sqlite3_mprintf( 
"SELECT tag_id FROM tagmap WHERE symbol_id=%d", symbolid )
   995                 : sqlite3_mprintf( 
"SELECT tag_id FROM ctagmap WHERE colorramp_id=%d", symbolid );
   997   sqlite3_stmt *ppStmt;
   998   int nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
  1001   while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
  1003     char *subquery = sqlite3_mprintf( 
"SELECT name FROM tag WHERE id=%d", sqlite3_column_int( ppStmt, 0 ) );
  1005     sqlite3_stmt *ppStmt2;
  1006     int pErr = sqlite3_prepare_v2( 
mCurrentDB, subquery, -1, &ppStmt2, 
nullptr );
  1007     if ( pErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
  1009       tagList << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt2, 0 ) ) );
  1011     sqlite3_finalize( ppStmt2 );
  1014   sqlite3_finalize( ppStmt );
  1023   sqlite3_stmt *ppStmt;
  1024   int nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
  1027   if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
  1029     id = sqlite3_column_int( ppStmt, 0 );
  1032   sqlite3_finalize( ppStmt );
  1041   sqlite3_stmt *ppStmt;
  1042   int nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
  1045   if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
  1047     name = 
QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 0 ) ) );
  1050   sqlite3_finalize( ppStmt );
  1057   return getId( 
"symbol", name );
  1062   return getId( 
"colorramp", name );
  1067   return getId( 
"symgroup", name );
  1072   return getName( 
"symgroup", groupId );
  1077   return getId( 
"tag", name );
  1082   return getId( 
"smartgroup", name );
  1093   constraints << 
"tag" << 
"group" << 
"name" << 
"!tag" << 
"!group" << 
"!name";
  1095   Q_FOREACH ( 
const QString &constraint, constraints )
  1098     Q_FOREACH ( 
const QString ¶m, parameters )
  1110   smartEl.
save( stream, 4 );
  1111   char *query = sqlite3_mprintf( 
"INSERT INTO smartgroup VALUES (NULL, '%q', '%q')",
  1116     return static_cast< int >( sqlite3_last_insert_rowid( 
mCurrentDB ) );
  1120     QgsDebugMsg( 
"Couldn't insert symbol into the database!" );
  1129     QgsDebugMsg( 
"Cannot open database for listing groups" );
  1133   char *query = sqlite3_mprintf( 
"SELECT * FROM smartgroup" );
  1136   sqlite3_stmt *ppStmt;
  1137   int nError = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
  1140   while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
  1146   sqlite3_finalize( ppStmt );
  1155     QgsDebugMsg( 
"Cannot open database for listing groups" );
  1159   char *query = sqlite3_mprintf( 
"SELECT name FROM smartgroup" );
  1162   sqlite3_stmt *ppStmt;
  1163   int nError = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
  1166   while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
  1168     groups << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 0 ) ) );
  1171   sqlite3_finalize( ppStmt );
  1180   char *query = sqlite3_mprintf( 
"SELECT xml FROM smartgroup WHERE id=%d", 
id );
  1182   sqlite3_stmt *ppStmt;
  1183   int nErr = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
  1184   if ( !( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW ) )
  1186     sqlite3_finalize( ppStmt );
  1201     bool firstSet = 
true;
  1202     for ( 
int i = 0; i < conditionNodes.
count(); i++ )
  1210       if ( constraint == 
"tag" )
  1214       else if ( constraint == 
"group" )
  1220       else if ( constraint == 
"name" )
  1231       else if ( constraint == 
"!tag" )
  1240       else if ( constraint == 
"!group" )
  1249       else if ( constraint == 
"!name" )
  1252         Q_FOREACH ( 
const QString &str, all )
  1254           if ( !str.
contains( param, Qt::CaseInsensitive ) )
  1262         symbols = resultNames;
  1269           symbols << resultNames;
  1271         else if ( op == 
"AND" )
  1275           Q_FOREACH ( 
const QString &result, resultNames )
  1285   sqlite3_finalize( ppStmt );
  1294     QgsDebugMsg( 
"Cannot open database for listing groups" );
  1300   char *query = sqlite3_mprintf( 
"SELECT xml FROM smartgroup WHERE id=%d", 
id );
  1302   sqlite3_stmt *ppStmt;
  1303   int nError = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
  1304   if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
  1316     for ( 
int i = 0; i < conditionNodes.
count(); i++ )
  1322       condition.
insert( constraint, param );
  1326   sqlite3_finalize( ppStmt );
  1335     QgsDebugMsg( 
"Cannot open database for listing groups" );
  1341   char *query = sqlite3_mprintf( 
"SELECT xml FROM smartgroup WHERE id=%d", 
id );
  1343   sqlite3_stmt *ppStmt;
  1344   int nError = sqlite3_prepare_v2( 
mCurrentDB, query, -1, &ppStmt, 
nullptr );
  1345   if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
  1357   sqlite3_finalize( ppStmt );
  1366     QgsDebugMsg( 
"Invalid filename for style export." );
  1390   QFile f( filename );
  1391   if ( !f.
open( QFile::WriteOnly ) )
  1393     mErrorString = 
"Couldn't open file for writing: " + filename;
  1410   QFile f( filename );
  1411   if ( !f.
open( QFile::ReadOnly ) )
  1414     QgsDebugMsg( 
"Error opening the style XML file." );
  1428   if ( docEl.
tagName() != 
"qgis_style" )
  1437     mErrorString = 
"Unknown style file version: " + version;
  1451       if ( e.
tagName() == 
"symbol" )
  1483     if ( e.
tagName() == 
"colorramp" )
  1517       QgsDebugMsg( 
"Update request received for unavailable symbol" );
  1524       QgsDebugMsg( 
"Couldn't convert symbol to valid XML!" );
  1527     symEl.
save( stream, 4 );
  1528     query = sqlite3_mprintf( 
"UPDATE symbol SET xml='%q' WHERE name='%q';",
  1535       QgsDebugMsg( 
"Update requested for unavailable color ramp." );
  1542       QgsDebugMsg( 
"Couldn't convert color ramp to valid XML!" );
  1545     symEl.
save( stream, 4 );
  1546     query = sqlite3_mprintf( 
"UPDATE colorramp SET xml='%q' WHERE name='%q';",
  1551     QgsDebugMsg( 
"Updating the unsupported StyleEntity" );
  1558     QgsDebugMsg( 
"Couldn't insert symbol into the database!" );
 
QStringList tagsOfSymbol(StyleEntity type, const QString &symbol)
return the tags associated with the symbol 
 
void setCodec(QTextCodec *codec)
 
QString smartgroupOperator(int id)
returns the operator for the smartgroup 
 
static QDomElement saveSymbols(QgsSymbolV2Map &symbols, const QString &tagName, QDomDocument &doc)
 
int getId(const QString &table, const QString &name)
gets the id from the table for the given name from the database, 0 if not found 
 
static QgsSymbolV2Map loadSymbols(QDomElement &element)
 
bool saveColorRamp(const QString &name, QgsVectorColorRampV2 *ramp, int groupid, const QStringList &tags)
add the colorramp to the DB 
 
void remove(StyleEntity type, int id)
remove the specified entity from the db 
 
QgsVectorColorRampV2 * colorRamp(const QString &name)
return a NEW copy of color ramp 
 
bool contains(const Key &key) const
 
static QgsVectorColorRampV2 * loadColorRamp(QDomElement &element)
 
bool importXML(const QString &filename)
Imports the symbols and colorramps into the default style database from the given XML file...
 
bool tagSymbol(StyleEntity type, const QString &symbol, const QStringList &tags)
tags the symbol with the tags in the list 
 
bool group(StyleEntity type, const QString &name, int groupid)
applies the specified group to the symbol or colorramp specified by StyleEntity 
 
QList< T > values() const
 
QDomNode appendChild(const QDomNode &newChild)
 
bool addSymbol(const QString &name, QgsSymbolV2 *symbol, bool update=false)
add symbol to style. takes symbol's ownership 
 
QString getName(const QString &table, int id) const
gets the name from the table for the given id from the database, empty if not found ...
 
QString attribute(const QString &name, const QString &defValue) const
 
int groupId(const QString &group)
return the DB id for the given group name 
 
static QDomElement saveColorRamp(const QString &name, QgsVectorColorRampV2 *ramp, QDomDocument &doc)
 
virtual QgsSymbolV2 * clone() const =0
 
const_iterator constBegin() const
 
QStringList symbolsOfGroup(StyleEntity type, int groupid)
returns the symbolnames of a given groupid 
 
bool contains(const QString &str, Qt::CaseSensitivity cs) const
 
static QDomElement saveSymbol(const QString &symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
 
QDomElement nextSiblingElement(const QString &tagName) const
 
bool exportXML(const QString &filename)
Exports the style as a XML file. 
 
bool addColorRamp(const QString &name, QgsVectorColorRampV2 *colorRamp, bool update=false)
add color ramp to style. takes ramp's ownership 
 
QDomElement documentElement() const
 
bool detagSymbol(StyleEntity type, const QString &symbol, const QStringList &tags)
detags the symbol with the given list 
 
bool updateSymbol(StyleEntity type, const QString &name)
updates the properties of an existing symbol/colorramp 
 
QString join(const QString &separator) const
 
QDomNodeList childNodes() const
 
QStringList colorRampNames()
return a list of names of color ramps 
 
char * getGroupRemoveQuery(int id)
prepares the complex query for removing a group, so that the children are not abandoned ...
 
bool copy(const QString &newName)
 
static QgsSymbolV2 * loadSymbol(const QDomElement &element)
Attempts to load a symbol from a DOM element. 
 
const QgsSymbolV2 * symbolRef(const QString &name) const
return a const pointer to a symbol (doesn't create new instance) 
 
const QgsVectorColorRampV2 * colorRampRef(const QString &name) const
return a const pointer to a symbol (doesn't create new instance) 
 
bool save(QString filename=QString())
save style into a file (will use current filename if empty string is passed) 
 
QList< int > groupIds() const
return the ids of all the groups in the style 
 
QDomElement toElement() const
 
QList< Key > keys() const
 
const char * name() const
 
QString number(int n, int base)
 
QgsSymbolGroupMap childGroupNames(const QString &parent="")
return a map of groupid and names for the given parent group 
 
bool renameColorRamp(const QString &oldName, const QString &newName)
change ramp's name 
 
QString fromUtf8(const char *str, int size)
 
bool saveSymbol(const QString &name, QgsSymbolV2 *symbol, int groupid, const QStringList &tags)
add the symbol to the DB with the tags 
 
int colorRampCount()
return count of color ramps 
 
static QgsStyleV2 * mDefaultStyle
 
void setAttribute(const QString &name, const QString &value)
 
virtual QgsVectorColorRampV2 * clone() const =0
Creates a clone of the color ramp. 
 
static QgsStyleV2 * defaultStyle()
return default application-wide style 
 
int removeAll(const T &value)
 
const_iterator constEnd() const
 
const char * constData() const
 
void rename(StyleEntity type, int id, const QString &newName)
rename the given entity with the specified id 
 
QMap< Key, T >::iterator insert(const Key &key, const T &value)
 
QStringList symbolsOfSmartgroup(StyleEntity type, int id)
returns the symbols for the smartgroup 
 
bool runEmptyQuery(char *query, bool freeQuery=true)
convenience function that would run queries which don't generate return values 
 
int addTag(const QString &tagName)
adds a new tag and returns the tag's id 
 
QStringList symbolNames()
return a list of names of symbols 
 
QMap< int, QString > QgsSymbolGroupMap
 
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
 
QgsSymbolGroupMap smartgroupsListMap()
returns the smart groups map with id as key and name as value 
 
int tagId(const QString &tag)
return the DB id for the given tag name 
 
QgsSymbolV2 * symbol(const QString &name)
return a NEW copy of symbol 
 
bool contains(QChar ch, Qt::CaseSensitivity cs) const
 
QStringList tags() const
Returns a list of all tags in the style database. 
 
static QString defaultStyleV2Path()
Returns the path to default style (works as a starting point). 
 
static QString userStyleV2Path()
Returns the path to user's style. 
 
QgsVectorColorRampV2Map mColorRamps
 
QStringList smartgroupNames()
returns the smart groups list 
 
QStringList symbolsWithTag(StyleEntity type, int tagid)
returns the symbol names with which have the given tag 
 
void clear()
remove all contents of the style 
 
bool load(const QString &filename)
load a file into the style 
 
void save(QTextStream &str, int indent) const
 
QString groupName(int groupId) const
return the group name for the given DB id 
 
bool renameSymbol(const QString &oldName, const QString &newName)
change symbol's name 
 
QDomElement firstChildElement(const QString &tagName) const
 
int symbolCount()
return count of symbols in style 
 
QList< T > toList() const
 
iterator insert(const Key &key, const T &value)
 
bool removeColorRamp(const QString &name)
remove color ramp from style (and delete it) 
 
QStringList filter(const QString &str, Qt::CaseSensitivity cs) const
 
QDomElement createElement(const QString &tagName)
 
StyleEntity
Enum for Entities involved in a style. 
 
int smartgroupId(const QString &smartgroup)
return the DB id for the given smartgroup name 
 
void symbolSaved(const QString &name, QgsSymbolV2 *symbol)
 
Abstract base class for color ramps. 
 
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
 
bool openDB(const QString &filename)
convenience function to open the DB and return a sqlite3 object 
 
int count(const Key &key) const
 
QStringList findSymbols(StyleEntity type, const QString &qword)
return the names of the symbols which have a matching 'substring' in its defintion ...
 
QStringList groupNames()
return the all the groups in the style 
 
#define STYLE_CURRENT_VERSION
 
QMultiMap< QString, QString > QgsSmartConditionMap
A multimap to hold the smart group conditions as constraint and parameter pairs. 
 
int addGroup(const QString &groupName, int parent=0)
adds a new group and returns the group's id 
 
QgsSmartConditionMap smartgroup(int id)
returns the QgsSmartConditionMap for the given id 
 
bool removeSymbol(const QString &name)
remove symbol from style (and delete it) 
 
QDomNode at(int index) const
 
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
 
int addSmartgroup(const QString &name, const QString &op, const QgsSmartConditionMap &conditions)
adds new smartgroup to the database and returns the id 
 
int symbolId(const QString &name)
return the id in the style database for the given symbol name returns 0 if not found ...
 
const T value(const Key &key) const
 
QByteArray toUtf8() const
 
int colorrampId(const QString &name)
return the id in the style database for the given colorramp name returns 0 if not found ...