QGIS API Documentation  2.10.1-Pisa
 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"
30 
31 class QgsMapCanvas;
32 class QgsMapLayerAction;
34 
46 {
47  Q_OBJECT
48 
49  public:
50  enum Role
51  {
52  SortRole = Qt::UserRole + 1,
53  FeatureIdRole = Qt::UserRole + 2,
54  FieldIndexRole = Qt::UserRole + 3
55  };
56 
57  public:
63  QgsAttributeTableModel( QgsVectorLayerCache *layerCache, QObject *parent = 0 );
64 
69  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
70 
75  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
76 
83  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
84 
90  virtual QVariant data( const QModelIndex &index, int role ) const override;
91 
98  virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
99 
104  Qt::ItemFlags flags( const QModelIndex &index ) const override;
105 
111  void reload( const QModelIndex &index1, const QModelIndex &index2 );
112 
116  bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
117 
123  inline void resetModel() { loadLayer(); }
124 
129  int idToRow( QgsFeatureId id ) const;
130 
131  QModelIndex idToIndex( QgsFeatureId id ) const;
132 
133  QModelIndexList idToIndexList( QgsFeatureId id ) const;
134 
138  int fieldIdx( int col ) const;
139 
143  int fieldCol( int idx ) const;
144 
149  QgsFeatureId rowToId( int row ) const;
150 
156  void swapRows( QgsFeatureId a, QgsFeatureId b );
157 
161  inline QgsVectorLayer* layer() const { return mLayerCache ? mLayerCache->layer() : NULL; }
162 
166  inline QgsVectorLayerCache* layerCache() const { return mLayerCache; }
167 
171  void executeAction( int action, const QModelIndex &idx ) const;
172 
176  void executeMapLayerAction( QgsMapLayerAction* action, const QModelIndex &idx ) const;
177 
182  QgsFeature feature( const QModelIndex &idx ) const;
183 
191  void prefetchColumnData( int column );
192 
200  void setRequest( const QgsFeatureRequest& request );
201 
205  const QgsFeatureRequest &request() const;
206 
213  void setEditorContext( const QgsAttributeEditorContext& context ) { mEditorContext = context; }
214 
221  const QgsAttributeEditorContext& editorContext() const { return mEditorContext; }
222 
223  public slots:
228  virtual void loadLayer();
229 
230  signals:
234  void modelChanged();
235 
237  void progress( int i, bool &cancel );
238  void finished();
239 
240  private slots:
244  virtual void updatedFields();
245 
251  virtual void editCommandEnded();
252 
256  virtual void attributeDeleted( int idx );
257 
258  protected slots:
265  virtual void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
270  virtual void featuresDeleted( QgsFeatureIds fids );
275  virtual void featureAdded( QgsFeatureId fid );
276 
280  virtual void layerDeleted();
281 
282  protected:
285 
286  mutable QgsFeature mFeat;
287 
292 
295 
299  virtual void loadAttributes();
300 
301  private:
309  virtual bool loadFeatureAtId( QgsFeatureId fid ) const;
310 
311  QgsFeatureRequest mFeatureRequest;
312 
314  int mCachedField;
316  QHash<QgsFeatureId, QVariant> mFieldCache;
317 
325  QRect mChangedCellBounds;
326 
327  QgsAttributeEditorContext mEditorContext;
328 };
329 
330 
331 #endif
static unsigned index
virtual int rowCount(const QModelIndex &parent) const =0
QHash< int, QgsFeatureId > mRowIdMap
This class contains context information for attribute editor widgets.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
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:105
void resetModel()
Resets the model.
QgsVectorLayerCache * mLayerCache
QVector< QgsEditorWidgetFactory * > mWidgetFactories
void setEditorContext(const QgsAttributeEditorContext &context)
Sets the context in which this table is shown.
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)...
QVector< QgsEditorWidgetConfig > mWidgetConfigs
QHash< QgsFeatureId, int > mIdRowMap
virtual QVariant data(const QModelIndex &index, int role) const =0
const QgsAttributeEditorContext & editorContext() const
Returns the context in which this table is shown.
QgsVectorLayerCache * layerCache() const
Returns the layer cache this model uses as backend.
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
This class caches features of a given QgsVectorLayer.
virtual bool removeRows(int row, int count, const QModelIndex &parent)
QVector< QVariant > mAttributeWidgetCaches
QgsVectorLayer * layer() const
Returns the layer this model uses as backend.
virtual int columnCount(const QModelIndex &parent) const =0
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
qint64 QgsFeatureId
Definition: qgsfeature.h:31
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Represents a vector layer which manages a vector based data sets.
An action which can run on map layers.
typedef ItemFlags