23 #include <QImageWriter> 35 pixmap_storage_format_(
"PNG")
38 static int cache_instances = 0;
39 QString connection_name = QString(
"ElementsCollectionCache-%1").arg(cache_instances++);
40 cache_db_ = QSqlDatabase::addDatabase(
"QSQLITE", connection_name);
44 qDebug() <<
"Unable to open the SQLite database " << database_path <<
" as " << connection_name <<
": " <<
cache_db_.lastError();
47 cache_db_.exec(
"PRAGMA temp_store = MEMORY");
48 cache_db_.exec(
"PRAGMA journal_mode = MEMORY");
49 cache_db_.exec(
"PRAGMA page_size = 4096");
50 cache_db_.exec(
"PRAGMA cache_size = 16384");
51 cache_db_.exec(
"PRAGMA locking_mode = EXCLUSIVE");
52 cache_db_.exec(
"PRAGMA synchronous = OFF");
57 if (table_name.exec(
"PRAGMA table_info(names)"))
59 if (table_name.seek(2))
61 QString str = table_name.value(1).toString();
66 error =
cache_db_.exec(
"DROP TABLE names");
67 error =
cache_db_.exec(
"DROP TABLE pixmaps");
77 "path VARCHAR(512) NOT NULL," 78 "locale VARCHAR(2) NOT NULL," 79 "uuid VARCHAR(512) NOT NULL," 81 "PRIMARY KEY(path, locale)" 86 "path VARCHAR(512) NOT NULL UNIQUE," 87 "uuid VARCHAR(512) NOT NULL," 88 "pixmap BLOB, PRIMARY KEY(path)," 89 "FOREIGN KEY(path) REFERENCES names (path) ON DELETE CASCADE);");
96 select_name_ -> prepare(
"SELECT name FROM names WHERE path = :path AND locale = :locale AND uuid = :uuid");
97 select_pixmap_ -> prepare(
"SELECT pixmap FROM pixmaps WHERE path = :path AND uuid = :uuid");
98 insert_name_ -> prepare(
"REPLACE INTO names (path, locale, uuid, name) VALUES (:path, :locale, :uuid, :name)");
99 insert_pixmap_ -> prepare(
"REPLACE INTO pixmaps (path, uuid, pixmap) VALUES (:path, :uuid, :pixmap)");
136 if (QImageWriter::supportedImageFormats().contains(format.toLatin1())) {
171 QString element_path = location.
toString();
175 if (got_name && got_pixmap) {
213 qDebug() <<
"ElementsCollectionCache::fetchData() : Le chargement du composant" << qPrintable(location.
toString()) <<
"a echoue avec le code d'erreur" << state;
245 qDebug() <<
"select_name_->exec() failed";
275 qDebug() <<
"select_pixmap_->exec() failed";
314 buffer.open(QIODevice::WriteOnly);
void setLocale(const QString &)
bool isProject() const
ElementsLocation::isProject.
QString current_name_
Last name fetched.
QString pixmapStorageFormat() const
~ElementsCollectionCache() override
bool cachePixmap(const QString &path, const QUuid &uuid=QUuid::createUuid())
ElementsCollectionCache::cachePixmap Cache the current (i.e. last retrieved) pixmap.
QPixmap current_pixmap_
Last pixmap fetched.
QSqlQuery * select_pixmap_
Prepared statement to fetch pixmaps from the cache.
QString pixmap_storage_format_
Storage format for cached pixmaps.
bool cacheName(const QString &path, const QUuid &uuid=QUuid::createUuid())
ElementsCollectionCache::cacheName Cache the current (i.e. last retrieved) name The cache entry will ...
ElementsCollectionCache(const QString &database_path, QObject *=nullptr)
QSqlQuery * insert_pixmap_
Prepared statement to insert pixmaps into the cache.
bool fetchNameFromCache(const QString &path, const QUuid &uuid)
ElementsCollectionCache::fetchNameFromCache Retrieve the name for an element, given its path and uuid...
QUuid uuid() const
ElementsLocation::uuid.
bool fetchData(const ElementsLocation &)
bool fetchPixmapFromCache(const QString &path, const QUuid &uuid)
ElementsCollectionCache::fetchPixmapFromCache Retrieve the pixmap for an element, given its path and ...
bool fetchElement(ElementsLocation &location)
ElementsCollectionCache::fetchElement Retrieve the data for a given element, using the cache if avail...
QSqlDatabase cache_db_
Object providing access to the SQLite database this cache relies on.
QSqlQuery * insert_name_
Prepared statement to insert names into the cache.
QSqlQuery * select_name_
Prepared statement to fetch names from the cache.
bool setPixmapStorageFormat(const QString &)
static ElementFactory * Instance()
QString locale_
Locale to be used when dealing with names.