|
QGIS API Documentation
master-59fd5e0
|
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a QAbstractItemView. More...
#include <qgsattributetablemodel.h>
Collaboration diagram for QgsAttributeTableModel: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. | |
| virtual | ~QgsAttributeTableModel () |
| int | columnCount (const QModelIndex &parent=QModelIndex()) const |
| Returns the number of columns. | |
| virtual QVariant | data (const QModelIndex &index, int role) const |
| Returns data on the given index. | |
| void | executeAction (int action, const QModelIndex &idx) const |
| Execute an action. | |
| 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 |
| Returns item flags for the index. | |
| QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const |
| Returns header data. | |
| QModelIndex | idToIndex (QgsFeatureId id) const |
| QModelIndexList | idToIndexList (QgsFeatureId id) const |
| int | idToRow (QgsFeatureId id) const |
| Maps feature id to table row. | |
| QgsVectorLayer * | layer () const |
| Returns the layer this model uses as backend. | |
| QgsVectorLayerCache * | layerCache () 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()) |
| Remove rows. | |
| void | resetModel () |
| Resets the model. | |
| virtual int | rowCount (const QModelIndex &parent=QModelIndex()) const |
| 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) |
| Updates data on given index. | |
| 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, bool inOperation=true) |
| 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 |
| QgsFeature | mFeat |
| int | mFieldCount |
| QHash< QgsFeatureId, int > | mIdRowMap |
| QgsVectorLayerCache * | mLayerCache |
| QHash< int, QgsFeatureId > | mRowIdMap |
| QMap< int, const QMap< QString, QVariant > * > | mValueMaps |
Private Slots | |
| virtual void | updatedFields () |
| Launched whenever the number of fields has changed. | |
Private Member Functions | |
| virtual bool | loadFeatureAtId (QgsFeatureId fid) const |
| Load feature fid into local cache (mFeat) | |
Private Attributes | |
| int | mCachedField |
| The currently cached column. | |
| QgsFeatureRequest | mFeatureRequest |
| QHash< QgsFeatureId, QVariant > | mFieldCache |
| Allows to cache one specific column (used for sorting) | |
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 42 of file qgsattributetablemodel.h.
Definition at line 47 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 34 of file qgsattributetablemodel.cpp.
References attributeValueChanged(), 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().
| QgsAttributeTableModel::~QgsAttributeTableModel | ( | ) | [virtual] |
Definition at line 60 of file qgsattributetablemodel.cpp.
References mValueMaps.
| void QgsAttributeTableModel::attributeValueChanged | ( | QgsFeatureId | fid, |
| int | idx, | ||
| const QVariant & | value | ||
| ) | [protected, virtual, slot] |
Launched when attribute value has been changed.
| fid | feature id |
| idx | attribute index |
| value | new value |
Definition at line 168 of file qgsattributetablemodel.cpp.
References fieldCol(), QgsFeature::id(), idToRow(), mCachedField, mFeat, mFieldCache, setData(), and QgsFeature::setValid().
Referenced by QgsAttributeTableModel().
| int QgsAttributeTableModel::columnCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const |
Returns the number of columns.
| parent | parent index |
Definition at line 407 of file qgsattributetablemodel.cpp.
References mFieldCount.
Referenced by featureAdded(), and idToIndexList().
| QVariant QgsAttributeTableModel::data | ( | const QModelIndex & | index, |
| int | role | ||
| ) | const [virtual] |
Returns data on the given index.
| index | model index |
| role | data role |
Definition at line 445 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().
| void QgsAttributeTableModel::executeAction | ( | int | action, |
| const QModelIndex & | idx | ||
| ) | const |
Execute an action.
Definition at line 591 of file qgsattributetablemodel.cpp.
References QgsVectorLayer::actions(), QgsAttributeAction::doAction(), feature(), fieldIdx(), and layer().
Referenced by QgsAttributeTableAction::execute().
| QgsFeature QgsAttributeTableModel::feature | ( | const QModelIndex & | idx | ) | const |
Return the feature attributes at given model index.
Definition at line 597 of file qgsattributetablemodel.cpp.
References data(), QgsFeature::initAttributes(), mAttributes, rowToId(), QgsFeature::setAttribute(), and QgsFeature::setFeatureId().
Referenced by executeAction().
| void QgsAttributeTableModel::featureAdded | ( | QgsFeatureId | fid, |
| bool | inOperation = true |
||
| ) | [protected, virtual, slot] |
Launched when a feature has been added.
| fid | feature id |
| inOperation | guard insertion with beginInsertRows() / endInsertRows() |
Definition at line 128 of file qgsattributetablemodel.cpp.
References columnCount(), mIdRowMap, mRowIdMap, prefetchColumnData(), reload(), and rowCount().
Referenced by loadLayer(), and QgsAttributeTableModel().
| void QgsAttributeTableModel::featureDeleted | ( | QgsFeatureId | fid | ) | [protected, virtual, slot] |
Launched when a feature has been deleted.
| fid | feature id |
Definition at line 77 of file qgsattributetablemodel.cpp.
References idToRow(), and prefetchColumnData().
Referenced by QgsAttributeTableModel().
| int QgsAttributeTableModel::fieldCol | ( | int | idx | ) | const |
get column from field index
Definition at line 396 of file qgsattributetablemodel.cpp.
References mAttributes.
Referenced by attributeValueChanged().
| int QgsAttributeTableModel::fieldIdx | ( | int | col | ) | const |
get field index from column
Definition at line 391 of file qgsattributetablemodel.cpp.
References mAttributes.
Referenced by executeAction().
| void QgsAttributeTableModel::finished | ( | ) | [signal] |
Referenced by loadLayer().
| Qt::ItemFlags QgsAttributeTableModel::flags | ( | const QModelIndex & | index | ) | const |
Returns item flags for the index.
| index | model index |
Definition at line 557 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 413 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 361 of file qgsattributetablemodel.cpp.
References idToRow().
Referenced by QgsFeatureListModel::fidToIdx().
| QModelIndexList QgsAttributeTableModel::idToIndexList | ( | QgsFeatureId | id | ) | const |
Definition at line 366 of file qgsattributetablemodel.cpp.
References columnCount(), and idToRow().
| int QgsAttributeTableModel::idToRow | ( | QgsFeatureId | id | ) | const |
Maps feature id to table row.
| id | feature id |
Definition at line 350 of file qgsattributetablemodel.cpp.
References mIdRowMap, and QgsDebugMsg.
Referenced by attributeValueChanged(), featureDeleted(), idToIndex(), idToIndexList(), and swapRows().
| QgsVectorLayer* QgsAttributeTableModel::layer | ( | ) | const [inline] |
Returns the layer this model uses as backend.
Retrieved from the layer cache.
Definition at line 164 of file qgsattributetablemodel.h.
Referenced by data(), executeAction(), flags(), headerData(), QgsAttributeTableDelegate::layer(), loadAttributes(), prefetchColumnData(), QgsAttributeTableModel(), and setData().
| QgsVectorLayerCache* QgsAttributeTableModel::layerCache | ( | ) | const [inline] |
Returns the layer cache this model uses as backend.
Definition at line 169 of file qgsattributetablemodel.h.
Referenced by QgsAttributeTableFilterModel::generateListOfVisibleFeatures().
| void QgsAttributeTableModel::layerDeleted | ( | ) | [protected, virtual, slot] |
Launched when layer has been deleted.
Definition at line 151 of file qgsattributetablemodel.cpp.
References mValueMaps, QgsDebugMsg, removeRows(), and rowCount().
Referenced by QgsAttributeTableModel().
| void QgsAttributeTableModel::loadAttributes | ( | ) | [protected, virtual] |
Gets mFieldCount, mAttributes and mValueMaps.
Definition at line 180 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().
| bool QgsAttributeTableModel::loadFeatureAtId | ( | QgsFeatureId | fid | ) | const [private, virtual] |
Load feature fid into local cache (mFeat)
| fid | feature id |
Definition at line 65 of file qgsattributetablemodel.cpp.
References QgsVectorLayerCache::featureAtId(), mFeat, MathUtils::min(), mLayerCache, and QgsDebugMsgLevel.
Referenced by data().
| 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 290 of file qgsattributetablemodel.cpp.
References featureAdded(), finished(), QgsVectorLayerCache::getFeatures(), QgsFeature::id(), mAttributes, mFeatureRequest, mFieldCount, mLayerCache, QgsFeatureIterator::nextFeature(), progress(), QgsDebugMsg, removeRows(), and rowCount().
Referenced by QgsDualView::initModels(), and QgsAttributeTableView::setCanvasAndLayerCache().
| void QgsAttributeTableModel::modelChanged | ( | ) | [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 610 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 featureAdded(), featureDeleted(), and QgsAttributeTableFilterModel::sort().
| void QgsAttributeTableModel::progress | ( | int | i, |
| bool & | cancel | ||
| ) | [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 574 of file qgsattributetablemodel.cpp.
References mFeat, MathUtils::min(), mLayerCache, QgsVectorLayerCache::removeCachedFeature(), rowToId(), and QgsFeature::setFeatureId().
Referenced by featureAdded().
| bool QgsAttributeTableModel::removeRows | ( | int | row, |
| int | count, | ||
| const QModelIndex & | parent = QModelIndex() |
||
| ) |
Remove rows.
Definition at line 88 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 586 of file qgsattributetablemodel.cpp.
| int QgsAttributeTableModel::rowCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const [virtual] |
Returns the number of rows.
| parent | parent index |
Definition at line 401 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 379 of file qgsattributetablemodel.cpp.
References MathUtils::min(), mRowIdMap, and QgsDebugMsg.
Referenced by data(), feature(), QgsAttributeTableAction::featureForm(), QgsAttributeTableFilterModel::filterAcceptsRow(), QgsFeatureListModel::idxToFid(), reload(), and QgsAttributeTableFilterModel::rowToId().
| bool QgsAttributeTableModel::setData | ( | const QModelIndex & | index, |
| const QVariant & | value, | ||
| int | role = Qt::EditRole |
||
| ) | [virtual] |
Updates data on given index.
| index | model index |
| value | new data value |
| role | data role |
Definition at line 542 of file qgsattributetablemodel.cpp.
References QgsVectorLayer::isEditable(), QgsVectorLayer::isModified(), layer(), and mFieldCount.
Referenced by attributeValueChanged().
| void QgsAttributeTableModel::swapRows | ( | QgsFeatureId | a, |
| QgsFeatureId | b | ||
| ) |
Swaps two rows.
| a | first row |
| b | second row |
Definition at line 327 of file qgsattributetablemodel.cpp.
| void QgsAttributeTableModel::updatedFields | ( | ) | [private, virtual, slot] |
Launched whenever the number of fields has changed.
Definition at line 144 of file qgsattributetablemodel.cpp.
References loadAttributes(), modelChanged(), and QgsDebugMsg.
Referenced by QgsAttributeTableModel().
QgsAttributeList QgsAttributeTableModel::mAttributes [protected] |
Definition at line 238 of file qgsattributetablemodel.h.
Referenced by data(), feature(), fieldCol(), fieldIdx(), flags(), headerData(), loadAttributes(), loadLayer(), and prefetchColumnData().
int QgsAttributeTableModel::mCachedField [private] |
The currently cached column.
Definition at line 262 of file qgsattributetablemodel.h.
Referenced by attributeValueChanged(), data(), and prefetchColumnData().
QgsFeature QgsAttributeTableModel::mFeat [mutable, protected] |
Definition at line 236 of file qgsattributetablemodel.h.
Referenced by attributeValueChanged(), data(), loadFeatureAtId(), QgsAttributeTableModel(), and reload().
Definition at line 259 of file qgsattributetablemodel.h.
Referenced by loadLayer(), and QgsAttributeTableModel().
QHash<QgsFeatureId, QVariant> QgsAttributeTableModel::mFieldCache [private] |
Allows to cache one specific column (used for sorting)
Definition at line 264 of file qgsattributetablemodel.h.
Referenced by attributeValueChanged(), data(), and prefetchColumnData().
int QgsAttributeTableModel::mFieldCount [protected] |
Definition at line 234 of file qgsattributetablemodel.h.
Referenced by columnCount(), data(), flags(), headerData(), loadAttributes(), loadLayer(), and setData().
QHash<QgsFeatureId, int> QgsAttributeTableModel::mIdRowMap [protected] |
Definition at line 241 of file qgsattributetablemodel.h.
Referenced by featureAdded(), idToRow(), removeRows(), and swapRows().
QgsVectorLayerCache* QgsAttributeTableModel::mLayerCache [protected] |
Definition at line 233 of file qgsattributetablemodel.h.
Referenced by loadFeatureAtId(), loadLayer(), prefetchColumnData(), QgsAttributeTableModel(), and reload().
QHash<int, QgsFeatureId> QgsAttributeTableModel::mRowIdMap [protected] |
Definition at line 242 of file qgsattributetablemodel.h.
Referenced by featureAdded(), removeRows(), rowCount(), rowToId(), and swapRows().
QMap< int, const QMap<QString, QVariant> * > QgsAttributeTableModel::mValueMaps [protected] |
Definition at line 239 of file qgsattributetablemodel.h.
Referenced by data(), layerDeleted(), loadAttributes(), and ~QgsAttributeTableModel().