26 #include <QDomDocument> 27 #include <QDomElement> 29 #include <QDomNodeList> 31 #include <QTextStream> 36 #define STYLE_CURRENT_VERSION "1" 83 if ( !symbol || name.
isEmpty() )
114 QgsDebugMsg(
"Couldn't convert symbol to valid XML!" );
121 symEl.
save( stream, 4 );
122 char *query = sqlite3_mprintf(
"INSERT INTO symbol VALUES (NULL, '%q', '%q', %d);",
127 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() )
220 QgsDebugMsg(
"Couldn't convert color ramp to valid XML!" );
227 rampEl.
save( stream, 4 );
228 char *query = sqlite3_mprintf(
"INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
233 QgsDebugMsg(
"Couldn't insert colorramp into the database!" );
246 char *query = sqlite3_mprintf(
"DELETE FROM colorramp WHERE name='%q'", name.
toUtf8().
constData() );
249 QgsDebugMsg(
"Couldn't remove color ramp from the database." );
261 return ramp ? ramp->
clone() :
nullptr;
297 if ( !
openDB( filename ) )
299 mErrorString =
"Unable to open database file specified";
305 char *query = sqlite3_mprintf(
"UPDATE symbol SET groupid=0 WHERE groupid IS NULL;" 306 "UPDATE colorramp SET groupid=0 WHERE groupid IS NULL;" 307 "UPDATE symgroup SET parent=0 WHERE parent IS NULL;" );
311 query = sqlite3_mprintf(
"SELECT * FROM symbol" );
313 sqlite3_stmt *ppStmt;
314 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
315 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
322 QgsDebugMsg(
"Cannot open symbol " + symbol_name );
332 sqlite3_finalize( ppStmt );
334 query = sqlite3_mprintf(
"SELECT * FROM colorramp" );
335 nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
336 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
389 if ( !f.
open( QFile::WriteOnly ) )
391 mErrorString =
"Couldn't open file for writing: " + filename;
408 QgsDebugMsg(
"Symbol of new name already exists" );
420 QgsDebugMsg(
"Sorry! Cannot open database to tag." );
427 QgsDebugMsg(
"No such symbol for tagging in database: " + oldName );
440 QgsDebugMsg(
"Color ramp of new name already exists." );
451 sqlite3_stmt *ppStmt;
452 char *query = sqlite3_mprintf(
"SELECT id FROM colorramp WHERE name='%q'", oldName.
toUtf8().
constData() );
453 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
454 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
456 rampid = sqlite3_column_int( ppStmt, 0 );
458 sqlite3_finalize( ppStmt );
467 sqlite3_stmt *ppStmt;
468 const char *query =
"SELECT * FROM symgroup";
469 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
470 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
472 groupNames << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt,
SymgroupName ) ) );
474 sqlite3_finalize( ppStmt );
481 sqlite3_stmt *ppStmt;
482 const char *query =
"SELECT * FROM symgroup";
483 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
484 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
486 groupIds << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt,
SymgroupId ) ) ).toInt();
488 sqlite3_finalize( ppStmt );
497 QgsDebugMsg(
"Cannot open database for listing groups" );
501 char *query =
nullptr;
503 sqlite3_stmt *ppStmt;
506 if ( parent ==
"" || parent ==
QString() )
508 query = sqlite3_mprintf(
"SELECT * FROM symgroup WHERE parent=0" );
512 char *subquery = sqlite3_mprintf(
"SELECT * FROM symgroup WHERE name='%q'", parent.
toUtf8().
constData() );
513 nError = sqlite3_prepare_v2(
mCurrentDB, subquery, -1, &ppStmt,
nullptr );
514 if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
516 query = sqlite3_mprintf(
"SELECT * FROM symgroup WHERE parent=%d", sqlite3_column_int( ppStmt,
SymgroupId ) );
518 sqlite3_finalize( ppStmt );
527 nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
528 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
534 sqlite3_finalize( ppStmt );
543 QgsDebugMsg(
QString(
"Cannot Open database for getting group symbols of groupid: %1" ).arg( groupid ) );
550 query = sqlite3_mprintf(
"SELECT name FROM symbol WHERE groupid=%d", groupid );
554 query = sqlite3_mprintf(
"SELECT name FROM colorramp WHERE groupid=%d", groupid );
562 sqlite3_stmt *ppStmt;
563 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
566 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
568 symbols << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 0 ) ) );
571 sqlite3_finalize( ppStmt );
580 QgsDebugMsg(
QString(
"Cannot open database to get symbols of tagid %1" ).arg( tagid ) );
587 subquery = sqlite3_mprintf(
"SELECT symbol_id FROM tagmap WHERE tag_id=%d", tagid );
591 subquery = sqlite3_mprintf(
"SELECT symbol_id FROM ctagmap WHERE tag_id=%d", tagid );
599 sqlite3_stmt *ppStmt;
600 int nErr = sqlite3_prepare_v2(
mCurrentDB, subquery, -1, &ppStmt,
nullptr );
604 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
606 int symbolId = sqlite3_column_int( ppStmt, 0 );
609 ? sqlite3_mprintf(
"SELECT name FROM symbol WHERE id=%d", symbolId )
610 : sqlite3_mprintf(
"SELECT name FROM colorramp WHERE id=%d", symbolId );
612 sqlite3_stmt *ppStmt2;
613 int sErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt2,
nullptr );
614 while ( sErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
616 symbols << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt2, 0 ) ) );
618 sqlite3_finalize( ppStmt2 );
620 sqlite3_finalize( ppStmt );
630 char *query = sqlite3_mprintf(
"INSERT INTO symgroup VALUES (NULL, '%q', %d)", groupName.
toUtf8().
constData(), parentid );
632 sqlite3_stmt *ppStmt;
633 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
634 if ( nErr == SQLITE_OK )
635 ( void )sqlite3_step( ppStmt );
637 sqlite3_finalize( ppStmt );
639 return static_cast< int >( sqlite3_last_insert_rowid(
mCurrentDB ) );
646 sqlite3_stmt *ppStmt;
648 char *query = sqlite3_mprintf(
"INSERT INTO tag VALUES (NULL, '%q')", tagname.
toUtf8().
constData() );
649 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
650 if ( nErr == SQLITE_OK )
651 ( void )sqlite3_step( ppStmt );
652 sqlite3_finalize( ppStmt );
654 return static_cast< int >( sqlite3_last_insert_rowid(
mCurrentDB ) );
663 query = sqlite3_mprintf(
"UPDATE symbol SET name='%q' WHERE id=%d", newName.
toUtf8().
constData(), id );
666 query = sqlite3_mprintf(
"UPDATE symgroup SET name='%q' WHERE id=%d", newName.
toUtf8().
constData(), id );
669 query = sqlite3_mprintf(
"UPDATE tag SET name='%q' WHERE id=%d", newName.
toUtf8().
constData(), id );
672 query = sqlite3_mprintf(
"UPDATE colorramp SET name='%q' WHERE id=%d", newName.
toUtf8().
constData(), id );
675 query = sqlite3_mprintf(
"UPDATE smartgroup SET name='%q' WHERE id=%d", newName.
toUtf8().
constData(), id );
687 char *query = sqlite3_mprintf(
"SELECT parent FROM symgroup WHERE id=%d",
id );
689 sqlite3_stmt *ppStmt;
690 int err = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
693 if ( err == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
694 parentid = sqlite3_column_int( ppStmt, 0 );
696 sqlite3_finalize( ppStmt );
698 return sqlite3_mprintf(
"UPDATE symbol SET groupid=%d WHERE groupid=%d;" 699 "UPDATE symgroup SET parent=%d WHERE parent=%d;" 700 "DELETE FROM symgroup WHERE id=%d", parentid,
id, parentid,
id,
id );
709 query = sqlite3_mprintf(
"DELETE FROM symbol WHERE id=%d; DELETE FROM tagmap WHERE symbol_id=%d",
id,
id );
715 query = sqlite3_mprintf(
"DELETE FROM tag WHERE id=%d; DELETE FROM tagmap WHERE tag_id=%d",
id,
id );
718 query = sqlite3_mprintf(
"DELETE FROM colorramp WHERE id=%d",
id );
721 query = sqlite3_mprintf(
"DELETE FROM smartgroup WHERE id=%d",
id );
739 char *zErr =
nullptr;
740 int nErr = sqlite3_exec(
mCurrentDB, query,
nullptr,
nullptr, &zErr );
744 sqlite3_free( query );
747 if ( nErr != SQLITE_OK )
752 return zErr == SQLITE_OK;
762 query = sqlite3_mprintf(
"UPDATE symbol SET groupid=%d WHERE name='%q'", groupid, name.
toUtf8().
constData() );
765 query = sqlite3_mprintf(
"UPDATE colorramp SET groupid=%d WHERE name='%q'", groupid, name.
toUtf8().
constData() );
769 QgsDebugMsg(
"Wrong entity value. cannot apply group" );
780 QgsDebugMsg(
"Sorry! Cannot open database to search" );
785 char *query = sqlite3_mprintf(
"SELECT name FROM %q WHERE name LIKE '%%%q%%'",
788 sqlite3_stmt *ppStmt;
789 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
792 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
794 symbols << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 0 ) ) );
797 sqlite3_finalize( ppStmt );
806 QgsDebugMsg(
"Sorry! Cannot open database to tag." );
813 QgsDebugMsg(
"No such symbol for tagging in database: " + symbol );
818 Q_FOREACH (
const QString &tag, tags )
821 char *query = sqlite3_mprintf(
"SELECT id FROM tag WHERE name='%q'", tag.
toUtf8().
constData() );
823 sqlite3_stmt *ppStmt;
824 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
827 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
829 tagid = sqlite3_column_int( ppStmt, 0 );
836 sqlite3_finalize( ppStmt );
840 ? sqlite3_mprintf(
"INSERT INTO tagmap VALUES (%d,%d)", tagid, symbolid )
841 : sqlite3_mprintf(
"INSERT INTO ctagmap VALUES (%d,%d)", tagid, symbolid );
843 char *zErr =
nullptr;
844 nErr = sqlite3_exec(
mCurrentDB, query,
nullptr,
nullptr, &zErr );
858 QgsDebugMsg(
"Sorry! Cannot open database for detgging." );
863 ? sqlite3_mprintf(
"SELECT id FROM symbol WHERE name='%q'", symbol.
toUtf8().
constData() )
864 : sqlite3_mprintf(
"SELECT id FROM colorramp WHERE name='%q'", symbol.
toUtf8().
constData() );
865 sqlite3_stmt *ppStmt;
866 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
869 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
871 symbolid = sqlite3_column_int( ppStmt, 0 );
874 sqlite3_finalize( ppStmt );
876 Q_FOREACH (
const QString &tag, tags )
878 query = sqlite3_mprintf(
"SELECT id FROM tag WHERE name='%q'", tag.
toUtf8().
constData() );
880 sqlite3_stmt *ppStmt2;
881 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt2,
nullptr );
884 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
886 tagid = sqlite3_column_int( ppStmt2, 0 );
889 sqlite3_finalize( ppStmt2 );
895 ? sqlite3_mprintf(
"DELETE FROM tagmap WHERE tag_id=%d AND symbol_id=%d", tagid, symbolid )
896 : sqlite3_mprintf(
"DELETE FROM ctagmap WHERE tag_id=%d AND colorramp_id=%d", tagid, symbolid );
911 QgsDebugMsg(
"Sorry! Cannot open database for getting the tags." );
921 ? sqlite3_mprintf(
"SELECT tag_id FROM tagmap WHERE symbol_id=%d", symbolid )
922 : sqlite3_mprintf(
"SELECT tag_id FROM ctagmap WHERE colorramp_id=%d", symbolid );
924 sqlite3_stmt *ppStmt;
925 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
928 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
930 char *subquery = sqlite3_mprintf(
"SELECT name FROM tag WHERE id=%d", sqlite3_column_int( ppStmt, 0 ) );
932 sqlite3_stmt *ppStmt2;
933 int pErr = sqlite3_prepare_v2(
mCurrentDB, subquery, -1, &ppStmt2,
nullptr );
934 if ( pErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
936 tagList << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt2, 0 ) ) );
938 sqlite3_finalize( ppStmt2 );
941 sqlite3_finalize( ppStmt );
950 sqlite3_stmt *ppStmt;
951 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
954 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
956 id = sqlite3_column_int( ppStmt, 0 );
959 sqlite3_finalize( ppStmt );
968 sqlite3_stmt *ppStmt;
969 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
972 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
974 name =
QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 0 ) ) );
977 sqlite3_finalize( ppStmt );
984 return getId(
"symbol", name );
989 return getId(
"colorramp", name );
994 return getId(
"symgroup", name );
999 return getName(
"symgroup", groupId );
1004 return getId(
"tag", name );
1009 return getId(
"smartgroup", name );
1020 constraints <<
"tag" <<
"group" <<
"name" <<
"!tag" <<
"!group" <<
"!name";
1022 Q_FOREACH (
const QString &constraint, constraints )
1025 Q_FOREACH (
const QString ¶m, parameters )
1037 smartEl.
save( stream, 4 );
1038 char *query = sqlite3_mprintf(
"INSERT INTO smartgroup VALUES (NULL, '%q', '%q')",
1043 return static_cast< int >( sqlite3_last_insert_rowid(
mCurrentDB ) );
1047 QgsDebugMsg(
"Couldn't insert symbol into the database!" );
1056 QgsDebugMsg(
"Cannot open database for listing groups" );
1060 char *query = sqlite3_mprintf(
"SELECT * FROM smartgroup" );
1063 sqlite3_stmt *ppStmt;
1064 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
1067 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1073 sqlite3_finalize( ppStmt );
1082 QgsDebugMsg(
"Cannot open database for listing groups" );
1086 char *query = sqlite3_mprintf(
"SELECT name FROM smartgroup" );
1089 sqlite3_stmt *ppStmt;
1090 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
1093 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1095 groups << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 0 ) ) );
1098 sqlite3_finalize( ppStmt );
1107 char *query = sqlite3_mprintf(
"SELECT xml FROM smartgroup WHERE id=%d",
id );
1109 sqlite3_stmt *ppStmt;
1110 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
1111 if ( !( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW ) )
1113 sqlite3_finalize( ppStmt );
1128 bool firstSet =
true;
1129 for (
int i = 0; i < conditionNodes.
count(); i++ )
1137 if ( constraint ==
"tag" )
1141 else if ( constraint ==
"group" )
1147 else if ( constraint ==
"name" )
1158 else if ( constraint ==
"!tag" )
1167 else if ( constraint ==
"!group" )
1176 else if ( constraint ==
"!name" )
1179 Q_FOREACH (
const QString &str, all )
1181 if ( !str.
contains( param, Qt::CaseInsensitive ) )
1189 symbols = resultNames;
1196 symbols << resultNames;
1198 else if ( op ==
"AND" )
1202 Q_FOREACH (
const QString &result, resultNames )
1212 sqlite3_finalize( ppStmt );
1221 QgsDebugMsg(
"Cannot open database for listing groups" );
1227 char *query = sqlite3_mprintf(
"SELECT xml FROM smartgroup WHERE id=%d",
id );
1229 sqlite3_stmt *ppStmt;
1230 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
1231 if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1244 for (
int i = 0; i < conditionNodes.
count(); i++ )
1250 condition.
insert( constraint, param );
1254 sqlite3_finalize( ppStmt );
1263 QgsDebugMsg(
"Cannot open database for listing groups" );
1269 char *query = sqlite3_mprintf(
"SELECT xml FROM smartgroup WHERE id=%d",
id );
1271 sqlite3_stmt *ppStmt;
1272 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt,
nullptr );
1273 if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1285 sqlite3_finalize( ppStmt );
1294 QgsDebugMsg(
"Invalid filename for style export." );
1318 QFile f( filename );
1319 if ( !f.
open( QFile::WriteOnly ) )
1321 mErrorString =
"Couldn't open file for writing: " + filename;
1338 QFile f( filename );
1339 if ( !f.
open( QFile::ReadOnly ) )
1342 QgsDebugMsg(
"Error opening the style XML file." );
1356 if ( docEl.
tagName() !=
"qgis_style" )
1365 mErrorString =
"Unknown style file version: " + version;
1379 if ( e.
tagName() ==
"symbol" )
1411 if ( e.
tagName() ==
"colorramp" )
1445 QgsDebugMsg(
"Update request received for unavailable symbol" );
1452 QgsDebugMsg(
"Couldn't convert symbol to valid XML!" );
1455 symEl.
save( stream, 4 );
1456 query = sqlite3_mprintf(
"UPDATE symbol SET xml='%q' WHERE name='%q';",
1463 QgsDebugMsg(
"Update requested for unavailable color ramp." );
1470 QgsDebugMsg(
"Couldn't convert color ramp to valid XML!" );
1473 symEl.
save( stream, 4 );
1474 query = sqlite3_mprintf(
"UPDATE colorramp SET xml='%q' WHERE name='%q';",
1479 QgsDebugMsg(
"Updating the unsupported StyleEntity" );
1486 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
QList< int > groupIds() const
return the ids of all the groups in the style
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)
const QgsVectorColorRampV2 * colorRampRef(const QString &name) const
return a const pointer to a symbol (doesn't create new instance)
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 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
QMultiMap< QString, QString > QgsSmartConditionMap
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)
QString groupName(int groupId) const
return the group name for the given DB id
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
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.
bool save(QString filename=QString())
save style into a file (will use current filename if empty string is passed)
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
const QgsSymbolV2 * symbolRef(const QString &name) const
return a const pointer to a symbol (doesn't create new instance)
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
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 ...
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
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
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
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)
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
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 ...