Class: QgsStyle¶
-
class
qgis.core.
QgsStyle
¶ Bases:
PyQt5.QtCore.QObject
Constructor for QgsStyle.
Enums
Methods
Adds a color ramp to the style.
Adds the specified symbol to favorites
Adds a new smartgroup to the database and returns the id.
Adds a symbol to style and takes symbol’s ownership
Adds a new tag and returns the tag’s id
Removes all contents of the style
Returns a new copy of the specified color ramp.
Returns count of color ramps
Returns a list of names of color ramps
Returns a const pointer to a symbol (doesn’t create new instance)
Returns the id in the style database for the given colorramp name returns 0 if not found
Creates an on-disk database
Creates a temporary memory database
Creates tables structure for new database
Returns default application-wide style
Detags the symbol with the given list
Returns last error from load/save operation
Exports the style as a XML file
Returns current file name of the style
Returns the names of the symbols which have a matching ‘substring’ in its definition
Imports the symbols and colorramps into the default style database from the given XML file
Tests if the file at
path
is a QGIS style XML file.Loads a file into the style
Removes the specified entity from the db
Removes color ramp from style (and delete it)
Removes the specified symbol from favorites
Removes symbol from style (and delete it)
Renames the given entity with the specified id
Changes ramp’s name
Renames a symbol from
oldName
tonewName
.Saves style into a file (will use current filename if empty string is passed)
Adds the colorramp to the DB
Adds the symbol to the DB with the tags
Returns the QgsSmartConditionMap for the given id
Returns the DB id for the given smartgroup name
Returns the smart groups list
Returns the operator for the smartgroup clumsy implementation TODO create a class for smartgroups
Returns the smart groups map with id as key and name as value
Returns a NEW copy of symbol
Returns count of symbols in style
Returns whether a given tag is associated with the symbol
Returns the id in the style database for the given symbol name returns 0 if not found
Returns a list of names of symbols
Returns a const pointer to a symbol (doesn’t create new instance)
Returns the symbol names which are flagged as favorite
Returns the symbols for the smartgroup
Returns the symbol names with which have the given tag
Returns the tag name for the given id
Returns the DB id for the given tag name
Tags the symbol with the tags in the list
Returns a list of all tags in the style database
Returns the tags associated with the symbol
Signals
Emitted whenever an
entity
’s tags are changed.Emitted whenever an
entity
is either favorited or un-favorited.Is emitted every time a tag or smartgroup has been added, removed, or renamed [signal]
Emitted whenever a color ramp has been added to the style and the database has been updated as a result.
Emitted whenever a color ramp’s definition is changed.
Emitted whenever a color ramp has been removed from the style and the database has been updated as a result.
Emitted whenever a color ramp has been renamed from
oldName
tonewName
Emitted whenever a symbol’s definition is changed.
Emitted whenever a symbol has been removed from the style and the database has been updated as a result.
Emitted whenever a symbol has been renamed from
oldName
tonewName
Emitted every time a new symbol has been added to the database.
Attributes
-
ColorrampEntity
= 2¶
-
SmartgroupEntity
= 3¶
-
class
StyleEntity
¶ Bases:
int
-
SymbolEntity
= 0¶
-
TagEntity
= 1¶
-
addColorRamp
(self, name: str, colorRamp: QgsColorRamp, update: bool = False) → bool¶ Adds a color ramp to the style. Calling this method takes the ramp’s ownership.
Note
Adding a color ramp with the name of existing one replaces it.
- Parameters
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
- Returns
success status of the operation
-
addFavorite
(self, type: QgsStyle.StyleEntity, name: str) → bool¶ Adds the specified symbol to favorites
- Parameters
type – is either SymbolEntity of ColorrampEntity
name – is the name of the symbol or coloramp whose is to be added to favorites
- Returns
returns the success state as bool
-
addSmartgroup
(self, name: str, op: str, matchTag: Iterable[str], noMatchTag: Iterable[str], matchName: Iterable[str], noMatchName: Iterable[str]) → int¶ Adds a new smartgroup to the database and returns the id.
- Parameters
name – is the name of the new Smart Group to be added
op – is the operator between the conditions; AND/OR as QString
matchTag – list of strings to match within tags
noMatchTag – list of strings to exclude matches from tags
matchName – list of string to match within names
noMatchName – list of strings to exclude matches from names
New in version 3.4.
-
addSymbol
(self, name: str, symbol: QgsSymbol, update: bool = False) → bool¶ Adds a symbol to style and takes symbol’s ownership
Note
Adding a symbol with the name of existing one replaces it.
- Parameters
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
- Returns
success status of the operation
-
addTag
(self, tagName: str) → int¶ Adds a new tag and returns the tag’s id
- Parameters
tagName – the name of the new tag to be created
- Returns
returns an int, which is the DB id of the new tag created, 0 if the tag couldn’t be created
-
childEvent
()¶
-
clear
(self)¶ Removes all contents of the style
-
colorRamp
(self, name: str) → QgsColorRamp¶ Returns a new copy of the specified color ramp. The caller takes responsibility for deleting the returned object.
-
colorRampCount
(self) → int¶ Returns count of color ramps
-
colorRampNames
(self) → List[str]¶ Returns a list of names of color ramps
-
colorRampRef
(self, name: str) → QgsColorRamp¶ Returns a const pointer to a symbol (doesn’t create new instance)
-
colorrampId
(self, name: str) → int¶ Returns the id in the style database for the given colorramp name returns 0 if not found
-
connectNotify
()¶
-
createDatabase
(self, filename: str) → bool¶ Creates an on-disk database
This function creates a new on-disk permanent style database.
- Returns
returns the success state of the database creation
See also
New in version 3.0.
-
createMemoryDatabase
(self) → bool¶ 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.
- Returns
returns the success state of the temporary memory database creation
See also
New in version 3.0.
-
createTables
(self)¶ Creates tables structure for new database
This function is used to create the tables structure in a newly-created database.
- Returns
returns the success state of the temporary memory database creation
See also
See also
New in version 3.0.
-
customEvent
()¶
-
defaultStyle
() → QgsStyle¶ Returns default application-wide style
-
detagSymbol
(self, type: QgsStyle.StyleEntity, symbol: str, tags: Iterable[str]) → bool¶ Detags the symbol with the given list
Removes the given tags for the specified symbol or colorramp
- Parameters
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
- Returns
returns the success state of the operation
detagSymbol(self, type: QgsStyle.StyleEntity, symbol: str) -> bool Clears the symbol from all attached tags
Removes all tags for the specified symbol or colorramp
- Parameters
type – is either SymbolEntity or ColorrampEntity
symbol – is the name of the symbol or colorramp
- Returns
returns the success state of the operation
-
disconnectNotify
()¶
-
entityTagsChanged
¶ Emitted whenever an
entity
’s tags are changed.New in version 3.4: [signal]
-
errorString
(self) → str¶ Returns last error from load/save operation
-
exportXml
(self, filename: str) → bool¶ Exports the style as a XML file
-
favoritedChanged
¶ Emitted whenever an
entity
is either favorited or un-favorited.New in version 3.4: [signal]
-
fileName
(self) → str¶ Returns current file name of the style
-
findSymbols
(self, type: QgsStyle.StyleEntity, qword: str) → List[str]¶ Returns the names of the symbols which have a matching ‘substring’ in its definition
- Parameters
type – is either SymbolEntity or ColorrampEntity
qword – is the query string to search the symbols or colorramps.
- Returns
A QStringList of the matched symbols or colorramps
-
groupsModified
¶ Is emitted every time a tag or smartgroup has been added, removed, or renamed [signal]
-
importXml
(self, filename: str) → bool¶ Imports the symbols and colorramps into the default style database from the given XML file
-
isSignalConnected
()¶
-
isXmlStyleFile
(path: str) → bool¶ Tests if the file at
path
is a QGIS style XML file.This method samples only the first line in the file, so is safe to call on large xml files.
New in version 3.6.
-
load
(self, filename: str) → bool¶ Loads a file into the style
This function will load an on-disk database and populate styles.
- Parameters
filename – location of the database to load styles from
- Returns
returns the success state of the database being loaded
-
rampAdded
¶ Emitted whenever a color ramp has been added to the style and the database has been updated as a result.
See also
See also
New in version 3.4: [signal]
-
rampChanged
¶ Emitted whenever a color ramp’s definition is changed. This does not include name or tag changes.
See also
New in version 3.4: [signal]
-
rampRemoved
¶ Emitted whenever a color ramp has been removed from the style and the database has been updated as a result.
See also
See also
New in version 3.4: [signal]
-
rampRenamed
¶ Emitted whenever a color ramp has been renamed from
oldName
tonewName
See also
New in version 3.4: [signal]
-
receivers
()¶
-
remove
(self, type: QgsStyle.StyleEntity, id: int) → bool¶ Removes the specified entity from the db
- Parameters
type – is any of the style entities. Refer enum StyleEntity.
id – is the DB id of the entity to be removed
-
removeColorRamp
(self, name: str) → bool¶ Removes color ramp from style (and delete it)
-
removeFavorite
(self, type: QgsStyle.StyleEntity, name: str) → bool¶ Removes the specified symbol from favorites
- Parameters
type – is either SymbolEntity of ColorrampEntity
name – is the name of the symbol or coloramp whose is to be removed from favorites
- Returns
returns the success state as bool
-
removeSymbol
(self, name: str) → bool¶ Removes symbol from style (and delete it)
-
rename
(self, type: QgsStyle.StyleEntity, id: int, newName: str) → bool¶ Renames the given entity with the specified id
- Parameters
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
-
renameColorRamp
(self, oldName: str, newName: str) → bool¶ Changes ramp’s name
-
renameSymbol
(self, oldName: str, newName: str) → bool¶ Renames a symbol from
oldName
tonewName
.Returns true if symbol was successfully renamed.
-
save
(self, filename: str = '') → bool¶ Saves style into a file (will use current filename if empty string is passed)
-
saveColorRamp
(self, name: str, ramp: QgsColorRamp, favorite: bool, tags: Iterable[str]) → bool¶ Adds the colorramp to the DB
- Parameters
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.
- Returns
returns the success state of the save operation
-
saveSymbol
(self, name: str, symbol: QgsSymbol, favorite: bool, tags: Iterable[str]) → bool¶ Adds the symbol to the DB with the tags
- Parameters
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.
- Returns
returns the success state of the save operation
-
sender
()¶
-
senderSignalIndex
()¶
-
smartgroup
(self, id: int) → object¶ Returns the QgsSmartConditionMap for the given id
-
smartgroupId
(self, smartgroup: str) → int¶ Returns the DB id for the given smartgroup name
-
smartgroupNames
(self) → List[str]¶ Returns the smart groups list
-
smartgroupOperator
(self, id: int) → str¶ Returns the operator for the smartgroup clumsy implementation TODO create a class for smartgroups
-
smartgroupsListMap
(self) → Dict[int, str]¶ Returns the smart groups map with id as key and name as value
-
symbol
(self, name: str) → QgsSymbol¶ Returns a NEW copy of symbol
-
symbolChanged
¶ Emitted whenever a symbol’s definition is changed. This does not include name or tag changes.
See also
New in version 3.4: [signal]
-
symbolCount
(self) → int¶ Returns count of symbols in style
-
symbolHasTag
(self, type: QgsStyle.StyleEntity, symbol: str, tag: str) → bool¶ Returns whether a given tag is associated with the symbol
- Parameters
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
- Returns
A boolean value identicating whether a tag was found attached to the symbol
-
symbolId
(self, name: str) → int¶ Returns the id in the style database for the given symbol name returns 0 if not found
-
symbolNames
(self) → List[str]¶ Returns a list of names of symbols
-
symbolRef
(self, name: str) → QgsSymbol¶ Returns a const pointer to a symbol (doesn’t create new instance)
-
symbolRemoved
¶ Emitted whenever a symbol has been removed from the style and the database has been updated as a result.
See also
See also
New in version 3.4: [signal]
-
symbolRenamed
¶ Emitted whenever a symbol has been renamed from
oldName
tonewName
See also
New in version 3.4: [signal]
-
symbolSaved
¶ Emitted every time a new symbol has been added to the database. Emitted whenever a symbol has been added to the style and the database has been updated as a result.
See also
See also
See also
symbolChanged()
[signal]
-
symbolsOfFavorite
(self, type: QgsStyle.StyleEntity) → List[str]¶ Returns the symbol names which are flagged as favorite
- Parameters
type – is either SymbolEntity or ColorampEntity
- Returns
A QStringList of the symbol or colorramp names flagged as favorite
-
symbolsOfSmartgroup
(self, type: QgsStyle.StyleEntity, id: int) → List[str]¶ Returns the symbols for the smartgroup
-
symbolsWithTag
(self, type: QgsStyle.StyleEntity, tagid: int) → List[str]¶ Returns the symbol names with which have the given tag
- Parameters
type – is either SymbolEntity or ColorampEntity
tagid – is id of the tag which has been applied over the symbol as int
- Returns
A QStringList of the symbol or colorramp names for the given tag id
-
tag
(self, id: int) → str¶ Returns the tag name for the given id
-
tagId
(self, tag: str) → int¶ Returns the DB id for the given tag name
-
tagSymbol
(self, type: QgsStyle.StyleEntity, symbol: str, tags: Iterable[str]) → bool¶ Tags the symbol with the tags in the list
Applies the given tags to the given symbol or colorramp
- Parameters
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
- Returns
returns the success state of the operation
Returns a list of all tags in the style database
See also
New in version 2.16.
Returns the tags associated with the symbol
- Parameters
type – is either SymbolEntity or ColorrampEntity
symbol – is the name of the symbol or color ramp
- Returns
A QStringList of the tags that have been applied to that symbol/colorramp
-
timerEvent
()¶
-