QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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_sip.h"
21#include "qgis_core.h"
22#include <QList>
23#include <QVariant>
24#include <QVector>
25
26class QgsVectorLayer;
27
28// TODO QGIS 4 : Remove class QgsSymbolLayerId
29
57class CORE_EXPORT QgsSymbolLayerId
58{
59 public:
61
65 QgsSymbolLayerId( const QString &key, int index )
66 : mSymbolKey( key ), mIndexPath( { index } )
67 {}
68
72 QgsSymbolLayerId( const QString &key, const QVector<int> &indexPath )
73 : mSymbolKey( key ), mIndexPath( { indexPath } )
74 {}
75
76 QgsSymbolLayerId( const QgsSymbolLayerId &other ) = default;
77 QgsSymbolLayerId &operator=( const QgsSymbolLayerId &other ) = default;
78
82 QString symbolKey() const { return mSymbolKey; }
83
87 QVector<int> symbolLayerIndexPath() const { return mIndexPath; }
88
89 // TODO c++20 - replace with = default
90
91 bool operator==( const QgsSymbolLayerId &other ) const
92 {
93 return ( mSymbolKey == other.mSymbolKey && mIndexPath == other.mIndexPath );
94 }
95
97 bool operator<( const QgsSymbolLayerId &other ) const
98 {
99 return ( mSymbolKey == other.mSymbolKey ) ?
100 mIndexPath < other.mIndexPath
101 : mSymbolKey < other.mSymbolKey;
102 }
103
104#ifdef SIP_RUN
105 SIP_PYOBJECT __repr__();
106 % MethodCode
107
108 QStringList pathString;
109 for ( int path : sipCpp->symbolLayerIndexPath() )
110 {
111 pathString.append( QString::number( path ) );
112 }
113 QString str = QStringLiteral( "<QgsSymbolLayerId: %1 (%2)>" ).arg( sipCpp->symbolKey(), pathString.join( ',' ) );
114 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
115 % End
116#endif
117
118 private:
120 QString mSymbolKey;
121
123 QVector<int> mIndexPath;
124};
125
133class CORE_EXPORT QgsSymbolLayerReference
134{
135 public:
136
138
145 Q_DECL_DEPRECATED QgsSymbolLayerReference( const QString &layerId, const QgsSymbolLayerId &symbolLayer ) SIP_DEPRECATED
146 : mLayerId( layerId ), mDeprecatedSymbolLayerId( symbolLayer )
147 {}
148
155 QgsSymbolLayerReference( const QString &layerId, const QString &symbolLayerId )
156 : mLayerId( layerId ), 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
179 && mSymbolLayerId == other.mSymbolLayerId
180 && mDeprecatedSymbolLayerId == other.mDeprecatedSymbolLayerId;
181 }
182
183#ifdef SIP_RUN
184 SIP_PYOBJECT __repr__();
185 % MethodCode
186
187 QStringList pathString;
188 for ( int path : sipCpp->symbolLayerId().symbolLayerIndexPath() )
189 {
190 pathString.append( QString::number( path ) );
191 }
192 QString str = QStringLiteral( "<QgsSymbolLayerReference: %1 - %2>" ).arg( sipCpp->layerId(), sipCpp->symbolLayerIdV2() );
193 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
194 % End
195#endif
196
197 private:
198 QString mLayerId;
199
200 // TODO QGIS 4 : remove mDeprecatedSymbolLayerId
201 QgsSymbolLayerId mDeprecatedSymbolLayerId;
202
203 QString mSymbolLayerId;
204};
205
206inline uint qHash( const QgsSymbolLayerId &id )
207{
208 return qHash( id.symbolKey() ) ^ qHash( id.symbolLayerIndexPath() );
209}
210
211inline uint qHash( const QgsSymbolLayerReference &r )
212{
213 return qHash( r.layerId() ) ^ qHash( r.symbolLayerIdV2() );
214}
215
216typedef QList<QgsSymbolLayerReference> QgsSymbolLayerReferenceList;
217
224
232
233#endif
We may need stable references to symbol layers, when pointers to symbol layers is 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 data sets.
#define str(x)
Definition qgis.cpp:38
#define SIP_DEPRECATED
Definition qgis_sip.h:106
QList< QgsSymbolLayerReference > QgsSymbolLayerReferenceList
CORE_EXPORT QString symbolLayerReferenceListToString(const QgsSymbolLayerReferenceList &)
Utilitary function to turn a QgsSymbolLayerReferenceList into a string.
CORE_EXPORT QgsSymbolLayerReferenceList stringToSymbolLayerReferenceList(const QString &)
Utilitary function to parse a string originated from symbolLayerReferenceListToString into a QgsSymbo...
uint qHash(const QgsSymbolLayerId &id)