mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Elements collection cache can fully fetch and cache element data from elementLocation
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4323 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -21,9 +21,12 @@
|
|||||||
#include "elementdefinition.h"
|
#include "elementdefinition.h"
|
||||||
#include "factory/elementfactory.h"
|
#include "factory/elementfactory.h"
|
||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include <QImageWriter>
|
|
||||||
#include "qet.h"
|
#include "qet.h"
|
||||||
|
|
||||||
|
#include <QImageWriter>
|
||||||
|
#include <QSqlQuery>
|
||||||
|
#include <QSqlError>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Construct a cache for elements collections.
|
Construct a cache for elements collections.
|
||||||
@param database_path Path of the SQLite database to open.
|
@param database_path Path of the SQLite database to open.
|
||||||
@@ -215,12 +218,21 @@ bool ElementsCollectionCache::fetchElement(ElementDefinition *element)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 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
|
||||||
|
* @param location The definition of an element
|
||||||
|
* @see pixmap()
|
||||||
|
* @see name()
|
||||||
|
* @return True if the retrieval succeeded, false otherwise
|
||||||
|
*/
|
||||||
bool ElementsCollectionCache::fetchElement(ElementLocation location)
|
bool ElementsCollectionCache::fetchElement(ElementLocation location)
|
||||||
{
|
{
|
||||||
if (fetchNameFromCache(location.collectionPath(), location.uuid()) &&
|
if (fetchNameFromCache(location.collectionPath(), location.uuid()) &&
|
||||||
fetchPixmapFromCache(location.collectionPath(), location.uuid()))
|
fetchPixmapFromCache(location.collectionPath(), location.uuid()))
|
||||||
return true;
|
return true;
|
||||||
else if (fetchData(ElementsLocation(location.collectionPath())))
|
else if (fetchData(location))
|
||||||
{
|
{
|
||||||
cacheName(location.collectionPath(), location.uuid());
|
cacheName(location.collectionPath(), location.uuid());
|
||||||
cachePixmap(location.collectionPath(), location.uuid());
|
cachePixmap(location.collectionPath(), location.uuid());
|
||||||
@@ -263,6 +275,30 @@ bool ElementsCollectionCache::fetchData(const ElementsLocation &location) {
|
|||||||
return(!state);
|
return(!state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementsCollectionCache::fetchData
|
||||||
|
* 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
|
||||||
|
* @param location : location of a given element
|
||||||
|
* @return True if the retrieval succeeded, false otherwise
|
||||||
|
*/
|
||||||
|
bool ElementsCollectionCache::fetchData(ElementLocation &location)
|
||||||
|
{
|
||||||
|
int state;
|
||||||
|
Element *element = ElementFactory::Instance()->createElement(location, 0, &state);
|
||||||
|
|
||||||
|
if(state)
|
||||||
|
qDebug() << "ElementsCollectionCache::fetchData() 2: Le chargement du composant" << qPrintable(location.fileSystemPath()) << "a echoue avec le code d'erreur" << state;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
current_name_ = element->name();
|
||||||
|
current_pixmap_ = element->pixmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
delete element;
|
||||||
|
return (!state);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementsCollectionCache::fetchNameFromCache
|
* @brief ElementsCollectionCache::fetchNameFromCache
|
||||||
* Retrieve the name for an element, given its path and uuid
|
* Retrieve the name for an element, given its path and uuid
|
||||||
|
|||||||
@@ -17,10 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef ELEMENTS_COLLECTION_CACHE_H
|
#ifndef ELEMENTS_COLLECTION_CACHE_H
|
||||||
#define ELEMENTS_COLLECTION_CACHE_H
|
#define ELEMENTS_COLLECTION_CACHE_H
|
||||||
#include <QtCore>
|
|
||||||
#include <QtSql>
|
#include <QSqlDatabase>
|
||||||
#include "elementslocation.h"
|
#include "elementslocation.h"
|
||||||
#include "elementlocation.h"
|
#include "elementlocation.h"
|
||||||
|
|
||||||
class ElementsCollection;
|
class ElementsCollection;
|
||||||
class ElementsCategory;
|
class ElementsCategory;
|
||||||
class ElementDefinition;
|
class ElementDefinition;
|
||||||
@@ -50,6 +51,7 @@ class ElementsCollectionCache : public QObject
|
|||||||
QString name() const;
|
QString name() const;
|
||||||
QPixmap pixmap() const;
|
QPixmap pixmap() const;
|
||||||
bool fetchData(const ElementsLocation &);
|
bool fetchData(const ElementsLocation &);
|
||||||
|
bool fetchData(ElementLocation &location);
|
||||||
bool fetchNameFromCache(const QString &path, const QUuid &uuid);
|
bool fetchNameFromCache(const QString &path, const QUuid &uuid);
|
||||||
bool fetchPixmapFromCache(const QString &path, const QUuid &uuid);
|
bool fetchPixmapFromCache(const QString &path, const QUuid &uuid);
|
||||||
bool cacheName(const QString &path, const QUuid &uuid = QUuid::createUuid());
|
bool cacheName(const QString &path, const QUuid &uuid = QUuid::createUuid());
|
||||||
|
|||||||
Reference in New Issue
Block a user