QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Types | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
QgsStyleV2 Class Reference

#include <qgsstylev2.h>

Public Types

enum  StyleEntity {
  SymbolEntity, GroupEntity, TagEntity, ColorrampEntity,
  SmartgroupEntity
}
 Enum for Entities involved in a style. More...

Signals

void symbolSaved (QString name, QgsSymbolV2 *symbol)

Public Member Functions

 QgsStyleV2 ()
 ~QgsStyleV2 ()
bool addColorRamp (QString name, QgsVectorColorRampV2 *colorRamp, bool update=false)
 add color ramp to style. takes ramp's ownership
int addGroup (QString groupName, int parent=0)
 adds a new group and returns the group's id
int addSmartgroup (QString name, QString op, QgsSmartConditionMap conditions)
 adds new smartgroup to the database and returns the id
bool addSymbol (QString name, QgsSymbolV2 *symbol, bool update=false)
 add symbol to style. takes symbol's ownership
int addTag (QString tagName)
 adds a new tag and returns the tag's id
QgsSymbolGroupMap childGroupNames (QString parent="")
 return a map of groupid and names for the given parent group
void clear ()
 remove all contents of the style
QgsVectorColorRampV2colorRamp (QString name)
 return a NEW copy of color ramp
int colorRampCount ()
 return count of color ramps
QStringList colorRampNames ()
 return a list of names of color ramps
const QgsVectorColorRampV2colorRampRef (QString name) const
 return a const pointer to a symbol (doesn't create new instance)
int colorrampId (QString name)
 return the id in the style database for the given colorramp name returns 0 if not found
bool tagSymbol (StyleEntity type, QString symbol, QStringList tags)
 tags the symbol with the tags in the list
bool detagSymbol (StyleEntity type, QString symbol, QStringList tags)
 detags the symbol with the given list
bool removeSymbol (QString name)
 remove symbol from style (and delete it)
bool renameSymbol (QString oldName, QString newName)
 change symbol's name
QgsSymbolV2symbol (QString name)
 return a NEW copy of symbol
const QgsSymbolV2symbolRef (QString name) const
 return a const pointer to a symbol (doesn't create new instance)
int symbolCount ()
 return count of symbols in style
QStringList symbolNames ()
 return a list of names of symbols
int symbolId (QString name)
 return the id in the style database for the given symbol name returns 0 if not found
int groupId (QString group)
 return the DB id for the given group name
int tagId (QString tag)
 return the DB id for the given tag name
int smartgroupId (QString smartgroup)
 return the DB id for the given smartgroup name
QStringList groupNames ()
 return the all the groups in the style
QStringList symbolsOfGroup (StyleEntity type, int groupid)
 returns the symbolnames of a given groupid
QStringList symbolsWithTag (StyleEntity type, int tagid)
 returns the symbol names with which have the given tag
bool group (StyleEntity type, QString name, int groupid)
 applies the specified group to the symbol or colorramp specified by StyleEntity
void rename (StyleEntity type, int id, QString newName)
 rename the given entity with the specified id
void remove (StyleEntity type, int id)
 remove the specified entity from the db
bool saveSymbol (QString name, QgsSymbolV2 *symbol, int groupid, QStringList tags)
 add the symbol to the DB with the tags
bool saveColorRamp (QString name, QgsVectorColorRampV2 *ramp, int groupid, QStringList tags)
 add the colorramp to the DB
bool removeColorRamp (QString name)
 remove color ramp from style (and delete it)
bool renameColorRamp (QString oldName, QString newName)
 change ramp's name
bool load (QString filename)
 load a file into the style
bool save (QString filename=QString())
 save style into a file (will use current filename if empty string is passed)
QString errorString ()
 return last error from load/save operation
QString fileName ()
 return current file name of the style
QStringList findSymbols (StyleEntity type, QString qword)
 return the names of the symbols which have a matching 'substring' in its defintion
QStringList tagsOfSymbol (StyleEntity type, QString symbol)
 return the tags associated with the symbol
QgsSymbolGroupMap smartgroupsListMap ()
 returns the smart groups map with id as key and name as value
QStringList smartgroupNames ()
 returns the smart groups list
QgsSmartConditionMap smartgroup (int id)
 returns the QgsSmartConditionMap for the given id
QString smartgroupOperator (int id)
 returns the operator for the smartgroup
QStringList symbolsOfSmartgroup (StyleEntity type, int id)
 returns the symbols for the smartgroup
bool exportXML (QString filename)
 Exports the style as a XML file.
bool importXML (QString filename)
 Imports the symbols and colorramps into the default style database from the given XML file.

Static Public Member Functions

static QgsStyleV2defaultStyle ()
 return default application-wide style

Protected Member Functions

bool openDB (QString filename)
 convenience function to open the DB and return a sqlite3 object
bool runEmptyQuery (char *query, bool freeQuery=true)
 convenience function that would run queries which don't generate return values
char * getGroupRemoveQuery (int id)
 prepares the complex query for removing a group, so that the children are not abandoned
int getId (QString table, QString name)
 gets the id from the table for the given name from the database, 0 if not found
bool updateSymbol (StyleEntity type, QString name)
 updates the properties of an existing symbol/colorramp

Protected Attributes

QgsSymbolV2Map mSymbols
QgsVectorColorRampV2Map mColorRamps
QString mErrorString
QString mFileName
sqlite3mCurrentDB

Static Protected Attributes

static QgsStyleV2mDefaultStyle = 0

Member Enumeration Documentation

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.

See Also
group(), rename(), remove(), symbolsOfGroup(), symbolsWithTag(), symbolsOfSmartgroup()
Enumerator:
SymbolEntity 
GroupEntity 
TagEntity 
ColorrampEntity 
SmartgroupEntity 

Constructor & Destructor Documentation

QgsStyleV2::QgsStyleV2 ( )
QgsStyleV2::~QgsStyleV2 ( )

Member Function Documentation

bool QgsStyleV2::addColorRamp ( QString  name,
QgsVectorColorRampV2 colorRamp,
bool  update = false 
)

add color ramp to style. takes ramp's ownership

Note
Adding a color ramp with the name of existing one replaces it.
Parameters
nameis the name of the color ramp being added or updated
colorRampis the Vector color ramp
updateset to true when the style DB has to be updated, by default it is false
Returns
success status of the operation
int QgsStyleV2::addGroup ( QString  groupName,
int  parent = 0 
)

adds a new group and returns the group's id

Parameters
groupNamethe name of the new group as QString
parentis the id of the parent group when a subgrouo is to be created. By default it is 0 indicating it is not a sub-group
Returns
returns an int, which is the DB id of the new group created, 0 if the group couldn't be created
int QgsStyleV2::addSmartgroup ( QString  name,
QString  op,
QgsSmartConditionMap  conditions 
)

adds new smartgroup to the database and returns the id

Parameters
nameis the name of the new Smart Group to be added
opis the operator between the conditions; AND/OR as QString
conditionsare the smart group conditions
bool QgsStyleV2::addSymbol ( QString  name,
QgsSymbolV2 symbol,
bool  update = false 
)

add symbol to style. takes symbol's ownership

Note
Adding a symbol with the name of existing one replaces it.
Parameters
nameis the name of the symbol being added or updated
symbolis the Vector symbol
updateset to true when the style DB has to be updated, by default it is false
Returns
success status of the operation
int QgsStyleV2::addTag ( QString  tagName)

adds a new tag and returns the tag's id

Parameters
tagNamethe 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
QgsSymbolGroupMap QgsStyleV2::childGroupNames ( QString  parent = "")

return a map of groupid and names for the given parent group

void QgsStyleV2::clear ( )

remove all contents of the style

QgsVectorColorRampV2 * QgsStyleV2::colorRamp ( QString  name)

return a NEW copy of color ramp

int QgsStyleV2::colorRampCount ( )

return count of color ramps

int QgsStyleV2::colorrampId ( QString  name)

return the id in the style database for the given colorramp name returns 0 if not found

QStringList QgsStyleV2::colorRampNames ( )

return a list of names of color ramps

const QgsVectorColorRampV2 * QgsStyleV2::colorRampRef ( QString  name) const

return a const pointer to a symbol (doesn't create new instance)

QgsStyleV2 * QgsStyleV2::defaultStyle ( )
static

return default application-wide style

bool QgsStyleV2::detagSymbol ( StyleEntity  type,
QString  symbol,
QStringList  tags 
)

detags the symbol with the given list

Removes the given tags for the specified symbol or colorramp

Parameters
typeis either SymbolEntity or ColorrampEntity
symbolis the name of the symbol or colorramp
tagsis the list of tags that are to be removed as QStringList
Returns
returns the success state of the operation
QString QgsStyleV2::errorString ( )
inline

return last error from load/save operation

bool QgsStyleV2::exportXML ( QString  filename)

Exports the style as a XML file.

QString QgsStyleV2::fileName ( )
inline

return current file name of the style

QStringList QgsStyleV2::findSymbols ( StyleEntity  type,
QString  qword 
)

return the names of the symbols which have a matching 'substring' in its defintion

Parameters
typeis either SymbolEntity or ColorrampEntity
qwordis the query string to search the symbols or colorramps.
Returns
A QStringList of the matched symbols or colorramps
char * QgsStyleV2::getGroupRemoveQuery ( int  id)
protected

prepares the complex query for removing a group, so that the children are not abandoned

int QgsStyleV2::getId ( QString  table,
QString  name 
)
protected

gets the id from the table for the given name from the database, 0 if not found

bool QgsStyleV2::group ( StyleEntity  type,
QString  name,
int  groupid 
)

applies the specified group to the symbol or colorramp specified by StyleEntity

Parameters
typeis either SymbolEntity of ColorrampEntity
nameis the name of the symbol or coloramp whose group is to be set
groupidis the id of the group to which the entity is assigned
Returns
returns the success state as bool
int QgsStyleV2::groupId ( QString  group)

return the DB id for the given group name

QStringList QgsStyleV2::groupNames ( )

return the all the groups in the style

bool QgsStyleV2::importXML ( QString  filename)

Imports the symbols and colorramps into the default style database from the given XML file.

bool QgsStyleV2::load ( QString  filename)

load a file into the style

bool QgsStyleV2::openDB ( QString  filename)
protected

convenience function to open the DB and return a sqlite3 object

void QgsStyleV2::remove ( StyleEntity  type,
int  id 
)

remove the specified entity from the db

Parameters
typeis any of the style entites. Refer enum StyleEntity.
idis the DB id of the entity to be removed
bool QgsStyleV2::removeColorRamp ( QString  name)

remove color ramp from style (and delete it)

bool QgsStyleV2::removeSymbol ( QString  name)

remove symbol from style (and delete it)

void QgsStyleV2::rename ( StyleEntity  type,
int  id,
QString  newName 
)

rename the given entity with the specified id

Parameters
typeis any of the style entites. Refer enum StyleEntity.
idis the DB id of the entity which is to be renamed
newNameis the new name of the entity
bool QgsStyleV2::renameColorRamp ( QString  oldName,
QString  newName 
)

change ramp's name

bool QgsStyleV2::renameSymbol ( QString  oldName,
QString  newName 
)

change symbol's name

bool QgsStyleV2::runEmptyQuery ( char *  query,
bool  freeQuery = true 
)
protected

convenience function that would run queries which don't generate return values

Parameters
queryquery to run
freeQueryrelease query memory
Returns
success true on success
bool QgsStyleV2::save ( QString  filename = QString())

save style into a file (will use current filename if empty string is passed)

bool QgsStyleV2::saveColorRamp ( QString  name,
QgsVectorColorRampV2 ramp,
int  groupid,
QStringList  tags 
)

add the colorramp to the DB

Parameters
nameis the name of the colorramp as QString
rampis the pointer to the new QgsVectorColorRampV2 being saved
groupidis the id of the group to which the Color Ramp belongs. Pass 0 if it doesn't belong to any group or not known.
tagsis a list of tags that are associated with the color ramp as a QStringList.
Returns
returns the success state of the save operation
bool QgsStyleV2::saveSymbol ( QString  name,
QgsSymbolV2 symbol,
int  groupid,
QStringList  tags 
)

add the symbol to the DB with the tags

Parameters
nameis the name of the symbol as QString
symbolis the pointer to the new QgsSymbolV2 being saved
groupidis the id of the group to which the symbol belongs. Pass 0 if it doesn't belong to any group or not known.
tagsis a list of tags that are associated with the symbol as a QStringList.
Returns
returns the success state of the save operation
QgsSmartConditionMap QgsStyleV2::smartgroup ( int  id)

returns the QgsSmartConditionMap for the given id

int QgsStyleV2::smartgroupId ( QString  smartgroup)

return the DB id for the given smartgroup name

QStringList QgsStyleV2::smartgroupNames ( )

returns the smart groups list

QString QgsStyleV2::smartgroupOperator ( int  id)

returns the operator for the smartgroup

QgsSymbolGroupMap QgsStyleV2::smartgroupsListMap ( )

returns the smart groups map with id as key and name as value

QgsSymbolV2 * QgsStyleV2::symbol ( QString  name)

return a NEW copy of symbol

int QgsStyleV2::symbolCount ( )

return count of symbols in style

int QgsStyleV2::symbolId ( QString  name)

return the id in the style database for the given symbol name returns 0 if not found

QStringList QgsStyleV2::symbolNames ( )

return a list of names of symbols

const QgsSymbolV2 * QgsStyleV2::symbolRef ( QString  name) const

return a const pointer to a symbol (doesn't create new instance)

void QgsStyleV2::symbolSaved ( QString  name,
QgsSymbolV2 symbol 
)
signal
QStringList QgsStyleV2::symbolsOfGroup ( StyleEntity  type,
int  groupid 
)

returns the symbolnames of a given groupid

Parameters
typeis either SymbolEntity or ColorampEntity
groupidis id of the group to which the symbols belong to, as int
Returns
A QStringList of the symbol or colorramp names for the given group id
QStringList QgsStyleV2::symbolsOfSmartgroup ( StyleEntity  type,
int  id 
)

returns the symbols for the smartgroup

QStringList QgsStyleV2::symbolsWithTag ( StyleEntity  type,
int  tagid 
)

returns the symbol names with which have the given tag

Parameters
typeis either SymbolEntity or ColorampEntity
tagidis 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
int QgsStyleV2::tagId ( QString  tag)

return the DB id for the given tag name

QStringList QgsStyleV2::tagsOfSymbol ( StyleEntity  type,
QString  symbol 
)

return the tags associated with the symbol

Parameters
typeis either SymbolEntity or ColorrampEntity
symbolis the name of the symbol or color ramp
Returns
A QStringList of the tags that have been applied to that symbol/colorramp
bool QgsStyleV2::tagSymbol ( StyleEntity  type,
QString  symbol,
QStringList  tags 
)

tags the symbol with the tags in the list

Applies the given tags to the given symbol or colorramp

Parameters
typeis either SymbolEntity or ColorrampEntity
symbolis the name of the symbol or colorramp as QString
tagsis the list of the tags that are to be applied as QStringList
Returns
returns the success state of the operation
bool QgsStyleV2::updateSymbol ( StyleEntity  type,
QString  name 
)
protected

updates the properties of an existing symbol/colorramp

Note
This should not be called separately, only called through addSymbol or addColorRamp
Parameters
typeis either SymbolEntity or ColorrampEntity
nameis the name of an existing symbol or a color ramp
Returns
Success state of the update operation

Member Data Documentation

QgsVectorColorRampV2Map QgsStyleV2::mColorRamps
protected
sqlite3* QgsStyleV2::mCurrentDB
protected
QgsStyleV2 * QgsStyleV2::mDefaultStyle = 0
staticprotected
QString QgsStyleV2::mErrorString
protected
QString QgsStyleV2::mFileName
protected
QgsSymbolV2Map QgsStyleV2::mSymbols
protected

The documentation for this class was generated from the following files: