QElectroTech
0.70
|
#include <elementscollectioncache.h>
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... | |
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.
Definition at line 30 of file elementscollectioncache.h.
ElementsCollectionCache::ElementsCollectionCache | ( | const QString & | database_path, |
QObject * | parent = nullptr |
||
) |
Construct a cache for elements collections.
database_path | Path of the SQLite database to open. |
parent | Parent QObject |
Definition at line 32 of file elementscollectioncache.cpp.
References cache_db_, insert_name_, insert_pixmap_, select_name_, and select_pixmap_.
|
override |
Destructor
Definition at line 106 of file elementscollectioncache.cpp.
References cache_db_, insert_name_, insert_pixmap_, select_name_, and select_pixmap_.
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().
path | : Element path (as obtained using ElementsLocation::toString()) |
uuid | :Element uuid |
Definition at line 288 of file elementscollectioncache.cpp.
References cache_db_, current_name_, insert_name_, and locale_.
Referenced by fetchElement().
bool ElementsCollectionCache::cachePixmap | ( | const QString & | path, |
const QUuid & | uuid = QUuid::createUuid() |
||
) |
ElementsCollectionCache::cachePixmap Cache the current (i.e. last retrieved) pixmap.
path | : Element path (as obtained using ElementsLocation::toString()) |
uuid | : Element uuid |
Definition at line 310 of file elementscollectioncache.cpp.
References cache_db_, current_pixmap_, insert_pixmap_, and pixmap_storage_format_.
Referenced by fetchElement().
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.
Location | Location of a given Element. |
Definition at line 209 of file elementscollectioncache.cpp.
References current_name_, current_pixmap_, ElementFactory::Instance(), name(), pixmap(), and ElementsLocation::toString().
Referenced by 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.
location | The definition of an element. |
Definition at line 160 of file elementscollectioncache.cpp.
References cache_db_, cacheName(), cachePixmap(), fetchData(), fetchNameFromCache(), fetchPixmapFromCache(), ElementsLocation::isProject(), ElementsLocation::toString(), and ElementsLocation::uuid().
Referenced by ElementsLocation::icon().
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.
path | : Element path (as obtained using ElementsLocation::toString()) |
uuid | : Element uuid |
Definition at line 230 of file elementscollectioncache.cpp.
References current_name_, locale_, and select_name_.
Referenced by fetchElement().
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.
path | : Element path (as obtained using ElementsLocation::toString()) |
uuid | : Element uuid |
Definition at line 258 of file elementscollectioncache.cpp.
References current_pixmap_, pixmap_storage_format_, and select_pixmap_.
Referenced by fetchElement().
QString ElementsCollectionCache::locale | ( | ) | const |
Definition at line 125 of file elementscollectioncache.cpp.
References locale_.
Referenced by setLocale().
QString ElementsCollectionCache::name | ( | ) | const |
Definition at line 191 of file elementscollectioncache.cpp.
References current_name_.
Referenced by fetchData().
QPixmap ElementsCollectionCache::pixmap | ( | ) | const |
Definition at line 198 of file elementscollectioncache.cpp.
References current_pixmap_.
Referenced by fetchData(), and ElementsLocation::icon().
QString ElementsCollectionCache::pixmapStorageFormat | ( | ) | const |
Definition at line 147 of file elementscollectioncache.cpp.
References pixmap_storage_format_.
void ElementsCollectionCache::setLocale | ( | const QString & | locale | ) |
Define the locale to be used when dealing with names.
locale | New locale to be used. |
Definition at line 118 of file elementscollectioncache.cpp.
References locale(), and locale_.
Referenced by QETApp::QETApp().
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.
format | The new pixmap storage format. |
Definition at line 135 of file elementscollectioncache.cpp.
References pixmap_storage_format_.
|
private |
Object providing access to the SQLite database this cache relies on.
Definition at line 54 of file elementscollectioncache.h.
Referenced by cacheName(), cachePixmap(), ElementsCollectionCache(), fetchElement(), and ~ElementsCollectionCache().
|
private |
Last name fetched.
Definition at line 61 of file elementscollectioncache.h.
Referenced by cacheName(), fetchData(), fetchNameFromCache(), and name().
|
private |
Last pixmap fetched.
Definition at line 62 of file elementscollectioncache.h.
Referenced by cachePixmap(), fetchData(), fetchPixmapFromCache(), and pixmap().
|
private |
Prepared statement to insert names into the cache.
Definition at line 57 of file elementscollectioncache.h.
Referenced by cacheName(), ElementsCollectionCache(), and ~ElementsCollectionCache().
|
private |
Prepared statement to insert pixmaps into the cache.
Definition at line 58 of file elementscollectioncache.h.
Referenced by cachePixmap(), ElementsCollectionCache(), and ~ElementsCollectionCache().
|
private |
Locale to be used when dealing with names.
Definition at line 59 of file elementscollectioncache.h.
Referenced by cacheName(), fetchNameFromCache(), locale(), and setLocale().
|
private |
Storage format for cached pixmaps.
Definition at line 60 of file elementscollectioncache.h.
Referenced by cachePixmap(), fetchPixmapFromCache(), pixmapStorageFormat(), and setPixmapStorageFormat().
|
private |
Prepared statement to fetch names from the cache.
Definition at line 55 of file elementscollectioncache.h.
Referenced by ElementsCollectionCache(), fetchNameFromCache(), and ~ElementsCollectionCache().
|
private |
Prepared statement to fetch pixmaps from the cache.
Definition at line 56 of file elementscollectioncache.h.
Referenced by ElementsCollectionCache(), fetchPixmapFromCache(), and ~ElementsCollectionCache().