QGIS API Documentation  2.0.1-Dufour
 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 QgsMapLayer;
28 class QgsSymbolV2;
30 
31 //Information about relationship between groups and layers
32 //key: group name (or null strings for single layers without groups)
33 //value: containter with layer ids contained in the group
34 typedef QPair< QString, QList<QString> > GroupLayerInfo;
35 
39 class CORE_EXPORT QgsLegendModel: public QStandardItemModel
40 {
41  Q_OBJECT
42 
43  public:
44 
45  enum ItemType
46  {
47  GroupItem = 0,
49  ClassificationItem
50  };
51 
53  ~QgsLegendModel();
54 
56  void setLayerSetAndGroups( const QStringList& layerIds, const QList< GroupLayerInfo >& groupInfo );
57  void setLayerSet( const QStringList& layerIds );
63  QStandardItem *addGroup( QString text = QString::null, int position = -1 );
64 
66  void updateItem( QStandardItem* item );
68  void updateLayer( QStandardItem* layerItem );
70  void updateVectorV2ClassificationItem( QStandardItem* classificationItem, QgsSymbolV2* symbol, QString itemText )
71  { Q_UNUSED( classificationItem ); Q_UNUSED( symbol ); Q_UNUSED( itemText ); }
72  void updateRasterClassificationItem( QStandardItem* classificationItem )
73  { Q_UNUSED( classificationItem ); }
74 
76  void updateItemText( QStandardItem* item );
77 
78 
79  bool writeXML( QDomElement& composerLegendElem, QDomDocument& doc ) const;
80  bool readXML( const QDomElement& legendModelElem, const QDomDocument& doc );
81 
82  Qt::DropActions supportedDropActions() const;
83  Qt::ItemFlags flags( const QModelIndex &index ) const;
84 
86  virtual bool removeRows( int row, int count, const QModelIndex & parent = QModelIndex() );
87 
89  QMimeData* mimeData( const QModelIndexList &indexes ) const;
90  QStringList mimeTypes() const;
91 
93  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent );
94 
95  void setAutoUpdate( bool autoUpdate );
96  bool autoUpdate() { return mAutoUpdate; }
97 
98  public slots:
99  void removeLayer( const QString& layerId );
100  void addLayer( QgsMapLayer* theMapLayer );
101 
102  signals:
103  void layersChanged();
104 
105  private:
107  int addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLayer* vlayer );
108 
111  int addRasterLayerItems( QStandardItem* layerItem, QgsMapLayer* rlayer );
112 
113  void updateLayerItemText( QStandardItem* layerItem );
114  void updateSymbolV2ItemText( QStandardItem* symbolItem );
115  void updateRasterSymbolItemText( QStandardItem* symbolItem );
116 
117 
118  protected:
119  QStringList mLayerIds;
123 
126 };
127 
128 #endif