25 #include <QTextStream> 39 : QAbstractItemModel( parent )
40 , mRootNode( rootNode )
41 , mFlags( ShowLegend | AllowLegendChangeState | DeferredLegendInvalidation )
42 , mAutoCollapseLegendNodesCount( -1 )
43 , mLegendFilterByScale( 0 )
44 , mLegendFilterUsesExtent( false )
45 , mLegendMapViewMupp( 0 )
46 , mLegendMapViewDpi( 0 )
47 , mLegendMapViewScale( 0 )
64 if ( !index.isValid() )
67 QObject *obj =
reinterpret_cast<QObject *
>( index.internalPointer() );
100 if ( column < 0 || column >=
columnCount( parent ) ||
101 row < 0 || row >=
rowCount( parent ) )
102 return QModelIndex();
109 return QModelIndex();
116 return createIndex( row, column, static_cast<QObject *>( n->
children().at( row ) ) );
122 if ( !child.isValid() )
123 return QModelIndex();
136 return QModelIndex();
144 Q_ASSERT( parentNode );
147 if ( !grandParentNode )
148 return QModelIndex();
150 int row = grandParentNode->
children().indexOf( parentNode );
151 Q_ASSERT( row >= 0 );
153 return createIndex( row, 0, static_cast<QObject *>( parentNode ) );
159 if ( !index.isValid() || index.column() > 1 )
166 if ( role == Qt::DisplayRole || role == Qt::EditRole )
174 QString name = nodeLayer->
name();
175 if ( nodeLayer->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toInt() && role == Qt::DisplayRole )
179 name += QStringLiteral(
" [%1]" ).arg( vlayer->
featureCount() );
184 else if ( role == Qt::DecorationRole && index.column() == 0 )
198 switch ( layer->
type() )
236 QPixmap pixmap( icon.pixmap( iconSize, iconSize ) );
238 QPainter painter( &pixmap );
239 painter.drawPixmap( 0, 0, iconSize, iconSize,
QgsApplication::getThemePixmap( vlayer->
isModified() ? QStringLiteral(
"/mIconEditableEdits.svg" ) : QStringLiteral(
"/mActionToggleEditing.svg" ) ) );
242 icon = QIcon( pixmap );
248 else if ( role == Qt::CheckStateRole )
268 else if ( role == Qt::FontRole )
272 f.setUnderline(
true );
278 f.setItalic( !f.italic() );
283 else if ( role == Qt::ForegroundRole )
285 QBrush brush( qApp->palette().color( QPalette::Text ), Qt::SolidPattern );
291 QColor fadedTextColor = brush.color();
292 fadedTextColor.setAlpha( 128 );
293 brush.setColor( fadedTextColor );
298 else if ( role == Qt::ToolTipRole )
305 !layer->
title().isEmpty() ? layer->title() :
306 !layer->shortName().isEmpty() ? layer->shortName() :
309 title =
"<b>" + title.toHtmlEscaped() +
"</b>";
311 if ( layer->isSpatial() && layer->crs().isValid() )
313 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ) )
316 title += tr(
" (%1)" ).arg( layer->crs().authid() ).toHtmlEscaped();
322 if ( !layer->abstract().isEmpty() )
325 const QStringList abstractLines = layer->abstract().split(
'\n' );
326 for (
const auto &l : abstractLines )
328 parts << l.toHtmlEscaped();
333 parts <<
"<i>" + layer->publicSource().toHtmlEscaped() +
"</i>";
335 return parts.join( QStringLiteral(
"<br/>" ) );
346 if ( !index.isValid() )
348 Qt::ItemFlags rootFlags = Qt::ItemFlags();
350 rootFlags |= Qt::ItemIsDropEnabled;
357 Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
360 f |= Qt::ItemIsEditable;
363 bool isEmbedded = node->
customProperty( QStringLiteral(
"embedded" ) ).toInt();
368 if ( !isEmbedded || ( isEmbedded && node->
parent() && !node->
parent()->
customProperty( QStringLiteral(
"embedded" ) ).toInt() ) )
369 f |= Qt::ItemIsDragEnabled;
373 f |= Qt::ItemIsUserCheckable;
376 f |= Qt::ItemIsDropEnabled;
388 bool res = sym->
setData( value, role );
390 emit dataChanged( index, index );
396 return QAbstractItemModel::setData( index, value, role );
398 if ( role == Qt::CheckStateRole )
403 bool checked =
static_cast< Qt::CheckState
>( value.toInt() ) == Qt::Checked;
404 if ( checked && node->
children().isEmpty() )
424 else if ( role == Qt::EditRole )
432 layer->
setName( value.toString() );
433 emit dataChanged( index, index );
438 emit dataChanged( index, index );
442 return QAbstractItemModel::setData( index, value, role );
447 if ( !node || !node->
parent() )
448 return QModelIndex();
453 Q_ASSERT( row >= 0 );
454 return index( row, 0, parentIndex );
463 if ( child->
parent() == node )
466 return _isChildOfNode( child->
parent(), node );
469 static bool _isChildOfNodes(
QgsLayerTreeNode *child,
const QList<QgsLayerTreeNode *> &nodes )
473 if ( _isChildOfNode( child, n ) )
483 QList<QgsLayerTreeNode *> nodes;
484 Q_FOREACH (
const QModelIndex &
index, list )
497 QList<QgsLayerTreeNode *> nodesFinal;
500 if ( !_isChildOfNodes( node, nodes ) )
531 emit dataChanged( idx, idx );
535 beginRemoveRows( idx, 0, std::max( oldNodeCount - 1, 0 ) );
557 if ( oldIndex.isValid() )
558 emit dataChanged( oldIndex, oldIndex );
559 if ( currentIndex.isValid() )
560 emit dataChanged( currentIndex, currentIndex );
626 if ( useExpressions )
632 if ( enabled && !expr.isEmpty() )
634 exprs[ nodeLayer->
layerId()] = expr;
639 if ( useExpressions && !useExtent && !polygonValid )
704 QFontMetrics fm( ( QFont() ) );
705 const double scale = 1.1 * standardSize / 24;
706 return static_cast< int >( std::floor( std::max(
Qgis::UI_SCALE_FACTOR * fm.height() * scale,
static_cast< double >( standardSize ) ) ) );
712 beginInsertRows(
node2index( node ), indexFrom, indexTo );
715 static QList<QgsLayerTreeLayer *> _layerNodesInSubtree(
QgsLayerTreeNode *node,
int indexFrom,
int indexTo )
717 QList<QgsLayerTreeNode *> children = node->
children();
718 QList<QgsLayerTreeLayer *> newLayerNodes;
719 for (
int i = indexFrom; i <= indexTo; ++i )
727 return newLayerNodes;
736 Q_FOREACH (
QgsLayerTreeLayer *newLayerNode, _layerNodesInSubtree( node, indexFrom, indexTo ) )
744 beginRemoveRows(
node2index( node ), indexFrom, indexTo );
747 Q_FOREACH (
QgsLayerTreeLayer *nodeLayer, _layerNodesInSubtree( node, indexFrom, indexTo ) )
761 emit dataChanged( index, index );
770 emit dataChanged( index, index );
833 emit dataChanged( index, index );
835 if ( nodeLayer->
customProperty( QStringLiteral(
"showFeatureCount" ) ).toInt() )
847 if ( index.isValid() )
848 emit dataChanged( index, index );
854 if ( !nodeLayer->
layer() )
913 disconnect( nodeLayer,
nullptr,
this,
nullptr );
915 if ( !nodeLayer->
layer() )
926 disconnect( nodeLayer->
layer(),
nullptr,
this, nullptr );
970 disconnect(
mRootNode,
nullptr,
this,
nullptr );
981 int count = node->
children().count();
984 emit dataChanged(
index( 0, 0, idx ),
index( count - 1, 0, idx ) );
985 for (
int i = 0; i < count; ++i )
1000 emit dataChanged( idx, idx );
1003 int count = node->
children().count();
1004 for (
int i = 0; i < count; ++i )
1010 return Qt::CopyAction | Qt::MoveAction;
1016 types << QStringLiteral(
"application/qgis.layertreemodeldata" );
1024 QModelIndexList sortedIndexes = indexes;
1025 std::sort( sortedIndexes.begin(), sortedIndexes.end(), std::less<QModelIndex>() );
1027 QList<QgsLayerTreeNode *> nodesFinal =
indexes2nodes( sortedIndexes,
true );
1029 if ( nodesFinal.isEmpty() )
1032 QMimeData *
mimeData =
new QMimeData();
1035 QDomElement rootElem = doc.createElement( QStringLiteral(
"layer_tree_model_data" ) );
1038 doc.appendChild( rootElem );
1039 QString txt = doc.toString();
1041 mimeData->setData( QStringLiteral(
"application/qgis.layertreemodeldata" ), txt.toUtf8() );
1050 if ( action == Qt::IgnoreAction )
1053 if ( !data->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) )
1063 QByteArray encodedData = data->data( QStringLiteral(
"application/qgis.layertreemodeldata" ) );
1066 if ( !doc.setContent( QString::fromUtf8( encodedData ) ) )
1069 QDomElement rootElem = doc.documentElement();
1070 if ( rootElem.tagName() != QLatin1String(
"layer_tree_model_data" ) )
1073 QList<QgsLayerTreeNode *> nodes;
1075 QDomElement elem = rootElem.firstChildElement();
1076 while ( !elem.isNull() )
1082 elem = elem.nextSiblingElement();
1085 if ( nodes.isEmpty() )
1088 if ( parent.isValid() && row == -1 )
1127 return mFlags.testFlag( f );
1137 QList<QgsLayerTreeModelLegendNode *> filtered;
1198 if (
mLegend.contains( nodeLayer ) )
1200 qDeleteAll(
mLegend[nodeLayer].originalNodes );
1201 delete mLegend[nodeLayer].tree;
1209 if ( !nodeL || !nodeL->
layer() )
1229 int widgetsCount = ml->
customProperty( QStringLiteral(
"embeddedWidgets/count" ), 0 ).toInt();
1230 while ( widgetsCount > 0 )
1232 lstNew.insert( 0,
new EmbeddedWidgetLegendNode( nodeL ) );
1237 QList<QgsLayerTreeModelLegendNode *> filteredLstNew =
filterLegendNodes( lstNew );
1241 n->setParent(
this );
1253 embeddedNode = legendNode;
1254 filteredLstNew.removeOne( legendNode );
1265 int count = legendTree ? legendTree->
children[
nullptr].count() : filteredLstNew.count();
1267 if ( !filteredLstNew.isEmpty() ) beginInsertRows(
node2index( nodeL ), 0, count - 1 );
1273 data.
tree = legendTree;
1277 if ( !filteredLstNew.isEmpty() ) endInsertRows();
1288 bool hasParentKeys =
false;
1293 hasParentKeys =
true;
1297 if ( !hasParentKeys )
1301 QHash<QString, QgsLayerTreeModelLegendNode *> rule2node;
1302 rule2node[QString()] =
nullptr;
1306 if ( ruleKey.isEmpty() )
1308 if ( rule2node.contains( ruleKey ) )
1310 rule2node[ruleKey] = n;
1335 context->setScaleFactor( dpi / 25.4 );
1336 context->setRendererScale( scale );
1338 return validData ? context.release() :
nullptr;
1356 int row = data.
tree->
children[parentLegendNode].indexOf( legendNode );
1357 return index( row, 0, parentIndex );
1362 int row = data.
tree->
children[
nullptr].indexOf( legendNode );
1363 return index( row, 0, parentIndex );
1368 Q_ASSERT( parentIndex.isValid() );
1371 return QModelIndex();
1373 return index( row, 0, parentIndex );
1389 if ( !
mLegend.contains( nL ) )
1403 Q_ASSERT(
mLegend.contains( nL ) );
1406 return createIndex( row, column, static_cast<QObject *>( data.tree->children[
nullptr].at( row ) ) );
1408 return createIndex( row, column, static_cast<QObject *>( data.activeNodes.at( row ) ) );
1416 return createIndex( row, column, static_cast<QObject *>( data.
tree->
children[node].at( row ) ) );
1418 return QModelIndex();
1431 int row = data.
tree->
children[grandParentNode].indexOf( parentNode );
1432 return createIndex( row, 0, static_cast<QObject *>( parentNode ) );
1446 return node->
data( role );
1452 Qt::ItemFlags f = node->
flags();
1454 f &= ~Qt::ItemIsUserCheckable;
1461 return static_cast< bool >(
mLegend[nodeLayer].embeddedNodeInParent );
1466 return mLegend[nodeLayer].embeddedNodeInParent;
1475 return QIcon( qvariant_cast<QPixmap>( legendNode->
data( Qt::DecorationRole ) ) );
1481 if ( !
mLegend.contains( nodeLayer ) )
1482 return QList<QgsLayerTreeModelLegendNode *>();
1485 QList<QgsLayerTreeModelLegendNode *> lst( data.
activeNodes );
1493 return mLegend.value( nodeLayer ).originalNodes;
1498 QMap<QgsLayerTreeLayer *, LayerLegendData>::const_iterator it =
mLegend.constBegin();
1499 for ( ; it !=
mLegend.constEnd(); ++it )
1502 if ( layer->
layerId() == layerId )
1536 std::unique_ptr<QgsRenderContext> context( createTemporaryRenderContext() );
1540 QList<QgsSymbolLegendNode *> symbolNodes;
1541 QMap<QString, int> widthMax;
1549 widthMax[parentKey] = std::max( sz.width(), widthMax.contains( parentKey ) ? widthMax[parentKey] : 0 );
1551 symbolNodes.append( n );
1557 Q_ASSERT( widthMax[parentKey] > 0 );
1558 const int twiceMarginWidth = 2;
1559 n->
setIconSize( QSize( widthMax[parentKey] + twiceMarginWidth, n->
iconSize().rheight() + twiceMarginWidth ) );
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
Returns 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)
Sets 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 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
Returns data associated with the item. Must be implemented in derived class.
static const double UI_SCALE_FACTOR
UI scaling factor.
QList< QgsLayerTreeModelLegendNode * > layerOriginalLegendNodes(QgsLayerTreeLayer *nodeLayer)
Returns 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.
Restore overridden layer style on destruction.
virtual void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context)=0
Write layer tree to XML.
virtual bool setData(const QVariant &value, int role)
Sets 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.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsLayerTreeModelLegendNode * legendNodeEmbeddedInParent(QgsLayerTreeLayer *nodeLayer) const
Returns 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
Returns 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
Gets font for a particular type of layer tree node. nodeType should come from QgsLayerTreeNode::NodeT...
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
QString layerId() const
Returns the ID for the map layer associated with this node.
Flags mFlags
Sets of flags for the model.
static QIcon iconDefault()
QModelIndex node2index(QgsLayerTreeNode *node) const
Returns index for a given node. If the node does not belong to the layer tree, the result is undefine...
QgsMapLayer::LayerType type() const
Returns the type of the layer.
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)
Sets 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
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.
bool isEditable() const FINAL
Returns true if the provider is in editing mode.
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
Returns 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()
Gets 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)
Returns index for a given legend node.
static QIcon iconPolygon()
void disconnectFromLayers(QgsLayerTreeGroup *parentGroup)
static int scaleIconSize(int standardSize)
Scales an layer tree model icon size to compensate for display pixel density, making the icon size hi...
#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)
Returns legend node for given index.
Qt::DropActions supportedDropActions() const override
QgsLayerTreeNode * parent()
Gets 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
Gets map of map layer style overrides (key: layer ID, value: style name) where a different style shou...
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
Returns 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)
Sets font for a particular type of layer tree node. nodeType should come from QgsLayerTreeNode::NodeT...
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...
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)
Sets 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
Returns the map layer associated with this node.
void setAutoCollapseLegendNodes(int nodeCount)
Sets at what number of legend nodes the layer node should be collapsed. Setting -1 disables the auto-...
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
Returns 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
Returns 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
Returns data associated with the item. Must be implemented in derived class.
void legendMapViewData(double *mapUnitsPerPixel, int *dpi, double *scale) const
Gets 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)
Returns filtered list of active legend nodes attached to a particular layer node (by default it retur...
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
Returns OR-ed combination of model flags.
QgsWkbTypes::GeometryType type
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Sets map of map layer style overrides (key: layer ID, value: style name) where a different style shou...
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 setOverrideStyle(const QString &style)
Temporarily apply a different style to the layer.
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.
static QIcon iconMesh()
Returns icon for mesh layer type.
void layerModified()
This signal is emitted when modifications has been done on layer.
static QString legendFilterByExpression(const QgsLayerTreeLayer &layer, bool *enabled=nullptr)
Returns 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
Gets 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.