Quantum GIS API Documentation
1.8
|
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 { Q_UNUSED( classificationItem ); Q_UNUSED( symbol ); Q_UNUSED( itemText ); } 00069 void updateVectorV2ClassificationItem( QStandardItem* classificationItem, QgsSymbolV2* symbol, QString itemText ) 00070 { Q_UNUSED( classificationItem ); Q_UNUSED( symbol ); Q_UNUSED( itemText ); } 00071 void updateRasterClassificationItem( QStandardItem* classificationItem ) 00072 { Q_UNUSED( classificationItem ); } 00073 00074 bool writeXML( QDomElement& composerLegendElem, QDomDocument& doc ) const; 00075 bool readXML( const QDomElement& legendModelElem, const QDomDocument& doc ); 00076 00077 Qt::DropActions supportedDropActions() const; 00078 Qt::ItemFlags flags( const QModelIndex &index ) const; 00079 00081 virtual bool removeRows( int row, int count, const QModelIndex & parent = QModelIndex() ); 00082 00084 QMimeData* mimeData( const QModelIndexList &indexes ) const; 00085 QStringList mimeTypes() const; 00086 00088 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ); 00089 00090 void setAutoUpdate( bool autoUpdate ); 00091 bool autoUpdate() { return mAutoUpdate; } 00092 00093 public slots: 00094 void removeLayer( const QString& layerId ); 00095 void addLayer( QgsMapLayer* theMapLayer ); 00096 00097 signals: 00098 void layersChanged(); 00099 00100 private: 00103 int addVectorLayerItems( QStandardItem* layerItem, QgsVectorLayer* vlayer ); 00104 00106 int addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLayer* vlayer ); 00107 00110 int addRasterLayerItems( QStandardItem* layerItem, QgsMapLayer* rlayer ); 00111 00113 QStandardItem* itemFromSymbol( QgsSymbol* s, int opacity, const QString& layerID ); 00114 00115 protected: 00116 QStringList mLayerIds; 00119 bool mHasTopLevelWindow; 00120 00122 bool mAutoUpdate; 00123 }; 00124 00125 #endif