QGIS API Documentation  2.6.0-Brighton
 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 modelChanged ()
 Model has been changed.
void progress (int i, bool &cancel)
void finished ()

Public Member Functions

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

Protected Slots

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

Protected Member Functions

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

Protected Attributes

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

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

Member Enumeration Documentation

Enumerator:
SortRole 
FeatureIdRole 
FieldIndexRole 

Constructor & Destructor Documentation

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

Constructor.

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

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
int QgsAttributeTableModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const

Returns the number of columns.

Parameters
parentparent index
QVariant QgsAttributeTableModel::data ( const QModelIndex &  index,
int  role 
) const
virtual

Returns data on the given index.

Parameters
indexmodel index
roledata role
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
void QgsAttributeTableModel::executeAction ( int  action,
const QModelIndex &  idx 
) const

Execute an action.

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

Execute a QgsMapLayerAction.

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

Return the feature attributes at given model index.

Returns
feature attributes at given model index
void QgsAttributeTableModel::featureAdded ( QgsFeatureId  fid)
protectedvirtualslot

Launched when a feature has been added.

Parameters
fidfeature id
void QgsAttributeTableModel::featureDeleted ( QgsFeatureId  fid)
protectedvirtualslot

Launched when a feature has been deleted.

Parameters
fidfeature id
int QgsAttributeTableModel::fieldCol ( int  idx) const

get column from field index

int QgsAttributeTableModel::fieldIdx ( int  col) const

get field index from column

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

Returns item flags for the index.

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

Returns header data.

Parameters
sectionrequired section
orientationhorizontal or vertical orientation
roledata role
QModelIndex QgsAttributeTableModel::idToIndex ( QgsFeatureId  id) const
QModelIndexList QgsAttributeTableModel::idToIndexList ( QgsFeatureId  id) const
int QgsAttributeTableModel::idToRow ( QgsFeatureId  id) const

Maps feature id to table row.

Parameters
idfeature id
QgsVectorLayer* QgsAttributeTableModel::layer ( ) const
inline

Returns the layer this model uses as backend.

Retrieved from the layer cache.

QgsVectorLayerCache* QgsAttributeTableModel::layerCache ( ) const
inline

Returns the layer cache this model uses as backend.

void QgsAttributeTableModel::layerDeleted ( )
protectedvirtualslot

Launched when layer has been deleted.

void QgsAttributeTableModel::loadAttributes ( )
protectedvirtual

Gets mFieldCount, mAttributes and mValueMaps.

void QgsAttributeTableModel::loadLayer ( )
virtual

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

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
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
bool QgsAttributeTableModel::removeRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)

Remove rows.

void QgsAttributeTableModel::resetModel ( )

Resets the model.

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

Returns the number of rows.

Parameters
parentparent index
QgsFeatureId QgsAttributeTableModel::rowToId ( int  row) const

Maps row to feature id.

Parameters
rowrow number
bool QgsAttributeTableModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Updates data on given index.

Parameters
indexmodel index
valuenew data value
roledata role
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
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.
void QgsAttributeTableModel::swapRows ( QgsFeatureId  a,
QgsFeatureId  b 
)

Swaps two rows.

Parameters
afirst row
bsecond row

Member Data Documentation

QgsAttributeList QgsAttributeTableModel::mAttributes
protected
QVector<QVariant> QgsAttributeTableModel::mAttributeWidgetCaches
protected
QgsFeature QgsAttributeTableModel::mFeat
mutableprotected
int QgsAttributeTableModel::mFieldCount
protected
QHash<QgsFeatureId, int> QgsAttributeTableModel::mIdRowMap
protected
QgsVectorLayerCache* QgsAttributeTableModel::mLayerCache
protected
QHash<int, QgsFeatureId> QgsAttributeTableModel::mRowIdMap
protected
QVector<QgsEditorWidgetConfig> QgsAttributeTableModel::mWidgetConfigs
protected
QVector<QgsEditorWidgetFactory*> QgsAttributeTableModel::mWidgetFactories
protected

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