16#ifndef QGSLAYERTREEMODEL_H
17#define QGSLAYERTREEMODEL_H
20#include <QAbstractItemModel>
62 if ( sipCpp->inherits(
"QgsLayerTreeModel" ) )
63 sipType = sipType_QgsLayerTreeModel;
82 int rowCount(
const QModelIndex &parent = QModelIndex() )
const override;
83 int columnCount(
const QModelIndex &parent = QModelIndex() )
const override;
84 QModelIndex index(
int row,
int column,
const QModelIndex &parent = QModelIndex() )
const override;
85 QModelIndex parent(
const QModelIndex &child )
const override;
86 QVariant data(
const QModelIndex &index,
int role = Qt::DisplayRole )
const override;
87 Qt::ItemFlags flags(
const QModelIndex &index )
const override;
88 bool setData(
const QModelIndex &index,
const QVariant &value,
int role = Qt::EditRole )
override;
89 Qt::DropActions supportedDropActions()
const override;
90 QStringList mimeTypes()
const override;
91 QMimeData *mimeData(
const QModelIndexList &indexes )
const override;
92 bool dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
const QModelIndex &parent )
override;
93 bool removeRows(
int row,
int count,
const QModelIndex &parent = QModelIndex() )
override;
101 ShowLegendAsTree = 0x0004,
102 DeferredLegendInvalidation = 0x0008,
103 UseEmbeddedWidgets = 0x0010,
104 UseTextFormatting = 0x0020,
107 AllowNodeReorder = 0x1000,
108 AllowNodeRename = 0x2000,
109 AllowNodeChangeVisibility = 0x4000,
110 AllowLegendChangeState = 0x8000,
111 ActionHierarchical = 0x10000,
112 UseThreadedHitTest = 0x20000,
114 Q_DECLARE_FLAGS( Flags, Flag )
117 void setFlags( QgsLayerTreeModel::Flags f );
119 void setFlag( Flag f,
bool on =
true );
123 bool testFlag( Flag f )
const;
138 QList<QgsLayerTreeNode *> indexes2nodes(
const QModelIndexList &list,
bool skipInternal =
false )
const;
160 QList<QgsLayerTreeModelLegendNode *> layerLegendNodes(
QgsLayerTreeLayer *nodeLayer,
bool skipNodeEmbeddedInParent =
false );
167 QList<QgsLayerTreeModelLegendNode *> layerOriginalLegendNodes(
QgsLayerTreeLayer *nodeLayer );
201 QModelIndex currentIndex()
const;
203 void setCurrentIndex(
const QModelIndex ¤tIndex );
206 void setLayerTreeNodeFont(
int nodeType,
const QFont &font );
208 QFont layerTreeNodeFont(
int nodeType )
const;
222 void setLegendFilterByScale(
double scale );
282 void setLegendMapViewData(
double mapUnitsPerPixel,
int dpi,
double scale );
289 void legendMapViewData(
double *mapUnitsPerPixel
SIP_OUT,
int *dpi
SIP_OUT,
double *scale
SIP_OUT ) const;
295 QMap<QString, QString> layerStyleOverrides() const;
301 void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
320 void waitForHitTestBlocking();
330 bool hitTestInProgress() const;
338 void messageEmitted( const QString &message,
Qgis::MessageLevel level =
Qgis::MessageLevel::Info,
int duration = 5 );
348 void hitTestStarted();
358 void hitTestCompleted();
361 void nodeWillAddChildren(
QgsLayerTreeNode *node,
int indexFrom,
int indexTo );
362 void nodeAddedChildren(
QgsLayerTreeNode *node,
int indexFrom,
int indexTo );
363 void nodeWillRemoveChildren(
QgsLayerTreeNode *node,
int indexFrom,
int indexTo );
364 void nodeRemovedChildren();
374 void nodeCustomPropertyChanged(
QgsLayerTreeNode *node, const QString &key );
376 void nodeLayerLoaded();
377 void nodeLayerWillBeUnloaded();
378 void layerLegendChanged();
384 void layerFlagsChanged();
386 void layerNeedsUpdate();
388 void legendNodeDataChanged();
390 void invalidateLegendMapBasedData();
401 void connectToRootNode();
402 void disconnectFromRootNode();
405 void recursivelyEmitDataChanged( const QModelIndex &index = QModelIndex() );
412 void refreshScaleBasedLayers( const QModelIndex &index = QModelIndex(),
double previousScale = 0.0 );
414 static QIcon iconGroup();
419 QModelIndex indexOfParentLayerTreeNode(
QgsLayerTreeNode *parentNode ) const;
430 void legendCleanup();
431 void legendInvalidateMapBasedData();
447 QPersistentModelIndex mCurrentIndex;
449 int mAutoCollapseLegendNodesCount = -1;
465 QMap<QgsLayerTreeModelLegendNode *, QgsLayerTreeModelLegendNode *>
parents;
467 QMap<QgsLayerTreeModelLegendNode *, QList<QgsLayerTreeModelLegendNode *> >
children;
513 QHash<QgsLayerTreeLayer *, LayerLegendData>
mLegend;
525 double mLegendFilterByScale = 0;
533 double mLegendMapViewMupp = 0;
534 int mLegendMapViewDpi = 0;
535 double mLegendMapViewScale = 0;
539 void legendNodeSizeChanged();
540 void hitTestTaskCompleted();
543 void handleHitTestResults();
568 mRuleKey = QStringLiteral(
"embedded-widget-" ) + QUuid::createUuid().toString();
571 QVariant
data(
int role )
const override
573 if ( role == RuleKeyRole )
The Qgis class provides global constants for use throughout the application.
Class for parsing and evaluation of expressions (formerly called "search strings").
A geometry is the spatial representation of a feature.
Contains settings relating to filtering the contents of QgsLayerTreeModel and views.
Layer tree group node serves as a container for layers and further groups.
Layer tree node points to a map layer.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
virtual QVariant data(int role) const =0
Returns data associated with the item. Must be implemented in derived class.
@ EmbeddedWidget
Embedded widget placeholder node type.
@ NodeTypeRole
Type of node. Added in 3.16.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
QTimer mDeferLegendInvalidationTimer
int autoCollapseLegendNodes() const
Returns at what number of legend nodes the layer node should be collapsed. -1 means no auto-collapse ...
double legendFilterByScale() const
Returns the scale which restricts the legend nodes which are visible.
std::unique_ptr< QgsLayerTreeFilterSettings > mFilterSettings
QMap< QString, QSet< QString > > mHitTestResults
void setAutoCollapseLegendNodes(int nodeCount)
Sets at what number of legend nodes the layer node should be collapsed. Setting -1 disables the auto-...
QHash< QgsLayerTreeLayer *, LayerLegendData > mLegend
Per layer data about layer's legend nodes.
QPointer< QgsMapHitTestTask > mHitTestTask
QMap< QString, QString > mLayerStyleOverrides
Overrides of map layers' styles: key = layer ID, value = style XML.
QSet< QgsLayerTreeLayer * > mInvalidatedNodes
Keep track of layer nodes for which the legend size needs to be recalculated.
This class is a base class for nodes in a layer tree.
Namespace with helper functions for layer tree operations.
Executes a QgsMapHitTest in a background thread.
Class that runs a hit test with given map settings.
The QgsMapSettings class contains configuration for rendering of the map.
Contains information about the context of a rendering operation.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
Structure that stores all data associated with one map layer.
LayerLegendData()=default
QList< QgsLayerTreeModelLegendNode * > originalNodes
Data structure for storage of legend nodes.
QList< QgsLayerTreeModelLegendNode * > activeNodes
Active legend nodes.
Structure that stores tree representation of map layer's legend.
QMap< QgsLayerTreeModelLegendNode *, QgsLayerTreeModelLegendNode * > parents
Pointer to parent for each active node. Top-level nodes have nullptr parent. Pointers are not owned.
QMap< QgsLayerTreeModelLegendNode *, QList< QgsLayerTreeModelLegendNode * > > children
List of children for each active node. Top-level nodes are under nullptr key. Pointers are not owned.