16 if ( !file.
open( QIODevice::ReadOnly ) )
18 errorMessage =
QString(
"Can not open file" );
26 errorMessage = message;
38 Q_UNUSED( errorMessage );
44 for (
int i = 0; i < ids.
size(); ++i )
56 for (
int i = 0; i < treeLayerNodes.
count(); ++i )
60 if ( layerElem.
attribute(
"id" ) == oldid )
68 bool loadInLegend =
true;
69 if ( !layerTreeElem.
isNull() )
92 path = path.
append(
".qlr" );
119 if ( file.
open( QFile::WriteOnly | QFile::Truncate ) )
122 doc.
save( qlayerstream, 2 );
Layer tree group node serves as a container for layers and further groups.
QString toString(Qt::DateFormat format) const
QString & append(QChar ch)
void readChildrenFromXML(QDomElement &element)
Read children from XML and append them to the group.
QDomNode appendChild(const QDomNode &newChild)
bool writeLayerXML(QDomElement &layerElement, QDomDocument &document, QString relativeBasePath=QString::null)
stores state in Dom node
bool takeChild(QgsLayerTreeNode *node)
Remove a child from a node.
QString attribute(const QString &name, const QString &defValue) const
QgsMapLayer * layer() const
QString errorString() const
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
static bool exportLayerDefinition(QString path, QList< QgsLayerTreeNode * > selectedTreeNodes, QString &errorMessage)
Export the selected layer tree nodes to a QLR file.
QDomElement documentElement() const
void insertChildNodes(int index, QList< QgsLayerTreeNode * > nodes)
Insert existing nodes at specified position. The nodes must not have a parent yet. The nodes will be owned by this group.
QDomElement toElement() const
QString canonicalFilePath() const
QString number(int n, int base)
QList< QgsMapLayer * > addMapLayers(QList< QgsMapLayer * > theMapLayers, bool addToLegend=true, bool takeOwnership=true)
Add a list of layers to the map of loaded layers.
void setAttribute(const QString &name, const QString &value)
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes. Searches recursively the whole sub-tree.
QDomNodeList elementsByTagName(const QString &tagname) const
void setNodeValue(const QString &v)
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
This class is a base class for nodes in a layer tree.
bool setCurrent(const QString &path)
QList< QgsLayerTreeNode * > children()
Get list of children of the node. Children are owned by the parent.
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
virtual void writeXML(QDomElement &parentElement) override
Write group (tree) as XML element <layer-tree-group> and add it to the given parent element...
QDateTime currentDateTime()
void save(QTextStream &str, int indent) const
QDomNode firstChild() const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QDomElement firstChildElement(const QString &tagName) const
void addChildNode(QgsLayerTreeNode *node)
Append an existing node. The node must not have a parent yet. The node will be owned by this group...
QString left(int n) const
static QList< QgsMapLayer * > fromLayerDefinition(QDomDocument &document)
Creates a new layer from a layer defininition document.
QDomElement createElement(const QString &tagName)
static bool loadLayerDefinition(const QString &path, QgsLayerTreeGroup *rootGroup, QString &errorMessage)
Loads the QLR at path into QGIS.
Layer tree node points to a map layer.
QDomNode at(int index) const
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)