QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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_sip.h"
20 #include "qgis_core.h"
21 #include <QList>
22 #include <QVariant>
23 #include <QVector>
24 
25 class QgsVectorLayer;
26 
53 class CORE_EXPORT QgsSymbolLayerId
54 {
55  public:
57 
61  QgsSymbolLayerId( const QString &key, int index )
62  : mSymbolKey( key ), mIndexPath( { index } )
63  {}
64 
68  QgsSymbolLayerId( const QString &key, const QVector<int> &indexPath )
69  : mSymbolKey( key ), mIndexPath( { indexPath } )
70  {}
71 
73  QgsSymbolLayerId( const QgsSymbolLayerId &other ) = default;
74 
76  QgsSymbolLayerId &operator=( const QgsSymbolLayerId &other ) = default;
77 
81  QString symbolKey() const { return mSymbolKey; }
82 
86  QVector<int> symbolLayerIndexPath() const { return mIndexPath; }
87 
88  // TODO c++20 - replace with = default
89 
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 
133 class CORE_EXPORT QgsSymbolLayerReference
134 {
135  public:
137  QgsSymbolLayerReference() = default;
138 
140  QgsSymbolLayerReference( const QString &layerId, const QgsSymbolLayerId &symbolLayer )
141  : mLayerId( layerId ), mSymbolLayerId( symbolLayer )
142  {}
143 
147  QString layerId() const { return mLayerId; }
148 
152  QgsSymbolLayerId symbolLayerId() const { return mSymbolLayerId; }
153 
155  bool operator==( const QgsSymbolLayerReference &other ) const
156  {
157  return mLayerId == other.mLayerId &&
158  mSymbolLayerId == other.mSymbolLayerId;
159  }
160 
161 #ifdef SIP_RUN
162  SIP_PYOBJECT __repr__();
163  % MethodCode
164 
165  QStringList pathString;
166  for ( int path : sipCpp->symbolLayerId().symbolLayerIndexPath() )
167  {
168  pathString.append( QString::number( path ) );
169  }
170  QString str = QStringLiteral( "<QgsSymbolLayerReference: %1 - %2 (%3)>" ).arg( sipCpp->layerId(), sipCpp->symbolLayerId().symbolKey(), pathString.join( ',' ) );
171  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
172  % End
173 #endif
174 
175  private:
176  QString mLayerId;
177  QgsSymbolLayerId mSymbolLayerId;
178 };
179 
180 inline uint qHash( const QgsSymbolLayerId &id )
181 {
182  return qHash( id.symbolKey() ) ^ qHash( id.symbolLayerIndexPath() );
183 }
184 
185 inline uint qHash( const QgsSymbolLayerReference &r )
186 {
187  return qHash( r.layerId() ) ^ qHash( r.symbolLayerId() );
188 }
189 
190 typedef QList<QgsSymbolLayerReference> QgsSymbolLayerReferenceList;
191 
198 
206 
207 #endif
QgsSymbolLayerId::operator==
bool operator==(const QgsSymbolLayerId &other) const
Equality operator.
Definition: qgssymbollayerreference.h:91
QgsSymbolLayerReference
Type used to refer to a specific symbol layer in a symbol of a layer.
Definition: qgssymbollayerreference.h:133
QgsSymbolLayerId::QgsSymbolLayerId
QgsSymbolLayerId()
Definition: qgssymbollayerreference.h:56
QgsSymbolLayerId::QgsSymbolLayerId
QgsSymbolLayerId(const QString &key, const QVector< int > &indexPath)
QgsSymbolLayerId constructor with a symbol key and an index path.
Definition: qgssymbollayerreference.h:68
QgsSymbolLayerReference::operator==
bool operator==(const QgsSymbolLayerReference &other) const
Comparison operator.
Definition: qgssymbollayerreference.h:155
qgis_sip.h
QgsSymbolLayerId::QgsSymbolLayerId
QgsSymbolLayerId(const QString &key, int index)
QgsSymbolLayerId constructor with a symbol key and a unique symbol layer index.
Definition: qgssymbollayerreference.h:61
QgsSymbolLayerReference::symbolLayerId
QgsSymbolLayerId symbolLayerId() const
The symbol layer's id.
Definition: qgssymbollayerreference.h:152
qHash
uint qHash(const QgsSymbolLayerId &id)
Definition: qgssymbollayerreference.h:180
QgsSymbolLayerId::symbolLayerIndexPath
QVector< int > symbolLayerIndexPath() const
Returns the symbol layer index path inside the symbol.
Definition: qgssymbollayerreference.h:86
QgsSymbolLayerReference::QgsSymbolLayerReference
QgsSymbolLayerReference(const QString &layerId, const QgsSymbolLayerId &symbolLayer)
Constructor.
Definition: qgssymbollayerreference.h:140
QgsSymbolLayerReferenceList
QList< QgsSymbolLayerReference > QgsSymbolLayerReferenceList
Definition: qgssymbollayerreference.h:190
str
#define str(x)
Definition: qgis.cpp:37
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsSymbolLayerId::operator<
bool operator<(const QgsSymbolLayerId &other) const
Comparison operator, for storage in a QSet or QMap.
Definition: qgssymbollayerreference.h:97
stringToSymbolLayerReferenceList
CORE_EXPORT QgsSymbolLayerReferenceList stringToSymbolLayerReferenceList(const QString &)
Utilitary function to parse a string originated from symbolLayerReferenceListToString into a QgsSymbo...
Definition: qgssymbollayerreference.cpp:40
QgsSymbolLayerId
We may need stable references to symbol layers, when pointers to symbol layers is not usable (when a ...
Definition: qgssymbollayerreference.h:53
QgsSymbolLayerId::symbolKey
QString symbolKey() const
Returns the key associated to the symbol.
Definition: qgssymbollayerreference.h:81
QgsSymbolLayerReference::layerId
QString layerId() const
The referenced vector layer / feature renderer.
Definition: qgssymbollayerreference.h:147
symbolLayerReferenceListToString
CORE_EXPORT QString symbolLayerReferenceListToString(const QgsSymbolLayerReferenceList &)
Utilitary function to turn a QgsSymbolLayerReferenceList into a string.
Definition: qgssymbollayerreference.cpp:20