QGIS API Documentation
2.2.0-Valmiera
|
This class caches features of a given QgsVectorLayer. More...
#include <qgsvectorlayercache.h>
Classes | |
class | QgsCachedFeature |
This is a wrapper class around a cached QgsFeature, which will inform the cache, when it has been deleted, so indexes can be updated that the wrapped feature needs to be fetched again if needed. More... |
Signals | |
void | progress (int i, bool &cancel) |
When filling the cache, this signal gets emitted periodically to notify about the progress and to be able to cancel an operation. | |
void | finished () |
When filling the cache, this signal gets emitted once the cache is fully initialized. | |
void | cachedLayerDeleted () |
Is emitted when the cached layer is deleted. | |
void | attributeValueChanged (const QgsFeatureId &fid, const int &field, const QVariant &value) |
Is emitted when an attribute is changed. | |
void | featureAdded (QgsFeatureId fid) |
Is emitted, when a new feature has been added to the layer and this cache. |
Public Member Functions | |
QgsVectorLayerCache (QgsVectorLayer *layer, int cacheSize, QObject *parent=NULL) | |
void | setCacheSize (int cacheSize) |
Sets the maximum number of features to keep in the cache. | |
int | cacheSize () |
Returns the maximum number of features this cache will hold. | |
void | setCacheGeometry (bool cacheGeometry) |
Enable or disable the caching of geometries. | |
void | setCacheSubsetOfAttributes (const QgsAttributeList &attributes) |
Set the subset of attributes to be cached. | |
void | setCacheAddedAttributes (bool cacheAddedAttributes) |
If this is enabled, the subset of cached attributes will automatically be extended to also include newly added attributes. | |
void | setFullCache (bool fullCache) |
This enables or disables full caching. | |
void | addCacheIndex (QgsAbstractCacheIndex *cacheIndex) |
Adds a QgsAbstractCacheIndex to this cache. | |
QgsFeatureIterator | getFeatures (const QgsFeatureRequest &featureRequest=QgsFeatureRequest()) |
Query this VectorLayerCache for features. | |
bool | isFidCached (const QgsFeatureId fid) |
Check if a certain feature id is cached. | |
bool | featureAtId (QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false) |
Gets the feature at the given feature id. | |
bool | removeCachedFeature (QgsFeatureId fid) |
Removes the feature identified by fid from the cache if present. | |
QgsVectorLayer * | layer () |
Returns the layer to which this cache belongs. |
Protected Member Functions | |
void | requestCompleted (QgsFeatureRequest featureRequest, QgsFeatureIds fids) |
Gets called, whenever the full list of feature ids for a certain request is known. | |
void | featureRemoved (QgsFeatureId fid) |
Gets called, whenever a feature has been removed. | |
bool | checkInformationCovered (const QgsFeatureRequest &featureRequest) |
Checks if the information required to complete the request is cached. |
Private Slots | |
void | onAttributeValueChanged (QgsFeatureId fid, int field, const QVariant &value) |
void | featureDeleted (QgsFeatureId fid) |
void | onFeatureAdded (QgsFeatureId fid) |
void | attributeAdded (int field) |
void | attributeDeleted (int field) |
void | geometryChanged (QgsFeatureId fid, QgsGeometry &geom) |
void | layerDeleted () |
void | updatedFields () |
Private Member Functions | |
void | cacheFeature (QgsFeature &feat) |
Private Attributes | |
QgsVectorLayer * | mLayer |
QCache< QgsFeatureId, QgsCachedFeature > | mCache |
bool | mCacheGeometry |
bool | mFullCache |
QList< QgsAbstractCacheIndex * > | mCacheIndices |
QgsAttributeList | mCachedAttributes |
Friends | |
class | QgsCachedFeatureIterator |
class | QgsCachedFeatureWriterIterator |
class | QgsCachedFeature |
This class caches features of a given QgsVectorLayer.
The cached features can be indexed by QgsAbstractCacheIndex.
Proper indexing for a given use-case may speed up performance substantially.
Definition at line 38 of file qgsvectorlayercache.h.
QgsVectorLayerCache::QgsVectorLayerCache | ( | QgsVectorLayer * | layer, |
int | cacheSize, | ||
QObject * | parent = NULL |
||
) |
Definition at line 22 of file qgsvectorlayercache.cpp.
References attributeDeleted(), attributeValueChanged(), featureAdded(), featureDeleted(), layerDeleted(), mCache, mLayer, onAttributeValueChanged(), onFeatureAdded(), QgsVectorLayer::pendingAllAttributesList(), setCacheAddedAttributes(), setCacheGeometry(), setCacheSubsetOfAttributes(), and updatedFields().
void QgsVectorLayerCache::addCacheIndex | ( | QgsAbstractCacheIndex * | cacheIndex | ) |
Adds a QgsAbstractCacheIndex to this cache.
Cache indices know about features present in this cache and decide, if enough information is present in the cache to respond to a QgsFeatureRequest.
cacheIndex | The cache index to add. |
Definition at line 111 of file qgsvectorlayercache.cpp.
References mCacheIndices.
|
privateslot |
Definition at line 219 of file qgsvectorlayercache.cpp.
References mCache, and mCachedAttributes.
Referenced by setCacheAddedAttributes().
|
privateslot |
Definition at line 226 of file qgsvectorlayercache.cpp.
References mCache.
Referenced by QgsVectorLayerCache().
|
signal |
Is emitted when an attribute is changed.
Is re-emitted after the layer itself emits this signal. You should connect to this signal, to be sure, to not get a cached value if querying the cache.
Referenced by onAttributeValueChanged(), and QgsVectorLayerCache().
|
signal |
Is emitted when the cached layer is deleted.
Is emitted when the cached layers layerDelete() signal is being emitted, but before the local reference to it has been set to NULL. So call to layer() will still return a valid pointer for cleanup purpose.
Referenced by layerDeleted().
|
inlineprivate |
Definition at line 268 of file qgsvectorlayercache.h.
References QgsFeature::id(), mCache, and QgsCachedFeature.
Referenced by featureAtId(), and QgsCachedFeatureWriterIterator::fetchFeature().
int QgsVectorLayerCache::cacheSize | ( | ) |
Returns the maximum number of features this cache will hold.
In case full caching is enabled, this number can change, as new features get added.
Definition at line 47 of file qgsvectorlayercache.cpp.
References mCache.
Referenced by onFeatureAdded().
|
protected |
Checks if the information required to complete the request is cached.
i.e. If all attributes required and the geometry is held in the cache. Please note, that this does not check, if the requested features are cached.
featureRequest | The QgsFeatureRequest to be answered |
Definition at line 313 of file qgsvectorlayercache.cpp.
References QgsFeatureRequest::flags(), mCachedAttributes, mCacheGeometry, mLayer, QgsFeatureRequest::NoGeometry, QgsVectorLayer::pendingAllAttributesList(), QgsFeatureRequest::SubsetOfAttributes, and QgsFeatureRequest::subsetOfAttributes().
Referenced by getFeatures().
|
signal |
Is emitted, when a new feature has been added to the layer and this cache.
You should connect to this signal instead of the layers', if you want to be sure that this cache has updated information for the new feature
fid | The featureid of the changed feature |
Referenced by onFeatureAdded(), and QgsVectorLayerCache().
bool QgsVectorLayerCache::featureAtId | ( | QgsFeatureId | featureId, |
QgsFeature & | feature, | ||
bool | skipCache = false |
||
) |
Gets the feature at the given feature id.
Considers the changed, added, deleted and permanent features
featureId | The id of the feature to query |
feature | The result of the operation will be written to this feature |
skipCache | Will query the layer regardless if the feature is in the cache already |
Definition at line 128 of file qgsvectorlayercache.cpp.
References cacheFeature(), QgsVectorLayerCache::QgsCachedFeature::feature(), QgsVectorLayer::getFeatures(), mCache, mCachedAttributes, mCacheGeometry, mLayer, QgsFeatureIterator::nextFeature(), and QgsFeatureRequest::NoGeometry.
Referenced by QgsDualView::attributeAdded(), QgsFeatureListModel::data(), QgsFeatureListModel::featureByIndex(), QgsAttributeTableModel::loadFeatureAtId(), onFeatureAdded(), QgsDualView::reloadAttribute(), and QgsDualView::saveEditChanges().
|
privateslot |
Definition at line 199 of file qgsvectorlayercache.cpp.
References mCache.
Referenced by QgsVectorLayerCache().
|
protected |
Gets called, whenever a feature has been removed.
Broadcasts this information to indices, so they can invalidate their cache if required.
fid | The feature id of the removed feature. |
Definition at line 179 of file qgsvectorlayercache.cpp.
References QgsAbstractCacheIndex::flushFeature(), and mCacheIndices.
|
signal |
When filling the cache, this signal gets emitted once the cache is fully initialized.
Referenced by setFullCache().
|
privateslot |
Definition at line 234 of file qgsvectorlayercache.cpp.
References mCache, QgsVectorLayerCache::QgsCachedFeature::mFeature, and QgsFeature::setGeometry().
Referenced by setCacheGeometry().
QgsFeatureIterator QgsVectorLayerCache::getFeatures | ( | const QgsFeatureRequest & | featureRequest = QgsFeatureRequest() | ) |
Query this VectorLayerCache for features.
If the VectorLayerCache (and moreover any of its indices) is able to satisfy the request, the returned QgsFeatureIterator will iterate over cached features. If it's not possible to fully satisfy the request from the cache, part or all of the features will be requested from the data provider.
featureRequest | The request specifying filter and required data. |
Definition at line 255 of file qgsvectorlayercache.cpp.
References checkInformationCovered(), QgsVectorLayer::dataProvider(), QgsFeatureRequest::flags(), QgsAbstractCacheIndex::getCacheIterator(), QgsVectorLayer::getFeatures(), QgsVectorLayer::hasGeometryType(), mCachedAttributes, mCacheGeometry, mCacheIndices, mFullCache, mLayer, QgsCachedFeatureIterator, QgsCachedFeatureWriterIterator, QgsAbstractFeatureIterator::QgsFeatureIterator, QgsFeatureRequest::setFlags(), QgsFeatureRequest::setSubsetOfAttributes(), and QgsFeatureRequest::subsetOfAttributes().
Referenced by QgsAttributeTableFilterModel::generateListOfVisibleFeatures(), QgsAttributeTableModel::loadLayer(), and QgsAttributeTableModel::prefetchColumnData().
bool QgsVectorLayerCache::isFidCached | ( | const QgsFeatureId | fid | ) |
Check if a certain feature id is cached.
fid | The feature id to look for |
Definition at line 308 of file qgsvectorlayercache.cpp.
References mCache.
Referenced by QgsCacheIndexFeatureId::getCacheIterator().
QgsVectorLayer * QgsVectorLayerCache::layer | ( | ) |
Returns the layer to which this cache belongs.
Definition at line 162 of file qgsvectorlayercache.cpp.
References mLayer.
Referenced by QgsDualView::attributeAdded(), QgsDualView::attributeDeleted(), QgsDualView::columnBoxInit(), QgsDualView::on_mFeatureList_currentEditSelectionChanged(), QgsDualView::previewExpressionBuilder(), QgsDualView::previewExpressionChanged(), QgsAttributeTableModel::QgsAttributeTableModel(), QgsCachedFeatureWriterIterator::QgsCachedFeatureWriterIterator(), QgsDualView::reloadAttribute(), QgsDualView::saveEditChanges(), QgsFeatureListView::setModel(), and QgsDualView::viewWillShowContextMenu().
|
privateslot |
Definition at line 244 of file qgsvectorlayercache.cpp.
References cachedLayerDeleted(), and mLayer.
Referenced by QgsVectorLayerCache().
|
privateslot |
Definition at line 187 of file qgsvectorlayercache.cpp.
References attributeValueChanged(), mCache, QgsVectorLayerCache::QgsCachedFeature::mFeature, and QgsFeature::setAttribute().
Referenced by QgsVectorLayerCache().
|
privateslot |
Definition at line 204 of file qgsvectorlayercache.cpp.
References cacheSize(), featureAdded(), featureAtId(), QgsVectorLayer::featureCount(), mFullCache, mLayer, and setCacheSize().
Referenced by QgsVectorLayerCache().
|
signal |
When filling the cache, this signal gets emitted periodically to notify about the progress and to be able to cancel an operation.
i | The number of already fetched features |
cancel | A reference to a boolean variable. Set to true and the operation will be canceled. |
Referenced by setFullCache().
bool QgsVectorLayerCache::removeCachedFeature | ( | QgsFeatureId | fid | ) |
Removes the feature identified by fid from the cache if present.
fid | The id of the feature to delete |
Definition at line 157 of file qgsvectorlayercache.cpp.
References mCache.
|
protected |
Gets called, whenever the full list of feature ids for a certain request is known.
Broadcasts this information to indices, so they can update their tables.
featureRequest | The feature request that was answered |
fids | The feature ids that have been returned |
Definition at line 167 of file qgsvectorlayercache.cpp.
References mCache, mCacheIndices, and QgsAbstractCacheIndex::requestCompleted().
Referenced by QgsCachedFeatureWriterIterator::fetchFeature().
void QgsVectorLayerCache::setCacheAddedAttributes | ( | bool | cacheAddedAttributes | ) |
If this is enabled, the subset of cached attributes will automatically be extended to also include newly added attributes.
cacheAddedAttributes | Automatically cache new attributes |
Definition at line 116 of file qgsvectorlayercache.cpp.
References attributeAdded(), and mLayer.
Referenced by QgsVectorLayerCache().
void QgsVectorLayerCache::setCacheGeometry | ( | bool | cacheGeometry | ) |
Enable or disable the caching of geometries.
cacheGeometry | Enable or disable the caching of geometries |
Definition at line 52 of file qgsvectorlayercache.cpp.
References geometryChanged(), QgsVectorLayer::hasGeometryType(), mCacheGeometry, and mLayer.
Referenced by QgsVectorLayerCache().
void QgsVectorLayerCache::setCacheSize | ( | int | cacheSize | ) |
Sets the maximum number of features to keep in the cache.
Some features will be removed from the cache if the number is smaller than the previous size of the cache.
cacheSize | indicates the maximum number of features to keep in the cache |
Definition at line 42 of file qgsvectorlayercache.cpp.
References mCache.
Referenced by onFeatureAdded(), and setFullCache().
void QgsVectorLayerCache::setCacheSubsetOfAttributes | ( | const QgsAttributeList & | attributes | ) |
Set the subset of attributes to be cached.
attributes | The attributes to be cached |
Definition at line 65 of file qgsvectorlayercache.cpp.
References mCachedAttributes.
Referenced by QgsVectorLayerCache().
void QgsVectorLayerCache::setFullCache | ( | bool | fullCache | ) |
This enables or disables full caching.
If enabled, all features will be held in the cache. The cache size will incrementally be increased to offer space for all features. When enabled, all features will be read into cache. As this feature will most likely be used for slow data sources, be aware, that the call to this method might take a long time.
fullCache | True: enable full caching, False: disable full caching |
Definition at line 70 of file qgsvectorlayercache.cpp.
References QgsVectorLayer::featureCount(), finished(), mCachedAttributes, mCacheGeometry, mFullCache, mLayer, QgsFeatureRequest::NoGeometry, progress(), QgsCachedFeatureWriterIterator, and setCacheSize().
|
privateslot |
Definition at line 250 of file qgsvectorlayercache.cpp.
References mCache.
Referenced by QgsVectorLayerCache().
|
friend |
Definition at line 285 of file qgsvectorlayercache.h.
Referenced by cacheFeature().
|
friend |
Definition at line 283 of file qgsvectorlayercache.h.
Referenced by getFeatures().
|
friend |
Definition at line 284 of file qgsvectorlayercache.h.
Referenced by getFeatures(), and setFullCache().
|
private |
Definition at line 275 of file qgsvectorlayercache.h.
Referenced by attributeAdded(), attributeDeleted(), cacheFeature(), cacheSize(), featureAtId(), featureDeleted(), QgsCachedFeatureIterator::fetchFeature(), geometryChanged(), isFidCached(), onAttributeValueChanged(), QgsCachedFeatureIterator::QgsCachedFeatureIterator(), QgsVectorLayerCache(), removeCachedFeature(), requestCompleted(), setCacheSize(), and updatedFields().
|
private |
Definition at line 281 of file qgsvectorlayercache.h.
Referenced by attributeAdded(), checkInformationCovered(), featureAtId(), getFeatures(), setCacheSubsetOfAttributes(), and setFullCache().
|
private |
Definition at line 277 of file qgsvectorlayercache.h.
Referenced by checkInformationCovered(), featureAtId(), getFeatures(), setCacheGeometry(), and setFullCache().
|
private |
Definition at line 279 of file qgsvectorlayercache.h.
Referenced by addCacheIndex(), featureRemoved(), getFeatures(), and requestCompleted().
|
private |
Definition at line 278 of file qgsvectorlayercache.h.
Referenced by getFeatures(), onFeatureAdded(), and setFullCache().
|
private |
Definition at line 274 of file qgsvectorlayercache.h.
Referenced by checkInformationCovered(), featureAtId(), getFeatures(), layer(), layerDeleted(), onFeatureAdded(), QgsVectorLayerCache(), setCacheAddedAttributes(), setCacheGeometry(), and setFullCache().