QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
32QVector<QgsSelectiveMaskSource> QgsSelectiveMaskingSourceSet::sources() const
33{
34 return mSources;
35}
36
37void QgsSelectiveMaskingSourceSet::setSources( const QVector<QgsSelectiveMaskSource> &sources )
38{
39 mSources = sources;
40 mIsValid = true;
41}
42
44{
45 mSources.append( source );
46}
47
48QDomElement QgsSelectiveMaskingSourceSet::writeXml( QDomDocument &document, const QgsReadWriteContext & ) const
49{
50 QDomElement setElem = document.createElement( u"selectiveMaskingSourceSet"_s );
51 setElem.setAttribute( u"id"_s, mId );
52 setElem.setAttribute( u"name"_s, mName );
53
54 for ( const QgsSelectiveMaskSource &source : mSources )
55 {
56 QDomElement sourceElem = document.createElement( u"source"_s );
57 sourceElem.setAttribute( u"layerId"_s, source.layerId() );
58 sourceElem.setAttribute( u"sourceType"_s, qgsEnumValueToKey( source.sourceType() ) );
59 sourceElem.setAttribute( u"sourceId"_s, source.sourceId() );
60 setElem.appendChild( sourceElem );
61 }
62
63 return setElem;
64}
65
66bool QgsSelectiveMaskingSourceSet::readXml( const QDomElement &element, const QDomDocument &, const QgsReadWriteContext & )
67{
68 if ( element.nodeName() != "selectiveMaskingSourceSet"_L1 )
69 {
70 return false;
71 }
72
73 setId( element.attribute( u"id"_s ) );
74 setName( element.attribute( u"name"_s ) );
75
76 mSources.clear();
77 const QDomNodeList sourceNodes = element.elementsByTagName( u"source"_s );
78 mSources.reserve( sourceNodes.count() );
79 for ( int i = 0; i < sourceNodes.count(); ++i )
80 {
81 const QDomElement sourceElem = sourceNodes.at( i ).toElement();
83 source.setLayerId( sourceElem.attribute( u"layerId"_s ) );
84 source.setSourceType( qgsEnumKeyToValue( sourceElem.attribute( u"sourceType"_s ), Qgis::SelectiveMaskSourceType::SymbolLayer ) );
85 source.setSourceId( sourceElem.attribute( u"sourceId"_s ) );
86 mSources.append( source );
87 }
88
89 return true;
90}
91
93{
94 return mSources[index];
95}
96
98{
99 return mSources.size();
100}
101
103{
104 return mSources.empty();
105}
@ SymbolLayer
A mask generated from a symbol layer.
Definition qgis.h:3169
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:7176
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7157