19 #include <QTextStream> 31 if ( !file.
open( QIODevice::ReadOnly ) )
41 errorMessage = message;
53 Q_UNUSED( errorMessage );
64 Q_FOREACH (
const QDomNode& node, sortedLayerNodes )
71 for (
int i = 0; i < childNodes.
size(); i++ )
81 for (
int i = 0; i < ids.
size(); ++i )
93 for (
int i = 0; i < treeLayerNodes.
count(); ++i )
97 if ( layerElem.
attribute(
"id" ) == oldid )
105 for (
int j = 0; j < vectorJoinNodes.
size(); ++j )
109 if ( joinElement.
attribute(
"joinLayerId" ) == oldid )
117 bool loadInLegend =
true;
118 if ( !layerTreeElem.
isNull() )
121 loadInLegend =
false;
151 path = path.
append(
".qlr" );
155 if ( !file.
open( QFile::WriteOnly | QFile::Truncate ) )
168 doc.
save( qlayerstream, 2 );
174 Q_UNUSED( errorMessage );
198 void QgsLayerDefinition::DependencySorter::init(
const QDomDocument& doc )
207 for (
int i = 0; i < nl.
count(); i++ )
218 if ( !layerDependenciesElem.
isNull() )
221 for (
int j = 0; j < dependencyList.
size(); ++j )
227 dependencies[id] = deps;
232 mSortedLayerNodes << node;
233 mSortedLayerIds << id;
236 layersToSort << qMakePair(
id, node );
242 Q_FOREACH (
const QString& depId, ids )
244 if ( !dependencies.
contains( depId ) )
247 mHasMissingDependency =
true;
248 for (
int i = 0; i < nl.
size(); i++ )
249 mSortedLayerNodes << nl.
at( i );
250 mSortedLayerIds = layerIds;
260 while ( !layersToSort.
empty() && !mHasCycle )
263 while ( it != layersToSort.
end() )
268 bool resolved =
true;
269 Q_FOREACH (
const QString& dep, dependencies[idToSort] )
271 if ( !sortedLayers.
contains( dep ) )
279 sortedLayers << idToSort;
280 mSortedLayerNodes << node;
281 mSortedLayerIds << idToSort;
282 it = layersToSort.
erase( it );
295 , mHasMissingDependency( false )
302 , mHasMissingDependency( false )
305 QFile pFile( fileName );
306 ( void )pFile.
open( QIODevice::ReadOnly );
void updateFields()
Assembles mUpdatedFields considering provider fields, joined fields and added fields.
Layer tree group node serves as a container for layers and further groups.
QDomNodeList elementsByTagName(const QString &tagname) const
QString toString(Qt::DateFormat format) const
Base class for all map layer types.
QString & append(QChar ch)
QDomNode item(int index) const
bool contains(const Key &key) const
QDomNode appendChild(const QDomNode &newChild)
bool takeChild(QgsLayerTreeNode *node)
Remove a child from a node.
QString attribute(const QString &name, const QString &defValue) const
QString errorString() const
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
Class used to work with layer dependencies stored in a XML project or layer definition file...
QVector< QDomNode > sortedLayerNodes() const
Get the layer nodes in an order where they can be loaded incrementally without dependency break...
static QList< QgsMapLayer * > fromLayerDefinition(QDomDocument &document, bool addToRegistry=false, bool addToLegend=false, const QString &relativeBasePath=QString())
Creates a new layer from a layer defininition document.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
iterator erase(iterator pos)
QDomElement documentElement() const
QDomNodeList childNodes() const
QDomElement toElement() const
DependencySorter(const QDomDocument &doc)
Constructor.
QString canonicalFilePath() const
QString number(int n, int base)
void setAttribute(const QString &name, const QString &value)
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)
void insertChildNodes(int index, const 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.
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...
QDomNode namedItem(const QString &name) const
bool hasMissingDependency() const
Whether some dependency is missing.
QgsMapLayer * layer() const
bool writeLayerXML(QDomElement &layerElement, QDomDocument &document, const QString &relativeBasePath=QString())
Stores state in Dom node.
const T & at(int i) const
QDateTime currentDateTime()
void save(QTextStream &str, int indent) const
QDomNode firstChild() const
static bool exportLayerDefinition(QString path, const QList< QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage)
Export the selected layer tree nodes to a QLR file.
QDomNode replaceChild(const QDomNode &newChild, const QDomNode &oldChild)
QDomNode cloneNode(bool deep) const
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
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes. Searches recursively the whole sub-tree.
QDomElement createElement(const QString &tagName)
void readChildrenFromXML(QDomElement &element, bool looseMatch=false)
Read children from XML and append them to the group.
Represents a vector layer which manages a vector based data sets.
static bool loadLayerDefinition(const QString &path, QgsLayerTreeGroup *rootGroup, QString &errorMessage)
Loads the QLR at path into QGIS.
void createJoinCaches()
Caches joined attributes if required (and not already done)
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)