QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsmaplayerstylemanager.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaplayerstylemanager.h
3  --------------------------------------
4  Date : January 2015
5  Copyright : (C) 2015 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMAPLAYERSTYLEMANAGER_H
17 #define QGSMAPLAYERSTYLEMANAGER_H
18 
19 
20 class QgsMapLayer;
21 
22 #include <QByteArray>
23 #include <QMap>
24 #include <QStringList>
25 
26 class QDomElement;
27 
36 class CORE_EXPORT QgsMapLayerStyle
37 {
38  public:
41 
43  explicit QgsMapLayerStyle( const QString& xmlData );
44 
46  bool isValid() const;
47 
49  void clear();
50 
52  QString xmlData() const;
53 
55  void readFromLayer( QgsMapLayer* layer );
57  void writeToLayer( QgsMapLayer* layer ) const;
58 
60  void readXml( const QDomElement& styleElement );
62  void writeXml( QDomElement& styleElement ) const;
63 
64  private:
65  QString mXmlData;
66 };
67 
68 
90 class CORE_EXPORT QgsMapLayerStyleManager : public QObject
91 {
92  Q_OBJECT
93  public:
96 
98  QgsMapLayer* layer() const { return mLayer; }
99 
101  void reset();
102 
104  void readXml( const QDomElement& mgrElement );
106  void writeXml( QDomElement& mgrElement ) const;
107 
109  QStringList styles() const;
111  QgsMapLayerStyle style( const QString& name ) const;
112 
115  bool addStyle( const QString& name, const QgsMapLayerStyle& style );
118  bool addStyleFromLayer( const QString& name );
121  bool removeStyle( const QString& name );
124  bool renameStyle( const QString& name, const QString& newName );
125 
127  QString currentStyle() const;
130  bool setCurrentStyle( const QString& name );
131 
135  bool setOverrideStyle( const QString& styleDef );
137  bool restoreOverrideStyle();
138 
139  signals:
141  void styleAdded( const QString& name );
143  void styleRemoved( const QString& name );
145  void styleRenamed( const QString& oldName, const QString& newName );
147  void currentStyleChanged( const QString& currentName );
148 
149  private:
150  QgsMapLayer* mLayer;
152  QString mCurrentStyle;
153  QgsMapLayerStyle* mOverriddenOriginalStyle;
154 };
155 
156 #endif // QGSMAPLAYERSTYLEMANAGER_H
Base class for all map layer types.
Definition: qgsmaplayer.h:49
Stores style information (renderer, transparency, labeling, diagrams etc.) applicable to a map layer...
QgsMapLayer * layer() const
Get pointer to the associated map layer.
Management of styles for use with one map layer.