QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgslegendmodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslegendmodel.h - description
3  -----------------
4  begin : June 2008
5  copyright : (C) 2008 by Marco Hugentobler
6  email : marco dot hugentobler at karto dot baug dot ethz dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSLEGENDMODEL_H
19 #define QGSLEGENDMODEL_H
20 
21 #include <QStandardItemModel>
22 #include <QStringList>
23 #include <QSet>
24 
25 class QDomDocument;
26 class QDomElement;
27 class QgsLayerTreeGroup;
28 class QgsMapLayer;
29 class QgsSymbolV2;
31 
32 //Information about relationship between groups and layers
33 //key: group name (or null strings for single layers without groups)
34 //value: containter with layer ids contained in the group
36 
40 class CORE_EXPORT QgsLegendModel : public QStandardItemModel
41 {
42  Q_OBJECT
43 
44  public:
45 
46  enum ItemType
47  {
48  GroupItem = 0,
50  ClassificationItem
51  };
52 
54  ~QgsLegendModel();
55 
59  void setLayerSetAndGroups( QgsLayerTreeGroup* rootGroup );
63  Q_DECL_DEPRECATED void setLayerSetAndGroups( const QStringList& layerIds, const QList< GroupLayerInfo >& groupInfo );
64  void setLayerSet( const QStringList& layerIds, double scaleDenominator = -1, const QString& rule = "" );
71  QStandardItem *addGroup( QString text = QString::null, int position = -1, QStandardItem* parentItem = nullptr );
72 
74  void updateItem( QStandardItem* item );
76  void updateLayer( QStandardItem* layerItem );
78  void updateVectorV2ClassificationItem( QStandardItem* classificationItem, QgsSymbolV2* symbol, const QString& itemText )
79  { Q_UNUSED( classificationItem ); Q_UNUSED( symbol ); Q_UNUSED( itemText ); }
80  void updateRasterClassificationItem( QStandardItem* classificationItem )
81  { Q_UNUSED( classificationItem ); }
82 
84  void updateItemText( QStandardItem* item );
85 
86 
87  bool writeXML( QDomElement& composerLegendElem, QDomDocument& doc ) const;
88  bool readXML( const QDomElement& legendModelElem, const QDomDocument& doc );
89 
90  Qt::DropActions supportedDropActions() const override;
91  Qt::ItemFlags flags( const QModelIndex &index ) const override;
92 
94  virtual bool removeRows( int row, int count, const QModelIndex & parent = QModelIndex() ) override;
95 
97  QMimeData* mimeData( const QModelIndexList &indexes ) const override;
98  QStringList mimeTypes() const override;
99 
101  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
102 
103  void setAutoUpdate( bool autoUpdate );
104  bool autoUpdate() { return mAutoUpdate; }
105 
106  public slots:
107  void removeLayer( const QString& layerId );
108  void addLayer( QgsMapLayer* theMapLayer, double scaleDenominator = -1, const QString& rule = "", QStandardItem* parentItem = nullptr );
109 
110  private slots:
111  void updateLayer();
112 
113  signals:
114  void layersChanged();
115 
116  private:
118  int addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLayer* vlayer, double scaleDenominator = -1, const QString& rule = "" );
119 
122  int addRasterLayerItems( QStandardItem* layerItem, QgsMapLayer* rlayer );
123 
124  void updateLayerItemText( QStandardItem* layerItem );
125  void updateSymbolV2ItemText( QStandardItem* symbolItem );
126  void updateRasterSymbolItemText( QStandardItem* symbolItem );
127 
128  void addGroupFromLayerTree( QgsLayerTreeGroup* parentGroup, QStandardItem* parentItem );
129 
130  protected:
135 
138 };
139 
140 #endif
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Layer tree group node serves as a container for layers and further groups.
static unsigned index
Base class for all map layer types.
Definition: qgsmaplayer.h:49
A model that provides group, layer and classification items.
QStringList mLayerIds
bool mHasTopLevelWindow
True if this application has toplevel windows (normally true).
virtual Qt::DropActions supportedDropActions() const
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
virtual bool removeRows(int row, int count, const QModelIndex &parent)
void updateRasterClassificationItem(QStandardItem *classificationItem)
QPair< QString, QList< QString > > GroupLayerInfo
virtual QStringList mimeTypes() const
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
bool mAutoUpdate
True if the legend is auto updated when layers are added or removed from the map canvas.
void updateVectorV2ClassificationItem(QStandardItem *classificationItem, QgsSymbolV2 *symbol, const QString &itemText)
Tries to update a single classification item.
typedef DropActions
Represents a vector layer which manages a vector based data sets.
typedef ItemFlags