QElectroTech  0.70
elementscollectioncache.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef ELEMENTS_COLLECTION_CACHE_H
19 #define ELEMENTS_COLLECTION_CACHE_H
20 
21 #include <QSqlDatabase>
22 #include "elementslocation.h"
23 
30 class ElementsCollectionCache : public QObject
31 {
32  public:
33  // constructor, destructor
34  ElementsCollectionCache(const QString &database_path, QObject * = nullptr);
35  ~ElementsCollectionCache() override;
36 
37  // methods
38  public:
39  void setLocale(const QString &);
40  QString locale() const;
41  bool setPixmapStorageFormat(const QString &);
42  QString pixmapStorageFormat() const;
43  bool fetchElement(ElementsLocation &location);
44  QString name() const;
45  QPixmap pixmap() const;
46  bool fetchData(const ElementsLocation &);
47  bool fetchNameFromCache(const QString &path, const QUuid &uuid);
48  bool fetchPixmapFromCache(const QString &path, const QUuid &uuid);
49  bool cacheName(const QString &path, const QUuid &uuid = QUuid::createUuid());
50  bool cachePixmap(const QString &path, const QUuid &uuid = QUuid::createUuid());
51 
52  // attributes
53  private:
54  QSqlDatabase cache_db_;
55  QSqlQuery *select_name_;
56  QSqlQuery *select_pixmap_;
57  QSqlQuery *insert_name_;
58  QSqlQuery *insert_pixmap_;
59  QString locale_;
61  QString current_name_;
62  QPixmap current_pixmap_;
63 };
64 #endif
QString current_name_
Last name fetched.
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...
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 &)
QString locale_
Locale to be used when dealing with names.