QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
89  bool operator==( const QgsSymbolLayerId &other ) const
90  {
91  return ( mSymbolKey == other.mSymbolKey && mIndexPath == other.mIndexPath );
92  }
93 
95  bool operator<( const QgsSymbolLayerId &other ) const
96  {
97  return ( mSymbolKey == other.mSymbolKey ) ?
98  mIndexPath < other.mIndexPath
99  : mSymbolKey < other.mSymbolKey;
100  }
101 
102 #ifdef SIP_RUN
103  SIP_PYOBJECT __repr__();
104  % MethodCode
105 
106  QStringList pathString;
107  for ( int path : sipCpp->symbolLayerIndexPath() )
108  {
109  pathString.append( QString::number( path ) );
110  }
111  QString str = QStringLiteral( "<QgsSymbolLayerId: %1 (%2)>" ).arg( sipCpp->symbolKey(), pathString.join( ',' ) );
112  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
113  % End
114 #endif
115 
116  private:
118  QString mSymbolKey;
119 
121  QVector<int> mIndexPath;
122 };
123 
131 class CORE_EXPORT QgsSymbolLayerReference
132 {
133  public:
136 
138  QgsSymbolLayerReference( const QString &layerId, const QgsSymbolLayerId &symbolLayer )
139  : mLayerId( layerId ), mSymbolLayerId( symbolLayer )
140  {}
141 
145  QString layerId() const { return mLayerId; }
146 
150  QgsSymbolLayerId symbolLayerId() const { return mSymbolLayerId; }
151 
153  bool operator==( const QgsSymbolLayerReference &other ) const
154  {
155  return mLayerId == other.mLayerId &&
156  mSymbolLayerId == other.mSymbolLayerId;
157  }
158 
159 #ifdef SIP_RUN
160  SIP_PYOBJECT __repr__();
161  % MethodCode
162 
163  QStringList pathString;
164  for ( int path : sipCpp->symbolLayerId().symbolLayerIndexPath() )
165  {
166  pathString.append( QString::number( path ) );
167  }
168  QString str = QStringLiteral( "<QgsSymbolLayerReference: %1 - %2 (%3)>" ).arg( sipCpp->layerId(), sipCpp->symbolLayerId().symbolKey(), pathString.join( ',' ) );
169  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
170  % End
171 #endif
172 
173  private:
174  QString mLayerId;
175  QgsSymbolLayerId mSymbolLayerId;
176 };
177 
178 inline uint qHash( const QgsSymbolLayerId &id )
179 {
180  return qHash( id.symbolKey() ) ^ qHash( id.symbolLayerIndexPath() );
181 }
182 
183 inline uint qHash( const QgsSymbolLayerReference &r )
184 {
185  return qHash( r.layerId() ) ^ qHash( r.symbolLayerId() );
186 }
187 
188 typedef QList<QgsSymbolLayerReference> QgsSymbolLayerReferenceList;
189 
196 
204 
205 #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.
bool operator==(const QgsSymbolLayerId &other) const
Equality operator.
QVector< int > symbolLayerIndexPath() const
Returns the symbol layer index path inside the symbol.
QgsSymbolLayerId(const QgsSymbolLayerId &other)=default
Default copy constructor.
QgsSymbolLayerId & operator=(const QgsSymbolLayerId &other)=default
Default assignment operator.
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.
QgsSymbolLayerReference(const QString &layerId, const QgsSymbolLayerId &symbolLayer)
Constructor.
bool operator==(const QgsSymbolLayerReference &other) const
Comparison operator.
QgsSymbolLayerId symbolLayerId() const
The symbol layer's id.
QString layerId() const
The referenced vector layer / feature renderer.
QgsSymbolLayerReference()=default
Default constructor.
Represents a vector layer which manages a vector based data sets.
#define str(x)
Definition: qgis.cpp:37
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)