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()
176 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.
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider.
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
Return whether the node should be shown as expanded or collapsed in GUI.
void layerLoaded()
Emitted when a previously unavailable layer got loaded.
virtual QString name() const =0
Return 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.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
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.
Reads and writes project states.
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)
Set whether the node should be shown as expanded or collapsed in GUI.
Leaf node pointing to a layer.
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 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)
QString dump() const override
Return 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)