QGIS API Documentation
2.18.21-Las Palmas (9fba24a)
|
This class caches features of a given QgsVectorLayer. More...
#include <qgsvectorlayercache.h>
Signals | |
void | attributeValueChanged (QgsFeatureId fid, int field, const QVariant &value) |
Is emitted when an attribute is changed. More... | |
void | cachedLayerDeleted () |
Is emitted when the cached layer is deleted. More... | |
void | featureAdded (QgsFeatureId fid) |
Is emitted, when a new feature has been added to the layer and this cache. More... | |
void | finished () |
When filling the cache, this signal gets emitted once the cache is fully initialized. More... | |
void | invalidated () |
The cache has been invalidated and cleared. More... | |
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. More... | |
Public Member Functions | |
QgsVectorLayerCache (QgsVectorLayer *layer, int cacheSize, QObject *parent=nullptr) | |
~QgsVectorLayerCache () | |
void | addCacheIndex (QgsAbstractCacheIndex *cacheIndex) |
Adds a QgsAbstractCacheIndex to this cache. More... | |
QgsFeatureIds | cachedFeatureIds () const |
Returns the set of feature IDs for features which are cached. More... | |
bool | cacheGeometry () const |
Returns true if the cache will fetch and cache feature geometries. More... | |
int | cacheSize () |
Returns the maximum number of features this cache will hold. More... | |
bool | featureAtId (QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false) |
Gets the feature at the given feature id. More... | |
QgsFeatureIterator | getFeatures (const QgsFeatureRequest &featureRequest=QgsFeatureRequest()) |
Query this VectorLayerCache for features. More... | |
bool | hasFullCache () const |
Returns true if the cache is complete, ie it contains all features. More... | |
bool | isFidCached (const QgsFeatureId fid) const |
Check if a certain feature id is cached. More... | |
QgsVectorLayer * | layer () |
Returns the layer to which this cache belongs. More... | |
bool | removeCachedFeature (QgsFeatureId fid) |
Removes the feature identified by fid from the cache if present. More... | |
void | setCacheAddedAttributes (bool cacheAddedAttributes) |
If this is enabled, the subset of cached attributes will automatically be extended to also include newly added attributes. More... | |
void | setCacheGeometry (bool cacheGeometry) |
Enable or disable the caching of geometries. More... | |
void | setCacheSize (int cacheSize) |
Sets the maximum number of features to keep in the cache. More... | |
void | setCacheSubsetOfAttributes (const QgsAttributeList &attributes) |
Set the subset of attributes to be cached. More... | |
void | setFullCache (bool fullCache) |
This enables or disables full caching. More... | |
Public Member Functions inherited from QObject | |
QObject (QObject *parent) | |
QObject (QObject *parent, const char *name) | |
virtual | ~QObject () |
bool | blockSignals (bool block) |
QObject * | child (const char *objName, const char *inheritsClass, bool recursiveSearch) const |
const QObjectList & | children () const |
const char * | className () const |
bool | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const |
void | deleteLater () |
void | destroyed (QObject *obj) |
bool | disconnect (const QObject *receiver, const char *method) |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QByteArray > | dynamicPropertyNames () const |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
T | findChild (const QString &name) const |
QList< T > | findChildren (const QRegExp ®Exp) const |
QList< T > | findChildren (const QString &name) const |
bool | inherits (const char *className) const |
void | insertChild (QObject *object) |
void | installEventFilter (QObject *filterObj) |
bool | isA (const char *className) const |
bool | isWidgetType () const |
void | killTimer (int id) |
virtual const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
const char * | name () const |
const char * | name (const char *defaultName) const |
QString | objectName () const |
QObject * | parent () const |
QVariant | property (const char *name) const |
void | removeChild (QObject *object) |
void | removeEventFilter (QObject *obj) |
void | setName (const char *name) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const char *name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval) |
QThread * | thread () const |
Protected Member Functions | |
bool | checkInformationCovered (const QgsFeatureRequest &featureRequest) |
Checks if the information required to complete the request is cached. More... | |
void | featureRemoved (QgsFeatureId fid) |
Gets called, whenever a feature has been removed. More... | |
void | requestCompleted (const QgsFeatureRequest &featureRequest, const QgsFeatureIds &fids) |
Gets called, whenever the full list of feature ids for a certain request is known. More... | |
Protected Member Functions inherited from QObject | |
bool | checkConnectArgs (const char *signal, const QObject *object, const char *method) |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const char *signal) |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const char *signal) |
int | receivers (const char *signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Friends | |
class | QgsCachedFeature |
class | QgsCachedFeatureIterator |
class | QgsCachedFeatureWriterIterator |
class | TestVectorLayerCache |
Additional Inherited Members | |
Static Public Member Functions inherited from QObject | |
bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
Static Protected Member Functions inherited from QObject | |
QByteArray | normalizeSignalSlot (const char *signalSlot) |
Properties inherited from QObject | |
objectName | |
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 = nullptr |
||
) |
Definition at line 22 of file qgsvectorlayercache.cpp.
QgsVectorLayerCache::~QgsVectorLayerCache | ( | ) |
Definition at line 44 of file qgsvectorlayercache.cpp.
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. The layer cache will take ownership of the index.
cacheIndex | The cache index to add. |
Definition at line 125 of file qgsvectorlayercache.cpp.
|
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.
|
inline |
Returns the set of feature IDs for features which are cached.
Definition at line 188 of file qgsvectorlayercache.h.
|
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.
|
inline |
Returns true if the cache will fetch and cache feature geometries.
Definition at line 115 of file qgsvectorlayercache.h.
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 55 of file qgsvectorlayercache.cpp.
|
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 380 of file qgsvectorlayercache.cpp.
|
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 |
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 142 of file qgsvectorlayercache.cpp.
|
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 197 of file qgsvectorlayercache.cpp.
|
signal |
When filling the cache, this signal gets emitted once the cache is fully initialized.
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 329 of file qgsvectorlayercache.cpp.
|
inline |
Returns true if the cache is complete, ie it contains all features.
This may happen as a result of a call to setFullCache() or by through a feature request which resulted in all available features being cached.
Definition at line 153 of file qgsvectorlayercache.h.
|
signal |
The cache has been invalidated and cleared.
Note that when a cache is invalidated the fullCache() setting will be cleared, and a full cache rebuild via setFullCache( true ) will need to be performed.
bool QgsVectorLayerCache::isFidCached | ( | const QgsFeatureId | fid | ) | const |
Check if a certain feature id is cached.
fid | The feature id to look for |
Definition at line 375 of file qgsvectorlayercache.cpp.
QgsVectorLayer * QgsVectorLayerCache::layer | ( | ) |
Returns the layer to which this cache belongs.
Definition at line 176 of file qgsvectorlayercache.cpp.
|
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. |
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 171 of file qgsvectorlayercache.cpp.
|
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 181 of file qgsvectorlayercache.cpp.
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 130 of file qgsvectorlayercache.cpp.
void QgsVectorLayerCache::setCacheGeometry | ( | bool | cacheGeometry | ) |
Enable or disable the caching of geometries.
cacheGeometry | Enable or disable the caching of geometries |
Definition at line 60 of file qgsvectorlayercache.cpp.
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 50 of file qgsvectorlayercache.cpp.
void QgsVectorLayerCache::setCacheSubsetOfAttributes | ( | const QgsAttributeList & | attributes | ) |
Set the subset of attributes to be cached.
attributes | The attributes to be cached |
Definition at line 79 of file qgsvectorlayercache.cpp.
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 84 of file qgsvectorlayercache.cpp.
|
friend |
Definition at line 320 of file qgsvectorlayercache.h.
|
friend |
Definition at line 318 of file qgsvectorlayercache.h.
|
friend |
Definition at line 319 of file qgsvectorlayercache.h.
|
friend |
Definition at line 331 of file qgsvectorlayercache.h.