QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
27 , mLayerName( layer->name() )
34 , mRef( layerId, name, source, provider )
35 , mLayerName( name.isEmpty() ? QStringLiteral(
"(?)" ) : name )
42 , mLayerName( other.mLayerName )
43 , mPatchShape( other.mPatchShape )
44 , mPatchSize( other.mPatchSize )
45 , mSplitBehavior( other.mSplitBehavior )
106 if ( element.tagName() != QLatin1String(
"layer-tree-layer" ) )
109 const QString layerID = element.attribute( QStringLiteral(
"id" ) );
110 const QString layerName = element.attribute( QStringLiteral(
"name" ) );
112 const QString providerKey = element.attribute( QStringLiteral(
"providerKey" ) );
113 const QString source = context.
pathResolver().
readPath( element.attribute( QStringLiteral(
"source" ) ) );
116 const bool isExpanded = ( element.attribute( QStringLiteral(
"expanded" ), QStringLiteral(
"1" ) ) == QLatin1String(
"1" ) );
117 const QString
labelExpression = element.attribute( QStringLiteral(
"legend_exp" ) );
128 const QDomElement patchElem = element.firstChildElement( QStringLiteral(
"patch" ) );
129 if ( !patchElem.isNull() )
132 patch.
readXml( patchElem, context );
153 QDomDocument doc = parentElement.ownerDocument();
154 QDomElement elem = doc.createElement( QStringLiteral(
"layer-tree-layer" ) );
155 elem.setAttribute( QStringLiteral(
"id" ),
layerId() );
156 elem.setAttribute( QStringLiteral(
"name" ),
name() );
164 elem.setAttribute( QStringLiteral(
"checked" ),
mChecked ? QStringLiteral(
"Qt::Checked" ) : QStringLiteral(
"Qt::Unchecked" ) );
165 elem.setAttribute( QStringLiteral(
"expanded" ),
mExpanded ?
"1" :
"0" );
168 if ( !mPatchShape.
isNull() )
170 QDomElement patchElem = doc.createElement( QStringLiteral(
"patch" ) );
171 mPatchShape.
writeXml( patchElem, doc, context );
172 elem.appendChild( patchElem );
176 elem.setAttribute( QStringLiteral(
"legend_split_behavior" ), mSplitBehavior );
180 parentElement.appendChild( elem );
193 void QgsLayerTreeLayer::layerWillBeDeleted()
216 void QgsLayerTreeLayer::layerNameChanged()
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
QString labelExpression() const
Returns the expression member of the LayerTreeNode.
QgsLayerTreeLayer(QgsMapLayer *layer)
This class is a base class for nodes in a layer tree.
QgsLegendPatchShape patchShape() const
Returns the symbol patch shape to use when rendering the legend node symbol.
void setItemVisibilityChecked(bool checked)
Check or uncheck a node (independently of its ancestors or children)
TYPE * resolveWeakly(const QgsProject *project, MatchType matchType=MatchType::All)
Resolves the map layer by attempting to find a matching layer in a project using a weak match.
The class is used as a container of context for various read/write operations on other objects.
void layerLoaded()
Emitted when a previously unavailable layer got loaded.
bool useLayerName() const
Returns whether the layer's name is used, or the name manually set.
QString layerId() const
Returns the ID for the map layer associated with this node.
void writeCommonXml(QDomElement &element)
Write common XML elements.
void setUseLayerName(bool use=true)
Uses the layer's name if use is true, or the name manually set if false.
void nameChanged(QgsLayerTreeNode *node, QString name)
Emitted when the name of the node is changed.
QString name() const override
Returns the layer's name.
QPointer< TYPE > layer
Weak pointer to map layer.
Represents a patch shape for use in map legends.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QString mLayerName
Layer name - only used if layer does not exist or if mUseLayerName is false.
QgsMapLayerRef mRef
Weak reference to the layer (or just it's ID if the reference is not resolved yet)
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context) override
Write layer tree to XML.
void setPatchSize(QSizeF size)
Sets the user (overridden) size for the legend node.
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
void setName(const QString &n) override
Sets the layer's name.
Layer tree node points to a map layer.
void nameChanged()
Emitted when the name has been changed.
LegendNodesSplitBehavior
Legend node column split behavior.
static Qt::CheckState checkStateFromXml(const QString &txt)
Convert QString to Qt::CheckState.
bool isExpanded() const
Returns whether the node should be shown as expanded or collapsed in GUI.
static QString encodeSize(QSizeF size)
Encodes a QSizeF to a string.
void layerWillBeUnloaded()
Emitted when a previously available layer got unloaded (from layer registry).
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
void setLabelExpression(const QString &expression)
set the expression to evaluate
QString mLabelExpression
Expression to evaluate in the legend.
void setName(const QString &name)
Set the display name of the layer.
Base class for all map layer types. This is the base class for all map layer types (vector,...
void resolveReferences(const QgsProject *project, bool looseMatching=false) override
Resolves reference to layer from stored layer ID (if it has not been resolved already)
QgsLayerTreeLayer * clone() const override
Create a copy of the node. Returns new instance.
bool mExpanded
whether the node should be shown in GUI as expanded
void setLegendSplitBehavior(LegendNodesSplitBehavior behavior)
Sets the column split behavior for the node.
virtual QString name() const =0
Returns a provider name.
QString dump() const override
Returns string with layer tree structure. For debug purposes only.
void setExpanded(bool expanded)
Sets whether the node should be shown as expanded or collapsed in GUI.
void writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
static QSizeF decodeSize(const QString &string)
Decodes a QSizeF from a string.
void setPatchShape(const QgsLegendPatchShape &shape)
Sets the symbol patch shape to use when rendering the legend node symbol.
static QgsLayerTreeLayer * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer node from XML.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Read settings from a DOM element.
TYPE * resolve(const QgsProject *project)
Resolves the map layer by attempting to find a layer with matching ID within a project.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
bool isNull() const
Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legen...
void readCommonXml(QDomElement &element)
Read common XML elements.