24 #include <QDomElement>
37 for (
int i = 0; i < legendChildren.
size(); ++i )
40 if ( currentChildElem.
tagName() ==
"legendlayer" )
44 else if ( currentChildElem.
tagName() ==
"legendgroup" )
59 for (
int i = 0; i < legendChildren.
size(); ++i )
62 if ( currentChildElem.
tagName() ==
"legendlayer" )
66 int layerIndex = currentChildElem.
attribute(
"drawingOrder" ).
toInt();
67 if ( layerIndex == -1 )
69 layerIndexes.
insert( layerIndex, layerFileElem.
attribute(
"layerid" ) );
71 else if ( currentChildElem.
tagName() ==
"legendgroup" )
87 hasCustomOrder = legendElem.
attribute(
"updateDrawingOrder" ) ==
"false";
95 if ( !res && hasCustomOrder )
98 Q_FOREACH (
const QString& layerId, layerIndexes )
110 int drawingOrder = -1;
111 if ( hasCustomOrder )
175 legendElem.
setAttribute(
"updateDrawingOrder", hasCustomOrder ?
"false" :
"true" );
187 case Qt::Unchecked:
return "Qt::Unchecked";
188 case Qt::PartiallyChecked:
return "Qt::PartiallyChecked";
189 case Qt::Checked:
default:
return "Qt::Checked";
195 if ( txt ==
"Qt::Unchecked" )
196 return Qt::Unchecked;
197 else if ( txt ==
"Qt::PartiallyChecked" )
198 return Qt::PartiallyChecked;
214 if ( groupElem.
attribute(
"embedded" ) ==
"1" )
220 for (
int i = 0; i < groupChildren.
size(); ++i )
223 if ( currentChildElem.
tagName() ==
"legendlayer" )
227 else if ( currentChildElem.
tagName() ==
"legendgroup" )
245 if ( layerFileElem.
attribute(
"isInOverview" ) ==
"1" )
248 if ( layerElem.
attribute(
"embedded" ) ==
"1" )
251 if ( layerElem.
attribute(
"showFeatureCount" ) ==
"1" )
299 nodesToRemove << node;
static QDomElement _writeOldLegendLayer(QDomDocument &doc, QgsLayerTreeLayer *nodeLayer, bool hasCustomOrder, const QStringList &order)
static bool readOldLegendLayerOrder(const QDomElement &legendElem, bool &hasCustomOrder, QStringList &order)
Try to load custom layer order from.
Layer tree group node serves as a container for layers and further groups.
static void _writeOldLegendGroupChildren(QDomDocument &doc, QDomElement &groupElem, QgsLayerTreeGroup *nodeGroup, bool hasCustomOrder, const QStringList &order)
static void removeInvalidLayers(QgsLayerTreeGroup *group)
Remove layer nodes that refer to invalid layers.
QString writePath(const QString &filename, const QString &relativeBasePath=QString::null) const
Prepare a filename to save it to the project file.
static QString checkStateToXml(Qt::CheckState state)
Convert Qt::CheckState to QString.
QDomNode appendChild(const QDomNode &newChild)
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QString attribute(const QString &name, const QString &defValue) const
QgsMapLayer * layer() const
void removeAllChildren()
Remove all child nodes. The nodes will be deleted.
static bool readOldLegend(QgsLayerTreeGroup *root, const QDomElement &legendElem)
Try to load layer tree from.
void removeChildNode(QgsLayerTreeNode *node)
Remove a child node from this group. The node will be deleted.
QDomNodeList childNodes() const
virtual bool isEditable() const override
Returns true if the provider is in editing mode.
QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group. No type checking is done - use isGroup() to find out whether this operation is ...
QDomElement toElement() const
Qt::CheckState isVisible() const
void append(const T &value)
int toInt(bool *ok) const
static void _readOldLegendLayer(const QDomElement &layerElem, QgsLayerTreeGroup *parent)
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const
static QDomElement _writeOldLegendGroup(QDomDocument &doc, QgsLayerTreeGroup *nodeGroup, bool hasCustomOrder, const QStringList &order)
static QDomElement writeOldLegend(QDomDocument &doc, QgsLayerTreeGroup *root, bool hasCustomOrder, const QStringList &order)
Return.
static void replaceChildrenOfEmbeddedGroups(QgsLayerTreeGroup *group)
Remove subtree of embedded groups and replaces it with a custom property embedded-visible-layers.
static void _readOldLegendGroup(const QDomElement &groupElem, QgsLayerTreeGroup *parent)
This class is a base class for nodes in a layer tree.
static Qt::CheckState checkStateFromXml(const QString &txt)
Convert QString to Qt::CheckState.
static void updateEmbeddedGroupsProjectPath(QgsLayerTreeGroup *group)
void setVisible(Qt::CheckState visible)
virtual bool isModified() const
Returns true if the provider has been modified since the last commit.
bool isExpanded() const
Return whether the node should be shown as expanded or collapsed in GUI.
QString name() const
Get group's name.
QList< QgsLayerTreeNode * > children()
Get list of children of the node. Children are owned by the parent.
static bool layersModified(const QList< QgsLayerTreeLayer * > &layerNodes)
Return true if any of the layers is modified.
bool isLayer(QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
Qt::CheckState isVisible() const
Return the check state of the group node.
static bool layersEditable(const QList< QgsLayerTreeLayer * > &layerNodes)
Return true if any of the layers is editable.
void setExpanded(bool expanded)
Set whether the node should be shown as expanded or collapsed in GUI.
QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer. No type checking is done - use isLayer() to find out whether this operation is ...
static QgsProject * instance()
access to canonical QgsProject instance
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...
static bool _readOldLegendLayerOrderGroup(const QDomElement &groupElem, QMap< int, QString > &layerIndexes)
int indexOf(const QRegExp &rx, int from) const
iterator insert(const Key &key, const T &value)
QDomElement createElement(const QString &tagName)
QString layerName() const
Represents a vector layer which manages a vector based data sets.
static QStringList invisibleLayerList(QgsLayerTreeNode *node)
get invisible layers
void setVisible(Qt::CheckState state)
Set check state of the group node - will also update children.
bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the node.
Layer tree node points to a map layer.
QDomNode at(int index) const