QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Types | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | List of all members
QgsAttributeTableModel Class Reference

A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a QAbstractItemView. More...

#include <qgsattributetablemodel.h>

Public Types

enum  Role { SortRole = Qt::UserRole + 1, FeatureIdRole = Qt::UserRole + 2, FieldIndexRole = Qt::UserRole + 3 }

Signals

void finished ()
void modelChanged ()
 Model has been changed.
void progress (int i, bool &cancel)

Public Member Functions

 QgsAttributeTableModel (QgsVectorLayerCache *layerCache, QObject *parent=0)
 Constructor.
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 Returns the number of columns.
virtual QVariant data (const QModelIndex &index, int role) const override
 Returns data on the given index.
const QgsAttributeEditorContexteditorContext () const
 Returns the context in which this table is shown.
void executeAction (int action, const QModelIndex &idx) const
 Execute an action.
void executeMapLayerAction (QgsMapLayerAction *action, const QModelIndex &idx) const
 Execute a QgsMapLayerAction.
QgsFeature feature (const QModelIndex &idx) const
 Return the feature attributes at given model index.
int fieldCol (int idx) const
 get column from field index
int fieldIdx (int col) const
 get field index from column
Qt::ItemFlags flags (const QModelIndex &index) const override
 Returns item flags for the index.
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 Returns header data.
QModelIndex idToIndex (QgsFeatureId id) const
QModelIndexList idToIndexList (QgsFeatureId id) const
int idToRow (QgsFeatureId id) const
 Maps feature id to table row.
QgsVectorLayerlayer () const
 Returns the layer this model uses as backend.
QgsVectorLayerCachelayerCache () const
 Returns the layer cache this model uses as backend.
virtual void loadLayer ()
 Loads the layer into the model Preferably to be called, before basing any other models on this model.
void prefetchColumnData (int column)
 Caches the entire data for one column.
void reload (const QModelIndex &index1, const QModelIndex &index2)
 Reloads the model data between indices.
bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) override
 Remove rows.
const QgsFeatureRequestrequest () const
 Get the the feature request.
void resetModel ()
 Resets the model.
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const override
 Returns the number of rows.
QgsFeatureId rowToId (int row) const
 Maps row to feature id.
virtual bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
 Updates data on given index.
void setEditorContext (const QgsAttributeEditorContext &context)
 Sets the context in which this table is shown.
void setRequest (const QgsFeatureRequest &request)
 Set a request that will be used to fill this attribute table model.
void swapRows (QgsFeatureId a, QgsFeatureId b)
 Swaps two rows.

Protected Slots

virtual void attributeValueChanged (QgsFeatureId fid, int idx, const QVariant &value)
 Launched when attribute value has been changed.
virtual void featureAdded (QgsFeatureId fid)
 Launched when a feature has been added.
virtual void featureDeleted (QgsFeatureId fid)
 Launched when a feature has been deleted.
virtual void layerDeleted ()
 Launched when layer has been deleted.

Protected Member Functions

virtual void loadAttributes ()
 Gets mFieldCount, mAttributes and mValueMaps.

Protected Attributes

QgsAttributeList mAttributes
QVector< QVariant > mAttributeWidgetCaches
QgsFeature mFeat
int mFieldCount
QHash< QgsFeatureId, int > mIdRowMap
QgsVectorLayerCachemLayerCache
QHash< int, QgsFeatureIdmRowIdMap
QVector< QgsEditorWidgetConfigmWidgetConfigs
QVector< QgsEditorWidgetFactory * > mWidgetFactories

Detailed Description

A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a QAbstractItemView.

Is able to generate editor widgets for its QModelIndexes as well. Is mostly referred to as "master model" within this doc and the source.

See Also
Qt Model View Programming

Definition at line 45 of file qgsattributetablemodel.h.

Member Enumeration Documentation

Enumerator:
SortRole 
FeatureIdRole 
FieldIndexRole 

Definition at line 50 of file qgsattributetablemodel.h.

Constructor & Destructor Documentation

QgsAttributeTableModel::QgsAttributeTableModel ( QgsVectorLayerCache layerCache,
QObject *  parent = 0 
)

Constructor.

Parameters
layerCacheA layer cache to use as backend
parentThe parent QObject (owner)

Definition at line 35 of file qgsattributetablemodel.cpp.

Member Function Documentation

void QgsAttributeTableModel::attributeValueChanged ( QgsFeatureId  fid,
int  idx,
const QVariant &  value 
)
protectedvirtualslot

Launched when attribute value has been changed.

Parameters
fidfeature id
idxattribute index
valuenew value

Definition at line 192 of file qgsattributetablemodel.cpp.

int QgsAttributeTableModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
override

Returns the number of columns.

Parameters
parentparent index

Definition at line 409 of file qgsattributetablemodel.cpp.

QVariant QgsAttributeTableModel::data ( const QModelIndex &  index,
int  role 
) const
overridevirtual

Returns data on the given index.

Parameters
indexmodel index
roledata role

Definition at line 447 of file qgsattributetablemodel.cpp.

const QgsAttributeEditorContext& QgsAttributeTableModel::editorContext ( ) const
inline

Returns the context in which this table is shown.

Will be forwarded to any editor widget created when editing data on this model.

Returns
The context

Definition at line 225 of file qgsattributetablemodel.h.

void QgsAttributeTableModel::executeAction ( int  action,
const QModelIndex &  idx 
) const

Execute an action.

Definition at line 581 of file qgsattributetablemodel.cpp.

void QgsAttributeTableModel::executeMapLayerAction ( QgsMapLayerAction action,
const QModelIndex &  idx 
) const

Execute a QgsMapLayerAction.

Definition at line 587 of file qgsattributetablemodel.cpp.

QgsFeature QgsAttributeTableModel::feature ( const QModelIndex &  idx) const

Return the feature attributes at given model index.

Returns
feature attributes at given model index

Definition at line 593 of file qgsattributetablemodel.cpp.

void QgsAttributeTableModel::featureAdded ( QgsFeatureId  fid)
protectedvirtualslot

Launched when a feature has been added.

Parameters
fidfeature id

Definition at line 131 of file qgsattributetablemodel.cpp.

void QgsAttributeTableModel::featureDeleted ( QgsFeatureId  fid)
protectedvirtualslot

Launched when a feature has been deleted.

Parameters
fidfeature id

Definition at line 76 of file qgsattributetablemodel.cpp.

int QgsAttributeTableModel::fieldCol ( int  idx) const

get column from field index

Definition at line 398 of file qgsattributetablemodel.cpp.

int QgsAttributeTableModel::fieldIdx ( int  col) const

get field index from column

Definition at line 393 of file qgsattributetablemodel.cpp.

void QgsAttributeTableModel::finished ( )
signal
Qt::ItemFlags QgsAttributeTableModel::flags ( const QModelIndex &  index) const
override

Returns item flags for the index.

Parameters
indexmodel index

Definition at line 552 of file qgsattributetablemodel.cpp.

QVariant QgsAttributeTableModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
override

Returns header data.

Parameters
sectionrequired section
orientationhorizontal or vertical orientation
roledata role

Definition at line 415 of file qgsattributetablemodel.cpp.

QModelIndex QgsAttributeTableModel::idToIndex ( QgsFeatureId  id) const

Definition at line 363 of file qgsattributetablemodel.cpp.

QModelIndexList QgsAttributeTableModel::idToIndexList ( QgsFeatureId  id) const

Definition at line 368 of file qgsattributetablemodel.cpp.

int QgsAttributeTableModel::idToRow ( QgsFeatureId  id) const

Maps feature id to table row.

Parameters
idfeature id

Definition at line 352 of file qgsattributetablemodel.cpp.

QgsVectorLayer* QgsAttributeTableModel::layer ( ) const
inline

Returns the layer this model uses as backend.

Retrieved from the layer cache.

Definition at line 165 of file qgsattributetablemodel.h.

QgsVectorLayerCache* QgsAttributeTableModel::layerCache ( ) const
inline

Returns the layer cache this model uses as backend.

Definition at line 170 of file qgsattributetablemodel.h.

void QgsAttributeTableModel::layerDeleted ( )
protectedvirtualslot

Launched when layer has been deleted.

Definition at line 178 of file qgsattributetablemodel.cpp.

void QgsAttributeTableModel::loadAttributes ( )
protectedvirtual

Gets mFieldCount, mAttributes and mValueMaps.

Definition at line 234 of file qgsattributetablemodel.cpp.

void QgsAttributeTableModel::loadLayer ( )
virtual

Loads the layer into the model Preferably to be called, before basing any other models on this model.

Definition at line 288 of file qgsattributetablemodel.cpp.

void QgsAttributeTableModel::modelChanged ( )
signal

Model has been changed.

void QgsAttributeTableModel::prefetchColumnData ( int  column)

Caches the entire data for one column.

This should be called prior to sorting, so the data does not have to be fetched for every single comparison. Specify -1 as column to invalidate the cache

Parameters
columnThe column index of the field to catch

Definition at line 606 of file qgsattributetablemodel.cpp.

void QgsAttributeTableModel::progress ( int  i,
bool &  cancel 
)
signal
Note
not available in python bindings
void QgsAttributeTableModel::reload ( const QModelIndex &  index1,
const QModelIndex &  index2 
)

Reloads the model data between indices.

Parameters
index1start index
index2end index

Definition at line 569 of file qgsattributetablemodel.cpp.

bool QgsAttributeTableModel::removeRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
override

Remove rows.

Definition at line 91 of file qgsattributetablemodel.cpp.

const QgsFeatureRequest & QgsAttributeTableModel::request ( ) const

Get the the feature request.

Definition at line 643 of file qgsattributetablemodel.cpp.

void QgsAttributeTableModel::resetModel ( )

Resets the model.

Definition at line 575 of file qgsattributetablemodel.cpp.

int QgsAttributeTableModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
overridevirtual

Returns the number of rows.

Parameters
parentparent index

Definition at line 403 of file qgsattributetablemodel.cpp.

QgsFeatureId QgsAttributeTableModel::rowToId ( int  row) const

Maps row to feature id.

Parameters
rowrow number

Definition at line 381 of file qgsattributetablemodel.cpp.

bool QgsAttributeTableModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
overridevirtual

Updates data on given index.

Parameters
indexmodel index
valuenew data value
roledata role

Definition at line 515 of file qgsattributetablemodel.cpp.

void QgsAttributeTableModel::setEditorContext ( const QgsAttributeEditorContext context)
inline

Sets the context in which this table is shown.

Will be forwarded to any editor widget created when editing data on this model.

Parameters
contextThe context

Definition at line 217 of file qgsattributetablemodel.h.

void QgsAttributeTableModel::setRequest ( const QgsFeatureRequest request)

Set a request that will be used to fill this attribute table model.

In contrast to a filter, the request will constrain the data shown without the possibility to dynamically adjust it.

Parameters
requestThe request to use to fill this table model.

Definition at line 636 of file qgsattributetablemodel.cpp.

void QgsAttributeTableModel::swapRows ( QgsFeatureId  a,
QgsFeatureId  b 
)

Swaps two rows.

Parameters
afirst row
bsecond row

Definition at line 329 of file qgsattributetablemodel.cpp.

Member Data Documentation

QgsAttributeList QgsAttributeTableModel::mAttributes
protected

Definition at line 285 of file qgsattributetablemodel.h.

QVector<QVariant> QgsAttributeTableModel::mAttributeWidgetCaches
protected

Definition at line 287 of file qgsattributetablemodel.h.

QgsFeature QgsAttributeTableModel::mFeat
mutableprotected

Definition at line 283 of file qgsattributetablemodel.h.

int QgsAttributeTableModel::mFieldCount
protected

Definition at line 281 of file qgsattributetablemodel.h.

QHash<QgsFeatureId, int> QgsAttributeTableModel::mIdRowMap
protected

Definition at line 290 of file qgsattributetablemodel.h.

QgsVectorLayerCache* QgsAttributeTableModel::mLayerCache
protected

Definition at line 280 of file qgsattributetablemodel.h.

QHash<int, QgsFeatureId> QgsAttributeTableModel::mRowIdMap
protected

Definition at line 291 of file qgsattributetablemodel.h.

QVector<QgsEditorWidgetConfig> QgsAttributeTableModel::mWidgetConfigs
protected

Definition at line 288 of file qgsattributetablemodel.h.

QVector<QgsEditorWidgetFactory*> QgsAttributeTableModel::mWidgetFactories
protected

Definition at line 286 of file qgsattributetablemodel.h.


The documentation for this class was generated from the following files: