QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
50 class CORE_EXPORT QgsSymbolLayerId
51 {
52  public:
54 
58  QgsSymbolLayerId( QString key, int index )
59  : mSymbolKey( key ), mIndexPath( { index } )
60  {}
61 
65  QgsSymbolLayerId( QString key, const QVector<int> &indexPath )
66  : mSymbolKey( key ), mIndexPath( { indexPath } )
67  {}
68 
70  QgsSymbolLayerId( const QgsSymbolLayerId &other ) = default;
71 
73  QgsSymbolLayerId &operator=( const QgsSymbolLayerId &other ) = default;
74 
78  QString symbolKey() const { return mSymbolKey; }
79 
83  QVector<int> symbolLayerIndexPath() const { return mIndexPath; }
84 
86  bool operator==( const QgsSymbolLayerId &other ) const
87  {
88  return ( mSymbolKey == other.mSymbolKey && mIndexPath == other.mIndexPath );
89  }
90 
92  bool operator<( const QgsSymbolLayerId &other ) const
93  {
94  return ( mSymbolKey == other.mSymbolKey ) ?
95  mIndexPath < other.mIndexPath
96  : mSymbolKey < other.mSymbolKey;
97  }
98 
99  private:
101  QString mSymbolKey;
102 
104  QVector<int> mIndexPath;
105 };
106 
114 class CORE_EXPORT QgsSymbolLayerReference
115 {
116  public:
118  QgsSymbolLayerReference() = default;
119 
121  QgsSymbolLayerReference( const QString &layerId, const QgsSymbolLayerId &symbolLayer )
122  : mLayerId( layerId ), mSymbolLayerId( symbolLayer )
123  {}
124 
128  QString layerId() const { return mLayerId; }
129 
133  QgsSymbolLayerId symbolLayerId() const { return mSymbolLayerId; }
134 
136  bool operator==( const QgsSymbolLayerReference &other ) const
137  {
138  return mLayerId == other.mLayerId &&
139  mSymbolLayerId == other.mSymbolLayerId;
140  }
141 
142  private:
143  QString mLayerId;
144  QgsSymbolLayerId mSymbolLayerId;
145 };
146 
147 inline uint qHash( const QgsSymbolLayerId &id )
148 {
149  return qHash( id.symbolKey() ) ^ qHash( id.symbolLayerIndexPath() );
150 }
151 
152 inline uint qHash( const QgsSymbolLayerReference &r )
153 {
154  return qHash( r.layerId() ) ^ qHash( r.symbolLayerId() );
155 }
156 
157 typedef QList<QgsSymbolLayerReference> QgsSymbolLayerReferenceList;
158 
165 
173 
174 #endif
QString layerId() const
The referenced vector layer / feature renderer.
QgsSymbolLayerId(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.
uint qHash(const QgsSymbolLayerId &id)
QgsSymbolLayerId(QString key, const QVector< int > &indexPath)
QgsSymbolLayerId constructor with a symbol key and an index path.
CORE_EXPORT QgsSymbolLayerReferenceList stringToSymbolLayerReferenceList(const QString &)
Utilitary function to parse a string originated from symbolLayerReferenceListToString into a QgsSymbo...
QVector< int > symbolLayerIndexPath() const
Returns the symbol layer index path inside the symbol.
bool operator==(const QgsSymbolLayerId &other) const
Equality operator.
bool operator==(const QgsSymbolLayerReference &other) const
Comparison operator.
bool operator<(const QgsSymbolLayerId &other) const
Comparison operator, for storage in a QSet or QMap.
QList< QgsSymbolLayerReference > QgsSymbolLayerReferenceList
QgsSymbolLayerId symbolLayerId() const
The symbol layer&#39;s id.
CORE_EXPORT QString symbolLayerReferenceListToString(const QgsSymbolLayerReferenceList &)
Utilitary function to turn a QgsSymbolLayerReferenceList into a string.
QgsSymbolLayerReference(const QString &layerId, const QgsSymbolLayerId &symbolLayer)
Constructor.
Type used to refer to a specific symbol layer in a symbol of a layer.
Represents a vector layer which manages a vector based data sets.
We may need stable references to symbol layers, when pointers to symbol layers is not usable (when a ...