QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
symbology
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
16
#include "
qgssymbollayerreference.h
"
17
18
#include "
qgis.h
"
19
20
#include <QRegularExpression>
21
#include <QString>
22
23
using namespace
Qt::StringLiterals;
24
25
QString
symbolLayerReferenceListToString
(
const
QgsSymbolLayerReferenceList
&lst )
26
{
27
QStringList slst;
28
slst.reserve( lst.size() * 2 );
29
for
(
const
QgsSymbolLayerReference
&ref : lst )
30
{
31
slst << ref.layerId();
32
slst << ref.symbolLayerIdV2();
33
}
34
return
slst.join(
';'
);
35
}
36
37
QgsSymbolLayerReferenceList
stringToSymbolLayerReferenceList
(
const
QString &str )
38
{
39
QgsSymbolLayerReferenceList
lst;
40
if
( str.isEmpty() )
41
return
lst;
42
43
if
( str.contains(
','
) )
44
{
45
// TODO QGIS 5 : remove this if branch, keep only else part
46
Q_NOWARN_DEPRECATED_PUSH
47
48
// old masked symbol layer format (before 3.30), we use unique id now!
49
// we load it the old fashion way and we will update the new one later when
50
// the whole project is loaded
51
52
// when saving we used ; as a concatenator... but that was silly, cos maybe the symbol keys contain this string!
53
// try to handle this gracefully via regex...
54
const
thread_local
QRegularExpression partsRx( u
"((?:.*?),(?:.*?),(?:(?:\\d+,)+)?(?:\\d+);)"
_s );
55
QRegularExpressionMatchIterator partsIt = partsRx.globalMatch( str +
';'
);
56
57
while
( partsIt.hasNext() )
58
{
59
const
QRegularExpressionMatch partMatch = partsIt.next();
60
const
QString tuple = partMatch.captured( 1 );
61
62
// We should have "layer_id,symbol_key,symbol_layer_index0,symbol_layer_index1,..."
63
// EXCEPT that the symbol_key CAN have commas, so this whole logic is extremely broken.
64
// Let's see if a messy regex can save the day!
65
const
thread_local
QRegularExpression rx( u
"(.*?),(.*?),((?:\\d+,)+)?(\\d+)"
_s );
66
67
const
QRegularExpressionMatch match = rx.match( tuple );
68
if
( !match.hasMatch() )
69
continue
;
70
71
const
QString layerId = match.captured( 1 );
72
const
QString symbolKey = match.captured( 2 );
73
const
QStringList indices = QString( match.captured( 3 ) + match.captured( 4 ) ).split(
','
);
74
75
QVector<int> indexPath;
76
indexPath.reserve( indices.size() );
77
for
(
const
QString &index : indices )
78
{
79
indexPath.append( index.toInt() );
80
}
81
lst.append(
QgsSymbolLayerReference
( layerId,
QgsSymbolLayerId
( symbolKey, indexPath ) ) );
82
Q_NOWARN_DEPRECATED_POP
83
}
84
}
85
else
86
{
87
const
QStringList elems = str.split(
';'
);
88
for
(
int
i = 0; i < elems.size(); )
89
{
90
lst <<
QgsSymbolLayerReference
( elems[i], elems[i + 1] );
91
i += 2;
92
}
93
}
94
95
return
lst;
96
}
QgsSymbolLayerId
We may need stable references to symbol layers, when pointers to symbol layers are not usable (when a...
Definition
qgssymbollayerreference.h:62
QgsSymbolLayerReference
Type used to refer to a specific symbol layer in a symbol of a layer.
Definition
qgssymbollayerreference.h:136
qgis.h
Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_POP
Definition
qgis.h:8407
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition
qgis.h:8406
symbolLayerReferenceListToString
QString symbolLayerReferenceListToString(const QgsSymbolLayerReferenceList &lst)
Utility function to turn a QgsSymbolLayerReferenceList into a string.
Definition
qgssymbollayerreference.cpp:25
stringToSymbolLayerReferenceList
QgsSymbolLayerReferenceList stringToSymbolLayerReferenceList(const QString &str)
Utility function to parse a string originated from symbolLayerReferenceListToString into a QgsSymbolL...
Definition
qgssymbollayerreference.cpp:37
qgssymbollayerreference.h
QgsSymbolLayerReferenceList
QList< QgsSymbolLayerReference > QgsSymbolLayerReferenceList
Definition
qgssymbollayerreference.h:218
Generated on
for QGIS API Documentation by
1.17.0