QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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>

Inheritance diagram for QgsAttributeTableModel:
Inheritance graph
[legend]

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. More...
 
void progress (int i, bool &cancel)
 

Public Member Functions

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

Protected Slots

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

Protected Member Functions

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

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

Returns the number of columns.

Parameters
parentparent index

Definition at line 407 of file qgsattributetablemodel.cpp.

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

Returns data on the given index.

Parameters
indexmodel index
roledata role

Definition at line 445 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 220 of file qgsattributetablemodel.h.

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

Execute an action.

Definition at line 579 of file qgsattributetablemodel.cpp.

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

Execute a QgsMapLayerAction.

Definition at line 585 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 591 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 396 of file qgsattributetablemodel.cpp.

int QgsAttributeTableModel::fieldIdx ( int  col) const

get field index from column

Definition at line 391 of file qgsattributetablemodel.cpp.

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

Returns item flags for the index.

Parameters
indexmodel index

Definition at line 550 of file qgsattributetablemodel.cpp.

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

Definition at line 413 of file qgsattributetablemodel.cpp.

QModelIndex QgsAttributeTableModel::idToIndex ( QgsFeatureId  id) const

Definition at line 361 of file qgsattributetablemodel.cpp.

QModelIndexList QgsAttributeTableModel::idToIndexList ( QgsFeatureId  id) const

Definition at line 366 of file qgsattributetablemodel.cpp.

int QgsAttributeTableModel::idToRow ( QgsFeatureId  id) const

Maps feature id to table row.

Parameters
idfeature id

Definition at line 350 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 232 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 286 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 604 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 567 of file qgsattributetablemodel.cpp.

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

Remove rows.

Definition at line 91 of file qgsattributetablemodel.cpp.

void QgsAttributeTableModel::resetModel ( )

Resets the model.

Definition at line 573 of file qgsattributetablemodel.cpp.

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

Returns the number of rows.

Parameters
parentparent index

Definition at line 401 of file qgsattributetablemodel.cpp.

QgsFeatureId QgsAttributeTableModel::rowToId ( int  row) const

Maps row to feature id.

Parameters
rowrow number

Definition at line 379 of file qgsattributetablemodel.cpp.

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

Definition at line 513 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 212 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 633 of file qgsattributetablemodel.cpp.

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

Swaps two rows.

Parameters
afirst row
bsecond row

Definition at line 327 of file qgsattributetablemodel.cpp.

Member Data Documentation

QgsAttributeList QgsAttributeTableModel::mAttributes
protected

Definition at line 280 of file qgsattributetablemodel.h.

QVector<QVariant> QgsAttributeTableModel::mAttributeWidgetCaches
protected

Definition at line 282 of file qgsattributetablemodel.h.

QgsFeature QgsAttributeTableModel::mFeat
mutableprotected

Definition at line 278 of file qgsattributetablemodel.h.

int QgsAttributeTableModel::mFieldCount
protected

Definition at line 276 of file qgsattributetablemodel.h.

QHash<QgsFeatureId, int> QgsAttributeTableModel::mIdRowMap
protected

Definition at line 285 of file qgsattributetablemodel.h.

QgsVectorLayerCache* QgsAttributeTableModel::mLayerCache
protected

Definition at line 275 of file qgsattributetablemodel.h.

QHash<int, QgsFeatureId> QgsAttributeTableModel::mRowIdMap
protected

Definition at line 286 of file qgsattributetablemodel.h.

QVector<QgsEditorWidgetConfig> QgsAttributeTableModel::mWidgetConfigs
protected

Definition at line 283 of file qgsattributetablemodel.h.

QVector<QgsEditorWidgetFactory*> QgsAttributeTableModel::mWidgetFactories
protected

Definition at line 281 of file qgsattributetablemodel.h.


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