The application now avoids reading and keeping in memory every element file in the collection.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1366 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2011-10-08 21:54:53 +00:00
parent 883da2a9c0
commit d431139d57
7 changed files with 59 additions and 16 deletions

View File

@@ -25,7 +25,8 @@
@param parent Item parent
*/
ElementsCollection::ElementsCollection(ElementsCollectionItem *parent) :
ElementsCollectionItem(parent)
ElementsCollectionItem(parent),
cache_(0)
{
}
@@ -414,3 +415,16 @@ ElementsCollectionItem *ElementsCollection::item(const QString &item_path, bool
return(result);
}
/**
@return The cache used by this collection, or 0 if this collection does not have any
*/
ElementsCollectionCache *ElementsCollection::cache() const {
return(cache_);
}
/**
@param cache The cache to be used by this collection
*/
void ElementsCollection::setCache(ElementsCollectionCache *cache) {
cache_ = cache;
}

View File

@@ -21,6 +21,7 @@
#include "elementscollectionitem.h"
class QETProject;
class ElementsCategory;
class ElementsCollectionCache;
class ElementDefinition;
class MoveElementsHandler;
/**
@@ -74,7 +75,6 @@ class ElementsCollection : public ElementsCollectionItem {
virtual ElementDefinition *createElement(const QString &);
virtual bool isEmpty();
virtual int count();
virtual bool isCacheable() const = 0;
// Methodes propres a la classe ElementsCollection
public:
@@ -83,6 +83,9 @@ class ElementsCollection : public ElementsCollectionItem {
*/
virtual ElementsCategory *rootCategory() = 0;
virtual ElementsCollectionItem *item(const QString &, bool = true);
virtual bool isCacheable() const = 0;
virtual ElementsCollectionCache *cache() const;
virtual void setCache(ElementsCollectionCache *);
// attributs
protected:
@@ -90,5 +93,7 @@ class ElementsCollection : public ElementsCollectionItem {
QString protocol_;
/// Projet auquel appartient cette collection
QETProject *project_;
/// Optional cache used to improve performance
ElementsCollectionCache *cache_;
};
#endif

View File

@@ -46,8 +46,6 @@ class ElementsCollectionCache : public QObject {
bool fetchElement(ElementDefinition *);
QString name() const;
QPixmap pixmap() const;
private:
bool fetchData(const ElementsLocation &);
bool fetchNameFromCache(const QString &, const QDateTime &);
bool fetchPixmapFromCache(const QString &, const QDateTime &);

View File

@@ -15,6 +15,7 @@
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "elementscollectioncache.h"
#include "fileelementdefinition.h"
#include "fileelementscategory.h"
#include "fileelementscollection.h"
@@ -43,8 +44,18 @@ FileElementDefinition::~FileElementDefinition() {
@return la definition XML de l'element
*/
QDomElement FileElementDefinition::xml() {
// ouvre le fichier
QFile file(file_path);
// charge le contenu du fichier en s'attendant a du XML
is_null = !xml_element_.setContent(&file);
if (is_null) {
return(QDomElement());
} else {
// l'ouverture de la definition a reussi
return(xml_element_.documentElement());
}
}
/**
Change la definition XML de l'element
@@ -122,18 +133,21 @@ void FileElementDefinition::reload() {
}
file_path = file_info.canonicalFilePath();
// ouvre le fichier
QFile file(file_path);
// charge le contenu du fichier en s'attendant a du XML
bool read_xml = xml_element_.setContent(&file);
if (!read_xml) {
is_null = true;
if (parentCollection()) {
ElementsCollectionCache *cache = parentCollection() -> cache();
if (cache && cache -> fetchNameFromCache(location().toString(), file_info.lastModified())) {
// the element file has not been modified since the last time
// we put its name in cache: we do not need to load it.
is_null = false;
return;
}
}
// l'ouverture de la definition a reussi
is_null = false;
// we need to ensure this is a valid XML document
QFile file(file_path);
QDomDocument xml_document;
is_null = !xml_document.setContent(&file);
xml_document.clear();
}
/**

View File

@@ -30,7 +30,6 @@ FileElementsCollection::FileElementsCollection(const QString &path, ElementsColl
protocol_ = "unknown";
project_ = 0;
root = 0;
reload();
}
/**

View File

@@ -21,6 +21,7 @@
#include "qetdiagrameditor.h"
#include "qetelementeditor.h"
#include "elementscollectionitem.h"
#include "elementscollectioncache.h"
#include "fileelementscollection.h"
#include "titleblocktemplate.h"
#include "templateeditor.h"
@@ -42,6 +43,7 @@ QString QETApp::config_dir = QString();
QString QETApp::lang_dir = QString();
FileElementsCollection *QETApp::common_collection = 0;
FileElementsCollection *QETApp::custom_collection = 0;
ElementsCollectionCache *QETApp::collections_cache_ = 0;
QMap<uint, QETProject *> QETApp::registered_projects_ = QMap<uint, QETProject *>();
uint QETApp::next_project_id = 0;
RecentFiles *QETApp::projects_recent_files_ = 0;
@@ -92,6 +94,13 @@ QETApp::QETApp(int &argc, char **argv) :
setQuitOnLastWindowClosed(false);
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(checkRemainingWindows()));
setSplashScreenStep(tr("Chargement... Initialisation du cache des collections d'\351l\351ments", "splash screen caption"));
if (!collections_cache_) {
QString cache_path = QETApp::configDir() + "/elements_cache.sqlite";
collections_cache_ = new ElementsCollectionCache(cache_path, this);
collections_cache_ -> setLocale(QLocale::system().name().left(2)); // @todo we need a unique function to get the good language
}
// loads known collections into memory (this does not include items rendering made in elements panels)
setSplashScreenStep(tr("Chargement... Lecture des collections d'\351l\351ments", "splash screen caption"));
foreach(ElementsCollection *collection, availableCollections()) {
@@ -228,6 +237,7 @@ ElementsCollection *QETApp::commonElementsCollection() {
if (!common_collection) {
common_collection = new FileElementsCollection(QETApp::commonElementsDir());
common_collection -> setProtocol("common");
common_collection -> setCache(collections_cache_);
}
return(common_collection);
}
@@ -239,6 +249,7 @@ ElementsCollection *QETApp::customElementsCollection() {
if (!custom_collection) {
custom_collection = new FileElementsCollection(QETApp::customElementsDir());
custom_collection -> setProtocol("custom");
custom_collection -> setCache(collections_cache_);
}
return(custom_collection);
}

View File

@@ -26,6 +26,7 @@ class AboutQET;
class QETDiagramEditor;
class QETElementEditor;
class ElementsCollection;
class ElementsCollectionCache;
class ElementsCollectionItem;
class FileElementsCollection;
class ElementsCategory;
@@ -137,6 +138,7 @@ class QETApp : public QETSingleApplication {
static FileElementsCollection *common_collection;
static FileElementsCollection *custom_collection;
static ElementsCollectionCache *collections_cache_;
static QMap<uint, QETProject *> registered_projects_;
static uint next_project_id;
static RecentFiles *projects_recent_files_;