|
QGIS API Documentation
master-6164ace
|
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 QgsSymbolV2; 00029 class QgsVectorLayer; 00030 00031 //Information about relationship between groups and layers 00032 //key: group name (or null strings for single layers without groups) 00033 //value: containter with layer ids contained in the group 00034 typedef QPair< QString, QList<QString> > GroupLayerInfo; 00035 00039 class CORE_EXPORT QgsLegendModel: public QStandardItemModel 00040 { 00041 Q_OBJECT 00042 00043 public: 00044 00045 enum ItemType 00046 { 00047 GroupItem = 0, 00048 LayerItem, 00049 ClassificationItem 00050 }; 00051 00052 QgsLegendModel(); 00053 ~QgsLegendModel(); 00054 00056 void setLayerSetAndGroups( const QStringList& layerIds, const QList< GroupLayerInfo >& groupInfo ); 00057 void setLayerSet( const QStringList& layerIds ); 00063 QStandardItem *addGroup( QString text = QString::null, int position = -1 ); 00064 00066 void updateItem( QStandardItem* item ); 00068 void updateLayer( QStandardItem* layerItem ); 00070 void updateVectorV2ClassificationItem( QStandardItem* classificationItem, QgsSymbolV2* symbol, QString itemText ) 00071 { Q_UNUSED( classificationItem ); Q_UNUSED( symbol ); Q_UNUSED( itemText ); } 00072 void updateRasterClassificationItem( QStandardItem* classificationItem ) 00073 { Q_UNUSED( classificationItem ); } 00074 00076 void updateItemText( QStandardItem* item ); 00077 00078 00079 bool writeXML( QDomElement& composerLegendElem, QDomDocument& doc ) const; 00080 bool readXML( const QDomElement& legendModelElem, const QDomDocument& doc ); 00081 00082 Qt::DropActions supportedDropActions() const; 00083 Qt::ItemFlags flags( const QModelIndex &index ) const; 00084 00086 virtual bool removeRows( int row, int count, const QModelIndex & parent = QModelIndex() ); 00087 00089 QMimeData* mimeData( const QModelIndexList &indexes ) const; 00090 QStringList mimeTypes() const; 00091 00093 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ); 00094 00095 void setAutoUpdate( bool autoUpdate ); 00096 bool autoUpdate() { return mAutoUpdate; } 00097 00098 public slots: 00099 void removeLayer( const QString& layerId ); 00100 void addLayer( QgsMapLayer* theMapLayer ); 00101 00102 signals: 00103 void layersChanged(); 00104 00105 private: 00107 int addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLayer* vlayer ); 00108 00111 int addRasterLayerItems( QStandardItem* layerItem, QgsMapLayer* rlayer ); 00112 00113 void updateLayerItemText( QStandardItem* layerItem ); 00114 void updateSymbolV2ItemText( QStandardItem* symbolItem ); 00115 void updateRasterSymbolItemText( QStandardItem* symbolItem ); 00116 00117 00118 protected: 00119 QStringList mLayerIds; 00122 bool mHasTopLevelWindow; 00123 00125 bool mAutoUpdate; 00126 }; 00127 00128 #endif