QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgssymbollayerreference.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssymbollayerreference.h
3 ---------------------
4 begin : June 2019
5 copyright : (C) 2019 by Hugo Mercier / Oslandia
6 email : infos at oslandia 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 QGSSYMBOLLAYERREFERENCE_H
17#define QGSSYMBOLLAYERREFERENCE_H
18
19#include "qgis.h"
20#include "qgis_core.h"
21#include "qgis_sip.h"
22
23#include <QList>
24#include <QVariant>
25#include <QVector>
26
27class QgsVectorLayer;
28
29// TODO QGIS 4 : Remove class QgsSymbolLayerId
30
58class CORE_EXPORT QgsSymbolLayerId
59{
60 public:
62
66 QgsSymbolLayerId( const QString &key, int index )
67 : mSymbolKey( key ), mIndexPath( { index } )
68 {}
69
73 QgsSymbolLayerId( const QString &key, const QVector<int> &indexPath )
74 : mSymbolKey( key ), mIndexPath( { indexPath } )
75 {}
76
77 QgsSymbolLayerId( const QgsSymbolLayerId &other ) = default;
78 QgsSymbolLayerId &operator=( const QgsSymbolLayerId &other ) = default;
79
83 QString symbolKey() const { return mSymbolKey; }
84
88 QVector<int> symbolLayerIndexPath() const { return mIndexPath; }
89
90 // TODO c++20 - replace with = default
91
92 bool operator==( const QgsSymbolLayerId &other ) const
93 {
94 return ( mSymbolKey == other.mSymbolKey && mIndexPath == other.mIndexPath );
95 }
96
98 bool operator<( const QgsSymbolLayerId &other ) const
99 {
100 return ( mSymbolKey == other.mSymbolKey ) ?
101 mIndexPath < other.mIndexPath
102 : mSymbolKey < other.mSymbolKey;
103 }
104
105#ifdef SIP_RUN
106 SIP_PYOBJECT __repr__();
107 % MethodCode
108
109 QStringList pathString;
110 for ( int path : sipCpp->symbolLayerIndexPath() )
111 {
112 pathString.append( QString::number( path ) );
113 }
114 QString str = QStringLiteral( "<QgsSymbolLayerId: %1 (%2)>" ).arg( sipCpp->symbolKey(), pathString.join( ',' ) );
115 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
116 % End
117#endif
118
119 private:
121 QString mSymbolKey;
122
124 QVector<int> mIndexPath;
125};
126
134class CORE_EXPORT QgsSymbolLayerReference
135{
136 public:
137
139
146 Q_DECL_DEPRECATED QgsSymbolLayerReference( const QString &layerId, const QgsSymbolLayerId &symbolLayer ) SIP_DEPRECATED
147 : mLayerId( layerId ), mDeprecatedSymbolLayerId( symbolLayer )
148 {}
149
156 QgsSymbolLayerReference( const QString &layerId, const QString &symbolLayerId )
157 : mLayerId( layerId ), mSymbolLayerId( symbolLayerId )
158 {}
159
163 QString layerId() const { return mLayerId; }
164
169 Q_DECL_DEPRECATED QgsSymbolLayerId symbolLayerId() const SIP_DEPRECATED { return mDeprecatedSymbolLayerId; }
170
175 QString symbolLayerIdV2() const { return mSymbolLayerId; }
176
177 bool operator==( const QgsSymbolLayerReference &other ) const
178 {
179 return mLayerId == other.mLayerId
180 && mSymbolLayerId == other.mSymbolLayerId
181 && mDeprecatedSymbolLayerId == other.mDeprecatedSymbolLayerId;
182 }
183
184#ifdef SIP_RUN
185 SIP_PYOBJECT __repr__();
186 % MethodCode
187
188 QStringList pathString;
189 for ( int path : sipCpp->symbolLayerId().symbolLayerIndexPath() )
190 {
191 pathString.append( QString::number( path ) );
192 }
193 QString str = QStringLiteral( "<QgsSymbolLayerReference: %1 - %2>" ).arg( sipCpp->layerId(), sipCpp->symbolLayerIdV2() );
194 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
195 % End
196#endif
197
198 private:
199 QString mLayerId;
200
201 // TODO QGIS 4 : remove mDeprecatedSymbolLayerId
202 QgsSymbolLayerId mDeprecatedSymbolLayerId;
203
204 QString mSymbolLayerId;
205};
206
207inline uint qHash( const QgsSymbolLayerId &id )
208{
209 return qHash( id.symbolKey() ) ^ qHash( id.symbolLayerIndexPath() );
210}
211
212inline uint qHash( const QgsSymbolLayerReference &r )
213{
214 return qHash( r.layerId() ) ^ qHash( r.symbolLayerIdV2() );
215}
216
217typedef QList<QgsSymbolLayerReference> QgsSymbolLayerReferenceList;
218
225
233
234#endif
We may need stable references to symbol layers, when pointers to symbol layers are not usable (when a...
bool operator<(const QgsSymbolLayerId &other) const
Comparison operator, for storage in a QSet or QMap.
QgsSymbolLayerId & operator=(const QgsSymbolLayerId &other)=default
bool operator==(const QgsSymbolLayerId &other) const
QVector< int > symbolLayerIndexPath() const
Returns the symbol layer index path inside the symbol.
QgsSymbolLayerId(const QgsSymbolLayerId &other)=default
QgsSymbolLayerId(const QString &key, int index)
QgsSymbolLayerId constructor with a symbol key and a unique symbol layer index.
QString symbolKey() const
Returns the key associated to the symbol.
QgsSymbolLayerId(const QString &key, const QVector< int > &indexPath)
QgsSymbolLayerId constructor with a symbol key and an index path.
Type used to refer to a specific symbol layer in a symbol of a layer.
bool operator==(const QgsSymbolLayerReference &other) const
QString symbolLayerIdV2() const
The symbol layer's id.
Q_DECL_DEPRECATED QgsSymbolLayerId symbolLayerId() const
The symbol layer's id.
QString layerId() const
The referenced vector layer / feature renderer.
QgsSymbolLayerReference(const QString &layerId, const QString &symbolLayerId)
Constructor.
QgsSymbolLayerReference()=default
Q_DECL_DEPRECATED QgsSymbolLayerReference(const QString &layerId, const QgsSymbolLayerId &symbolLayer)
Constructor.
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
QList< QgsSymbolLayerReference > QgsSymbolLayerReferenceList
CORE_EXPORT QString symbolLayerReferenceListToString(const QgsSymbolLayerReferenceList &)
Utility function to turn a QgsSymbolLayerReferenceList into a string.
CORE_EXPORT QgsSymbolLayerReferenceList stringToSymbolLayerReferenceList(const QString &)
Utility function to parse a string originated from symbolLayerReferenceListToString into a QgsSymbolL...
uint qHash(const QgsSymbolLayerId &id)