QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsattributetablemodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  QgsAttributeTableModel.h - Models for attribute table
3  -------------------
4  date : Feb 2009
5  copyright : Vita Cizek
6  email : weetya (at) gmail.com
7 
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSATTRIBUTETABLEMODEL_H
18 #define QGSATTRIBUTETABLEMODEL_H
19 
20 #include <QAbstractTableModel>
21 #include <QModelIndex>
22 #include <QObject>
23 #include <QHash>
24 #include <QQueue>
25 #include <QMap>
26 
27 #include "qgsvectorlayer.h" // QgsAttributeList
28 #include "qgsvectorlayercache.h"
29 
30 class QgsMapCanvas;
31 class QgsMapLayerAction;
33 
44 class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
45 {
46  Q_OBJECT
47 
48  public:
49  enum Role
50  {
51  SortRole = Qt::UserRole + 1,
52  FeatureIdRole = Qt::UserRole + 2,
53  FieldIndexRole = Qt::UserRole + 3
54  };
55 
56  public:
62  QgsAttributeTableModel( QgsVectorLayerCache *layerCache, QObject *parent = 0 );
63 
68  virtual void loadLayer();
69 
74  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
75 
80  int columnCount( const QModelIndex &parent = QModelIndex() ) const;
81 
88  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
89 
95  virtual QVariant data( const QModelIndex &index, int role ) const;
96 
103  virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
104 
109  Qt::ItemFlags flags( const QModelIndex &index ) const;
110 
116  void reload( const QModelIndex &index1, const QModelIndex &index2 );
117 
121  bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
122 
126  void resetModel();
127 
132  int idToRow( QgsFeatureId id ) const;
133 
134  QModelIndex idToIndex( QgsFeatureId id ) const;
135 
136  QModelIndexList idToIndexList( QgsFeatureId id ) const;
137 
141  int fieldIdx( int col ) const;
142 
146  int fieldCol( int idx ) const;
147 
152  QgsFeatureId rowToId( int row ) const;
153 
159  void swapRows( QgsFeatureId a, QgsFeatureId b );
160 
164  inline QgsVectorLayer* layer() const { return mLayerCache ? mLayerCache->layer() : NULL; }
165 
169  inline QgsVectorLayerCache* layerCache() const { return mLayerCache; }
170 
174  void executeAction( int action, const QModelIndex &idx ) const;
175 
179  void executeMapLayerAction( QgsMapLayerAction* action, const QModelIndex &idx ) const;
180 
185  QgsFeature feature( const QModelIndex &idx ) const;
186 
194  void prefetchColumnData( int column );
195 
196  void setRequest( const QgsFeatureRequest& request );
197 
198  signals:
202  void modelChanged();
203 
205  void progress( int i, bool &cancel );
206  void finished();
207 
208  private slots:
212  virtual void updatedFields();
213 
219  virtual void editCommandEnded();
220 
224  virtual void attributeDeleted( int idx );
225 
226  protected slots:
233  virtual void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
238  virtual void featureDeleted( QgsFeatureId fid );
243  virtual void featureAdded( QgsFeatureId fid );
244 
248  virtual void layerDeleted();
249 
250  protected:
253 
254  mutable QgsFeature mFeat;
255 
257  QVector<QgsEditorWidgetFactory*> mWidgetFactories;
258  QVector<QVariant> mAttributeWidgetCaches;
259  QVector<QgsEditorWidgetConfig> mWidgetConfigs;
260 
261  QHash<QgsFeatureId, int> mIdRowMap;
262  QHash<int, QgsFeatureId> mRowIdMap;
263 
267  virtual void loadAttributes();
268 
269  private:
277  virtual bool loadFeatureAtId( QgsFeatureId fid ) const;
278 
280 
284  QHash<QgsFeatureId, QVariant> mFieldCache;
285 
294 };
295 
296 
297 #endif
QRect mChangedCellBounds
Holds the bounds of changed cells while an update operation is running top = min row left = min colum...
static unsigned index
QHash< int, QgsFeatureId > mRowIdMap
QgsFeatureRequest mFeatureRequest
QHash< QgsFeatureId, QVariant > mFieldCache
Allows caching of one specific column (used for sorting)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:104
QgsVectorLayerCache * mLayerCache
int mCachedField
The currently cached column.
QVector< QgsEditorWidgetFactory * > mWidgetFactories
Every attribute editor widget needs a factory, which inherits this class.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
QVector< QgsEditorWidgetConfig > mWidgetConfigs
QHash< QgsFeatureId, int > mIdRowMap
QgsVectorLayerCache * layerCache() const
Returns the layer cache this model uses as backend.
This class caches features of a given QgsVectorLayer.
QVector< QVariant > mAttributeWidgetCaches
QgsVectorLayer * layer() const
Returns the layer this model uses as backend.
qint64 QgsFeatureId
Definition: qgsfeature.h:30
Represents a vector layer which manages a vector based data sets.
An action which can run on map layers.