QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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
qgsmaplayerstyle.h
QgsMapLayerStyleManager::styleRenamed
void styleRenamed(const QString &oldName, const QString &newName)
Emitted when a style has been renamed.
QgsMapLayerStyleManager::currentStyleChanged
void currentStyleChanged(const QString &currentName)
Emitted when the current style has been changed.
QgsMapLayerStyleManager
Management of styles for use with one map layer.
Definition: qgsmaplayerstylemanager.h:56
QgsMapLayerStyleManager::styleAdded
void styleAdded(const QString &name)
Emitted when a new style has been added.
qgis_sip.h
QgsMapLayerStyleManager::styleRemoved
void styleRemoved(const QString &name)
Emitted when a style has been removed.
QgsMapLayerStyleManager::layer
QgsMapLayer * layer() const
Gets pointer to the associated map layer.
Definition: qgsmaplayerstylemanager.h:67
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsMapLayerStyle
Stores style information (renderer, opacity, labeling, diagrams etc.) applicable to a map layer.
Definition: qgsmaplayerstyle.h:43
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53