|
QGIS API Documentation
master-6227475
|
00001 /*************************************************************************** 00002 QgsAttributeTableModel.h - Models for attribute table 00003 ------------------- 00004 date : Feb 2009 00005 copyright : Vita Cizek 00006 email : weetya (at) gmail.com 00007 00008 *************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 00017 #ifndef QGSATTRIBUTETABLEMODEL_H 00018 #define QGSATTRIBUTETABLEMODEL_H 00019 00020 #include <QAbstractTableModel> 00021 #include <QModelIndex> 00022 #include <QObject> 00023 #include <QHash> 00024 #include <QQueue> 00025 #include <QMap> 00026 00027 #include "qgsvectorlayer.h" // QgsAttributeList 00028 #include "qgsvectorlayercache.h" 00029 00030 class QgsMapCanvas; 00031 00042 class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel 00043 { 00044 Q_OBJECT 00045 00046 public: 00047 enum Role 00048 { 00049 SortRole = Qt::UserRole + 1, 00050 FeatureIdRole = Qt::UserRole + 2, 00051 FieldIndexRole = Qt::UserRole + 3 00052 }; 00053 00054 public: 00060 QgsAttributeTableModel( QgsVectorLayerCache *layerCache, QObject *parent = 0 ); 00061 00062 virtual ~QgsAttributeTableModel(); 00063 00068 virtual void loadLayer(); 00069 00074 virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; 00075 00080 int columnCount( const QModelIndex &parent = QModelIndex() ) const; 00081 00088 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; 00089 00095 virtual QVariant data( const QModelIndex &index, int role ) const; 00096 00103 virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ); 00104 00109 Qt::ItemFlags flags( const QModelIndex &index ) const; 00110 00116 void reload( const QModelIndex &index1, const QModelIndex &index2 ); 00117 00121 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ); 00122 00126 void resetModel(); 00127 00132 int idToRow( QgsFeatureId id ) const; 00133 00134 QModelIndex idToIndex( QgsFeatureId id ) const; 00135 00136 QModelIndexList idToIndexList( QgsFeatureId id ) const; 00137 00141 int fieldIdx( int col ) const; 00142 00146 int fieldCol( int idx ) const; 00147 00152 QgsFeatureId rowToId( int row ) const; 00153 00159 void swapRows( QgsFeatureId a, QgsFeatureId b ); 00160 00164 inline QgsVectorLayer* layer() const { return mLayerCache ? mLayerCache->layer() : NULL; } 00165 00169 inline QgsVectorLayerCache* layerCache() const { return mLayerCache; } 00170 00174 void executeAction( int action, const QModelIndex &idx ) const; 00175 00180 QgsFeature feature( const QModelIndex &idx ) const; 00181 00189 void prefetchColumnData( int column ); 00190 00191 signals: 00195 void modelChanged(); 00196 00198 void progress( int i, bool &cancel ); 00199 void finished(); 00200 00201 private slots: 00205 virtual void updatedFields(); 00206 00207 protected slots: 00214 virtual void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value ); 00219 virtual void featureDeleted( QgsFeatureId fid ); 00225 virtual void featureAdded( QgsFeatureId fid, bool inOperation = true ); 00226 00230 virtual void layerDeleted(); 00231 00232 protected: 00233 QgsVectorLayerCache *mLayerCache; 00234 int mFieldCount; 00235 00236 mutable QgsFeature mFeat; 00237 00238 QgsAttributeList mAttributes; 00239 QMap< int, const QMap<QString, QVariant> * > mValueMaps; 00240 00241 QHash<QgsFeatureId, int> mIdRowMap; 00242 QHash<int, QgsFeatureId> mRowIdMap; 00243 00247 virtual void loadAttributes(); 00248 00249 private: 00257 virtual bool loadFeatureAtId( QgsFeatureId fid ) const; 00258 00259 QgsFeatureRequest mFeatureRequest; 00260 00262 int mCachedField; 00264 QHash<QgsFeatureId, QVariant> mFieldCache; 00265 }; 00266 00267 00268 #endif