QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
QgsAbstractContentCache< T > Class Template Reference

Abstract base class for file content caches, such as SVG or raster image caches. More...

#include <qgsabstractcontentcache.h>

Inheritance diagram for QgsAbstractContentCache< T >:
Inheritance graph
[legend]

Public Member Functions

 QgsAbstractContentCache (QObject *parent=nullptr, const QString &typeString=QString(), long maxCacheSize=20000000, int fileModifiedCheckTimeout=30000)
 Constructor for QgsAbstractContentCache, with the specified parent object.
 
 ~QgsAbstractContentCache () override
 
- Public Member Functions inherited from QgsAbstractContentCacheBase
 QgsAbstractContentCacheBase (QObject *parent)
 Constructor for QgsAbstractContentCacheBase, with the specified parent object.
 

Protected Member Functions

T * findExistingEntry (T *entryTemplate)
 Returns the existing entry from the cache which matches entryTemplate (deleting entryTemplate when done), or if no existing entry is found then entryTemplate is transferred to the cache and returned.
 
QByteArray getContent (const QString &path, const QByteArray &missingContent, const QByteArray &fetchingContent, bool blocking=false) const
 Gets the file content corresponding to the given path.
 
void onRemoteContentFetched (const QString &url, bool success) override
 Triggered after remote content (i.e.
 
void trimToMaximumSize ()
 Removes the least used cache entries until the maximum cache size is under the predefined size limit.
 
bool waitForTaskFinished (QgsNetworkContentFetcherTask *task) const
 Blocks the current thread until the task finishes (or user's preset network timeout expires)
 
- Protected Member Functions inherited from QgsAbstractContentCacheBase
virtual bool checkReply (QNetworkReply *reply, const QString &path) const
 Runs additional checks on a network reply to ensure that the reply content is consistent with that required by the cache.
 

Protected Attributes

long mMaxCacheSize = 20000000
 Maximum cache size.
 
QRecursiveMutex mMutex
 
long mTotalSize = 0
 Estimated total size of all cached content.
 

Friends

class TestQgsImageCache
 
class TestQgsSvgCache
 

Additional Inherited Members

- Signals inherited from QgsAbstractContentCacheBase
void remoteContentFetched (const QString &url)
 Emitted when the cache has finished retrieving content from a remote url.
 
- Static Public Member Functions inherited from QgsAbstractContentCacheBase
static bool isBase64Data (const QString &path)
 Returns true if path represents base64 encoded data.
 
static bool parseBase64DataUrl (const QString &path, QString *mimeType=nullptr, QString *data=nullptr)
 Parses a path to determine if it represents a base 64 encoded HTML data URL, and if so, extracts the components of the URL.
 
- Protected Slots inherited from QgsAbstractContentCacheBase

Detailed Description

template<class T>
class QgsAbstractContentCache< T >

Abstract base class for file content caches, such as SVG or raster image caches.

Handles trimming the maximum cached content size to a desired limit, fetching remote content (via HTTP), and automatically invalidating cached content when the corresponding file is changed.

Note
Not available in Python bindings.
Since
QGIS 3.6

Definition at line 214 of file qgsabstractcontentcache.h.

Constructor & Destructor Documentation

◆ QgsAbstractContentCache()

template<class T >
QgsAbstractContentCache< T >::QgsAbstractContentCache ( QObject *  parent = nullptr,
const QString &  typeString = QString(),
long  maxCacheSize = 20000000,
int  fileModifiedCheckTimeout = 30000 
)
inline

Constructor for QgsAbstractContentCache, with the specified parent object.

The maxCacheSize argument dictates the maximum allowable total size of the cache, in bytes. This in turn dictates the maximum allowable size for caching individual entries.

The fileModifiedCheckTimeout dictates the minimum time (in milliseconds) between consecutive checks of whether a file's content has been modified (and existing cache entries should be discarded).

Definition at line 230 of file qgsabstractcontentcache.h.

◆ ~QgsAbstractContentCache()

template<class T >
QgsAbstractContentCache< T >::~QgsAbstractContentCache ( )
inlineoverride

Definition at line 241 of file qgsabstractcontentcache.h.

Member Function Documentation

◆ findExistingEntry()

template<class T >
T * QgsAbstractContentCache< T >::findExistingEntry ( T *  entryTemplate)
inlineprotected

Returns the existing entry from the cache which matches entryTemplate (deleting entryTemplate when done), or if no existing entry is found then entryTemplate is transferred to the cache and returned.

I.e. either way ownership of entryTemplate is transferred by calling this method.

If an existing entry was found, then the corresponding file MAY be rechecked for changes (only if a suitable time has occurred since the last check).

Definition at line 346 of file qgsabstractcontentcache.h.

◆ getContent()

template<class T >
QByteArray QgsAbstractContentCache< T >::getContent ( const QString &  path,
const QByteArray &  missingContent,
const QByteArray &  fetchingContent,
bool  blocking = false 
) const
protected

Gets the file content corresponding to the given path.

path may be a local file, remote (HTTP) url, or a base 64 encoded string (with a "base64:" prefix).

The missingContent byte array is returned if the path could not be resolved or is broken. If the path corresponds to a remote URL, then fetchingContent will be returned while the content is in the process of being fetched. The blocking boolean forces to wait for loading before returning result. The content is loaded in the same thread to ensure provided the remote content. WARNING: the blocking parameter must NEVER be true from GUI based applications (like the main QGIS application) or crashes will result. Only for use in external scripts or QGIS server.

Definition at line 26 of file qgsabstractcontentcache_p.h.

◆ onRemoteContentFetched()

template<class T >
void QgsAbstractContentCache< T >::onRemoteContentFetched ( const QString &  url,
bool  success 
)
inlineoverrideprotectedvirtual

Triggered after remote content (i.e.

HTTP linked content at the given url) has been fetched.

The success argument will be true if the content was successfully fetched, or false if it was not fetched successfully.

Reimplemented from QgsAbstractContentCacheBase.

Definition at line 286 of file qgsabstractcontentcache.h.

◆ trimToMaximumSize()

template<class T >
void QgsAbstractContentCache< T >::trimToMaximumSize ( )
inlineprotected

Removes the least used cache entries until the maximum cache size is under the predefined size limit.

Definition at line 251 of file qgsabstractcontentcache.h.

◆ waitForTaskFinished()

template<class T >
bool QgsAbstractContentCache< T >::waitForTaskFinished ( QgsNetworkContentFetcherTask task) const
inlineprotected

Blocks the current thread until the task finishes (or user's preset network timeout expires)

Warning
this method must NEVER be used from GUI based applications (like the main QGIS application) or crashes will result. Only for use in external scripts or QGIS server.

The result will be false if the wait timed out and true in any other case.

Since
QGIS 3.10

Definition at line 318 of file qgsabstractcontentcache.h.

Friends And Related Symbol Documentation

◆ TestQgsImageCache

template<class T >
friend class TestQgsImageCache
friend

Definition at line 511 of file qgsabstractcontentcache.h.

◆ TestQgsSvgCache

template<class T >
friend class TestQgsSvgCache
friend

Definition at line 510 of file qgsabstractcontentcache.h.

Member Data Documentation

◆ mMaxCacheSize

template<class T >
long QgsAbstractContentCache< T >::mMaxCacheSize = 20000000
protected

Maximum cache size.

Definition at line 408 of file qgsabstractcontentcache.h.

◆ mMutex

template<class T >
QRecursiveMutex QgsAbstractContentCache< T >::mMutex
mutableprotected

Definition at line 402 of file qgsabstractcontentcache.h.

◆ mTotalSize

template<class T >
long QgsAbstractContentCache< T >::mTotalSize = 0
protected

Estimated total size of all cached content.

Definition at line 405 of file qgsabstractcontentcache.h.


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