QElectroTech  0.8-dev
elementscollectioncache.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 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,
35  QObject * = nullptr);
36  ~ElementsCollectionCache() override;
37 
38  // methods
39  public:
40  void setLocale(const QString &);
41  QString locale() const;
42  bool setPixmapStorageFormat(const QString &);
43  QString pixmapStorageFormat() const;
44  bool fetchElement(ElementsLocation &location);
45  QString name() const;
46  QPixmap pixmap() const;
47  bool fetchData(const ElementsLocation &);
48  bool fetchNameFromCache(const QString &path, const QUuid &uuid);
49  bool fetchPixmapFromCache(const QString &path, const QUuid &uuid);
50  bool cacheName(const QString &path,
51  const QUuid &uuid = QUuid::createUuid());
52  bool cachePixmap(const QString &path,
53  const QUuid &uuid = QUuid::createUuid());
54 
55  // attributes
56  private:
57  QSqlDatabase cache_db_;
58  QSqlQuery *select_name_;
59  QSqlQuery *select_pixmap_;
60  QSqlQuery *insert_name_;
61  QSqlQuery *insert_pixmap_;
62  QString locale_;
64  QString current_name_;
65  QPixmap current_pixmap_;
66 };
67 #endif
ElementsCollectionCache::fetchElement
bool fetchElement(ElementsLocation &location)
ElementsCollectionCache::fetchElement Retrieve the data for a given element, using the cache if avail...
Definition: elementscollectioncache.cpp:161
ElementsCollectionCache::pixmap_storage_format_
QString pixmap_storage_format_
Storage format for cached pixmaps.
Definition: elementscollectioncache.h:63
ElementsCollectionCache::locale_
QString locale_
Locale to be used when dealing with names.
Definition: elementscollectioncache.h:62
ElementsCollectionCache::fetchNameFromCache
bool fetchNameFromCache(const QString &path, const QUuid &uuid)
ElementsCollectionCache::fetchNameFromCache Retrieve the name for an element, given its path and uuid...
Definition: elementscollectioncache.cpp:235
elementscollectioncache.h
ElementsCollectionCache::locale
QString locale() const
Definition: elementscollectioncache.cpp:126
ElementsCollectionCache::cacheName
bool cacheName(const QString &path, const QUuid &uuid=QUuid::createUuid())
ElementsCollectionCache::cacheName Cache the current (i.e. last retrieved) name The cache entry will ...
Definition: elementscollectioncache.cpp:295
ElementsCollectionCache::cache_db_
QSqlDatabase cache_db_
Object providing access to the SQLite database this cache relies on.
Definition: elementscollectioncache.h:57
ElementsCollectionCache
Definition: elementscollectioncache.h:31
ElementsCollectionCache::fetchData
bool fetchData(const ElementsLocation &)
Definition: elementscollectioncache.cpp:211
ElementsCollectionCache::insert_name_
QSqlQuery * insert_name_
Prepared statement to insert names into the cache.
Definition: elementscollectioncache.h:60
ElementsCollectionCache::name
QString name() const
Definition: elementscollectioncache.cpp:193
ElementsLocation::uuid
QUuid uuid() const
ElementsLocation::uuid.
Definition: elementslocation.cpp:737
ElementsCollectionCache::select_pixmap_
QSqlQuery * select_pixmap_
Prepared statement to fetch pixmaps from the cache.
Definition: elementscollectioncache.h:59
ElementsCollectionCache::pixmapStorageFormat
QString pixmapStorageFormat() const
Definition: elementscollectioncache.cpp:148
ElementsCollectionCache::select_name_
QSqlQuery * select_name_
Prepared statement to fetch names from the cache.
Definition: elementscollectioncache.h:58
ElementsCollectionCache::~ElementsCollectionCache
~ElementsCollectionCache() override
Definition: elementscollectioncache.cpp:107
ElementsCollectionCache::fetchPixmapFromCache
bool fetchPixmapFromCache(const QString &path, const QUuid &uuid)
ElementsCollectionCache::fetchPixmapFromCache Retrieve the pixmap for an element, given its path and ...
Definition: elementscollectioncache.cpp:264
qet.h
ElementsCollectionCache::current_pixmap_
QPixmap current_pixmap_
Last pixmap fetched.
Definition: elementscollectioncache.h:65
elementslocation.h
ElementsCollectionCache::current_name_
QString current_name_
Last name fetched.
Definition: elementscollectioncache.h:64
ElementsCollectionCache::setLocale
void setLocale(const QString &)
Definition: elementscollectioncache.cpp:119
element.h
ElementsCollectionCache::insert_pixmap_
QSqlQuery * insert_pixmap_
Prepared statement to insert pixmaps into the cache.
Definition: elementscollectioncache.h:61
Element
Definition: element.h:41
ElementsLocation::isProject
bool isProject() const
ElementsLocation::isProject.
Definition: elementslocation.cpp:459
ElementFactory::Instance
static ElementFactory * Instance()
Definition: elementfactory.h:38
ElementsLocation
The ElementsLocation class This class represents the location, the location of an element or of a cat...
Definition: elementslocation.h:46
ElementsCollectionCache::ElementsCollectionCache
ElementsCollectionCache(const QString &database_path, QObject *=nullptr)
Definition: elementscollectioncache.cpp:32
elementfactory.h
ElementsCollectionCache::pixmap
QPixmap pixmap() const
Definition: elementscollectioncache.cpp:200
ElementsLocation::toString
QString toString() const
ElementsLocation::toString.
Definition: elementslocation.cpp:396
ElementsCollectionCache::setPixmapStorageFormat
bool setPixmapStorageFormat(const QString &)
Definition: elementscollectioncache.cpp:136
ElementsCollectionCache::cachePixmap
bool cachePixmap(const QString &path, const QUuid &uuid=QUuid::createUuid())
ElementsCollectionCache::cachePixmap Cache the current (i.e. last retrieved) pixmap.
Definition: elementscollectioncache.cpp:318