QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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( QString key, int index )
62  : mSymbolKey( key ), mIndexPath( { index } )
63  {}
64 
68  QgsSymbolLayerId( 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  private:
104  QString mSymbolKey;
105 
107  QVector<int> mIndexPath;
108 };
109 
117 class CORE_EXPORT QgsSymbolLayerReference
118 {
119  public:
121  QgsSymbolLayerReference() = default;
122 
124  QgsSymbolLayerReference( const QString &layerId, const QgsSymbolLayerId &symbolLayer )
125  : mLayerId( layerId ), mSymbolLayerId( symbolLayer )
126  {}
127 
131  QString layerId() const { return mLayerId; }
132 
136  QgsSymbolLayerId symbolLayerId() const { return mSymbolLayerId; }
137 
139  bool operator==( const QgsSymbolLayerReference &other ) const
140  {
141  return mLayerId == other.mLayerId &&
142  mSymbolLayerId == other.mSymbolLayerId;
143  }
144 
145  private:
146  QString mLayerId;
147  QgsSymbolLayerId mSymbolLayerId;
148 };
149 
150 inline uint qHash( const QgsSymbolLayerId &id )
151 {
152  return qHash( id.symbolKey() ) ^ qHash( id.symbolLayerIndexPath() );
153 }
154 
155 inline uint qHash( const QgsSymbolLayerReference &r )
156 {
157  return qHash( r.layerId() ) ^ qHash( r.symbolLayerId() );
158 }
159 
160 typedef QList<QgsSymbolLayerReference> QgsSymbolLayerReferenceList;
161 
168 
176 
177 #endif
QgsSymbolLayerId::QgsSymbolLayerId
QgsSymbolLayerId(QString key, const QVector< int > &indexPath)
QgsSymbolLayerId constructor with a symbol key and an index path.
Definition: qgssymbollayerreference.h:68
QgsSymbolLayerId::operator==
bool operator==(const QgsSymbolLayerId &other) const
Equality operator.
Definition: qgssymbollayerreference.h:89
QgsSymbolLayerReference
Definition: qgssymbollayerreference.h:117
QgsSymbolLayerId::QgsSymbolLayerId
QgsSymbolLayerId()
Definition: qgssymbollayerreference.h:56
QgsSymbolLayerId::QgsSymbolLayerId
QgsSymbolLayerId(QString key, int index)
QgsSymbolLayerId constructor with a symbol key and a unique symbol layer index.
Definition: qgssymbollayerreference.h:61
QgsSymbolLayerReference::operator==
bool operator==(const QgsSymbolLayerReference &other) const
Comparison operator.
Definition: qgssymbollayerreference.h:139
qgis_sip.h
QgsSymbolLayerReference::symbolLayerId
QgsSymbolLayerId symbolLayerId() const
The symbol layer's id.
Definition: qgssymbollayerreference.h:136
qHash
uint qHash(const QgsSymbolLayerId &id)
Definition: qgssymbollayerreference.h:150
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:124
QgsSymbolLayerReferenceList
QList< QgsSymbolLayerReference > QgsSymbolLayerReferenceList
Definition: qgssymbollayerreference.h:160
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsSymbolLayerId::operator<
bool operator<(const QgsSymbolLayerId &other) const
Comparison operator, for storage in a QSet or QMap.
Definition: qgssymbollayerreference.h:95
stringToSymbolLayerReferenceList
CORE_EXPORT QgsSymbolLayerReferenceList stringToSymbolLayerReferenceList(const QString &)
Utilitary function to parse a string originated from symbolLayerReferenceListToString into a QgsSymbo...
Definition: qgssymbollayerreference.cpp:34
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:131
symbolLayerReferenceListToString
CORE_EXPORT QString symbolLayerReferenceListToString(const QgsSymbolLayerReferenceList &)
Utilitary function to turn a QgsSymbolLayerReferenceList into a string.
Definition: qgssymbollayerreference.cpp:19