QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
35 typedef QPair< QString, QList<QString> > GroupLayerInfo;
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, QString rule = "" );
71  QStandardItem *addGroup( QString text = QString::null, int position = -1, QStandardItem* parentItem = 0 );
72 
74  void updateItem( QStandardItem* item );
76  void updateLayer( QStandardItem* layerItem );
78  void updateVectorV2ClassificationItem( QStandardItem* classificationItem, QgsSymbolV2* symbol, 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, QString rule = "", QStandardItem* parentItem = 0 );
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, 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:
131  QStringList mLayerIds;
135 
138 };
139 
140 #endif