24 #include <QTextStream> 37 : QAbstractItemModel( parent )
38 , mRootNode( rootNode )
39 , mFlags( ShowLegend | AllowLegendChangeState | DeferredLegendInvalidation )
40 , mAutoCollapseLegendNodesCount( -1 )
41 , mLegendFilterByScale( 0 )
42 , mLegendFilterUsesExtent( false )
43 , mLegendMapViewMupp( 0 )
44 , mLegendMapViewDpi( 0 )
45 , mLegendMapViewScale( 0 )
62 if ( !index.isValid() )
65 QObject *obj =
reinterpret_cast<QObject *
>( index.internalPointer() );
98 if ( column < 0 || column >=
columnCount( parent ) ||
99 row < 0 || row >=
rowCount( parent ) )
100 return QModelIndex();
107 return QModelIndex();
114 return createIndex( row, column, static_cast<QObject *>( n->
children().at( row ) ) );
120 if ( !child.isValid() )
121 return QModelIndex();
134 return QModelIndex();
142 Q_ASSERT( parentNode );
145 if ( !grandParentNode )
146 return QModelIndex();
148 int row = grandParentNode->
children().indexOf( parentNode );
149 Q_ASSERT( row >= 0 );
151 return createIndex( row, 0, static_cast<QObject *>( parentNode ) );
157 if ( !index.isValid() || index.column() > 1 )
164 if ( role == Qt::DisplayRole || role == Qt::EditRole )
172 QString name = nodeLayer->
name();
173 if ( nodeLayer->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toInt() && role == Qt::DisplayRole )
177 name += QStringLiteral(
" [%1]" ).arg( vlayer->
featureCount() );
182 else if ( role == Qt::DecorationRole && index.column() == 0 )
225 QPixmap pixmap( icon.pixmap( 16, 16 ) );
227 QPainter painter( &pixmap );
231 icon = QIcon( pixmap );
237 else if ( role == Qt::CheckStateRole )
257 else if ( role == Qt::FontRole )
260 if ( node->
customProperty( QStringLiteral(
"embedded" ) ).toInt() )
263 f.setUnderline(
true );
266 else if ( role == Qt::ForegroundRole )
268 QBrush brush( Qt::black, Qt::SolidPattern );
274 brush.setColor( Qt::lightGray );
279 else if ( role == Qt::ToolTipRole )
286 !layer->
title().isEmpty() ? layer->title() :
287 !layer->shortName().isEmpty() ? layer->shortName() :
290 title =
"<b>" + title.toHtmlEscaped() +
"</b>";
292 if ( layer->crs().isValid() )
294 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ) )
297 title += tr(
" (%1)" ).arg( layer->crs().authid() ).toHtmlEscaped();
303 if ( !layer->abstract().isEmpty() )
306 const QStringList abstractLines = layer->abstract().split(
"\n" );
307 for (
const auto &l : abstractLines )
309 parts << l.toHtmlEscaped();
314 parts <<
"<i>" + layer->publicSource().toHtmlEscaped() +
"</i>";
316 return parts.join( QStringLiteral(
"<br/>" ) );
327 if ( !index.isValid() )
329 Qt::ItemFlags rootFlags = Qt::ItemFlags();
331 rootFlags |= Qt::ItemIsDropEnabled;
338 Qt::ItemFlags
f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
341 f |= Qt::ItemIsEditable;
344 bool isEmbedded = node->
customProperty( QStringLiteral(
"embedded" ) ).toInt();
349 if ( !isEmbedded || ( isEmbedded && node->
parent() && !node->
parent()->
customProperty( QStringLiteral(
"embedded" ) ).toInt() ) )
350 f |= Qt::ItemIsDragEnabled;
354 f |= Qt::ItemIsUserCheckable;
357 f |= Qt::ItemIsDropEnabled;
369 bool res = sym->
setData( value, role );
371 emit dataChanged( index, index );
377 return QAbstractItemModel::setData( index, value, role );
379 if ( role == Qt::CheckStateRole )
384 bool checked =
static_cast< Qt::CheckState
>( value.toInt() ) == Qt::Checked;
385 if ( checked && node->
children().isEmpty() )
405 else if ( role == Qt::EditRole )
413 layer->
setName( value.toString() );
414 emit dataChanged( index, index );
419 emit dataChanged( index, index );
423 return QAbstractItemModel::setData( index, value, role );
428 if ( !node || !node->
parent() )
429 return QModelIndex();
434 Q_ASSERT( row >= 0 );
435 return index( row, 0, parentIndex );
444 if ( child->
parent() == node )
447 return _isChildOfNode( child->
parent(), node );
450 static bool _isChildOfNodes(
QgsLayerTreeNode *child,
const QList<QgsLayerTreeNode *> &nodes )
454 if ( _isChildOfNode( child, n ) )
464 QList<QgsLayerTreeNode *> nodes;
465 Q_FOREACH (
const QModelIndex &
index, list )
478 QList<QgsLayerTreeNode *> nodesFinal;
481 if ( !_isChildOfNodes( node, nodes ) )
512 emit dataChanged( idx, idx );
516 beginRemoveRows( idx, 0, std::max( oldNodeCount - 1, 0 ) );
538 if ( oldIndex.isValid() )
539 emit dataChanged( oldIndex, oldIndex );
540 if ( currentIndex.isValid() )
541 emit dataChanged( currentIndex, currentIndex );
607 if ( useExpressions )
613 if ( enabled && !expr.isEmpty() )
615 exprs[ nodeLayer->
layerId()] = expr;
620 if ( useExpressions && !useExtent && !polygonValid )
686 beginInsertRows(
node2index( node ), indexFrom, indexTo );
689 static QList<QgsLayerTreeLayer *> _layerNodesInSubtree(
QgsLayerTreeNode *node,
int indexFrom,
int indexTo )
691 QList<QgsLayerTreeNode *> children = node->
children();
692 QList<QgsLayerTreeLayer *> newLayerNodes;
693 for (
int i = indexFrom; i <= indexTo; ++i )
701 return newLayerNodes;
710 Q_FOREACH (
QgsLayerTreeLayer *newLayerNode, _layerNodesInSubtree( node, indexFrom, indexTo ) )
718 beginRemoveRows(
node2index( node ), indexFrom, indexTo );
721 Q_FOREACH (
QgsLayerTreeLayer *nodeLayer, _layerNodesInSubtree( node, indexFrom, indexTo ) )
735 emit dataChanged( index, index );
744 emit dataChanged( index, index );
807 emit dataChanged( index, index );
809 if ( nodeLayer->
customProperty( QStringLiteral(
"showFeatureCount" ) ).toInt() )
821 if ( index.isValid() )
822 emit dataChanged( index, index );
828 if ( !nodeLayer->
layer() )
887 disconnect( nodeLayer,
nullptr,
this,
nullptr );
889 if ( !nodeLayer->
layer() )
900 disconnect( nodeLayer->
layer(),
nullptr,
this, nullptr );
944 disconnect(
mRootNode,
nullptr,
this,
nullptr );
955 int count = node->
children().count();
958 emit dataChanged(
index( 0, 0, idx ),
index( count - 1, 0, idx ) );
959 for (
int i = 0; i < count; ++i )
974 emit dataChanged( idx, idx );
977 int count = node->
children().count();
978 for (
int i = 0; i < count; ++i )
984 return Qt::CopyAction | Qt::MoveAction;
990 types << QStringLiteral(
"application/qgis.layertreemodeldata" );
998 QModelIndexList sortedIndexes = indexes;
999 std::sort( sortedIndexes.begin(), sortedIndexes.end(), std::less<QModelIndex>() );
1001 QList<QgsLayerTreeNode *> nodesFinal =
indexes2nodes( sortedIndexes,
true );
1003 if ( nodesFinal.isEmpty() )
1006 QMimeData *
mimeData =
new QMimeData();
1009 QDomElement rootElem = doc.createElement( QStringLiteral(
"layer_tree_model_data" ) );
1012 doc.appendChild( rootElem );
1013 QString txt = doc.toString();
1015 mimeData->setData( QStringLiteral(
"application/qgis.layertreemodeldata" ), txt.toUtf8() );
1024 if ( action == Qt::IgnoreAction )
1027 if ( !data->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) )
1037 QByteArray encodedData = data->data( QStringLiteral(
"application/qgis.layertreemodeldata" ) );
1040 if ( !doc.setContent( QString::fromUtf8( encodedData ) ) )
1043 QDomElement rootElem = doc.documentElement();
1044 if ( rootElem.tagName() != QLatin1String(
"layer_tree_model_data" ) )
1047 QList<QgsLayerTreeNode *> nodes;
1049 QDomElement elem = rootElem.firstChildElement();
1050 while ( !elem.isNull() )
1056 elem = elem.nextSiblingElement();
1059 if ( nodes.isEmpty() )
1062 if ( parent.isValid() && row == -1 )
1101 return mFlags.testFlag( f );
1111 QList<QgsLayerTreeModelLegendNode *> filtered;
1172 if (
mLegend.contains( nodeLayer ) )
1174 qDeleteAll(
mLegend[nodeLayer].originalNodes );
1175 delete mLegend[nodeLayer].tree;
1183 if ( !nodeL || !nodeL->
layer() )
1192 if ( hasStyleOverride )
1203 int widgetsCount = ml->
customProperty( QStringLiteral(
"embeddedWidgets/count" ), 0 ).toInt();
1204 while ( widgetsCount > 0 )
1206 lstNew.insert( 0,
new EmbeddedWidgetLegendNode( nodeL ) );
1211 QList<QgsLayerTreeModelLegendNode *> filteredLstNew =
filterLegendNodes( lstNew );
1215 n->setParent(
this );
1227 embeddedNode = legendNode;
1228 filteredLstNew.removeOne( legendNode );
1239 int count = legendTree ? legendTree->
children[
nullptr].count() : filteredLstNew.count();
1241 if ( !filteredLstNew.isEmpty() ) beginInsertRows(
node2index( nodeL ), 0, count - 1 );
1247 data.
tree = legendTree;
1251 if ( !filteredLstNew.isEmpty() ) endInsertRows();
1253 if ( hasStyleOverride )
1265 bool hasParentKeys =
false;
1270 hasParentKeys =
true;
1274 if ( !hasParentKeys )
1278 QHash<QString, QgsLayerTreeModelLegendNode *> rule2node;
1279 rule2node[QString()] =
nullptr;
1283 if ( ruleKey.isEmpty() )
1285 if ( rule2node.contains( ruleKey ) )
1287 rule2node[ruleKey] = n;
1312 context->setScaleFactor( dpi / 25.4 );
1313 context->setRendererScale( scale );
1315 return validData ? context.release() :
nullptr;
1333 int row = data.
tree->
children[parentLegendNode].indexOf( legendNode );
1334 return index( row, 0, parentIndex );
1339 int row = data.
tree->
children[
nullptr].indexOf( legendNode );
1340 return index( row, 0, parentIndex );
1345 Q_ASSERT( parentIndex.isValid() );
1348 return QModelIndex();
1350 return index( row, 0, parentIndex );
1366 if ( !
mLegend.contains( nL ) )
1380 Q_ASSERT(
mLegend.contains( nL ) );
1383 return createIndex( row, column, static_cast<QObject *>( data.tree->children[
nullptr].at( row ) ) );
1385 return createIndex( row, column, static_cast<QObject *>( data.activeNodes.at( row ) ) );
1393 return createIndex( row, column, static_cast<QObject *>( data.
tree->
children[node].at( row ) ) );
1395 return QModelIndex();
1408 int row = data.
tree->
children[grandParentNode].indexOf( parentNode );
1409 return createIndex( row, 0, static_cast<QObject *>( parentNode ) );
1423 return node->
data( role );
1429 Qt::ItemFlags
f = node->
flags();
1431 f &= ~Qt::ItemIsUserCheckable;
1438 return static_cast< bool >(
mLegend[nodeLayer].embeddedNodeInParent );
1443 return mLegend[nodeLayer].embeddedNodeInParent;
1452 return QIcon( qvariant_cast<QPixmap>( legendNode->
data( Qt::DecorationRole ) ) );
1458 if ( !
mLegend.contains( nodeLayer ) )
1459 return QList<QgsLayerTreeModelLegendNode *>();
1462 QList<QgsLayerTreeModelLegendNode *> lst( data.
activeNodes );
1470 return mLegend.value( nodeLayer ).originalNodes;
1475 QMap<QgsLayerTreeLayer *, LayerLegendData>::const_iterator it =
mLegend.constBegin();
1476 for ( ; it !=
mLegend.constEnd(); ++it )
1479 if ( layer->
layerId() == layerId )
1513 std::unique_ptr<QgsRenderContext> context( createTemporaryRenderContext() );
1517 QList<QgsSymbolLegendNode *> symbolNodes;
1518 QMap<QString, int> widthMax;
1526 widthMax[parentKey] = std::max( sz.width(), widthMax.contains( parentKey ) ? widthMax[parentKey] : 0 );
1528 symbolNodes.append( n );
1534 Q_ASSERT( widthMax[parentKey] > 0 );
1535 const int twiceMarginWidth = 2;
1536 n->
setIconSize( QSize( widthMax[parentKey] + twiceMarginWidth, n->
iconSize().rheight() + twiceMarginWidth ) );
bool restoreOverrideStyle()
Restore the original store after a call to setOverrideStyle()
Layer tree group node serves as a container for layers and further groups.
void legendInvalidateMapBasedData()
double mLegendMapViewMupp
QgsLayerTreeModel(QgsLayerTree *rootNode, QObject *parent=nullptr)
Construct a new tree model with given layer tree (root node must not be null pointer).
The class is used as a container of context for various read/write operations on other objects...
static QIcon iconRaster()
void removeChildren(int from, int count)
Remove child nodes from index "from".
QModelIndex parent(const QModelIndex &child) const override
QMap< QgsLayerTreeLayer *, LayerLegendData > mLegend
Per layer data about layer's legend nodes.
void refreshScaleBasedLayers(const QModelIndex &index=QModelIndex())
Updates layer data for scale dependent layers, should be called when map scale changes.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
Base class for all map layer types.
virtual bool isEmbeddedInParent() const
QMimeData * mimeData(const QModelIndexList &indexes) const override
virtual Qt::ItemFlags flags() const
Return item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.
void removeLegendFromLayer(QgsLayerTreeLayer *nodeLayer)
void connectToLayer(QgsLayerTreeLayer *nodeLayer)
QList< QgsLayerTreeModelLegendNode * > originalNodes
Data structure for storage of legend nodes.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
void setCurrentIndex(const QModelIndex ¤tIndex)
Set index of the current item. May be used by view. Item marked as current is underlined.
QList< QgsLayerTreeNode * > indexes2nodes(const QModelIndexList &list, bool skipInternal=false) const
Convert a list of indexes to a list of layer tree nodes.
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
bool itemVisibilityChecked() const
Returns whether a node is checked (independently of its ancestors or children)
LayerLegendTree * tree
Optional pointer to a tree structure - see LayerLegendTree for details.
QVariant data(int role) const override
Return data associated with the item. Must be implemented in derived class.
QList< QgsLayerTreeModelLegendNode * > layerOriginalLegendNodes(QgsLayerTreeLayer *nodeLayer)
Return original (unfiltered) list of legend nodes attached to a particular layer node.
void nodeCustomPropertyChanged(QgsLayerTreeNode *node, const QString &key)
void addLegendToLayer(QgsLayerTreeLayer *nodeL)
QgsMapLayerLegend * legend() const
Can be null.
virtual void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context)=0
Write layer tree to XML.
virtual bool setData(const QVariant &value, int role)
Set some data associated with the item. Default implementation does nothing and returns false...
void disconnectFromRootNode()
QModelIndex indexOfParentLayerTreeNode(QgsLayerTreeNode *parentNode) const
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
bool testFlag(Flag f) const
Check whether a flag is enabled.
QgsLayerTreeModelLegendNode * legendNodeEmbeddedInParent(QgsLayerTreeLayer *nodeLayer) const
Return legend node that may be embedded in parent (i.e.
void setIconSize(QSize sz)
Set the icon size.
Structure that stores tree representation of map layer's legend.
void willRemoveChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes will be removed from a node within the tree.
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
QgsLayerTreeLayer * layerNode() const
Return pointer to the parent layer node.
QgsLayerTreeModelLegendNode * embeddedNodeInParent
A legend node that is not displayed separately, its icon is instead shown within the layer node's ite...
QgsLayerTreeModelLegendNode * findLegendNode(const QString &layerId, const QString &ruleKey) const
Searches through the layer tree to find a legend node with a matching layer ID and rule key...
QFont layerTreeNodeFont(int nodeType) const
Get font for a particular type of layer tree node. nodeType should come from QgsLayerTreeNode::NodeTy...
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
A geometry is the spatial representation of a feature.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
bool isVisible() const
Returns whether a node is really visible (ie checked and all its ancestors checked as well) ...
void recursivelyEmitDataChanged(const QModelIndex &index=QModelIndex())
emit dataChanged() for layer tree node items
void legendNodeDataChanged()
QMap< QgsLayerTreeModelLegendNode *, QList< QgsLayerTreeModelLegendNode * > > children
List of children for each active node. Top-level nodes are under null pointer key. Pointers are not owned.
LayerLegendTree * tryBuildLegendTree(const QList< QgsLayerTreeModelLegendNode *> &nodes)
std::unique_ptr< QgsMapHitTest > mLegendFilterHitTest
static QgsLayerTreeNode * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer tree from XML.
void layerLoaded()
Emitted when a previously unavailable layer got loaded.
bool mLegendFilterUsesExtent
whether to use map filtering
Flags mFlags
Set of flags for the model.
bool isEditable() const override
Returns true if the provider is in editing mode.
static QIcon iconDefault()
QModelIndex node2index(QgsLayerTreeNode *node) const
Return index for a given node. If the node does not belong to the layer tree, the result is undefined...
QgsMapLayer::LayerType type() const
Returns the type of the layer.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
std::unique_ptr< QgsMapSettings > mLegendFilterMapSettings
static QPixmap getThemePixmap(const QString &name)
Helper to get a theme icon as a pixmap.
void willAddChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes will be added to a node within the tree.
void nodeAddedChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
bool legendEmbeddedInParent(QgsLayerTreeLayer *nodeLayer) const
void nodeWillAddChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Allow check boxes for legend nodes (if supported by layer's legend)
void setFlags(QgsLayerTreeModel::Flags f)
Set OR-ed combination of model flags.
void connectToLayers(QgsLayerTreeGroup *parentGroup)
~QgsLayerTreeModel() override
void layerLegendChanged()
void removedChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes has been removed from a node within the tree.
The QgsMapSettings class contains configuration for rendering of the map.
QVariant legendNodeData(QgsLayerTreeModelLegendNode *node, int role) const
QgsMapLayerStyleManager * styleManager() const
Get access to the layer's style manager.
QSize minimumIconSize() const
Calculates the minimum icon size to prevent cropping.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Perform transforms between map coordinates and device coordinates.
Allow renaming of groups and layers.
Rule key of the parent legend node - for legends with tree hierarchy (QString). Added in 2...
QModelIndex legendParent(QgsLayerTreeModelLegendNode *legendNode) const
virtual void setItemVisibilityCheckedRecursive(bool checked)
Check or uncheck a node and all its children (taking into account exclusion rules) ...
void disconnectFromLayer(QgsLayerTreeLayer *nodeLayer)
virtual QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer)=0
Return list of legend nodes to be used for a particular layer tree layer node.
QString name() const override
Returns the layer's name.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
QList< QgsLayerTreeNode * > children()
Get list of children of the node. Children are owned by the parent.
virtual bool isScaleOK(double scale) const
QTimer mDeferLegendInvalidationTimer
Namespace with helper functions for layer tree operations.
QModelIndex legendNode2index(QgsLayerTreeModelLegendNode *legendNode)
Return index for a given legend node.
static QIcon iconPolygon()
void disconnectFromLayers(QgsLayerTreeGroup *parentGroup)
#define QgsDebugMsgLevel(str, level)
Rule key of the node (QString)
void setLegendFilterByMap(const QgsMapSettings *settings)
Force only display of legend nodes which are valid for given map settings.
long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
void addedChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes have been added to a node within the tree.
static QgsLayerTreeModelLegendNode * index2legendNode(const QModelIndex &index)
Return legend node for given index.
Qt::DropActions supportedDropActions() const override
QgsLayerTreeNode * parent()
Get pointer to the parent. If parent is a null pointer, the node is a root node.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
QMap< QString, QString > layerStyleOverrides() const
Get map of map layer style overrides (key: layer ID, value: style name) where a different style shoul...
void editingStopped()
Is emitted, when edited changes successfully have been written to the data provider.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer. Properties are stored in a map and saved in project file...
void setName(const QString &n) override
Sets the group's name.
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
This class is a base class for nodes in a layer tree.
void setLegendFilterByScale(double scale)
Force only display of legend nodes which are valid for a given scale.
void insertChildNodes(int index, const QList< QgsLayerTreeNode *> &nodes)
Insert existing nodes at specified position.
bool hasValidSettings() const
Check whether the map settings are valid and can be used for rendering.
int autoCollapseLegendNodes() const
Return at what number of legend nodes the layer node should be collapsed. -1 means no auto-collapse (...
Class that runs a hit test with given map settings.
int legendNodeRowCount(QgsLayerTreeModelLegendNode *node) const
void setLayerTreeNodeFont(int nodeType, const QFont &font)
Set font for a particular type of layer tree node. nodeType should come from QgsLayerTreeNode::NodeTy...
void setFlag(Flag f, bool on=true)
Enable or disable a model flag.
void editingStarted()
Is emitted, when editing on this layer has started.
void dataChanged()
Emitted on internal data change so the layer tree model can forward the signal to views...
QgsWkbTypes::GeometryType type() const
Returns type of the geometry as a QgsWkbTypes::GeometryType.
QModelIndex legendNodeIndex(int row, int column, QgsLayerTreeModelLegendNode *node) const
NodeType nodeType() const
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
QPersistentModelIndex mCurrentIndex
Current index - will be underlined.
double mLegendMapViewScale
double mLegendFilterByScale
scale denominator for filtering of legend nodes (<= 0 means no filtering)
void setName(const QString &n) override
Sets the layer's name.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Defer legend model invalidation.
void refreshLayerLegend(QgsLayerTreeLayer *nodeLayer)
Force a refresh of legend nodes of a layer node.
void setExpanded(bool expanded)
Set whether the node should be shown as expanded or collapsed in GUI.
void setLegendMapViewData(double mapUnitsPerPixel, int dpi, double scale)
Give the layer tree model hints about the currently associated map view so that legend nodes that use...
QMap< QgsLayerTreeModelLegendNode *, QgsLayerTreeModelLegendNode * > parents
Pointer to parent for each active node. Top-level nodes have null parent. Pointers are not owned...
void setItemVisibilityCheckedParentRecursive(bool checked)
Check or uncheck a node and all its parents.
QgsMapLayer * layer() const
void setAutoCollapseLegendNodes(int nodeCount)
Set at what number of legend nodes the layer node should be collapsed. Setting -1 disables the auto-c...
Leaf node pointing to a layer.
QIcon legendIconEmbeddedInParent(QgsLayerTreeLayer *nodeLayer) const
Contains information about the context of a rendering operation.
QMap< QString, QString > LayerFilterExpression
Maps an expression string to a layer id.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
int mAutoCollapseLegendNodesCount
Minimal number of nodes when legend should be automatically collapsed. -1 = disabled.
QgsLayerTreeNode * index2node(const QModelIndex &index) const
Return layer tree node for given index.
QList< QgsLayerTreeModelLegendNode * > filterLegendNodes(const QList< QgsLayerTreeModelLegendNode *> &nodes)
Filter nodes from QgsMapLayerLegend according to the current filtering rules.
QgsLayerTree * rootGroup() const
Return pointer to the root node of the layer tree. Always a non-null pointer.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
static void applyLayerNodeProperties(QgsLayerTreeLayer *nodeLayer, QList< QgsLayerTreeModelLegendNode *> &nodes)
update according to layer node's custom properties (order of items, user labels for items) ...
Layer nodes may optionally include extra embedded widgets (if used in QgsLayerTreeView). Added in 2.16.
void visibilityChanged(QgsLayerTreeNode *node)
Emitted when check state of a node within the tree has been changed.
void setRootGroup(QgsLayerTree *newRootGroup)
Reset the model and use a new root group node.
void nodeRemovedChildren()
static QgsProject * instance()
Returns the QgsProject singleton instance.
void nodeNameChanged(QgsLayerTreeNode *node, const QString &name)
Updates model when node's name has changed.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
virtual bool isModified() const
Returns true if the provider has been modified since the last commit.
QStringList mimeTypes() const override
void invalidateLegendMapBasedData()
int legendRootRowCount(QgsLayerTreeLayer *nL) const
void legendChanged()
Signal emitted when legend of the layer has changed.
virtual QVariant data(int role) const =0
Return data associated with the item. Must be implemented in derived class.
void legendMapViewData(double *mapUnitsPerPixel, int *dpi, double *scale) const
Get hints about map view - to be used in legend nodes.
static QString displayString(Type type)
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
void layerWillBeUnloaded()
Emitted when a previously available layer got unloaded (from layer registry).
Check/uncheck action has consequences on children (or parents for leaf node)
QList< QgsLayerTreeModelLegendNode * > layerLegendNodes(QgsLayerTreeLayer *nodeLayer, bool skipNodeEmbeddedInParent=false)
Return filtered list of active legend nodes attached to a particular layer node (by default it return...
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
void setItemVisibilityChecked(bool checked)
Check or uncheck a node (independently of its ancestors or children)
Allow user to set node visibility with a checkbox.
QList< QgsLayerTreeModelLegendNode * > activeNodes
Active legend nodes.
static QByteArray layerTreeNodesToUriList(const QList< QgsLayerTreeNode *> &nodes)
Returns encoded URI list from a list of layer tree nodes.
QString name() const override
Returns the group's name.
Flags flags() const
Return OR-ed combination of model flags.
bool setOverrideStyle(const QString &styleDef)
Temporarily apply a different style to the layer.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Set map of map layer style overrides (key: layer ID, value: style name) where a different style shoul...
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes.
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
void customPropertyChanged(QgsLayerTreeNode *node, const QString &key)
Emitted when a custom property of a node within the tree has been changed or removed.
QModelIndex legendRootIndex(int row, int column, QgsLayerTreeLayer *nL) const
Container of other groups and layers.
void nameChanged(QgsLayerTreeNode *node, QString name)
Emitted when the name of the node is changed.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
For legends that support it, will show them in a tree instead of a list (needs also ShowLegend)...
QMap< QString, QString > mLayerStyleOverrides
Overrides of map layers' styles: key = layer ID, value = style XML.
void setLegendFilter(const QgsMapSettings *settings, bool useExtent=true, const QgsGeometry &polygon=QgsGeometry(), bool useExpressions=true)
Filter display of legend nodes for given map settings.
Represents a vector layer which manages a vector based data sets.
void layerModified()
This signal is emitted when modifications has been done on layer.
static QString legendFilterByExpression(const QgsLayerTreeLayer &layer, bool *enabled=nullptr)
Return the expression filter of a legend layer.
Allow reordering with drag'n'drop.
Add legend nodes for layer nodes.
QgsLayerTree * mRootNode
Pointer to the root node of the layer tree. Not owned by the model.
virtual void invalidateMapBasedData()
Notification from model that information from associated map view has changed.
void nodeWillRemoveChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
void nodeLayerWillBeUnloaded()
Qt::ItemFlags legendNodeFlags(QgsLayerTreeModelLegendNode *node) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Layer tree node points to a map layer.
QModelIndex currentIndex() const
Get index of the item marked as current. Item marked as current is underlined.
void nodeVisibilityChanged(QgsLayerTreeNode *node)
Structure that stores all data associated with one map layer.