QGIS API Documentation  2.14.0-Essen
Signals | Public Member Functions | List of all members
QgsMapLayerStyleManager Class Reference

Management of styles for use with one map layer. More...

#include <qgsmaplayerstylemanager.h>

Inheritance diagram for QgsMapLayerStyleManager:
Inheritance graph
[legend]

Signals

void currentStyleChanged (const QString &currentName)
 Emitted when the current style has been changed. More...
 
void styleAdded (const QString &name)
 Emitted when a new style has been added. More...
 
void styleRemoved (const QString &name)
 Emitted when a style has been removed. More...
 
void styleRenamed (const QString &oldName, const QString &newName)
 Emitted when a style has been renamed. More...
 

Public Member Functions

 QgsMapLayerStyleManager (QgsMapLayer *layer)
 Construct a style manager associated with a map layer (must not be null) More...
 
bool addStyle (const QString &name, const QgsMapLayerStyle &style)
 Add a style with given name and data. More...
 
bool addStyleFromLayer (const QString &name)
 Add style by cloning the current one. More...
 
QString currentStyle () const
 Return name of the current style. More...
 
QgsMapLayerlayer () const
 Get pointer to the associated map layer. More...
 
void readXml (const QDomElement &mgrElement)
 Read configuration (for project loading) More...
 
bool removeStyle (const QString &name)
 Remove a stored style. More...
 
bool renameStyle (const QString &name, const QString &newName)
 Rename a stored style to a different name. More...
 
void reset ()
 Reset the style manager to a basic state - with one default style which is set as current. More...
 
bool restoreOverrideStyle ()
 Restore the original store after a call to setOverrideStyle() More...
 
bool setCurrentStyle (const QString &name)
 Set a different style as the current style - will apply it to the layer. More...
 
bool setOverrideStyle (const QString &styleDef)
 Temporarily apply a different style to the layer. More...
 
QgsMapLayerStyle style (const QString &name) const
 Return data of a stored style - accessed by its unique name. More...
 
QStringList styles () const
 Return list of all defined style names. More...
 
void writeXml (QDomElement &mgrElement) const
 Write configuration (for project saving) 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
 

Additional Inherited Members

- 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 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)
 
- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

Management of styles for use with one map layer.

Stored styles are identified by their names. The manager always keep track of which style of the stored ones is currently active. When the current style is changed, the new style is applied to the associated layer.

The class takes care of updating itself when the layer's current style configuration changes. When some of layer style's properties change (e.g. transparency / colors), the style manager will record them in the currently active style without any extra effort required.

When an instance is created, it creates "default" style (with empty name) recorded from the associated map layer and it is set as the current style. The instance must always contain at least one style (which is the current).

The style which is marked as current has no style data stored in its entry. This is to avoid duplication of data as all data is stored in map layer and can be retrieved easily. Also when saving, the entry for the current style will be saved with no data because everything is already saved by the map layer itself.

The class also features support for temporary change of the layer's style, ideal for short-term use of a custom style followed by restoration of the original style (for example, when rendering a map with a different than current style).

Note
added in 2.8

Definition at line 91 of file qgsmaplayerstylemanager.h.

Constructor & Destructor Documentation

QgsMapLayerStyleManager::QgsMapLayerStyleManager ( QgsMapLayer layer)

Construct a style manager associated with a map layer (must not be null)

Definition at line 24 of file qgsmaplayerstylemanager.cpp.

Member Function Documentation

bool QgsMapLayerStyleManager::addStyle ( const QString name,
const QgsMapLayerStyle style 
)

Add a style with given name and data.

Returns
true on success (name is unique and style is valid)

Definition at line 86 of file qgsmaplayerstylemanager.cpp.

bool QgsMapLayerStyleManager::addStyleFromLayer ( const QString name)

Add style by cloning the current one.

Returns
true on success

Definition at line 98 of file qgsmaplayerstylemanager.cpp.

QString QgsMapLayerStyleManager::currentStyle ( ) const

Return name of the current style.

Definition at line 141 of file qgsmaplayerstylemanager.cpp.

void QgsMapLayerStyleManager::currentStyleChanged ( const QString currentName)
signal

Emitted when the current style has been changed.

QgsMapLayer* QgsMapLayerStyleManager::layer ( ) const
inline

Get pointer to the associated map layer.

Definition at line 99 of file qgsmaplayerstylemanager.h.

void QgsMapLayerStyleManager::readXml ( const QDomElement mgrElement)

Read configuration (for project loading)

Definition at line 37 of file qgsmaplayerstylemanager.cpp.

bool QgsMapLayerStyleManager::removeStyle ( const QString name)

Remove a stored style.

Returns
true on success (style exists and it is not the last one)

Definition at line 105 of file qgsmaplayerstylemanager.cpp.

bool QgsMapLayerStyleManager::renameStyle ( const QString name,
const QString newName 
)

Rename a stored style to a different name.

Returns
true on success (style exists and new name is unique)

Definition at line 127 of file qgsmaplayerstylemanager.cpp.

void QgsMapLayerStyleManager::reset ( )

Reset the style manager to a basic state - with one default style which is set as current.

Definition at line 31 of file qgsmaplayerstylemanager.cpp.

bool QgsMapLayerStyleManager::restoreOverrideStyle ( )

Restore the original store after a call to setOverrideStyle()

Definition at line 192 of file qgsmaplayerstylemanager.cpp.

bool QgsMapLayerStyleManager::setCurrentStyle ( const QString name)

Set a different style as the current style - will apply it to the layer.

Returns
true on success

Definition at line 146 of file qgsmaplayerstylemanager.cpp.

bool QgsMapLayerStyleManager::setOverrideStyle ( const QString styleDef)

Temporarily apply a different style to the layer.

The argument can be either a style name or a full QML style definition. Each call must be paired with restoreOverrideStyle()

Definition at line 164 of file qgsmaplayerstylemanager.cpp.

QgsMapLayerStyle QgsMapLayerStyleManager::style ( const QString name) const

Return data of a stored style - accessed by its unique name.

Definition at line 73 of file qgsmaplayerstylemanager.cpp.

void QgsMapLayerStyleManager::styleAdded ( const QString name)
signal

Emitted when a new style has been added.

void QgsMapLayerStyleManager::styleRemoved ( const QString name)
signal

Emitted when a style has been removed.

void QgsMapLayerStyleManager::styleRenamed ( const QString oldName,
const QString newName 
)
signal

Emitted when a style has been renamed.

QStringList QgsMapLayerStyleManager::styles ( ) const

Return list of all defined style names.

Definition at line 68 of file qgsmaplayerstylemanager.cpp.

void QgsMapLayerStyleManager::writeXml ( QDomElement mgrElement) const

Write configuration (for project saving)

Definition at line 54 of file qgsmaplayerstylemanager.cpp.


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