QElectroTech  0.8-dev
Public Member Functions | Private Attributes | List of all members
ElementsCollectionCache Class Reference

#include <elementscollectioncache.h>

Inherits QObject.

Collaboration diagram for ElementsCollectionCache:
Collaboration graph

Public Member Functions

 ElementsCollectionCache (const QString &database_path, QObject *=nullptr)
 
 ~ElementsCollectionCache () override
 
void setLocale (const QString &)
 
QString locale () const
 
bool setPixmapStorageFormat (const QString &)
 
QString pixmapStorageFormat () const
 
bool fetchElement (ElementsLocation &location)
 ElementsCollectionCache::fetchElement Retrieve the data for a given element, using the cache if available, filling it otherwise. Data are then available through pixmap() and name() methods. More...
 
QString name () const
 
QPixmap pixmap () const
 
bool fetchData (const ElementsLocation &)
 
bool fetchNameFromCache (const QString &path, const QUuid &uuid)
 ElementsCollectionCache::fetchNameFromCache Retrieve the name for an element, given its path and uuid The value is then available through the name() method. More...
 
bool fetchPixmapFromCache (const QString &path, const QUuid &uuid)
 ElementsCollectionCache::fetchPixmapFromCache Retrieve the pixmap for an element, given its path and uuid. It is then available through the pixmap() method. More...
 
bool cacheName (const QString &path, const QUuid &uuid=QUuid::createUuid())
 ElementsCollectionCache::cacheName Cache the current (i.e. last retrieved) name The cache entry will use the locale set via setLocale(). More...
 
bool cachePixmap (const QString &path, const QUuid &uuid=QUuid::createUuid())
 ElementsCollectionCache::cachePixmap Cache the current (i.e. last retrieved) pixmap. More...
 

Private Attributes

QSqlDatabase cache_db_
 Object providing access to the SQLite database this cache relies on. More...
 
QSqlQuery * select_name_
 Prepared statement to fetch names from the cache. More...
 
QSqlQuery * select_pixmap_
 Prepared statement to fetch pixmaps from the cache. More...
 
QSqlQuery * insert_name_
 Prepared statement to insert names into the cache. More...
 
QSqlQuery * insert_pixmap_
 Prepared statement to insert pixmaps into the cache. More...
 
QString locale_
 Locale to be used when dealing with names. More...
 
QString pixmap_storage_format_
 Storage format for cached pixmaps. More...
 
QString current_name_
 Last name fetched. More...
 
QPixmap current_pixmap_
 Last pixmap fetched. More...
 

Detailed Description

This class implements a SQLite cache for data related to elements collections, mainly names and pixmaps. This avoids the cost of parsing XML definitions of elements and building full CustomElement objects when (re)loading the elements panel.

Constructor & Destructor Documentation

◆ ElementsCollectionCache()

ElementsCollectionCache::ElementsCollectionCache ( const QString &  database_path,
QObject *  parent = nullptr 
)

Construct a cache for elements collections.

Parameters
database_pathPath of the SQLite database to open.
parentParent QObject

◆ ~ElementsCollectionCache()

ElementsCollectionCache::~ElementsCollectionCache ( )
override

Destructor

Member Function Documentation

◆ cacheName()

bool ElementsCollectionCache::cacheName ( const QString &  path,
const QUuid &  uuid = QUuid::createUuid() 
)

ElementsCollectionCache::cacheName Cache the current (i.e. last retrieved) name The cache entry will use the locale set via setLocale().

Parameters
path: Element path (as obtained using ElementsLocation::toString())
uuid:Element uuid
Returns
True if the caching succeeded, false otherwise.
See also
name()
Here is the caller graph for this function:

◆ cachePixmap()

bool ElementsCollectionCache::cachePixmap ( const QString &  path,
const QUuid &  uuid = QUuid::createUuid() 
)

ElementsCollectionCache::cachePixmap Cache the current (i.e. last retrieved) pixmap.

Parameters
path: Element path (as obtained using ElementsLocation::toString())
uuid: Element uuid
Returns
True if the caching succeeded, false otherwise.
See also
pixmap()
Here is the caller graph for this function:

◆ fetchData()

bool ElementsCollectionCache::fetchData ( const ElementsLocation location)

Retrieve the data by building the full CustomElement object matching the given location, without using the cache. Data are then available through pixmap() and name() methods.

Parameters
locationLocation of a given Element.
Returns
True if the retrieval succeeded, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetchElement()

bool ElementsCollectionCache::fetchElement ( ElementsLocation location)

ElementsCollectionCache::fetchElement Retrieve the data for a given element, using the cache if available, filling it otherwise. Data are then available through pixmap() and name() methods.

Parameters
locationThe definition of an element.
See also
pixmap()
name()
Returns
True if the retrieval succeeded, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetchNameFromCache()

bool ElementsCollectionCache::fetchNameFromCache ( const QString &  path,
const QUuid &  uuid 
)

ElementsCollectionCache::fetchNameFromCache Retrieve the name for an element, given its path and uuid The value is then available through the name() method.

Parameters
path: Element path (as obtained using ElementsLocation::toString())
uuid: Element uuid
Returns
True if the retrieval succeeded, false otherwise.
Here is the caller graph for this function:

◆ fetchPixmapFromCache()

bool ElementsCollectionCache::fetchPixmapFromCache ( const QString &  path,
const QUuid &  uuid 
)

ElementsCollectionCache::fetchPixmapFromCache Retrieve the pixmap for an element, given its path and uuid. It is then available through the pixmap() method.

Parameters
path: Element path (as obtained using ElementsLocation::toString())
uuid: Element uuid
Returns
True if the retrieval succeeded, false otherwise.
Here is the caller graph for this function:

◆ locale()

QString ElementsCollectionCache::locale ( ) const
Returns
The locale to be used when dealing with names.
Here is the caller graph for this function:

◆ name()

QString ElementsCollectionCache::name ( ) const
Returns
The last name fetched through fetchElement().
Here is the caller graph for this function:

◆ pixmap()

QPixmap ElementsCollectionCache::pixmap ( ) const
Returns
The last pixmap fetched through fetchElement().
Here is the caller graph for this function:

◆ pixmapStorageFormat()

QString ElementsCollectionCache::pixmapStorageFormat ( ) const
Returns
the pixmap storage format. Default is "PNG"
See also
setPixmapStorageFormat()

◆ setLocale()

void ElementsCollectionCache::setLocale ( const QString &  locale)

Define the locale to be used when dealing with names.

Parameters
localeNew locale to be used.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPixmapStorageFormat()

bool ElementsCollectionCache::setPixmapStorageFormat ( const QString &  format)

Define the storage format for the pixmaps within the SQLite database. See Qt's QPixmap documentation for more information.

Parameters
formatThe new pixmap storage format.
Returns
True if the format change was accepted, false otherwise.

Member Data Documentation

◆ cache_db_

QSqlDatabase ElementsCollectionCache::cache_db_
private

Object providing access to the SQLite database this cache relies on.

◆ current_name_

QString ElementsCollectionCache::current_name_
private

Last name fetched.

◆ current_pixmap_

QPixmap ElementsCollectionCache::current_pixmap_
private

Last pixmap fetched.

◆ insert_name_

QSqlQuery* ElementsCollectionCache::insert_name_
private

Prepared statement to insert names into the cache.

◆ insert_pixmap_

QSqlQuery* ElementsCollectionCache::insert_pixmap_
private

Prepared statement to insert pixmaps into the cache.

◆ locale_

QString ElementsCollectionCache::locale_
private

Locale to be used when dealing with names.

◆ pixmap_storage_format_

QString ElementsCollectionCache::pixmap_storage_format_
private

Storage format for cached pixmaps.

◆ select_name_

QSqlQuery* ElementsCollectionCache::select_name_
private

Prepared statement to fetch names from the cache.

◆ select_pixmap_

QSqlQuery* ElementsCollectionCache::select_pixmap_
private

Prepared statement to fetch pixmaps from the cache.


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