QGIS API Documentation  3.17.0-Master (8af46bc54f)
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 
145  void copyStylesFrom( QgsMapLayerStyleManager *other );
146 
147  signals:
149  void styleAdded( const QString &name );
151  void styleRemoved( const QString &name );
153  void styleRenamed( const QString &oldName, const QString &newName );
155  void currentStyleChanged( const QString &currentName );
156 
157  private:
158  QgsMapLayer *mLayer = nullptr;
159  QMap<QString, QgsMapLayerStyle> mStyles;
160  QString mCurrentStyle;
161  QgsMapLayerStyle *mOverriddenOriginalStyle = nullptr;
162  QString defaultStyleName() const;
163 };
164 
165 #endif // QGSMAPLAYERSTYLEMANAGER_H
Base class for all map layer types.
Definition: qgsmaplayer.h:83
#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.