QGIS API Documentation  3.0.2-Girona (307d082)
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 #include "qgis_core.h"
28 #include "qgis_sip.h"
29 
30 class QDomElement;
31 
41 class CORE_EXPORT QgsMapLayerStyle
42 {
43  public:
45  QgsMapLayerStyle() = default;
46 
48  explicit QgsMapLayerStyle( const QString &xmlData );
49 
51  bool isValid() const;
52 
54  void clear();
55 
57  QString xmlData() const;
58 
60  void readFromLayer( QgsMapLayer *layer );
62  void writeToLayer( QgsMapLayer *layer ) const;
63 
65  void readXml( const QDomElement &styleElement );
67  void writeXml( QDomElement &styleElement ) const;
68 
69  private:
70  QString mXmlData;
71 };
72 
73 
96 class CORE_EXPORT QgsMapLayerStyleManager : public QObject
97 {
98  Q_OBJECT
99  public:
100 
106 
108  QgsMapLayer *layer() const { return mLayer; }
109 
111  void reset();
112 
114  void readXml( const QDomElement &mgrElement );
116  void writeXml( QDomElement &mgrElement ) const;
117 
119  QStringList styles() const;
120 
126  QMap<QString, QgsMapLayerStyle> mapLayerStyles() const;
127 
129  QgsMapLayerStyle style( const QString &name ) const;
130 
135  bool addStyle( const QString &name, const QgsMapLayerStyle &style );
136 
141  bool addStyleFromLayer( const QString &name );
142 
147  bool removeStyle( const QString &name );
148 
153  bool renameStyle( const QString &name, const QString &newName );
154 
156  QString currentStyle() const;
157 
162  bool setCurrentStyle( const QString &name );
163 
169  bool setOverrideStyle( const QString &styleDef );
171  bool restoreOverrideStyle();
172 
178  bool isDefault( const QString &styleName ) const;
179 
180  signals:
182  void styleAdded( const QString &name );
184  void styleRemoved( const QString &name );
186  void styleRenamed( const QString &oldName, const QString &newName );
188  void currentStyleChanged( const QString &currentName );
189 
190  private:
191  QgsMapLayer *mLayer = nullptr;
192  QMap<QString, QgsMapLayerStyle> mStyles;
193  QString mCurrentStyle;
194  QgsMapLayerStyle *mOverriddenOriginalStyle = nullptr;
195  QString defaultStyleName() const;
196 };
197 
198 #endif // QGSMAPLAYERSTYLEMANAGER_H
Base class for all map layer types.
Definition: qgsmaplayer.h:56
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Stores style information (renderer, opacity, 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.