QGIS API Documentation  2.14.0-Essen
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>

Inheritance diagram for QgsStyleV2:
Inheritance graph
[legend]

Public Types

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

Signals

void symbolSaved (const QString &name, QgsSymbolV2 *symbol)
 

Public Member Functions

 QgsStyleV2 ()
 
 ~QgsStyleV2 ()
 
bool addColorRamp (const QString &name, QgsVectorColorRampV2 *colorRamp, bool update=false)
 add color ramp to style. takes ramp's ownership More...
 
int addGroup (const QString &groupName, int parent=0)
 adds a new group and returns the group's id More...
 
int addSmartgroup (const QString &name, const QString &op, const QgsSmartConditionMap &conditions)
 adds new smartgroup to the database and returns the id More...
 
bool addSymbol (const QString &name, QgsSymbolV2 *symbol, bool update=false)
 add symbol to style. takes symbol's ownership More...
 
int addTag (const QString &tagName)
 adds a new tag and returns the tag's id More...
 
QgsSymbolGroupMap childGroupNames (const QString &parent="")
 return a map of groupid and names for the given parent group More...
 
void clear ()
 remove all contents of the style More...
 
QgsVectorColorRampV2colorRamp (const QString &name)
 return a NEW copy of color ramp More...
 
int colorRampCount ()
 return count of color ramps More...
 
int colorrampId (const QString &name)
 return the id in the style database for the given colorramp name returns 0 if not found More...
 
QStringList colorRampNames ()
 return a list of names of color ramps More...
 
const QgsVectorColorRampV2colorRampRef (const QString &name) const
 return a const pointer to a symbol (doesn't create new instance) More...
 
bool detagSymbol (StyleEntity type, const QString &symbol, const QStringList &tags)
 detags the symbol with the given list More...
 
QString errorString ()
 return last error from load/save operation More...
 
bool exportXML (const QString &filename)
 Exports the style as a XML file. More...
 
QString fileName ()
 return current file name of the style More...
 
QStringList findSymbols (StyleEntity type, const QString &qword)
 return the names of the symbols which have a matching 'substring' in its defintion More...
 
bool group (StyleEntity type, const QString &name, int groupid)
 applies the specified group to the symbol or colorramp specified by StyleEntity More...
 
int groupId (const QString &group)
 return the DB id for the given group name More...
 
QList< int > groupIds () const
 return the ids of all the groups in the style More...
 
QString groupName (int groupId) const
 return the group name for the given DB id More...
 
QStringList groupNames ()
 return the all the groups in the style 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)
 load a file into the style More...
 
void remove (StyleEntity type, int id)
 remove the specified entity from the db More...
 
bool removeColorRamp (const QString &name)
 remove color ramp from style (and delete it) More...
 
bool removeSymbol (const QString &name)
 remove symbol from style (and delete it) More...
 
void rename (StyleEntity type, int id, const QString &newName)
 rename the given entity with the specified id More...
 
bool renameColorRamp (const QString &oldName, const QString &newName)
 change ramp's name More...
 
bool renameSymbol (const QString &oldName, const QString &newName)
 change symbol's name More...
 
bool save (QString filename=QString())
 save style into a file (will use current filename if empty string is passed) More...
 
bool saveColorRamp (const QString &name, QgsVectorColorRampV2 *ramp, int groupid, const QStringList &tags)
 add the colorramp to the DB More...
 
bool saveSymbol (const QString &name, QgsSymbolV2 *symbol, int groupid, const QStringList &tags)
 add 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)
 return 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 More...
 
QgsSymbolGroupMap smartgroupsListMap ()
 returns the smart groups map with id as key and name as value More...
 
QgsSymbolV2symbol (const QString &name)
 return a NEW copy of symbol More...
 
int symbolCount ()
 return count of symbols in style More...
 
int symbolId (const QString &name)
 return the id in the style database for the given symbol name returns 0 if not found More...
 
QStringList symbolNames ()
 return a list of names of symbols More...
 
const QgsSymbolV2symbolRef (const QString &name) const
 return a const pointer to a symbol (doesn't create new instance) More...
 
QStringList symbolsOfGroup (StyleEntity type, int groupid)
 returns the symbolnames of a given groupid More...
 
QStringList symbolsOfSmartgroup (StyleEntity type, int id)
 returns the symbols for the smartgroup More...
 
QStringList symbolsWithTag (StyleEntity type, int tagid)
 returns the symbol names with which have the given tag More...
 
int tagId (const QString &tag)
 return the DB id for the given tag name More...
 
QStringList tagsOfSymbol (StyleEntity type, const QString &symbol)
 return 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...
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
virtual  ~QObject ()
 
bool blockSignals (bool block)
 
QObjectchild (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArraydynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObjectparent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThreadthread () const
 

Static Public Member Functions

static QgsStyleV2defaultStyle ()
 return default application-wide style More...
 
- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Protected Member Functions

char * getGroupRemoveQuery (int id)
 prepares the complex query for removing a group, so that the children are not abandoned More...
 
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 More...
 
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 More...
 
bool openDB (const QString &filename)
 convenience function to open the DB and return a sqlite3 object More...
 
bool runEmptyQuery (char *query, bool freeQuery=true)
 convenience function that would run queries which don't generate return values More...
 
bool updateSymbol (StyleEntity type, const QString &name)
 updates the properties of an existing symbol/colorramp More...
 
- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObjectsender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Protected Attributes

QgsVectorColorRampV2Map mColorRamps
 
sqlite3mCurrentDB
 
QString mErrorString
 
QString mFileName
 
QgsSymbolV2Map mSymbols
 

Static Protected Attributes

static QgsStyleV2mDefaultStyle = nullptr
 

Additional Inherited Members

- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

Definition at line 66 of file qgsstylev2.h.

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 

Definition at line 80 of file qgsstylev2.h.

Constructor & Destructor Documentation

QgsStyleV2::QgsStyleV2 ( )

Definition at line 41 of file qgsstylev2.cpp.

QgsStyleV2::~QgsStyleV2 ( )

Definition at line 46 of file qgsstylev2.cpp.

Member Function Documentation

bool QgsStyleV2::addColorRamp ( const 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

Definition at line 186 of file qgsstylev2.cpp.

int QgsStyleV2::addGroup ( const 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

Definition at line 625 of file qgsstylev2.cpp.

int QgsStyleV2::addSmartgroup ( const QString name,
const QString op,
const 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

Definition at line 1012 of file qgsstylev2.cpp.

bool QgsStyleV2::addSymbol ( const 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

Definition at line 81 of file qgsstylev2.cpp.

int QgsStyleV2::addTag ( const 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

Definition at line 642 of file qgsstylev2.cpp.

QgsSymbolGroupMap QgsStyleV2::childGroupNames ( const QString parent = "")

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

Definition at line 492 of file qgsstylev2.cpp.

void QgsStyleV2::clear ( )

remove all contents of the style

Definition at line 70 of file qgsstylev2.cpp.

QgsVectorColorRampV2 * QgsStyleV2::colorRamp ( const QString name)

return a NEW copy of color ramp

Definition at line 258 of file qgsstylev2.cpp.

int QgsStyleV2::colorRampCount ( )

return count of color ramps

Definition at line 269 of file qgsstylev2.cpp.

int QgsStyleV2::colorrampId ( const QString name)

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

Definition at line 987 of file qgsstylev2.cpp.

QStringList QgsStyleV2::colorRampNames ( )

return a list of names of color ramps

Definition at line 274 of file qgsstylev2.cpp.

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

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

Definition at line 264 of file qgsstylev2.cpp.

QgsStyleV2 * QgsStyleV2::defaultStyle ( )
static

return default application-wide style

Definition at line 51 of file qgsstylev2.cpp.

bool QgsStyleV2::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

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

Definition at line 854 of file qgsstylev2.cpp.

QString QgsStyleV2::errorString ( )
inline

return last error from load/save operation

Definition at line 279 of file qgsstylev2.h.

bool QgsStyleV2::exportXML ( const QString filename)

Exports the style as a XML file.

Definition at line 1290 of file qgsstylev2.cpp.

QString QgsStyleV2::fileName ( )
inline

return current file name of the style

Definition at line 282 of file qgsstylev2.h.

QStringList QgsStyleV2::findSymbols ( StyleEntity  type,
const 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

Definition at line 776 of file qgsstylev2.cpp.

char * QgsStyleV2::getGroupRemoveQuery ( int  id)
protected

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

Definition at line 685 of file qgsstylev2.cpp.

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

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

Definition at line 946 of file qgsstylev2.cpp.

QString QgsStyleV2::getName ( const QString table,
int  id 
) const
protected

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

Definition at line 964 of file qgsstylev2.cpp.

bool QgsStyleV2::group ( StyleEntity  type,
const 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

Definition at line 755 of file qgsstylev2.cpp.

int QgsStyleV2::groupId ( const QString group)

return the DB id for the given group name

Definition at line 992 of file qgsstylev2.cpp.

QList< int > QgsStyleV2::groupIds ( ) const

return the ids of all the groups in the style

Definition at line 478 of file qgsstylev2.cpp.

QString QgsStyleV2::groupName ( int  groupId) const

return the group name for the given DB id

Definition at line 997 of file qgsstylev2.cpp.

QStringList QgsStyleV2::groupNames ( )

return the all the groups in the style

Definition at line 464 of file qgsstylev2.cpp.

bool QgsStyleV2::importXML ( const QString filename)

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

Definition at line 1334 of file qgsstylev2.cpp.

bool QgsStyleV2::load ( const QString filename)

load a file into the style

Definition at line 292 of file qgsstylev2.cpp.

bool QgsStyleV2::openDB ( const QString filename)
protected

convenience function to open the DB and return a sqlite3 object

Definition at line 279 of file qgsstylev2.cpp.

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

Definition at line 703 of file qgsstylev2.cpp.

bool QgsStyleV2::removeColorRamp ( const QString name)

remove color ramp from style (and delete it)

Definition at line 240 of file qgsstylev2.cpp.

bool QgsStyleV2::removeSymbol ( const QString name)

remove symbol from style (and delete it)

Definition at line 136 of file qgsstylev2.cpp.

void QgsStyleV2::rename ( StyleEntity  type,
int  id,
const 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

Definition at line 657 of file qgsstylev2.cpp.

bool QgsStyleV2::renameColorRamp ( const QString oldName,
const QString newName 
)

change ramp's name

Definition at line 436 of file qgsstylev2.cpp.

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

change symbol's name

Definition at line 404 of file qgsstylev2.cpp.

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

Definition at line 734 of file qgsstylev2.cpp.

bool QgsStyleV2::save ( QString  filename = QString())

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

Definition at line 358 of file qgsstylev2.cpp.

bool QgsStyleV2::saveColorRamp ( const QString name,
QgsVectorColorRampV2 ramp,
int  groupid,
const 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

Definition at line 210 of file qgsstylev2.cpp.

bool QgsStyleV2::saveSymbol ( const QString name,
QgsSymbolV2 symbol,
int  groupid,
const 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

Definition at line 105 of file qgsstylev2.cpp.

QgsSmartConditionMap QgsStyleV2::smartgroup ( int  id)

returns the QgsSmartConditionMap for the given id

Definition at line 1217 of file qgsstylev2.cpp.

int QgsStyleV2::smartgroupId ( const QString smartgroup)

return the DB id for the given smartgroup name

Definition at line 1007 of file qgsstylev2.cpp.

QStringList QgsStyleV2::smartgroupNames ( )

returns the smart groups list

Definition at line 1078 of file qgsstylev2.cpp.

QString QgsStyleV2::smartgroupOperator ( int  id)

returns the operator for the smartgroup

Definition at line 1259 of file qgsstylev2.cpp.

QgsSymbolGroupMap QgsStyleV2::smartgroupsListMap ( )

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

Definition at line 1052 of file qgsstylev2.cpp.

QgsSymbolV2 * QgsStyleV2::symbol ( const QString name)

return a NEW copy of symbol

Definition at line 164 of file qgsstylev2.cpp.

int QgsStyleV2::symbolCount ( )

return count of symbols in style

Definition at line 175 of file qgsstylev2.cpp.

int QgsStyleV2::symbolId ( const QString name)

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

Definition at line 982 of file qgsstylev2.cpp.

QStringList QgsStyleV2::symbolNames ( )

return a list of names of symbols

Definition at line 180 of file qgsstylev2.cpp.

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

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

Definition at line 170 of file qgsstylev2.cpp.

void QgsStyleV2::symbolSaved ( const 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

Definition at line 539 of file qgsstylev2.cpp.

QStringList QgsStyleV2::symbolsOfSmartgroup ( StyleEntity  type,
int  id 
)

returns the symbols for the smartgroup

Definition at line 1103 of file qgsstylev2.cpp.

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

Definition at line 576 of file qgsstylev2.cpp.

int QgsStyleV2::tagId ( const QString tag)

return the DB id for the given tag name

Definition at line 1002 of file qgsstylev2.cpp.

QStringList QgsStyleV2::tagsOfSymbol ( StyleEntity  type,
const 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

Definition at line 907 of file qgsstylev2.cpp.

bool QgsStyleV2::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

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

Definition at line 802 of file qgsstylev2.cpp.

bool QgsStyleV2::updateSymbol ( StyleEntity  type,
const 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

Definition at line 1430 of file qgsstylev2.cpp.

Member Data Documentation

QgsVectorColorRampV2Map QgsStyleV2::mColorRamps
protected

Definition at line 328 of file qgsstylev2.h.

sqlite3* QgsStyleV2::mCurrentDB
protected

Definition at line 333 of file qgsstylev2.h.

QgsStyleV2 * QgsStyleV2::mDefaultStyle = nullptr
staticprotected

Definition at line 335 of file qgsstylev2.h.

QString QgsStyleV2::mErrorString
protected

Definition at line 330 of file qgsstylev2.h.

QString QgsStyleV2::mFileName
protected

Definition at line 331 of file qgsstylev2.h.

QgsSymbolV2Map QgsStyleV2::mSymbols
protected

Definition at line 327 of file qgsstylev2.h.


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