QGIS API Documentation
3.2.0-Bonn (bc43194)
|
#include <qgsstyle.h>
Public Types | |
enum | StyleEntity { SymbolEntity, TagEntity, ColorrampEntity, SmartgroupEntity } |
Enum for Entities involved in a style. More... | |
Signals | |
void | groupsModified () |
Is emitted every time a tag or smartgroup has been added, removed, or renamed. More... | |
void | symbolSaved (const QString &name, QgsSymbol *symbol) |
Is emitted every time a new symbol has been added to the database. More... | |
Public Member Functions | |
QgsStyle ()=default | |
Constructor for QgsStyle. More... | |
~QgsStyle () override | |
bool | addColorRamp (const QString &name, QgsColorRamp *colorRamp, bool update=false) |
Adds a color ramp to the style. More... | |
bool | addFavorite (StyleEntity type, const QString &name) |
Adds the specified symbol to favorites. More... | |
int | addSmartgroup (const QString &name, const QString &op, const QgsSmartConditionMap &conditions) |
Adds a new smartgroup to the database and returns the id. More... | |
bool | addSymbol (const QString &name, QgsSymbol *symbol, bool update=false) |
Adds a symbol to style and takes symbol's ownership. More... | |
int | addTag (const QString &tagName) |
Adds a new tag and returns the tag's id. More... | |
void | clear () |
Removes all contents of the style. More... | |
QgsColorRamp * | colorRamp (const QString &name) const |
Returns a new copy of the specified color ramp. More... | |
int | colorRampCount () |
Returns count of color ramps. More... | |
int | colorrampId (const QString &name) |
Returns the id in the style database for the given colorramp name returns 0 if not found. More... | |
QStringList | colorRampNames () |
Returns a list of names of color ramps. More... | |
const QgsColorRamp * | colorRampRef (const QString &name) const |
Returns a const pointer to a symbol (doesn't create new instance) More... | |
bool | createDatabase (const QString &filename) |
Creates an on-disk database. More... | |
bool | createMemoryDatabase () |
Creates a temporary memory database. More... | |
void | createTables () |
Creates tables structure for new database. More... | |
bool | detagSymbol (StyleEntity type, const QString &symbol, const QStringList &tags) |
Detags the symbol with the given list. More... | |
bool | detagSymbol (StyleEntity type, const QString &symbol) |
Clears the symbol from all attached tags. More... | |
QString | errorString () |
Returns last error from load/save operation. More... | |
bool | exportXml (const QString &filename) |
Exports the style as a XML file. More... | |
QString | fileName () |
Returns current file name of the style. More... | |
QStringList | findSymbols (StyleEntity type, const QString &qword) |
Returns the names of the symbols which have a matching 'substring' in its definition. More... | |
bool | importXml (const QString &filename) |
Imports the symbols and colorramps into the default style database from the given XML file. More... | |
bool | load (const QString &filename) |
Loads a file into the style. More... | |
void | remove (StyleEntity type, int id) |
Removes the specified entity from the db. More... | |
bool | removeColorRamp (const QString &name) |
Removes color ramp from style (and delete it) More... | |
bool | removeFavorite (StyleEntity type, const QString &name) |
Removes the specified symbol from favorites. More... | |
bool | removeSymbol (const QString &name) |
Removes symbol from style (and delete it) More... | |
void | rename (StyleEntity type, int id, const QString &newName) |
Renames the given entity with the specified id. More... | |
bool | renameColorRamp (const QString &oldName, const QString &newName) |
Changes ramp's name. More... | |
bool | renameSymbol (const QString &oldName, const QString &newName) |
Changessymbol's name. More... | |
bool | save (QString filename=QString()) |
Saves style into a file (will use current filename if empty string is passed) More... | |
bool | saveColorRamp (const QString &name, QgsColorRamp *ramp, bool favorite, const QStringList &tags) |
Adds the colorramp to the DB. More... | |
bool | saveSymbol (const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags) |
Adds the symbol to the DB with the tags. More... | |
QgsSmartConditionMap | smartgroup (int id) |
Returns the QgsSmartConditionMap for the given id. More... | |
int | smartgroupId (const QString &smartgroup) |
Returns the DB id for the given smartgroup name. More... | |
QStringList | smartgroupNames () |
Returns the smart groups list. More... | |
QString | smartgroupOperator (int id) |
Returns the operator for the smartgroup clumsy implementation TODO create a class for smartgroups. More... | |
QgsSymbolGroupMap | smartgroupsListMap () |
Returns the smart groups map with id as key and name as value. More... | |
QgsSymbol * | symbol (const QString &name) |
Returns a NEW copy of symbol. More... | |
int | symbolCount () |
Returns count of symbols in style. More... | |
bool | symbolHasTag (StyleEntity type, const QString &symbol, const QString &tag) |
Returns whether a given tag is associated with the symbol. More... | |
int | symbolId (const QString &name) |
Returns the id in the style database for the given symbol name returns 0 if not found. More... | |
QStringList | symbolNames () |
Returns a list of names of symbols. More... | |
const QgsSymbol * | symbolRef (const QString &name) const |
Returns a const pointer to a symbol (doesn't create new instance) More... | |
QStringList | symbolsOfFavorite (StyleEntity type) const |
Returns the symbol names which are flagged as favorite. More... | |
QStringList | symbolsOfSmartgroup (StyleEntity type, int id) |
Returns the symbols for the smartgroup. More... | |
QStringList | symbolsWithTag (StyleEntity type, int tagid) const |
Returns the symbol names with which have the given tag. More... | |
QString | tag (int id) const |
Returns the tag name for the given id. More... | |
int | tagId (const QString &tag) |
Returns the DB id for the given tag name. More... | |
QStringList | tags () const |
Returns a list of all tags in the style database. More... | |
QStringList | tagsOfSymbol (StyleEntity type, const QString &symbol) |
Returns the tags associated with the symbol. More... | |
bool | tagSymbol (StyleEntity type, const QString &symbol, const QStringList &tags) |
Tags the symbol with the tags in the list. More... | |
Static Public Member Functions | |
static void | cleanDefaultStyle () |
Deletes the default style. Only to be used by QgsApplication::exitQgis() More... | |
static QgsStyle * | defaultStyle () |
Returns default application-wide style. More... | |
Definition at line 76 of file qgsstyle.h.
Enum for Entities involved in a style.
The enumerator is used for identifying the entity being operated on when generic database functions are being run.
Enumerator | |
---|---|
SymbolEntity | |
TagEntity | |
ColorrampEntity | |
SmartgroupEntity |
Definition at line 95 of file qgsstyle.h.
|
default |
Constructor for QgsStyle.
|
override |
Definition at line 41 of file qgsstyle.cpp.
bool QgsStyle::addColorRamp | ( | const QString & | name, |
QgsColorRamp * | colorRamp, | ||
bool | update = false |
||
) |
Adds a color ramp to the style.
Calling this method takes the ramp's ownership.
name | is the name of the color ramp being added or updated |
colorRamp | is the color ramp. Ownership is transferred. |
update | set to true when the style DB has to be updated, by default it is false |
Definition at line 191 of file qgsstyle.cpp.
bool QgsStyle::addFavorite | ( | StyleEntity | type, |
const QString & | name | ||
) |
Adds the specified symbol to favorites.
type | is either SymbolEntity of ColorrampEntity |
name | is the name of the symbol or coloramp whose is to be added to favorites |
Definition at line 745 of file qgsstyle.cpp.
int QgsStyle::addSmartgroup | ( | const QString & | name, |
const QString & | op, | ||
const QgsSmartConditionMap & | conditions | ||
) |
Adds a new smartgroup to the database and returns the id.
name | is the name of the new Smart Group to be added |
op | is the operator between the conditions; AND/OR as QString |
conditions | are the smart group conditions |
Definition at line 1143 of file qgsstyle.cpp.
bool QgsStyle::addSymbol | ( | const QString & | name, |
QgsSymbol * | symbol, | ||
bool | update = false |
||
) |
Adds a symbol to style and takes symbol's ownership.
name | is the name of the symbol being added or updated |
symbol | is the Vector symbol |
update | set to true when the style DB has to be updated, by default it is false |
Definition at line 86 of file qgsstyle.cpp.
int QgsStyle::addTag | ( | const QString & | tagName | ) |
Adds a new tag and returns the tag's id.
tagName | the name of the new tag to be created |
Definition at line 610 of file qgsstyle.cpp.
|
static |
Deletes the default style. Only to be used by QgsApplication::exitQgis()
Definition at line 71 of file qgsstyle.cpp.
void QgsStyle::clear | ( | ) |
Removes all contents of the style.
Definition at line 77 of file qgsstyle.cpp.
QgsColorRamp * QgsStyle::colorRamp | ( | const QString & | name | ) | const |
Returns a new copy of the specified color ramp.
The caller takes responsibility for deleting the returned object.
Definition at line 262 of file qgsstyle.cpp.
int QgsStyle::colorRampCount | ( | ) |
Returns count of color ramps.
Definition at line 273 of file qgsstyle.cpp.
int QgsStyle::colorrampId | ( | const QString & | name | ) |
Returns the id in the style database for the given colorramp name returns 0 if not found.
Definition at line 1128 of file qgsstyle.cpp.
QStringList QgsStyle::colorRampNames | ( | ) |
Returns a list of names of color ramps.
Definition at line 278 of file qgsstyle.cpp.
const QgsColorRamp * QgsStyle::colorRampRef | ( | const QString & | name | ) | const |
Returns a const pointer to a symbol (doesn't create new instance)
Definition at line 268 of file qgsstyle.cpp.
bool QgsStyle::createDatabase | ( | const QString & | filename | ) |
Creates an on-disk database.
This function creates a new on-disk permanent style database.
Definition at line 295 of file qgsstyle.cpp.
bool QgsStyle::createMemoryDatabase | ( | ) |
Creates a temporary memory database.
This function is used to create a temporary style database in case a permanent on-disk database is not needed.
Definition at line 310 of file qgsstyle.cpp.
void QgsStyle::createTables | ( | ) |
Creates tables structure for new database.
This function is used to create the tables structure in a newly-created database.
Definition at line 325 of file qgsstyle.cpp.
|
static |
Returns default application-wide style.
Definition at line 46 of file qgsstyle.cpp.
bool QgsStyle::detagSymbol | ( | StyleEntity | type, |
const QString & | symbol, | ||
const QStringList & | tags | ||
) |
Detags the symbol with the given list.
Removes the given tags for the specified symbol or colorramp
type | is either SymbolEntity or ColorrampEntity |
symbol | is the name of the symbol or colorramp |
tags | is the list of tags that are to be removed as QStringList |
Definition at line 901 of file qgsstyle.cpp.
bool QgsStyle::detagSymbol | ( | StyleEntity | type, |
const QString & | symbol | ||
) |
Clears the symbol from all attached tags.
Removes all tags for the specified symbol or colorramp
type | is either SymbolEntity or ColorrampEntity |
symbol | is the name of the symbol or colorramp |
Definition at line 954 of file qgsstyle.cpp.
|
inline |
Returns last error from load/save operation.
Definition at line 357 of file qgsstyle.h.
bool QgsStyle::exportXml | ( | const QString & | filename | ) |
Exports the style as a XML file.
Definition at line 1402 of file qgsstyle.cpp.
|
inline |
Returns current file name of the style.
Definition at line 360 of file qgsstyle.h.
QStringList QgsStyle::findSymbols | ( | StyleEntity | type, |
const QString & | qword | ||
) |
Returns the names of the symbols which have a matching 'substring' in its definition.
type | is either SymbolEntity or ColorrampEntity |
qword | is the query string to search the symbols or colorramps. |
Definition at line 787 of file qgsstyle.cpp.
|
signal |
Is emitted every time a tag or smartgroup has been added, removed, or renamed.
bool QgsStyle::importXml | ( | const QString & | filename | ) |
Imports the symbols and colorramps into the default style database from the given XML file.
Definition at line 1474 of file qgsstyle.cpp.
bool QgsStyle::load | ( | const QString & | filename | ) |
Loads a file into the style.
This function will load an on-disk database and populate styles.
filename | location of the database to load styles from |
Definition at line 353 of file qgsstyle.cpp.
void QgsStyle::remove | ( | StyleEntity | type, |
int | id | ||
) |
Removes the specified entity from the db.
type | is any of the style entities. Refer enum StyleEntity. |
id | is the DB id of the entity to be removed |
Definition at line 687 of file qgsstyle.cpp.
bool QgsStyle::removeColorRamp | ( | const QString & | name | ) |
Removes color ramp from style (and delete it)
Definition at line 244 of file qgsstyle.cpp.
bool QgsStyle::removeFavorite | ( | StyleEntity | type, |
const QString & | name | ||
) |
Removes the specified symbol from favorites.
type | is either SymbolEntity of ColorrampEntity |
name | is the name of the symbol or coloramp whose is to be removed from favorites |
Definition at line 766 of file qgsstyle.cpp.
bool QgsStyle::removeSymbol | ( | const QString & | name | ) |
Removes symbol from style (and delete it)
Definition at line 141 of file qgsstyle.cpp.
void QgsStyle::rename | ( | StyleEntity | type, |
int | id, | ||
const QString & | newName | ||
) |
Renames the given entity with the specified id.
type | is any of the style entities. Refer enum StyleEntity. |
id | is the DB id of the entity which is to be renamed |
newName | is the new name of the entity |
Definition at line 650 of file qgsstyle.cpp.
bool QgsStyle::renameColorRamp | ( | const QString & | oldName, |
const QString & | newName | ||
) |
Changes ramp's name.
Definition at line 497 of file qgsstyle.cpp.
bool QgsStyle::renameSymbol | ( | const QString & | oldName, |
const QString & | newName | ||
) |
Changessymbol's name.
Definition at line 465 of file qgsstyle.cpp.
bool QgsStyle::save | ( | QString | filename = QString() | ) |
Saves style into a file (will use current filename if empty string is passed)
Definition at line 419 of file qgsstyle.cpp.
bool QgsStyle::saveColorRamp | ( | const QString & | name, |
QgsColorRamp * | ramp, | ||
bool | favorite, | ||
const QStringList & | tags | ||
) |
Adds the colorramp to the DB.
name | is the name of the colorramp as QString |
ramp | is the pointer to the new QgsColorRamp being saved |
favorite | is a boolean value to specify whether the colorramp should be added to favorites |
tags | is a list of tags that are associated with the color ramp as a QStringList. |
Definition at line 215 of file qgsstyle.cpp.
bool QgsStyle::saveSymbol | ( | const QString & | name, |
QgsSymbol * | symbol, | ||
bool | favorite, | ||
const QStringList & | tags | ||
) |
Adds the symbol to the DB with the tags.
name | is the name of the symbol as QString |
symbol | is the pointer to the new QgsSymbol being saved |
favorite | is a boolean value to specify whether the symbol should be added to favorites |
tags | is a list of tags that are associated with the symbol as a QStringList. |
Definition at line 110 of file qgsstyle.cpp.
QgsSmartConditionMap QgsStyle::smartgroup | ( | int | id | ) |
Returns the QgsSmartConditionMap for the given id.
Definition at line 1332 of file qgsstyle.cpp.
int QgsStyle::smartgroupId | ( | const QString & | smartgroup | ) |
Returns the DB id for the given smartgroup name.
Definition at line 1138 of file qgsstyle.cpp.
QStringList QgsStyle::smartgroupNames | ( | ) |
Returns the smart groups list.
Definition at line 1212 of file qgsstyle.cpp.
QString QgsStyle::smartgroupOperator | ( | int | id | ) |
Returns the operator for the smartgroup clumsy implementation TODO create a class for smartgroups.
Definition at line 1372 of file qgsstyle.cpp.
QgsSymbolGroupMap QgsStyle::smartgroupsListMap | ( | ) |
Returns the smart groups map with id as key and name as value.
Definition at line 1187 of file qgsstyle.cpp.
QgsSymbol * QgsStyle::symbol | ( | const QString & | name | ) |
Returns a NEW copy of symbol.
Definition at line 169 of file qgsstyle.cpp.
int QgsStyle::symbolCount | ( | ) |
Returns count of symbols in style.
Definition at line 180 of file qgsstyle.cpp.
bool QgsStyle::symbolHasTag | ( | StyleEntity | type, |
const QString & | symbol, | ||
const QString & | tag | ||
) |
Returns whether a given tag is associated with the symbol.
type | is either SymbolEntity or ColorrampEntity |
symbol | is the name of the symbol or color ramp |
tag | the name of the tag to look for |
Definition at line 1028 of file qgsstyle.cpp.
int QgsStyle::symbolId | ( | const QString & | name | ) |
Returns the id in the style database for the given symbol name returns 0 if not found.
Definition at line 1123 of file qgsstyle.cpp.
QStringList QgsStyle::symbolNames | ( | ) |
Returns a list of names of symbols.
Definition at line 185 of file qgsstyle.cpp.
const QgsSymbol * QgsStyle::symbolRef | ( | const QString & | name | ) | const |
Returns a const pointer to a symbol (doesn't create new instance)
Definition at line 175 of file qgsstyle.cpp.
|
signal |
Is emitted every time a new symbol has been added to the database.
QStringList QgsStyle::symbolsOfFavorite | ( | StyleEntity | type | ) | const |
Returns the symbol names which are flagged as favorite.
type | is either SymbolEntity or ColorampEntity |
Definition at line 525 of file qgsstyle.cpp.
QStringList QgsStyle::symbolsOfSmartgroup | ( | StyleEntity | type, |
int | id | ||
) |
Returns the symbols for the smartgroup.
Definition at line 1236 of file qgsstyle.cpp.
QStringList QgsStyle::symbolsWithTag | ( | StyleEntity | type, |
int | tagid | ||
) | const |
Returns the symbol names with which have the given tag.
type | is either SymbolEntity or ColorampEntity |
tagid | is id of the tag which has been applied over the symbol as int |
Definition at line 561 of file qgsstyle.cpp.
QString QgsStyle::tag | ( | int | id | ) | const |
Returns the tag name for the given id.
Definition at line 1058 of file qgsstyle.cpp.
int QgsStyle::tagId | ( | const QString & | tag | ) |
Returns the DB id for the given tag name.
Definition at line 1133 of file qgsstyle.cpp.
QStringList QgsStyle::tags | ( | ) | const |
Returns a list of all tags in the style database.
Definition at line 630 of file qgsstyle.cpp.
QStringList QgsStyle::tagsOfSymbol | ( | StyleEntity | type, |
const QString & | symbol | ||
) |
Returns the tags associated with the symbol.
type | is either SymbolEntity or ColorrampEntity |
symbol | is the name of the symbol or color ramp |
Definition at line 991 of file qgsstyle.cpp.
bool QgsStyle::tagSymbol | ( | StyleEntity | type, |
const QString & | symbol, | ||
const QStringList & | tags | ||
) |
Tags the symbol with the tags in the list.
Applies the given tags to the given symbol or colorramp
type | is either SymbolEntity or ColorrampEntity |
symbol | is the name of the symbol or colorramp as QString |
tags | is the list of the tags that are to be applied as QStringList |
Definition at line 851 of file qgsstyle.cpp.