Skip to content

Commit

Permalink
Add Python bindings for map layer style manager
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jan 7, 2015
1 parent f00f4fd commit 2144be0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/core/core.sip
Expand Up @@ -54,6 +54,7 @@
%Include qgsmaplayerlegend.sip
%Include qgsmaplayerregistry.sip
%Include qgsmaplayerrenderer.sip
%Include qgsmaplayerstylemanager.sip
%Include qgsmaprenderer.sip
%Include qgsmaprenderercache.sip
%Include qgsmaprenderercustompainterjob.sip
Expand Down
20 changes: 20 additions & 0 deletions python/core/qgsmaplayer.sip
Expand Up @@ -370,6 +370,21 @@ class QgsMapLayer : QObject
*/
QgsMapLayerLegend* legend() const;

/**
* Enable or disable layer's style manager. When disabled (default), the styleManager() will return null pointer.
* By enabling the style manager will be created with one default style (same as the layer's active style).
* By disabling the style manager all associated styles will be lost (only the layer's active style will stay).
* @note added in 2.8
*/
void enableStyleManager( bool enable = true );

/**
* Get access to the layer's style manager. Style manager allows switching between multiple styles.
* If the style manager is not enabled, null pointer will be returned.
* @note added in 2.8
*/
QgsMapLayerStyleManager* styleManager() const;

/**Returns the minimum scale denominator at which the layer is visible.
* Scale based visibility is only used if hasScaleBasedVisibility is true.
* @returns minimum scale denominator at which the layer will render
Expand Down Expand Up @@ -517,6 +532,11 @@ class QgsMapLayer : QObject
/** Write custom properties to project file. */
void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;

/** Read style manager's configuration (if any). To be called by subclasses. */
void readStyleManager( const QDomNode& layerNode );
/** Write style manager's configuration (if exists). To be called by subclasses. */
void writeStyleManager( QDomNode& layerNode, QDomDocument& doc ) const;

/** debugging member - invoked when a connect() is made to this object */
void connectNotify( const char * signal );

Expand Down
63 changes: 63 additions & 0 deletions python/core/qgsmaplayerstylemanager.sip
@@ -0,0 +1,63 @@

class QgsMapLayerStyle
{
%TypeHeaderCode
#include <qgsmaplayerstylemanager.h>
%End
public:
//! construct invalid style
QgsMapLayerStyle();

//! Tell whether the style is valid (i.e. there is something stored in it)
bool isValid() const;

//! Return information about the style - for debugging purposes only
QString dump() const;

//! Store layer's active style information in the instance
void readFromLayer( QgsMapLayer* layer );
//! Apply stored layer's style information to the layer
void writeToLayer( QgsMapLayer* layer ) const;

//! Read style configuration (for project file reading)
void readXml( const QDomElement& styleElement );
//! Write style configuration (for project file writing)
void writeXml( QDomElement& styleElement ) const;
};


class QgsMapLayerStyleManager
{
%TypeHeaderCode
#include <qgsmaplayerstylemanager.h>
%End
public:
//! Construct a style manager associated with a map layer (must not be null)
QgsMapLayerStyleManager( QgsMapLayer* layer );

//! Read configuration (for project loading)
void readXml( const QDomElement& mgrElement );
//! Write configuration (for project saving)
void writeXml( QDomElement& mgrElement ) const;

//! Return list of all defined style names
QStringList styles() const;
//! Return data of a stored style - accessed by its unique name
QgsMapLayerStyle style( const QString& name ) const;

//! Add a style with given name and data
//! @return true on success (name is unique and style is valid)
bool addStyle( const QString& name, const QgsMapLayerStyle& style );
//! Add style by cloning the current one
//! @return true on success
bool addStyleFromLayer( const QString& name );
//! Remove a stored style
//! @return true on success (style exists and it is not the last one)
bool removeStyle( const QString& name );

//! Return name of the current style
QString currentStyle() const;
//! Set a different style as the current style - will apply it to the layer
//! @return true on success
bool setCurrentStyle( const QString& name );
};

0 comments on commit 2144be0

Please sign in to comment.