QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgssymbollayerreference.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbollayerreference.cpp
3  ---------------------
4  begin : July 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 
17 #include "qgis.h"
18 
20 {
21  QStringList slst;
22  for ( const QgsSymbolLayerReference &ref : lst )
23  {
24  QStringList indexPathStr;
25  for ( int index : ref.symbolLayerId().symbolLayerIndexPath() )
26  {
27  indexPathStr.append( QString::number( index ) );
28  }
29  slst.append( QStringLiteral( "%1,%2,%3" ).arg( ref.layerId(), ref.symbolLayerId().symbolKey(), indexPathStr.join( ',' ) ) );
30  }
31  return slst.join( ';' );
32 }
33 
35 {
37  QStringList slst;
38  const QStringList split = str.split( ';' );
39  for ( QString tuple : split )
40  {
41  // We should have "layer_id,symbol_key,symbol_layer_index0,symbol_layer_index1,..."
42  QStringList elements = tuple.split( ',' );
43  if ( elements.size() >= 3 )
44  {
45  QVector<int> indexPath;
46  for ( int i = 2; i < elements.size(); i++ )
47  {
48  indexPath.append( elements[i].toInt() );
49  }
50  lst.append( QgsSymbolLayerReference( elements[0], QgsSymbolLayerId( elements[1], indexPath ) ) );
51  }
52  }
53  return lst;
54 }
QgsSymbolLayerReference
Type used to refer to a specific symbol layer in a symbol of a layer.
Definition: qgssymbollayerreference.h:118
qgis.h
qgssymbollayerreference.h
stringToSymbolLayerReferenceList
QgsSymbolLayerReferenceList stringToSymbolLayerReferenceList(const QString &str)
Utilitary function to parse a string originated from symbolLayerReferenceListToString into a QgsSymbo...
Definition: qgssymbollayerreference.cpp:34
symbolLayerReferenceListToString
QString symbolLayerReferenceListToString(const QgsSymbolLayerReferenceList &lst)
Utilitary function to turn a QgsSymbolLayerReferenceList into a string.
Definition: qgssymbollayerreference.cpp:19
QgsSymbolLayerReferenceList
QList< QgsSymbolLayerReference > QgsSymbolLayerReferenceList
Definition: qgssymbollayerreference.h:160
QgsSymbolLayerId
We may need stable references to symbol layers, when pointers to symbol layers is not usable (when a ...
Definition: qgssymbollayerreference.h:54