QGIS API Documentation 3.99.0-Master (8e76e220402)
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 <QString>
25#include <QVariant>
26#include <QVector>
27
28using namespace Qt::StringLiterals;
29
30class QgsVectorLayer;
31
32// TODO QGIS 5 : Remove class QgsSymbolLayerId
33
61class CORE_EXPORT QgsSymbolLayerId
62{
63 public:
65
69 QgsSymbolLayerId( const QString &key, int index )
70 : mSymbolKey( key ), mIndexPath( { index } )
71 {}
72
76 QgsSymbolLayerId( const QString &key, const QVector<int> &indexPath )
77 : mSymbolKey( key ), mIndexPath( { indexPath } )
78 {}
79
80 QgsSymbolLayerId( const QgsSymbolLayerId &other ) = default;
81 QgsSymbolLayerId &operator=( const QgsSymbolLayerId &other ) = default;
82
86 QString symbolKey() const { return mSymbolKey; }
87
91 QVector<int> symbolLayerIndexPath() const { return mIndexPath; }
92
93 // TODO c++20 - replace with = default
94
95 bool operator==( const QgsSymbolLayerId &other ) const
96 {
97 return ( mSymbolKey == other.mSymbolKey && mIndexPath == other.mIndexPath );
98 }
99
101 bool operator<( const QgsSymbolLayerId &other ) const
102 {
103 return ( mSymbolKey == other.mSymbolKey ) ?
104 mIndexPath < other.mIndexPath
105 : mSymbolKey < other.mSymbolKey;
106 }
107
108#ifdef SIP_RUN
109 SIP_PYOBJECT __repr__();
110 % MethodCode
111
112 QStringList pathString;
113 for ( int path : sipCpp->symbolLayerIndexPath() )
114 {
115 pathString.append( QString::number( path ) );
116 }
117 QString str = u"<QgsSymbolLayerId: %1 (%2)>"_s.arg( sipCpp->symbolKey(), pathString.join( ',' ) );
118 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
119 % End
120#endif
121
122 private:
124 QString mSymbolKey;
125
127 QVector<int> mIndexPath;
128};
129
137class CORE_EXPORT QgsSymbolLayerReference
138{
139 public:
140
142
149 Q_DECL_DEPRECATED QgsSymbolLayerReference( const QString &layerId, const QgsSymbolLayerId &symbolLayer ) SIP_DEPRECATED
150 : mLayerId( layerId ), mDeprecatedSymbolLayerId( symbolLayer )
151 {}
152
159 QgsSymbolLayerReference( const QString &layerId, const QString &symbolLayerId )
160 : mLayerId( layerId ), mSymbolLayerId( symbolLayerId )
161 {}
162
166 QString layerId() const { return mLayerId; }
167
172 Q_DECL_DEPRECATED QgsSymbolLayerId symbolLayerId() const SIP_DEPRECATED { return mDeprecatedSymbolLayerId; }
173
178 QString symbolLayerIdV2() const { return mSymbolLayerId; }
179
180 bool operator==( const QgsSymbolLayerReference &other ) const
181 {
182 return mLayerId == other.mLayerId
183 && mSymbolLayerId == other.mSymbolLayerId
184 && mDeprecatedSymbolLayerId == other.mDeprecatedSymbolLayerId;
185 }
186
187#ifdef SIP_RUN
188 SIP_PYOBJECT __repr__();
189 % MethodCode
190
191 QStringList pathString;
192 for ( int path : sipCpp->symbolLayerId().symbolLayerIndexPath() )
193 {
194 pathString.append( QString::number( path ) );
195 }
196 QString str = u"<QgsSymbolLayerReference: %1 - %2>"_s.arg( sipCpp->layerId(), sipCpp->symbolLayerIdV2() );
197 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
198 % End
199#endif
200
201 private:
202 QString mLayerId;
203
204 // TODO QGIS 5 : remove mDeprecatedSymbolLayerId
205 QgsSymbolLayerId mDeprecatedSymbolLayerId;
206
207 QString mSymbolLayerId;
208};
209
210inline uint qHash( const QgsSymbolLayerId &id )
211{
212 return qHash( id.symbolKey() ) ^ qHash( id.symbolLayerIndexPath() );
213}
214
215inline uint qHash( const QgsSymbolLayerReference &r )
216{
217 return qHash( r.layerId() ) ^ qHash( r.symbolLayerIdV2() );
218}
219
220typedef QList<QgsSymbolLayerReference> QgsSymbolLayerReferenceList;
221
228
236
237#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)