QGIS API Documentation
2.2.0-Valmiera
|
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 | ~QgsAttributeTableModel () |
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. | |
QgsVectorLayer * | layer () const |
Returns the layer this model uses as backend. | |
QgsVectorLayerCache * | layerCache () 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) |
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 | |
QgsVectorLayerCache * | mLayerCache |
int | mFieldCount |
QgsFeature | mFeat |
QgsAttributeList | mAttributes |
QMap< int, const QMap< QString, QVariant > * > | mValueMaps |
QHash< QgsFeatureId, int > | mIdRowMap |
QHash< int, QgsFeatureId > | mRowIdMap |
Private Slots | |
virtual void | updatedFields () |
Launched whenever the number of fields has changed. | |
virtual void | editCommandEnded () |
Gets called when an edit command ends This will synchronize all fields which have been changed since the last edit command in one single go. | |
virtual void | attributeDeleted (int idx) |
Called whenever a column is removed;. |
Private Member Functions | |
virtual bool | loadFeatureAtId (QgsFeatureId fid) const |
Load feature fid into local cache (mFeat) |
Private Attributes | |
QgsFeatureRequest | mFeatureRequest |
int | mCachedField |
The currently cached column. | |
QHash< QgsFeatureId, QVariant > | mFieldCache |
Allows to cache one specific column (used for sorting) | |
QRect | mChangedCellBounds |
Holds the bounds of changed cells while an update operation is running top = min row left = min column bottom = max row right = max column. |
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.
Definition at line 43 of file qgsattributetablemodel.h.
Definition at line 48 of file qgsattributetablemodel.h.
QgsAttributeTableModel::QgsAttributeTableModel | ( | QgsVectorLayerCache * | layerCache, |
QObject * | parent = 0 |
||
) |
Constructor.
layerCache | A layer cache to use as backend |
parent | The parent QObject (owner) |
Definition at line 35 of file qgsattributetablemodel.cpp.
References attributeDeleted(), attributeValueChanged(), editCommandEnded(), featureAdded(), featureDeleted(), QgsVectorLayer::geometryType(), layer(), QgsVectorLayerCache::layer(), layerDeleted(), loadAttributes(), mFeat, mFeatureRequest, MathUtils::min(), mLayerCache, QgsFeatureRequest::NoGeometry, QGis::NoGeometry, QgsDebugMsg, QgsFeature::setFeatureId(), QgsFeatureRequest::setFlags(), and updatedFields().
|
virtual |
Definition at line 63 of file qgsattributetablemodel.cpp.
References mValueMaps.
|
privatevirtualslot |
Called whenever a column is removed;.
Definition at line 174 of file qgsattributetablemodel.cpp.
References mCachedField, and prefetchColumnData().
Referenced by QgsAttributeTableModel().
|
protectedvirtualslot |
Launched when attribute value has been changed.
fid | feature id |
idx | attribute index |
value | new value |
Definition at line 199 of file qgsattributetablemodel.cpp.
References QgsFeatureRequest::acceptFeature(), featureAdded(), featureDeleted(), fieldCol(), QgsFeatureRequest::FilterNone, QgsFeatureRequest::filterType(), idToRow(), index, loadFeatureAtId(), mCachedField, mFeat, mFeatureRequest, mFieldCache, mIdRowMap, QgsDebugMsgLevel, and setData().
Referenced by QgsAttributeTableModel().
int QgsAttributeTableModel::columnCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const |
Returns the number of columns.
parent | parent index |
Definition at line 467 of file qgsattributetablemodel.cpp.
References mFieldCount.
Referenced by featureAdded(), and idToIndexList().
|
virtual |
Returns data on the given index.
index | model index |
role | data role |
Definition at line 505 of file qgsattributetablemodel.cpp.
References QgsFeature::attribute(), QgsVectorLayer::Calendar, QgsField::displayString(), QgsVectorLayer::editType(), FeatureIdRole, FieldIndexRole, QgsFeature::id(), QgsFeature::isValid(), layer(), loadFeatureAtId(), mAttributes, mCachedField, mFeat, mFieldCache, mFieldCount, mValueMaps, QgsVectorLayer::pendingFields(), rowToId(), SortRole, and QgsField::type().
Referenced by feature(), and loadAttributes().
|
privatevirtualslot |
Gets called when an edit command ends This will synchronize all fields which have been changed since the last edit command in one single go.
Definition at line 166 of file qgsattributetablemodel.cpp.
References mChangedCellBounds, and reload().
Referenced by QgsAttributeTableModel().
void QgsAttributeTableModel::executeAction | ( | int | action, |
const QModelIndex & | idx | ||
) | const |
Execute an action.
Definition at line 667 of file qgsattributetablemodel.cpp.
References QgsVectorLayer::actions(), QgsAttributeAction::doAction(), feature(), fieldIdx(), and layer().
Referenced by QgsAttributeTableAction::execute().
void QgsAttributeTableModel::executeMapLayerAction | ( | QgsMapLayerAction * | action, |
const QModelIndex & | idx | ||
) | const |
Execute a QgsMapLayerAction.
Definition at line 673 of file qgsattributetablemodel.cpp.
References feature(), layer(), and QgsMapLayerAction::triggerForFeature().
Referenced by QgsAttributeTableMapLayerAction::execute().
QgsFeature QgsAttributeTableModel::feature | ( | const QModelIndex & | idx | ) | const |
Return the feature attributes at given model index.
Definition at line 679 of file qgsattributetablemodel.cpp.
References data(), index, QgsFeature::initAttributes(), mAttributes, rowToId(), QgsFeature::setAttribute(), and QgsFeature::setFeatureId().
Referenced by executeAction(), and executeMapLayerAction().
|
protectedvirtualslot |
Launched when a feature has been added.
fid | feature id |
Definition at line 135 of file qgsattributetablemodel.cpp.
References QgsFeatureRequest::acceptFeature(), QgsFeature::attribute(), columnCount(), QgsFeatureRequest::filterType(), QgsFeature::id(), index, loadFeatureAtId(), mCachedField, mFeat, mFeatureRequest, mFieldCache, mIdRowMap, mRowIdMap, QgsDebugMsgLevel, reload(), and rowCount().
Referenced by attributeValueChanged(), loadLayer(), and QgsAttributeTableModel().
|
protectedvirtualslot |
Launched when a feature has been deleted.
fid | feature id |
Definition at line 80 of file qgsattributetablemodel.cpp.
References QgsFeatureRequest::filterType(), idToRow(), mFeatureRequest, mFieldCache, and QgsDebugMsgLevel.
Referenced by attributeValueChanged(), and QgsAttributeTableModel().
int QgsAttributeTableModel::fieldCol | ( | int | idx | ) | const |
get column from field index
Definition at line 456 of file qgsattributetablemodel.cpp.
References mAttributes.
Referenced by attributeValueChanged().
int QgsAttributeTableModel::fieldIdx | ( | int | col | ) | const |
get field index from column
Definition at line 451 of file qgsattributetablemodel.cpp.
References mAttributes.
Referenced by executeAction().
|
signal |
Referenced by loadLayer().
Qt::ItemFlags QgsAttributeTableModel::flags | ( | const QModelIndex & | index | ) | const |
Returns item flags for the index.
index | model index |
Definition at line 639 of file qgsattributetablemodel.cpp.
References QgsVectorLayer::Immutable, layer(), mAttributes, and mFieldCount.
Referenced by loadAttributes().
QVariant QgsAttributeTableModel::headerData | ( | int | section, |
Qt::Orientation | orientation, | ||
int | role = Qt::DisplayRole |
||
) | const |
Returns header data.
section | required section |
orientation | horizontal or vertical orientation |
role | data role |
Definition at line 473 of file qgsattributetablemodel.cpp.
References QgsVectorLayer::attributeAlias(), layer(), mAttributes, mFieldCount, QgsField::name(), QgsVectorLayer::pendingFields(), and tr.
QModelIndex QgsAttributeTableModel::idToIndex | ( | QgsFeatureId | id | ) | const |
Definition at line 421 of file qgsattributetablemodel.cpp.
References idToRow(), and index.
Referenced by QgsFeatureListModel::fidToIdx().
QModelIndexList QgsAttributeTableModel::idToIndexList | ( | QgsFeatureId | id | ) | const |
Definition at line 426 of file qgsattributetablemodel.cpp.
References columnCount(), idToRow(), and index.
int QgsAttributeTableModel::idToRow | ( | QgsFeatureId | id | ) | const |
Maps feature id to table row.
id | feature id |
Definition at line 410 of file qgsattributetablemodel.cpp.
References mIdRowMap, and QgsDebugMsg.
Referenced by attributeValueChanged(), featureDeleted(), idToIndex(), idToIndexList(), and swapRows().
|
inline |
Returns the layer this model uses as backend.
Retrieved from the layer cache.
Definition at line 165 of file qgsattributetablemodel.h.
Referenced by data(), executeAction(), executeMapLayerAction(), flags(), headerData(), QgsAttributeTableDelegate::layer(), loadAttributes(), QgsRelationEditorWidget::on_mAddFeatureButton_clicked(), prefetchColumnData(), QgsAttributeTableModel(), setData(), and setRequest().
|
inline |
Returns the layer cache this model uses as backend.
Definition at line 170 of file qgsattributetablemodel.h.
Referenced by QgsAttributeTableFilterModel::generateListOfVisibleFeatures().
|
protectedvirtualslot |
Launched when layer has been deleted.
Definition at line 182 of file qgsattributetablemodel.cpp.
References mValueMaps, QgsDebugMsg, removeRows(), and rowCount().
Referenced by QgsAttributeTableModel().
|
protectedvirtual |
Gets mFieldCount, mAttributes and mValueMaps.
Definition at line 239 of file qgsattributetablemodel.cpp.
References QgsFeature::attribute(), QgsFields::count(), data(), QgsVectorLayer::editType(), QgsExpression::evaluate(), QgsVectorLayer::fieldNameIndex(), flags(), QgsVectorLayer::getFeatures(), QgsExpression::hasParserError(), QgsVectorLayer::Hidden, QgsMapLayerRegistry::instance(), layer(), QgsMapLayerRegistry::mapLayer(), mAttributes, mFieldCount, QgsVectorLayer::ValueRelationData::mFilterExpression, QgsVectorLayer::ValueRelationData::mKey, QgsVectorLayer::ValueRelationData::mLayer, QgsVectorLayer::ValueRelationData::mValue, mValueMaps, QgsExpression::needsGeometry(), QgsFeatureRequest::NoFlags, QgsFeatureRequest::NoGeometry, QgsVectorLayer::pendingFields(), QgsExpression::prepare(), QgsExpression::referencedColumns(), QgsVectorLayer::ValueMap, QgsVectorLayer::ValueRelation, and QgsVectorLayer::valueRelation().
Referenced by QgsAttributeTableModel(), and updatedFields().
|
privatevirtual |
Load feature fid into local cache (mFeat)
fid | feature id |
Definition at line 68 of file qgsattributetablemodel.cpp.
References QgsVectorLayerCache::featureAtId(), mFeat, MathUtils::min(), mLayerCache, and QgsDebugMsgLevel.
Referenced by attributeValueChanged(), data(), and featureAdded().
|
virtual |
Loads the layer into the model Preferably to be called, before basing any other models on this model.
Definition at line 349 of file qgsattributetablemodel.cpp.
References featureAdded(), finished(), QgsVectorLayerCache::getFeatures(), QgsFeature::id(), mAttributes, mFeat, mFeatureRequest, mFieldCount, mLayerCache, QgsFeatureIterator::nextFeature(), progress(), QgsDebugMsg, removeRows(), and rowCount().
Referenced by QgsDualView::initModels().
|
signal |
Model has been changed.
Referenced by updatedFields().
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
column | The column index of the field to catch |
Definition at line 692 of file qgsattributetablemodel.cpp.
References QgsFeature::attribute(), QgsVectorLayerCache::getFeatures(), QgsFeature::id(), layer(), mAttributes, mCachedField, mFieldCache, mLayerCache, QgsFeatureIterator::nextFeature(), QgsFeatureRequest::NoGeometry, and QgsVectorLayer::pendingFields().
Referenced by attributeDeleted(), and QgsAttributeTableFilterModel::sort().
|
signal |
Referenced by loadLayer().
void QgsAttributeTableModel::reload | ( | const QModelIndex & | index1, |
const QModelIndex & | index2 | ||
) |
Reloads the model data between indices.
index1 | start index |
index2 | end index |
Definition at line 656 of file qgsattributetablemodel.cpp.
References mFeat, MathUtils::min(), and QgsFeature::setFeatureId().
Referenced by editCommandEnded(), and featureAdded().
bool QgsAttributeTableModel::removeRows | ( | int | row, |
int | count, | ||
const QModelIndex & | parent = QModelIndex() |
||
) |
Remove rows.
Definition at line 95 of file qgsattributetablemodel.cpp.
References FID_TO_STRING, mIdRowMap, mRowIdMap, and QgsDebugMsgLevel.
Referenced by layerDeleted(), and loadLayer().
void QgsAttributeTableModel::resetModel | ( | ) |
Resets the model.
Definition at line 662 of file qgsattributetablemodel.cpp.
|
virtual |
Returns the number of rows.
parent | parent index |
Definition at line 461 of file qgsattributetablemodel.cpp.
References mRowIdMap.
Referenced by featureAdded(), QgsDualView::featureCount(), layerDeleted(), and loadLayer().
QgsFeatureId QgsAttributeTableModel::rowToId | ( | int | row | ) | const |
Maps row to feature id.
row | row number |
Definition at line 439 of file qgsattributetablemodel.cpp.
References MathUtils::min(), mRowIdMap, and QgsDebugMsg.
Referenced by data(), feature(), QgsAttributeTableAction::featureForm(), QgsAttributeTableFilterModel::filterAcceptsRow(), QgsFeatureListModel::idxToFid(), and QgsAttributeTableFilterModel::rowToId().
|
virtual |
Updates data on given index.
index | model index |
value | new data value |
role | data role |
Definition at line 602 of file qgsattributetablemodel.cpp.
References QgsVectorLayer::isEditable(), QgsVectorLayer::isModified(), layer(), mChangedCellBounds, and mFieldCount.
Referenced by attributeValueChanged().
void QgsAttributeTableModel::setRequest | ( | const QgsFeatureRequest & | request | ) |
Definition at line 721 of file qgsattributetablemodel.cpp.
References QgsFeatureRequest::flags(), layer(), mFeatureRequest, QgsFeatureRequest::NoGeometry, and QgsFeatureRequest::setFlags().
Referenced by QgsDualView::initModels(), and QgsDualView::setRequest().
void QgsAttributeTableModel::swapRows | ( | QgsFeatureId | a, |
QgsFeatureId | b | ||
) |
Swaps two rows.
a | first row |
b | second row |
Definition at line 387 of file qgsattributetablemodel.cpp.
|
privatevirtualslot |
Launched whenever the number of fields has changed.
Definition at line 159 of file qgsattributetablemodel.cpp.
References loadAttributes(), modelChanged(), and QgsDebugMsg.
Referenced by QgsAttributeTableModel().
|
protected |
Definition at line 257 of file qgsattributetablemodel.h.
Referenced by data(), feature(), fieldCol(), fieldIdx(), flags(), headerData(), loadAttributes(), loadLayer(), and prefetchColumnData().
|
private |
The currently cached column.
Definition at line 281 of file qgsattributetablemodel.h.
Referenced by attributeDeleted(), attributeValueChanged(), data(), featureAdded(), and prefetchColumnData().
|
private |
Holds the bounds of changed cells while an update operation is running top = min row left = min column bottom = max row right = max column.
Definition at line 292 of file qgsattributetablemodel.h.
Referenced by editCommandEnded(), and setData().
|
mutableprotected |
Definition at line 255 of file qgsattributetablemodel.h.
Referenced by attributeValueChanged(), data(), featureAdded(), loadFeatureAtId(), loadLayer(), QgsAttributeTableModel(), and reload().
|
private |
Definition at line 278 of file qgsattributetablemodel.h.
Referenced by attributeValueChanged(), featureAdded(), featureDeleted(), loadLayer(), QgsAttributeTableModel(), and setRequest().
|
private |
Allows to cache one specific column (used for sorting)
Definition at line 283 of file qgsattributetablemodel.h.
Referenced by attributeValueChanged(), data(), featureAdded(), featureDeleted(), and prefetchColumnData().
|
protected |
Definition at line 253 of file qgsattributetablemodel.h.
Referenced by columnCount(), data(), flags(), headerData(), loadAttributes(), loadLayer(), and setData().
|
protected |
Definition at line 260 of file qgsattributetablemodel.h.
Referenced by attributeValueChanged(), featureAdded(), idToRow(), removeRows(), and swapRows().
|
protected |
Definition at line 252 of file qgsattributetablemodel.h.
Referenced by loadFeatureAtId(), loadLayer(), prefetchColumnData(), and QgsAttributeTableModel().
|
protected |
Definition at line 261 of file qgsattributetablemodel.h.
Referenced by featureAdded(), removeRows(), rowCount(), rowToId(), and swapRows().
|
protected |
Definition at line 258 of file qgsattributetablemodel.h.
Referenced by data(), layerDeleted(), loadAttributes(), and ~QgsAttributeTableModel().