QGIS API Documentation 4.1.0-Master (60fea48833c)
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 )
71 , mIndexPath( { index } )
72 {}
73
77 QgsSymbolLayerId( const QString &key, const QVector<int> &indexPath )
78 : mSymbolKey( key )
79 , mIndexPath( { indexPath } )
80 {}
81
82 QgsSymbolLayerId( const QgsSymbolLayerId &other ) = default;
83 QgsSymbolLayerId &operator=( const QgsSymbolLayerId &other ) = default;
84
88 QString symbolKey() const { return mSymbolKey; }
89
93 QVector<int> symbolLayerIndexPath() const { return mIndexPath; }
94
95 // TODO c++20 - replace with = default
96
97 bool operator==( const QgsSymbolLayerId &other ) const { return ( mSymbolKey == other.mSymbolKey && mIndexPath == other.mIndexPath ); }
98
100 bool operator<( const QgsSymbolLayerId &other ) const { return ( mSymbolKey == other.mSymbolKey ) ? mIndexPath < other.mIndexPath : mSymbolKey < other.mSymbolKey; }
101
102#ifdef SIP_RUN
103 // clang-format off
104 SIP_PYOBJECT __repr__();
105 % MethodCode
106
107 QStringList pathString;
108 for ( int path : sipCpp->symbolLayerIndexPath() )
109 {
110 pathString.append( QString::number( path ) );
111 }
112 QString str = u"<QgsSymbolLayerId: %1 (%2)>"_s.arg( sipCpp->symbolKey(), pathString.join( ',' ) );
113 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
114 % End
115// clang-format on
116#endif
117
118 // clang-format off
119 private:
120 // clang-format on
122 QString mSymbolKey;
123
125 QVector<int> mIndexPath;
126};
127
135class CORE_EXPORT QgsSymbolLayerReference
136{
137 public:
139
146 Q_DECL_DEPRECATED QgsSymbolLayerReference( const QString &layerId, const QgsSymbolLayerId &symbolLayer ) SIP_DEPRECATED : mLayerId( layerId ), mDeprecatedSymbolLayerId( symbolLayer ) {}
147
154 QgsSymbolLayerReference( const QString &layerId, const QString &symbolLayerId )
155 : mLayerId( layerId )
156 , mSymbolLayerId( symbolLayerId )
157 {}
158
162 QString layerId() const { return mLayerId; }
163
168 Q_DECL_DEPRECATED QgsSymbolLayerId symbolLayerId() const SIP_DEPRECATED { return mDeprecatedSymbolLayerId; }
169
174 QString symbolLayerIdV2() const { return mSymbolLayerId; }
175
176 bool operator==( const QgsSymbolLayerReference &other ) const
177 {
178 return mLayerId == other.mLayerId && mSymbolLayerId == other.mSymbolLayerId && mDeprecatedSymbolLayerId == other.mDeprecatedSymbolLayerId;
179 }
180
181#ifdef SIP_RUN
182 // clang-format off
183 SIP_PYOBJECT __repr__();
184 % MethodCode
185
186 QStringList pathString;
187 for ( int path : sipCpp->symbolLayerId().symbolLayerIndexPath() )
188 {
189 pathString.append( QString::number( path ) );
190 }
191 QString str = u"<QgsSymbolLayerReference: %1 - %2>"_s.arg( sipCpp->layerId(), sipCpp->symbolLayerIdV2() );
192 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
193 % End
194// clang-format on
195#endif
196
197 // clang-format off
198 private:
199 // clang-format on
200 QString mLayerId;
201
202 // TODO QGIS 5 : remove mDeprecatedSymbolLayerId
203 QgsSymbolLayerId mDeprecatedSymbolLayerId;
204
205 QString mSymbolLayerId;
206};
207
208inline uint qHash( const QgsSymbolLayerId &id )
209{
210 return qHash( id.symbolKey() ) ^ qHash( id.symbolLayerIndexPath() );
211}
212
213inline uint qHash( const QgsSymbolLayerReference &r )
214{
215 return qHash( r.layerId() ) ^ qHash( r.symbolLayerIdV2() );
216}
217
218typedef QList<QgsSymbolLayerReference> QgsSymbolLayerReferenceList;
219
226
234
235#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:113
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)