QGIS API Documentation 3.99.0-Master (e9821da5c6b)
Loading...
Searching...
No Matches
qgsselectivemaskingsourceset.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsselectivemaskingsourceset.cpp
3 ---------------
4 begin : January 2026
5 copyright : (C) 2026 by Nyall Dawson
6 email : nyall dot dawson at gmail 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
18#include "qgsreadwritecontext.h"
20
21#include <QDomDocument>
22#include <QDomElement>
23#include <QString>
24#include <QUuid>
25
26using namespace Qt::StringLiterals;
27
29 : mId( QUuid::createUuid().toString() )
30{
31
32}
33
34QVector<QgsSelectiveMaskSource> QgsSelectiveMaskingSourceSet::sources() const
35{
36 return mSources;
37}
38
39void QgsSelectiveMaskingSourceSet::setSources( const QVector<QgsSelectiveMaskSource> &sources )
40{
41 mSources = sources;
42 mIsValid = true;
43}
44
46{
47 mSources.append( source );
48}
49
50QDomElement QgsSelectiveMaskingSourceSet::writeXml( QDomDocument &document, const QgsReadWriteContext & ) const
51{
52 QDomElement setElem = document.createElement( u"selectiveMaskingSourceSet"_s );
53 setElem.setAttribute( u"id"_s, mId );
54 setElem.setAttribute( u"name"_s, mName );
55
56 for ( const QgsSelectiveMaskSource &source : mSources )
57 {
58 QDomElement sourceElem = document.createElement( u"source"_s );
59 sourceElem.setAttribute( u"layerId"_s, source.layerId() );
60 sourceElem.setAttribute( u"sourceType"_s, qgsEnumValueToKey( source.sourceType() ) );
61 sourceElem.setAttribute( u"sourceId"_s, source.sourceId() );
62 setElem.appendChild( sourceElem );
63 }
64
65 return setElem;
66}
67
68bool QgsSelectiveMaskingSourceSet::readXml( const QDomElement &element, const QDomDocument &, const QgsReadWriteContext & )
69{
70 if ( element.nodeName() != "selectiveMaskingSourceSet"_L1 )
71 {
72 return false;
73 }
74
75 setId( element.attribute( u"id"_s ) );
76 setName( element.attribute( u"name"_s ) );
77
78 mSources.clear();
79 const QDomNodeList sourceNodes = element.elementsByTagName( u"source"_s );
80 mSources.reserve( sourceNodes.count() );
81 for ( int i = 0; i < sourceNodes.count(); ++i )
82 {
83 const QDomElement sourceElem = sourceNodes.at( i ).toElement();
85 source.setLayerId( sourceElem.attribute( u"layerId"_s ) );
86 source.setSourceType( qgsEnumKeyToValue( sourceElem.attribute( u"sourceType"_s ), Qgis::SelectiveMaskSourceType::SymbolLayer ) );
87 source.setSourceId( sourceElem.attribute( u"sourceId"_s ) );
88 mSources.append( source );
89 }
90
91 return true;
92}
93
95{
96 return mSources[index];
97}
98
100{
101 return mSources.size();
102}
103
105{
106 return mSources.empty();
107}
@ SymbolLayer
A mask generated from a symbol layer.
Definition qgis.h:3126
A container for the context for various read/write operations on objects.
Encapsulates a single source for selective masking (e.g.
void setSourceId(const QString &id)
Sets the symbol layer or label rule id.
void setLayerId(const QString &id)
Sets the source layer id.
void setSourceType(Qgis::SelectiveMaskSourceType type)
Sets the source type.
void setName(const QString &name)
Sets the set's unique name.
void setSources(const QVector< QgsSelectiveMaskSource > &sources)
Sets the list of selective mask sources for this set.
bool isEmpty() const
Returns true if the set is empty.
QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const
Writes the set's state to a DOM element.
QgsSelectiveMaskingSourceSet()
Constructor for an empty (invalid) QgsSelectiveMaskingSourceSet.
void setId(const QString &id)
Sets the unique identifier for the set.
int size() const
Returns the number of sources in the set.
QVector< QgsSelectiveMaskSource > sources() const
Returns the list of selective mask sources configured in this set.
QgsSelectiveMaskSource & operator[](int index)
Returns the mask source at the specified index.
void append(const QgsSelectiveMaskSource &source)
Appends a source to the set.
bool readXml(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets the set's state from a DOM element.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition qgis.h:7134
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7115