QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 #include "qgsmaplayerstyle.h"
22 
23 #include <QByteArray>
24 #include <QMap>
25 #include <QStringList>
26 #include <QObject>
27 
28 
29 class QDomElement;
30 
31 class QgsMapLayer;
32 
55 class CORE_EXPORT QgsMapLayerStyleManager : public QObject
56 {
57  Q_OBJECT
58  public:
59 
65 
67  QgsMapLayer *layer() const { return mLayer; }
68 
70  void reset();
71 
73  void readXml( const QDomElement &mgrElement );
75  void writeXml( QDomElement &mgrElement ) const;
76 
78  QStringList styles() const;
79 
85  QMap<QString, QgsMapLayerStyle> mapLayerStyles() const;
86 
88  QgsMapLayerStyle style( const QString &name ) const;
89 
94  bool addStyle( const QString &name, const QgsMapLayerStyle &style );
95 
100  bool addStyleFromLayer( const QString &name );
101 
106  bool removeStyle( const QString &name );
107 
112  bool renameStyle( const QString &name, const QString &newName );
113 
115  QString currentStyle() const;
116 
121  bool setCurrentStyle( const QString &name );
122 
128  bool setOverrideStyle( const QString &styleDef );
130  bool restoreOverrideStyle();
131 
137  bool isDefault( const QString &styleName ) const;
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 = nullptr;
151  QMap<QString, QgsMapLayerStyle> mStyles;
152  QString mCurrentStyle;
153  QgsMapLayerStyle *mOverriddenOriginalStyle = nullptr;
154  QString defaultStyleName() const;
155 };
156 
157 #endif // QGSMAPLAYERSTYLEMANAGER_H
Base class for all map layer types.
Definition: qgsmaplayer.h:79
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
Stores style information (renderer, opacity, labeling, diagrams etc.) applicable to a map layer...
QgsMapLayer * layer() const
Gets pointer to the associated map layer.
Management of styles for use with one map layer.