QGIS API Documentation  2.11.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 #include "qgsconditionalstyle.h"
31 
32 class QgsMapCanvas;
33 class QgsMapLayerAction;
35 
36 
48 {
49  Q_OBJECT
50 
51  public:
52  enum Role
53  {
54  SortRole = Qt::UserRole + 1,
55  FeatureIdRole = Qt::UserRole + 2,
56  FieldIndexRole = Qt::UserRole + 3
57  };
58 
59  public:
65  QgsAttributeTableModel( QgsVectorLayerCache *layerCache, QObject *parent = 0 );
66 
71  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
72 
77  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
78 
85  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
86 
92  virtual QVariant data( const QModelIndex &index, int role ) const override;
93 
100  virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
101 
106  Qt::ItemFlags flags( const QModelIndex &index ) const override;
107 
113  void reload( const QModelIndex &index1, const QModelIndex &index2 );
114 
118  bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
119 
125  inline void resetModel() { loadLayer(); }
126 
131  int idToRow( QgsFeatureId id ) const;
132 
133  QModelIndex idToIndex( QgsFeatureId id ) const;
134 
135  QModelIndexList idToIndexList( QgsFeatureId id ) const;
136 
140  int fieldIdx( int col ) const;
141 
145  int fieldCol( int idx ) const;
146 
151  QgsFeatureId rowToId( int row ) const;
152 
158  void swapRows( QgsFeatureId a, QgsFeatureId b );
159 
163  inline QgsVectorLayer* layer() const { return mLayerCache ? mLayerCache->layer() : NULL; }
164 
168  inline QgsVectorLayerCache* layerCache() const { return mLayerCache; }
169 
173  void executeAction( int action, const QModelIndex &idx ) const;
174 
178  void executeMapLayerAction( QgsMapLayerAction* action, const QModelIndex &idx ) const;
179 
184  QgsFeature feature( const QModelIndex &idx ) const;
185 
193  void prefetchColumnData( int column );
194 
202  void setRequest( const QgsFeatureRequest& request );
203 
207  const QgsFeatureRequest &request() const;
208 
215  void setEditorContext( const QgsAttributeEditorContext& context ) { mEditorContext = context; }
216 
223  const QgsAttributeEditorContext& editorContext() const { return mEditorContext; }
224 
225  public slots:
230  virtual void loadLayer();
231 
236  void fieldConditionalStyleChanged( const QString& fieldName );
237 
238  signals:
242  void modelChanged();
243 
245  void progress( int i, bool &cancel );
246  void finished();
247 
248  private slots:
252  virtual void updatedFields();
253 
259  virtual void editCommandEnded();
260 
264  virtual void attributeDeleted( int idx );
265 
266  protected slots:
273  virtual void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
278  virtual void featuresDeleted( QgsFeatureIds fids );
283  virtual void featureAdded( QgsFeatureId fid );
284 
288  virtual void layerDeleted();
289 
290  protected:
293 
294  mutable QgsFeature mFeat;
295 
300 
304 
306 
310  virtual void loadAttributes();
311 
312  private:
320  virtual bool loadFeatureAtId( QgsFeatureId fid ) const;
321 
322  QgsFeatureRequest mFeatureRequest;
323 
325  int mCachedField;
327  QHash<QgsFeatureId, QVariant> mFieldCache;
328 
336  QRect mChangedCellBounds;
337 
338  QgsAttributeEditorContext mEditorContext;
339 };
340 
341 
342 #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
QgsExpressionContext mExpressionContext
void setEditorContext(const QgsAttributeEditorContext &context)
Sets the context in which this table is shown.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
QHash< int, QList< QgsConditionalStyle > > mRowStylesMap
typedef ItemFlags