21#include <QDomDocument>
26using namespace Qt::StringLiterals;
29 : mId( QUuid::createUuid().toString() )
47 mSources.append( source );
52 QDomElement setElem = document.createElement( u
"selectiveMaskingSourceSet"_s );
53 setElem.setAttribute( u
"id"_s, mId );
54 setElem.setAttribute( u
"name"_s, mName );
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 );
70 if ( element.nodeName() !=
"selectiveMaskingSourceSet"_L1 )
75 setId( element.attribute( u
"id"_s ) );
76 setName( element.attribute( u
"name"_s ) );
79 const QDomNodeList sourceNodes = element.elementsByTagName( u
"source"_s );
80 mSources.reserve( sourceNodes.count() );
81 for (
int i = 0; i < sourceNodes.count(); ++i )
83 const QDomElement sourceElem = sourceNodes.at( i ).toElement();
85 source.
setLayerId( sourceElem.attribute( u
"layerId"_s ) );
87 source.
setSourceId( sourceElem.attribute( u
"sourceId"_s ) );
88 mSources.append( source );
96 return mSources[index];
101 return mSources.size();
106 return mSources.empty();
@ SymbolLayer
A mask generated from a symbol layer.
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.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.