QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 #include <QObject>
26 
27 class QDomElement;
28 
37 class CORE_EXPORT QgsMapLayerStyle
38 {
39  public:
42 
44  explicit QgsMapLayerStyle( const QString& xmlData );
45 
47  bool isValid() const;
48 
50  void clear();
51 
53  QString xmlData() const;
54 
56  void readFromLayer( QgsMapLayer* layer );
58  void writeToLayer( QgsMapLayer* layer ) const;
59 
61  void readXml( const QDomElement& styleElement );
63  void writeXml( QDomElement& styleElement ) const;
64 
65  private:
66  QString mXmlData;
67 };
68 
69 
91 class CORE_EXPORT QgsMapLayerStyleManager : public QObject
92 {
93  Q_OBJECT
94  public:
97 
99  QgsMapLayer* layer() const { return mLayer; }
100 
102  void reset();
103 
105  void readXml( const QDomElement& mgrElement );
107  void writeXml( QDomElement& mgrElement ) const;
108 
110  QStringList styles() const;
112  QgsMapLayerStyle style( const QString& name ) const;
113 
116  bool addStyle( const QString& name, const QgsMapLayerStyle& style );
119  bool addStyleFromLayer( const QString& name );
122  bool removeStyle( const QString& name );
125  bool renameStyle( const QString& name, const QString& newName );
126 
128  QString currentStyle() const;
131  bool setCurrentStyle( const QString& name );
132 
136  bool setOverrideStyle( const QString& styleDef );
138  bool restoreOverrideStyle();
139 
140  signals:
142  void styleAdded( const QString& name );
144  void styleRemoved( const QString& name );
146  void styleRenamed( const QString& oldName, const QString& newName );
148  void currentStyleChanged( const QString& currentName );
149 
150  private:
151  QgsMapLayer* mLayer;
153  QString mCurrentStyle;
154  QgsMapLayerStyle* mOverriddenOriginalStyle;
155 };
156 
157 #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.