26 , mLayerName( layer->name() )
33 ,
mRef( layerId, name, source, provider )
34 ,
mLayerName( name.isEmpty() ? QStringLiteral(
"(?)" ) : name )
102 if ( element.tagName() != QLatin1String(
"layer-tree-layer" ) )
105 QString layerID = element.attribute( QStringLiteral(
"id" ) );
106 QString layerName = element.attribute( QStringLiteral(
"name" ) );
108 QString providerKey = element.attribute( QStringLiteral(
"providerKey" ) );
109 QString source = context.
pathResolver().
readPath( element.attribute( QStringLiteral(
"source" ) ) );
112 bool isExpanded = ( element.attribute( QStringLiteral(
"expanded" ), QStringLiteral(
"1" ) ) == QLatin1String(
"1" ) );
134 QDomDocument doc = parentElement.ownerDocument();
135 QDomElement elem = doc.createElement( QStringLiteral(
"layer-tree-layer" ) );
136 elem.setAttribute( QStringLiteral(
"id" ),
layerId() );
137 elem.setAttribute( QStringLiteral(
"name" ),
name() );
145 elem.setAttribute( QStringLiteral(
"checked" ),
mChecked ? QStringLiteral(
"Qt::Checked" ) : QStringLiteral(
"Qt::Unchecked" ) );
146 elem.setAttribute( QStringLiteral(
"expanded" ),
mExpanded ?
"1" :
"0" );
150 parentElement.appendChild( elem );
163 void QgsLayerTreeLayer::layerWillBeDeleted()
186 void QgsLayerTreeLayer::layerNameChanged()
The class is used as a container of context for various read/write operations on other objects...
Base class for all map layer types.
bool useLayerName() const
Returns whether the layer's name is used, or the name manually set.
void setUseLayerName(bool use=true)
Uses the layer's name if use is true, or the name manually set if false.
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
bool mExpanded
whether the node should be shown in GUI as expanded
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
TYPE * resolveWeakly(const QgsProject *project)
Resolves the map layer by attempting to find a matching layer in a project using a weak match...
bool isExpanded() const
Returns whether the node should be shown as expanded or collapsed in GUI.
void layerLoaded()
Emitted when a previously unavailable layer got loaded.
QString layerId() const
Returns the ID for the map layer associated with this node.
virtual QString name() const =0
Returns a provider name.
QgsMapLayerRef mRef
Weak reference to the layer (or just it's ID if the reference is not resolved yet) ...
QString mLayerName
Layer name - only used if layer does not exist or if mUseLayerName is false.
QString name() const override
Returns the layer's name.
void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context) override
Write layer tree to XML.
QPointer< TYPE > layer
Weak pointer to map layer.
void nameChanged()
Emitted when the name has been changed.
void writeCommonXml(QDomElement &element)
Write common XML elements.
This class is a base class for nodes in a layer tree.
static Qt::CheckState checkStateFromXml(const QString &txt)
Convert QString to Qt::CheckState.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example...
void setName(const QString &name)
Set the display name of the layer.
void setName(const QString &n) override
Sets the layer's name.
void setExpanded(bool expanded)
Sets whether the node should be shown as expanded or collapsed in GUI.
Leaf node pointing to a layer.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
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 readCommonXml(QDomElement &element)
Read common XML elements.
QString mLabelExpression
Expression to evaluate in the legend.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
void layerWillBeUnloaded()
Emitted when a previously available layer got unloaded (from layer registry).
void setItemVisibilityChecked(bool checked)
Check or uncheck a node (independently of its ancestors or children)
void setLabelExpression(const QString &expression)
set the expression to evaluate
QString dump() const override
Returns string with layer tree structure. For debug purposes only.
void nameChanged(QgsLayerTreeNode *node, QString name)
Emitted when the name of the node is changed.
TYPE * resolve(const QgsProject *project)
Resolves the map layer by attempting to find a layer with matching ID within a project.
static QgsLayerTreeLayer * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer node from XML.
QgsLayerTreeLayer * clone() const override
Create a copy of the node. Returns new instance.
Layer tree node points to a map layer.
QgsLayerTreeLayer(QgsMapLayer *layer)