Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 QgsMapLayer;
28 class QgsSymbol;
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 
57  void setLayerSetAndGroups( const QStringList& layerIds, const QList< GroupLayerInfo >& groupInfo );
58  void setLayerSet( const QStringList& layerIds );
60  QStandardItem* addGroup( QString text = tr( "Group" ), int position = -1 );
61 
63  void updateItem( QStandardItem* item );
65  void updateLayer( QStandardItem* layerItem );
67  void updateVectorClassificationItem( QStandardItem* classificationItem, QgsSymbol* symbol, QString itemText ) {}
68  void updateVectorV2ClassificationItem( QStandardItem* classificationItem, QgsSymbolV2* symbol, QString itemText ) {}
69  void updateRasterClassificationItem( QStandardItem* classificationItem ) {}
70 
71  bool writeXML( QDomElement& composerLegendElem, QDomDocument& doc ) const;
72  bool readXML( const QDomElement& legendModelElem, const QDomDocument& doc );
73 
74  Qt::DropActions supportedDropActions() const;
75  Qt::ItemFlags flags( const QModelIndex &index ) const;
76 
78  virtual bool removeRows( int row, int count, const QModelIndex & parent = QModelIndex() );
79 
81  QMimeData* mimeData( const QModelIndexList &indexes ) const;
82  QStringList mimeTypes() const;
83 
85  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent );
86 
87  void setAutoUpdate( bool autoUpdate );
88  bool autoUpdate() { return mAutoUpdate; }
89 
90  public slots:
91  void removeLayer( const QString& layerId );
92  void addLayer( QgsMapLayer* theMapLayer );
93 
94  signals:
95  void layersChanged();
96 
97  private:
100  int addVectorLayerItems( QStandardItem* layerItem, QgsVectorLayer* vlayer );
101 
103  int addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLayer* vlayer );
104 
107  int addRasterLayerItem( QStandardItem* layerItem, QgsMapLayer* rlayer );
108 
110  QStandardItem* itemFromSymbol( QgsSymbol* s, int opacity, const QString& layerID );
111 
112  protected:
113  QStringList mLayerIds;
117 
120 };
121 
122 #endif