24#include "moc_qgslayertreelayer.cpp"
45 , mPatchShape( other.mPatchShape )
46 , mPatchSize( other.mPatchSize )
47 , mSplitBehavior( other.mSplitBehavior )
59 mRef.resolve( project );
63 mRef.resolveWeakly( project );
92 if (
mRef->name() == n )
108 if ( element.tagName() != QLatin1String(
"layer-tree-layer" ) )
111 const QString layerID = element.attribute( QStringLiteral(
"id" ) );
112 const QString layerName = element.attribute( QStringLiteral(
"name" ) );
114 const QString providerKey = element.attribute( QStringLiteral(
"providerKey" ) );
115 const QString sourceRaw = element.attribute( QStringLiteral(
"source" ) );
119 const bool isExpanded = ( element.attribute( QStringLiteral(
"expanded" ), QStringLiteral(
"1" ) ) == QLatin1String(
"1" ) );
120 const QString
labelExpression = element.attribute( QStringLiteral(
"legend_exp" ) );
131 const QDomElement patchElem = element.firstChildElement( QStringLiteral(
"patch" ) );
132 if ( !patchElem.isNull() )
135 patch.
readXml( patchElem, context );
156 QDomDocument doc = parentElement.ownerDocument();
157 QDomElement elem = doc.createElement( QStringLiteral(
"layer-tree-layer" ) );
158 elem.setAttribute( QStringLiteral(
"id" ),
layerId() );
159 elem.setAttribute( QStringLiteral(
"name" ),
name() );
163 const QString providerKey =
mRef->dataProvider() ?
mRef->dataProvider()->name() : QString();
165 elem.setAttribute( QStringLiteral(
"source" ), source );
166 elem.setAttribute( QStringLiteral(
"providerKey" ), providerKey );
169 elem.setAttribute( QStringLiteral(
"checked" ),
mChecked ? QStringLiteral(
"Qt::Checked" ) : QStringLiteral(
"Qt::Unchecked" ) );
170 elem.setAttribute( QStringLiteral(
"expanded" ),
mExpanded ?
"1" :
"0" );
173 if ( !mPatchShape.isNull() )
175 QDomElement patchElem = doc.createElement( QStringLiteral(
"patch" ) );
176 mPatchShape.writeXml( patchElem, doc, context );
177 elem.appendChild( patchElem );
181 elem.setAttribute( QStringLiteral(
"legend_split_behavior" ), mSplitBehavior );
185 parentElement.appendChild( elem );
198void QgsLayerTreeLayer::layerWillBeDeleted()
221void QgsLayerTreeLayer::layerNameChanged()
QString dump() const override
Returns string with layer tree structure. For debug purposes only.
void resolveReferences(const QgsProject *project, bool looseMatching=false) override
Resolves reference to layer from stored layer ID (if it has not been resolved already).
void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context) override
Write layer tree to XML.
QString layerId() const
Returns the ID for the map layer associated with this node.
QString mLabelExpression
Expression to evaluate in the legend.
void setPatchSize(QSizeF size)
Sets the user (overridden) size for the legend node.
QgsMapLayerRef mRef
Weak reference to the layer (or just it's ID if the reference is not resolved yet).
void layerWillBeUnloaded()
Emitted when a previously available layer got unloaded (from layer registry).
void setName(const QString &n) override
Sets the layer's name.
QString labelExpression() const
Returns the expression member of the LayerTreeNode.
LegendNodesSplitBehavior
Legend node column split behavior.
void setUseLayerName(bool use=true)
Uses the layer's name if use is true, or the name manually set if false.
QgsLegendPatchShape patchShape() const
Returns the symbol patch shape to use when rendering the legend node symbol.
void setLabelExpression(const QString &expression)
set the expression to evaluate
QgsLayerTreeLayer(QgsMapLayer *layer)
bool useLayerName() const
Returns whether the layer's name is used, or the name manually set.
void setPatchShape(const QgsLegendPatchShape &shape)
Sets the symbol patch shape to use when rendering the legend node symbol.
QString name() const override
Returns the layer's name.
void layerLoaded()
Emitted when a previously unavailable layer got loaded.
static QgsLayerTreeLayer * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer node from XML.
void setLegendSplitBehavior(LegendNodesSplitBehavior behavior)
Sets the column split behavior for the node.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
QString mLayerName
Layer name - only used if layer does not exist or if mUseLayerName is false.
QgsLayerTreeLayer * clone() const override
Create a copy of the node. Returns new instance.
@ NodeLayer
Leaf node pointing to a layer.
void nameChanged(QgsLayerTreeNode *node, QString name)
Emitted when the name of the node is changed.
void setExpanded(bool expanded)
Sets whether the node should be shown as expanded or collapsed in GUI.
QgsLayerTreeNode(NodeType t, bool checked=true)
Constructor.
void writeCommonXml(QDomElement &element)
Write common XML elements.
bool mExpanded
whether the node should be shown in GUI as expanded
bool isExpanded() const
Returns whether the node should be shown as expanded or collapsed in GUI.
void setItemVisibilityChecked(bool checked)
Check or uncheck a node (independently of its ancestors or children).
void readCommonXml(const QDomElement &element)
Read common XML elements.
static Qt::CheckState checkStateFromXml(const QString &txt)
Convert QString to Qt::CheckState.
Represents a patch shape for use in map legends.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Read settings from a DOM element.
Base class for all map layer types.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
void nameChanged()
Emitted when the name has been changed.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QString absoluteToRelativeUri(const QString &providerKey, const QString &uri, const QgsReadWriteContext &context) const
Converts absolute path(s) to relative path(s) in the given provider-specific URI.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString relativeToAbsoluteUri(const QString &providerKey, const QString &uri, const QgsReadWriteContext &context) const
Converts relative path(s) to absolute path(s) in the given provider-specific URI.
A container for the context for various read/write operations on objects.
static QString encodeSize(QSizeF size)
Encodes a QSizeF to a string.
static QSizeF decodeSize(const QString &string)
Decodes a QSizeF from a string.
QPointer< TYPE > layer
Weak pointer to map layer.