LCOV - code coverage report
Current view: top level - core/layertree - qgslayertreemodel.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 23 0.0 %
Date: 2021-04-10 08:29:14 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :   qgslayertreemodel.h
       3                 :            :   --------------------------------------
       4                 :            :   Date                 : May 2014
       5                 :            :   Copyright            : (C) 2014 by Martin Dobias
       6                 :            :   Email                : wonder dot sk at gmail dot com
       7                 :            :  ***************************************************************************
       8                 :            :  *                                                                         *
       9                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      10                 :            :  *   it under the terms of the GNU General Public License as published by  *
      11                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      12                 :            :  *   (at your option) any later version.                                   *
      13                 :            :  *                                                                         *
      14                 :            :  ***************************************************************************/
      15                 :            : 
      16                 :            : #ifndef QGSLAYERTREEMODEL_H
      17                 :            : #define QGSLAYERTREEMODEL_H
      18                 :            : 
      19                 :            : #include "qgis_core.h"
      20                 :            : #include <QAbstractItemModel>
      21                 :            : #include <QFont>
      22                 :            : #include <QIcon>
      23                 :            : #include <QTimer>
      24                 :            : #include <QUuid>
      25                 :            : #include <memory>
      26                 :            : 
      27                 :            : #include "qgsgeometry.h"
      28                 :            : #include "qgslayertreemodellegendnode.h"
      29                 :            : 
      30                 :            : class QgsLayerTreeNode;
      31                 :            : class QgsLayerTreeGroup;
      32                 :            : class QgsLayerTreeLayer;
      33                 :            : class QgsMapHitTest;
      34                 :            : class QgsMapSettings;
      35                 :            : class QgsExpression;
      36                 :            : class QgsRenderContext;
      37                 :            : class QgsLayerTree;
      38                 :            : 
      39                 :            : /**
      40                 :            :  * \ingroup core
      41                 :            :  * \brief The QgsLayerTreeModel class is model implementation for Qt item views framework.
      42                 :            :  *
      43                 :            :  * The model can be used in any QTreeView, it is however recommended to use it
      44                 :            :  * with QgsLayerTreeView which brings additional functionality specific to layer tree handling.
      45                 :            :  *
      46                 :            :  * The model listens to the changes in the layer tree and signals the changes as appropriate,
      47                 :            :  * so that any view that uses the model is updated accordingly.
      48                 :            :  *
      49                 :            :  * Behavior of the model can be customized with flags. For example, whether to show legend or
      50                 :            :  * whether to allow changes to the layer tree.
      51                 :            :  *
      52                 :            :  * \see QgsLayerTreeView
      53                 :            :  * \since QGIS 2.4
      54                 :            :  */
      55                 :            : class CORE_EXPORT QgsLayerTreeModel : public QAbstractItemModel
      56                 :            : {
      57                 :            : 
      58                 :            : #ifdef SIP_RUN
      59                 :            :     SIP_CONVERT_TO_SUBCLASS_CODE
      60                 :            :     if ( sipCpp->inherits( "QgsLayerTreeModel" ) )
      61                 :            :       sipType = sipType_QgsLayerTreeModel;
      62                 :            :     else
      63                 :            :       sipType = 0;
      64                 :            :     SIP_END
      65                 :            : #endif
      66                 :            : 
      67                 :          0 :     Q_OBJECT
      68                 :            :   public:
      69                 :            : 
      70                 :            :     /**
      71                 :            :      * Construct a new tree model with given layer tree (root node must not be NULLPTR).
      72                 :            :      * The root node is not transferred by the model.
      73                 :            :      */
      74                 :            :     explicit QgsLayerTreeModel( QgsLayerTree *rootNode, QObject *parent SIP_TRANSFERTHIS = nullptr );
      75                 :            : 
      76                 :            :     ~QgsLayerTreeModel() override;
      77                 :            : 
      78                 :            :     // Implementation of virtual functions from QAbstractItemModel
      79                 :            : 
      80                 :            :     int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
      81                 :            :     int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
      82                 :            :     QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
      83                 :            :     QModelIndex parent( const QModelIndex &child ) const override;
      84                 :            :     QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
      85                 :            :     Qt::ItemFlags flags( const QModelIndex &index ) const override;
      86                 :            :     bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
      87                 :            :     Qt::DropActions supportedDropActions() const override;
      88                 :            :     QStringList mimeTypes() const override;
      89                 :            :     QMimeData *mimeData( const QModelIndexList &indexes ) const override;
      90                 :            :     bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
      91                 :            :     bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
      92                 :            : 
      93                 :            :     // New stuff
      94                 :            : 
      95                 :            :     enum Flag
      96                 :            :     {
      97                 :            :       // display flags
      98                 :            :       ShowLegend                 = 0x0001,  //!< Add legend nodes for layer nodes
      99                 :            :       ShowLegendAsTree           = 0x0004,  //!< For legends that support it, will show them in a tree instead of a list (needs also ShowLegend). Added in 2.8
     100                 :            :       DeferredLegendInvalidation = 0x0008,  //!< Defer legend model invalidation
     101                 :            :       UseEmbeddedWidgets         = 0x0010,  //!< Layer nodes may optionally include extra embedded widgets (if used in QgsLayerTreeView). Added in 2.16
     102                 :            :       UseTextFormatting          = 0x0020,  //!< Layer nodes will alter text appearance based on layer properties, such as scale based visibility
     103                 :            : 
     104                 :            :       // behavioral flags
     105                 :            :       AllowNodeReorder           = 0x1000,  //!< Allow reordering with drag'n'drop
     106                 :            :       AllowNodeRename            = 0x2000,  //!< Allow renaming of groups and layers
     107                 :            :       AllowNodeChangeVisibility  = 0x4000,  //!< Allow user to set node visibility with a checkbox
     108                 :            :       AllowLegendChangeState     = 0x8000,  //!< Allow check boxes for legend nodes (if supported by layer's legend)
     109                 :            :       ActionHierarchical         = 0x10000, //!< Check/uncheck action has consequences on children (or parents for leaf node)
     110                 :            :     };
     111                 :            :     Q_DECLARE_FLAGS( Flags, Flag )
     112                 :            : 
     113                 :            :     //! Sets OR-ed combination of model flags
     114                 :            :     void setFlags( QgsLayerTreeModel::Flags f );
     115                 :            :     //! Enable or disable a model flag
     116                 :            :     void setFlag( Flag f, bool on = true );
     117                 :            :     //! Returns OR-ed combination of model flags
     118                 :            :     Flags flags() const;
     119                 :            :     //! Check whether a flag is enabled
     120                 :            :     bool testFlag( Flag f ) const;
     121                 :            : 
     122                 :            :     /**
     123                 :            :      * Returns layer tree node for given index. Returns root node for invalid index.
     124                 :            :      * Returns NULLPTR if index does not refer to a layer tree node (e.g. it is a legend node)
     125                 :            :      */
     126                 :            :     QgsLayerTreeNode *index2node( const QModelIndex &index ) const;
     127                 :            :     //! Returns index for a given node. If the node does not belong to the layer tree, the result is undefined
     128                 :            :     QModelIndex node2index( QgsLayerTreeNode *node ) const;
     129                 :            : 
     130                 :            :     /**
     131                 :            :      * Convert a \a list of indexes to a list of layer tree nodes.
     132                 :            :      * Indices that do not represent layer tree nodes are skipped.
     133                 :            :      * If \a skipInternal is TRUE, a node is included in the output list only if no parent node is in the list.
     134                 :            :      */
     135                 :            :     QList<QgsLayerTreeNode *> indexes2nodes( const QModelIndexList &list, bool skipInternal = false ) const;
     136                 :            : 
     137                 :            :     /**
     138                 :            :      * Returns legend node for given index. Returns NULLPTR for invalid index
     139                 :            :      * \since QGIS 2.6
     140                 :            :      */
     141                 :            :     static QgsLayerTreeModelLegendNode *index2legendNode( const QModelIndex &index );
     142                 :            : 
     143                 :            :     /**
     144                 :            :      * Returns index for a given legend node. If the legend node does not belong to the layer tree, the result is undefined.
     145                 :            :      * If the legend node is belongs to the tree but it is filtered out, invalid model index is returned.
     146                 :            :      * \since QGIS 2.6
     147                 :            :      */
     148                 :            :     QModelIndex legendNode2index( QgsLayerTreeModelLegendNode *legendNode );
     149                 :            : 
     150                 :            :     /**
     151                 :            :      * Returns filtered list of active legend nodes attached to a particular layer node
     152                 :            :      * (by default it returns also legend node embedded in parent layer node (if any) unless skipNodeEmbeddedInParent is TRUE)
     153                 :            :      * \note Parameter skipNodeEmbeddedInParent added in QGIS 2.18
     154                 :            :      * \see layerOriginalLegendNodes()
     155                 :            :      * \since QGIS 2.6
     156                 :            :      */
     157                 :            :     QList<QgsLayerTreeModelLegendNode *> layerLegendNodes( QgsLayerTreeLayer *nodeLayer, bool skipNodeEmbeddedInParent = false );
     158                 :            : 
     159                 :            :     /**
     160                 :            :      * Returns original (unfiltered) list of legend nodes attached to a particular layer node
     161                 :            :      * \see layerLegendNodes()
     162                 :            :      * \since QGIS 2.14
     163                 :            :      */
     164                 :            :     QList<QgsLayerTreeModelLegendNode *> layerOriginalLegendNodes( QgsLayerTreeLayer *nodeLayer );
     165                 :            : 
     166                 :            :     /**
     167                 :            :      * Returns legend node that may be embedded in parent (i.e. its icon will be used for layer's icon).
     168                 :            :      * \since QGIS 2.18
     169                 :            :      */
     170                 :            :     QgsLayerTreeModelLegendNode *legendNodeEmbeddedInParent( QgsLayerTreeLayer *nodeLayer ) const;
     171                 :            : 
     172                 :            :     /**
     173                 :            :      * Searches through the layer tree to find a legend node with a matching layer ID
     174                 :            :      * and rule key.
     175                 :            :      * \param layerId map layer ID
     176                 :            :      * \param ruleKey legend node rule key
     177                 :            :      * \returns QgsLayerTreeModelLegendNode if found
     178                 :            :      * \since QGIS 2.14
     179                 :            :      */
     180                 :            :     QgsLayerTreeModelLegendNode *findLegendNode( const QString &layerId, const QString &ruleKey ) const;
     181                 :            : 
     182                 :            :     //! Returns pointer to the root node of the layer tree. Always a non NULLPTR value.
     183                 :            :     QgsLayerTree *rootGroup() const;
     184                 :            : 
     185                 :            :     /**
     186                 :            :      * Reset the model and use a new root group node
     187                 :            :      * \since QGIS 2.6
     188                 :            :      */
     189                 :            :     void setRootGroup( QgsLayerTree *newRootGroup );
     190                 :            : 
     191                 :            :     /**
     192                 :            :      * Force a refresh of legend nodes of a layer node.
     193                 :            :      * Not necessary to call when layer's renderer is changed as the model listens to these events.
     194                 :            :      */
     195                 :            :     void refreshLayerLegend( QgsLayerTreeLayer *nodeLayer );
     196                 :            : 
     197                 :            :     //! Gets index of the item marked as current. Item marked as current is underlined.
     198                 :            :     QModelIndex currentIndex() const;
     199                 :            :     //! Sets index of the current item. May be used by view. Item marked as current is underlined.
     200                 :            :     void setCurrentIndex( const QModelIndex &currentIndex );
     201                 :            : 
     202                 :            :     //! Sets font for a particular type of layer tree node. nodeType should come from QgsLayerTreeNode::NodeType enumeration
     203                 :            :     void setLayerTreeNodeFont( int nodeType, const QFont &font );
     204                 :            :     //! Gets font for a particular type of layer tree node. nodeType should come from QgsLayerTreeNode::NodeType enumeration
     205                 :            :     QFont layerTreeNodeFont( int nodeType ) const;
     206                 :            : 
     207                 :            :     //! Sets at what number of legend nodes the layer node should be collapsed. Setting -1 disables the auto-collapse (default).
     208                 :          0 :     void setAutoCollapseLegendNodes( int nodeCount ) { mAutoCollapseLegendNodesCount = nodeCount; }
     209                 :            :     //! Returns at what number of legend nodes the layer node should be collapsed. -1 means no auto-collapse (default).
     210                 :          0 :     int autoCollapseLegendNodes() const { return mAutoCollapseLegendNodesCount; }
     211                 :            : 
     212                 :            :     /**
     213                 :            :      * Force only display of legend nodes which are valid for a given \a scale.
     214                 :            :      * The \a scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
     215                 :            :      * Setting \a scale <= 0 will disable the functionality.
     216                 :            :      * \see legendFilterByScale()
     217                 :            :      * \since QGIS 2.6
     218                 :            :      */
     219                 :            :     void setLegendFilterByScale( double scale );
     220                 :            : 
     221                 :            :     /**
     222                 :            :      * Returns the scale which restricts the legend nodes which are visible.
     223                 :            :      * The  scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
     224                 :            :      * A scale <= 0 indicates that no scale filtering is being performed.
     225                 :            :      * \see setLegendFilterByScale()
     226                 :            :      * \since QGIS 2.6
     227                 :            :      */
     228                 :            :     double legendFilterByScale() const { return mLegendFilterByScale; }
     229                 :            : 
     230                 :            :     /**
     231                 :            :      * Force only display of legend nodes which are valid for given map settings.
     232                 :            :      * Setting NULLPTR or invalid map settings will disable the functionality.
     233                 :            :      * Ownership of map settings pointer does not change, a copy is made.
     234                 :            :      * \since QGIS 2.6
     235                 :            :      */
     236                 :            :     void setLegendFilterByMap( const QgsMapSettings *settings );
     237                 :            : 
     238                 :            :     /**
     239                 :            :      * Filter display of legend nodes for given map settings
     240                 :            :      * \param settings Map settings. Setting NULLPTR or invalid settings will disable any filter. Ownership is not changed, a copy is made
     241                 :            :      * \param useExtent Whether to use the extent of the map settings as a first spatial filter on legend nodes
     242                 :            :      * \param polygon If not empty, this polygon will be used instead of the map extent to filter legend nodes
     243                 :            :      * \param useExpressions Whether to use legend node filter expressions
     244                 :            :      * \since QGIS 2.14
     245                 :            :      */
     246                 :            :     void setLegendFilter( const QgsMapSettings *settings, bool useExtent = true, const QgsGeometry &polygon = QgsGeometry(), bool useExpressions = true );
     247                 :            : 
     248                 :            :     /**
     249                 :            :      * Returns the current map settings used for the current legend filter (or NULLPTR if none is enabled)
     250                 :            :      * \since QGIS 2.14
     251                 :            :      */
     252                 :          0 :     const QgsMapSettings *legendFilterMapSettings() const { return mLegendFilterMapSettings.get(); }
     253                 :            : 
     254                 :            :     /**
     255                 :            :      * Give the layer tree model hints about the currently associated map view
     256                 :            :      * so that legend nodes that use map units can be scaled correctly
     257                 :            :      * \since QGIS 2.6
     258                 :            :      */
     259                 :            :     void setLegendMapViewData( double mapUnitsPerPixel, int dpi, double scale );
     260                 :            : 
     261                 :            :     /**
     262                 :            :      * Gets hints about map view - to be used in legend nodes. Arguments that are not NULLPTR will receive values.
     263                 :            :      * If there are no valid map view data (from previous call to setLegendMapViewData()), returned values are zeros.
     264                 :            :      * \since QGIS 2.6
     265                 :            :      */
     266                 :            :     void legendMapViewData( double *mapUnitsPerPixel SIP_OUT, int *dpi SIP_OUT, double *scale  SIP_OUT ) const;
     267                 :            : 
     268                 :            :     /**
     269                 :            :      * Gets map of map layer style overrides (key: layer ID, value: style name) where a different style should be used instead of the current one
     270                 :            :      * \since QGIS 2.10
     271                 :            :      */
     272                 :            :     QMap<QString, QString> layerStyleOverrides() const;
     273                 :            : 
     274                 :            :     /**
     275                 :            :      * Sets map of map layer style overrides (key: layer ID, value: style name) where a different style should be used instead of the current one
     276                 :            :      * \since QGIS 2.10
     277                 :            :      */
     278                 :            :     void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
     279                 :            : 
     280                 :            :     /**
     281                 :            :      * Scales an layer tree model icon size to compensate for display pixel density, making the icon
     282                 :            :      * size hi-dpi friendly, whilst still resulting in pixel-perfect sizes for low-dpi
     283                 :            :      * displays.
     284                 :            :      *
     285                 :            :      * \a standardSize should be set to a standard icon size, e.g. 16, 24, 48, etc.
     286                 :            :      *
     287                 :            :      * \since QGIS 3.6
     288                 :            :      */
     289                 :            :     static int scaleIconSize( int standardSize );
     290                 :            : 
     291                 :            :   signals:
     292                 :            : 
     293                 :            :     /**
     294                 :            :      * Emits a message than can be displayed to the user in a GUI class
     295                 :            :      * \since QGIS 3.14
     296                 :            :      */
     297                 :            :     void messageEmitted( const QString &message, Qgis::MessageLevel level = Qgis::Info, int duration = 5 );
     298                 :            : 
     299                 :            :   protected slots:
     300                 :            :     void nodeWillAddChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
     301                 :            :     void nodeAddedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
     302                 :            :     void nodeWillRemoveChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
     303                 :            :     void nodeRemovedChildren();
     304                 :            : 
     305                 :            :     void nodeVisibilityChanged( QgsLayerTreeNode *node );
     306                 :            : 
     307                 :            :     /**
     308                 :            :      * Updates model when node's name has changed
     309                 :            :      * \since QGIS 3.0
     310                 :            :      */
     311                 :            :     void nodeNameChanged( QgsLayerTreeNode *node, const QString &name );
     312                 :            : 
     313                 :            :     void nodeCustomPropertyChanged( QgsLayerTreeNode *node, const QString &key );
     314                 :            : 
     315                 :            :     void nodeLayerLoaded();
     316                 :            :     void nodeLayerWillBeUnloaded();
     317                 :            :     void layerLegendChanged();
     318                 :            : 
     319                 :            :     /**
     320                 :            :      * Emitted when layer flags have changed.
     321                 :            :      * \since QGIS 3.18
     322                 :            :      */
     323                 :            :     void layerFlagsChanged();
     324                 :            : 
     325                 :            :     void layerNeedsUpdate();
     326                 :            : 
     327                 :            :     void legendNodeDataChanged();
     328                 :            : 
     329                 :            :     void invalidateLegendMapBasedData();
     330                 :            : 
     331                 :            :   protected:
     332                 :            :     void removeLegendFromLayer( QgsLayerTreeLayer *nodeLayer );
     333                 :            :     void addLegendToLayer( QgsLayerTreeLayer *nodeL );
     334                 :            : 
     335                 :            :     void connectToLayer( QgsLayerTreeLayer *nodeLayer );
     336                 :            :     void disconnectFromLayer( QgsLayerTreeLayer *nodeLayer );
     337                 :            : 
     338                 :            :     void connectToLayers( QgsLayerTreeGroup *parentGroup );
     339                 :            :     void disconnectFromLayers( QgsLayerTreeGroup *parentGroup );
     340                 :            :     void connectToRootNode();
     341                 :            :     void disconnectFromRootNode();
     342                 :            : 
     343                 :            :     //! emit dataChanged() for layer tree node items
     344                 :            :     void recursivelyEmitDataChanged( const QModelIndex &index = QModelIndex() );
     345                 :            : 
     346                 :            :     /**
     347                 :            :      * Updates layer data for scale dependent layers, should be called when map scale changes.
     348                 :            :      * Emits dataChanged() for all scale dependent layers.
     349                 :            :      * \since QGIS 2.16
     350                 :            :      */
     351                 :            :     void refreshScaleBasedLayers( const QModelIndex &index = QModelIndex(), double previousScale = 0.0 );
     352                 :            : 
     353                 :            :     static QIcon iconGroup();
     354                 :            : 
     355                 :            :     //! Filter nodes from QgsMapLayerLegend according to the current filtering rules
     356                 :            :     QList<QgsLayerTreeModelLegendNode *> filterLegendNodes( const QList<QgsLayerTreeModelLegendNode *> &nodes );
     357                 :            : 
     358                 :            :     QModelIndex indexOfParentLayerTreeNode( QgsLayerTreeNode *parentNode ) const;
     359                 :            : 
     360                 :            :     int legendRootRowCount( QgsLayerTreeLayer *nL ) const;
     361                 :            :     int legendNodeRowCount( QgsLayerTreeModelLegendNode *node ) const;
     362                 :            :     QModelIndex legendRootIndex( int row, int column, QgsLayerTreeLayer *nL ) const;
     363                 :            :     QModelIndex legendNodeIndex( int row, int column, QgsLayerTreeModelLegendNode *node ) const;
     364                 :            :     QModelIndex legendParent( QgsLayerTreeModelLegendNode *legendNode ) const;
     365                 :            :     QVariant legendNodeData( QgsLayerTreeModelLegendNode *node, int role ) const;
     366                 :            :     Qt::ItemFlags legendNodeFlags( QgsLayerTreeModelLegendNode *node ) const;
     367                 :            :     bool legendEmbeddedInParent( QgsLayerTreeLayer *nodeLayer ) const;
     368                 :            :     QIcon legendIconEmbeddedInParent( QgsLayerTreeLayer *nodeLayer ) const;
     369                 :            :     void legendCleanup();
     370                 :            :     void legendInvalidateMapBasedData();
     371                 :            : 
     372                 :            :   protected:
     373                 :            :     //! Pointer to the root node of the layer tree. Not owned by the model
     374                 :            :     QgsLayerTree *mRootNode = nullptr;
     375                 :            :     //! Sets of flags for the model
     376                 :            :     Flags mFlags;
     377                 :            :     //! Current index - will be underlined
     378                 :            :     QPersistentModelIndex mCurrentIndex;
     379                 :            :     //! Minimal number of nodes when legend should be automatically collapsed. -1 = disabled
     380                 :            :     int mAutoCollapseLegendNodesCount;
     381                 :            : 
     382                 :            :     /**
     383                 :            :      * Structure that stores tree representation of map layer's legend.
     384                 :            :      * This structure is used only when the following requirements are met:
     385                 :            :      *
     386                 :            :      * # tree legend representation is enabled in model (ShowLegendAsTree flag)
     387                 :            :      * # some legend nodes have non-null parent rule key (accessible via data(ParentRuleKeyRole) method)
     388                 :            :      *
     389                 :            :      * The tree structure (parents and children of each node) is extracted by analyzing nodes' parent rules.
     390                 :            :      * \note not available in Python bindings
     391                 :            :      */
     392                 :            : #ifndef SIP_RUN
     393                 :          0 :     struct LayerLegendTree
     394                 :            :     {
     395                 :            :       //! Pointer to parent for each active node. Top-level nodes have NULLPTR parent. Pointers are not owned.
     396                 :            :       QMap<QgsLayerTreeModelLegendNode *, QgsLayerTreeModelLegendNode *> parents;
     397                 :            :       //! List of children for each active node. Top-level nodes are under NULLPTR key. Pointers are not owned.
     398                 :            :       QMap<QgsLayerTreeModelLegendNode *, QList<QgsLayerTreeModelLegendNode *> > children;
     399                 :            :     };
     400                 :            : #endif
     401                 :            : 
     402                 :            :     /**
     403                 :            :      * Structure that stores all data associated with one map layer
     404                 :            :      * \note not available in Python bindings
     405                 :            :      */
     406                 :            : #ifndef SIP_RUN
     407                 :          0 :     struct LayerLegendData
     408                 :            :     {
     409                 :          0 :       LayerLegendData() = default;
     410                 :            : 
     411                 :            :       /**
     412                 :            :        * Active legend nodes. May have been filtered.
     413                 :            :        * Owner of legend nodes is still originalNodes !
     414                 :            :        */
     415                 :            :       QList<QgsLayerTreeModelLegendNode *> activeNodes;
     416                 :            : 
     417                 :            :       /**
     418                 :            :        * A legend node that is not displayed separately, its icon is instead
     419                 :            :        * shown within the layer node's item.
     420                 :            :        * May be NULLPTR. if non-null, node is owned by originalNodes !
     421                 :            :        */
     422                 :          0 :       QgsLayerTreeModelLegendNode *embeddedNodeInParent = nullptr;
     423                 :            : 
     424                 :            :       /**
     425                 :            :        * Data structure for storage of legend nodes.
     426                 :            :        * These are nodes as received from QgsMapLayerLegend
     427                 :            :        */
     428                 :            :       QList<QgsLayerTreeModelLegendNode *> originalNodes;
     429                 :            :       //! Optional pointer to a tree structure - see LayerLegendTree for details
     430                 :          0 :       LayerLegendTree *tree = nullptr;
     431                 :            :     };
     432                 :            : #endif
     433                 :            : 
     434                 :            :     //! \note not available in Python bindings
     435                 :            :     LayerLegendTree *tryBuildLegendTree( const QList<QgsLayerTreeModelLegendNode *> &nodes ) SIP_SKIP;
     436                 :            : 
     437                 :            :     /**
     438                 :            :      * Overrides of map layers' styles: key = layer ID, value = style XML.
     439                 :            :      * This allows showing a legend that is different from the current style of layers
     440                 :            :      */
     441                 :            :     QMap<QString, QString> mLayerStyleOverrides;
     442                 :            : 
     443                 :            :     //! Per layer data about layer's legend nodes
     444                 :            :     QHash<QgsLayerTreeLayer *, LayerLegendData> mLegend;
     445                 :            : 
     446                 :            :     /**
     447                 :            :      * Keep track of layer nodes for which the legend
     448                 :            :      * size needs to be recalculated
     449                 :            :      */
     450                 :            :     QSet<QgsLayerTreeLayer *> mInvalidatedNodes;
     451                 :            : 
     452                 :            :     QFont mFontLayer;
     453                 :            :     QFont mFontGroup;
     454                 :            : 
     455                 :            :     //! scale denominator for filtering of legend nodes (<= 0 means no filtering)
     456                 :            :     double mLegendFilterByScale;
     457                 :            : 
     458                 :            :     std::unique_ptr<QgsMapSettings> mLegendFilterMapSettings;
     459                 :            :     std::unique_ptr<QgsMapHitTest> mLegendFilterHitTest;
     460                 :            : 
     461                 :            :     //! whether to use map filtering
     462                 :            :     bool mLegendFilterUsesExtent;
     463                 :            : 
     464                 :            :     double mLegendMapViewMupp;
     465                 :            :     int mLegendMapViewDpi;
     466                 :            :     double mLegendMapViewScale;
     467                 :            :     QTimer mDeferLegendInvalidationTimer;
     468                 :            : 
     469                 :            :   private slots:
     470                 :            :     void legendNodeSizeChanged();
     471                 :            : 
     472                 :            :   private:
     473                 :            : 
     474                 :            :     //! Returns a temporary render context
     475                 :            :     QgsRenderContext *createTemporaryRenderContext() const;
     476                 :            : 
     477                 :            : };
     478                 :            : 
     479                 :          0 : Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayerTreeModel::Flags )
     480                 :            : 
     481                 :            : ///@cond PRIVATE
     482                 :            : #ifndef SIP_RUN
     483                 :            : 
     484                 :            : /**
     485                 :            :  * In order to support embedded widgets in layer tree view, the model
     486                 :            :  * generates one placeholder legend node for each embedded widget.
     487                 :            :  * The placeholder will be replaced by an embedded widget in QgsLayerTreeView
     488                 :            :  */
     489                 :          0 : class EmbeddedWidgetLegendNode : public QgsLayerTreeModelLegendNode
     490                 :            : {
     491                 :            :     Q_OBJECT
     492                 :            : 
     493                 :            :   public:
     494                 :          0 :     EmbeddedWidgetLegendNode( QgsLayerTreeLayer *nodeL )
     495                 :          0 :       : QgsLayerTreeModelLegendNode( nodeL )
     496                 :          0 :     {
     497                 :            :       // we need a valid rule key to allow the model to build a tree out of legend nodes
     498                 :            :       // if that's possible (if there is a node without a rule key, building of tree is canceled)
     499                 :          0 :       mRuleKey = QStringLiteral( "embedded-widget-" ) + QUuid::createUuid().toString();
     500                 :          0 :     }
     501                 :            : 
     502                 :          0 :     QVariant data( int role ) const override
     503                 :            :     {
     504                 :          0 :       if ( role == RuleKeyRole )
     505                 :          0 :         return mRuleKey;
     506                 :          0 :       else if ( role == QgsLayerTreeModelLegendNode::NodeTypeRole )
     507                 :          0 :         return QgsLayerTreeModelLegendNode::EmbeddedWidget;
     508                 :          0 :       return QVariant();
     509                 :          0 :     }
     510                 :            : 
     511                 :            :   private:
     512                 :            :     QString mRuleKey;
     513                 :            : };
     514                 :            : #endif
     515                 :            : 
     516                 :            : ///@endcond
     517                 :            : 
     518                 :            : #endif // QGSLAYERTREEMODEL_H

Generated by: LCOV version 1.14