Quantum GIS API Documentation
1.7.4
|
00001 /*************************************************************************** 00002 qgslegendmodel.h - description 00003 ----------------- 00004 begin : June 2008 00005 copyright : (C) 2008 by Marco Hugentobler 00006 email : marco dot hugentobler at karto dot baug dot ethz dot ch 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef QGSLEGENDMODEL_H 00019 #define QGSLEGENDMODEL_H 00020 00021 #include <QStandardItemModel> 00022 #include <QStringList> 00023 #include <QSet> 00024 00025 class QDomDocument; 00026 class QDomElement; 00027 class QgsMapLayer; 00028 class QgsSymbol; 00029 class QgsSymbolV2; 00030 class QgsVectorLayer; 00031 00032 //Information about relationship between groups and layers 00033 //key: group name (or null strings for single layers without groups) 00034 //value: containter with layer ids contained in the group 00035 typedef QPair< QString, QList<QString> > GroupLayerInfo; 00036 00040 class CORE_EXPORT QgsLegendModel: public QStandardItemModel 00041 { 00042 Q_OBJECT 00043 00044 public: 00045 00046 enum ItemType 00047 { 00048 GroupItem = 0, 00049 LayerItem, 00050 ClassificationItem 00051 }; 00052 00053 QgsLegendModel(); 00054 ~QgsLegendModel(); 00055 00057 void setLayerSetAndGroups( const QStringList& layerIds, const QList< GroupLayerInfo >& groupInfo ); 00058 void setLayerSet( const QStringList& layerIds ); 00060 QStandardItem* addGroup( QString text = tr( "Group" ), int position = -1 ); 00061 00063 void updateItem( QStandardItem* item ); 00065 void updateLayer( QStandardItem* layerItem ); 00067 void updateVectorClassificationItem( QStandardItem* classificationItem, QgsSymbol* symbol, QString itemText ) {} 00068 void updateVectorV2ClassificationItem( QStandardItem* classificationItem, QgsSymbolV2* symbol, QString itemText ) {} 00069 void updateRasterClassificationItem( QStandardItem* classificationItem ) {} 00070 00071 bool writeXML( QDomElement& composerLegendElem, QDomDocument& doc ) const; 00072 bool readXML( const QDomElement& legendModelElem, const QDomDocument& doc ); 00073 00074 Qt::DropActions supportedDropActions() const; 00075 Qt::ItemFlags flags( const QModelIndex &index ) const; 00076 00078 virtual bool removeRows( int row, int count, const QModelIndex & parent = QModelIndex() ); 00079 00081 QMimeData* mimeData( const QModelIndexList &indexes ) const; 00082 QStringList mimeTypes() const; 00083 00085 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ); 00086 00087 void setAutoUpdate( bool autoUpdate ); 00088 bool autoUpdate() { return mAutoUpdate; } 00089 00090 public slots: 00091 void removeLayer( const QString& layerId ); 00092 void addLayer( QgsMapLayer* theMapLayer ); 00093 00094 signals: 00095 void layersChanged(); 00096 00097 private: 00100 int addVectorLayerItems( QStandardItem* layerItem, QgsVectorLayer* vlayer ); 00101 00103 int addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLayer* vlayer ); 00104 00107 int addRasterLayerItem( QStandardItem* layerItem, QgsMapLayer* rlayer ); 00108 00110 QStandardItem* itemFromSymbol( QgsSymbol* s, int opacity, const QString& layerID ); 00111 00112 protected: 00113 QStringList mLayerIds; 00116 bool mHasTopLevelWindow; 00117 00119 bool mAutoUpdate; 00120 }; 00121 00122 #endif