mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Improve file access on windows and mac OSX
This commit is contained in:
@@ -243,6 +243,8 @@ void ElementsCollectionModel::loadCollections(bool common_collection, bool custo
|
|||||||
list.append(projectItems(project));
|
list.append(projectItems(project));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ElementsLocation::clearAcces();
|
||||||
|
qDebug() << "acces count " << ElementsLocation::accesCount();
|
||||||
QTime t;
|
QTime t;
|
||||||
t.start();
|
t.start();
|
||||||
QFuture<void> futur = QtConcurrent::map(list, setUpData);
|
QFuture<void> futur = QtConcurrent::map(list, setUpData);
|
||||||
@@ -252,7 +254,7 @@ void ElementsCollectionModel::loadCollections(bool common_collection, bool custo
|
|||||||
}
|
}
|
||||||
int ms = t.elapsed();
|
int ms = t.elapsed();
|
||||||
|
|
||||||
QMessageBox::about(nullptr, tr("Chargement collection d'élément"), tr("Le chargement de la collection d'éléments à été éffectué en %1 ms").arg(ms));
|
QMessageBox::about(nullptr, tr("Chargement collection d'élément"), tr("Le chargement de la collection d'éléments à été éffectué en %1 ms %2 acces").arg(ms).arg(ElementsLocation::accesCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2019 The QElectroTech Team
|
Copyright 2006-2019 The QElectroTech Team
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "qetxml.h"
|
#include "qetxml.h"
|
||||||
#include <QPicture>
|
#include <QPicture>
|
||||||
|
|
||||||
|
static int acces;
|
||||||
// make this class usable with QVariant
|
// make this class usable with QVariant
|
||||||
int ElementsLocation::MetaTypeId = qRegisterMetaType<ElementsLocation>("ElementsLocation");
|
int ElementsLocation::MetaTypeId = qRegisterMetaType<ElementsLocation>("ElementsLocation");
|
||||||
|
|
||||||
@@ -538,6 +539,7 @@ QDomElement ElementsLocation::xml() const
|
|||||||
{
|
{
|
||||||
if (!m_project)
|
if (!m_project)
|
||||||
{
|
{
|
||||||
|
++acces;
|
||||||
QFile file (m_file_system_path);
|
QFile file (m_file_system_path);
|
||||||
QDomDocument docu;
|
QDomDocument docu;
|
||||||
if (docu.setContent(&file))
|
if (docu.setContent(&file))
|
||||||
@@ -568,11 +570,28 @@ QDomElement ElementsLocation::xml() const
|
|||||||
*/
|
*/
|
||||||
pugi::xml_document ElementsLocation::pugiXml() const
|
pugi::xml_document ElementsLocation::pugiXml() const
|
||||||
{
|
{
|
||||||
if (!m_project)
|
//Except for linux OS (because linux keep in cache the file), we keep in memory the xml
|
||||||
|
//to avoid multiple access to file.
|
||||||
|
//keep in memory the XML, consumes a little more RAM, for this reason we don't use it for linux to minimize the RAM footprint.
|
||||||
|
#ifndef Q_OS_LINUX
|
||||||
|
if (!m_string_stream.str().empty())
|
||||||
{
|
{
|
||||||
|
pugi::xml_document docu;
|
||||||
|
docu.load_string(m_string_stream.str().c_str());
|
||||||
|
return docu;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (!m_project)
|
||||||
|
{
|
||||||
|
++acces;
|
||||||
pugi::xml_document docu;
|
pugi::xml_document docu;
|
||||||
if (docu.load_file(m_file_system_path.toStdString().c_str()))
|
if (docu.load_file(m_file_system_path.toStdString().c_str()))
|
||||||
|
{
|
||||||
|
#ifndef Q_OS_LINUX
|
||||||
|
docu.save(m_string_stream);
|
||||||
|
#endif
|
||||||
return docu;
|
return docu;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -778,14 +797,24 @@ DiagramContext ElementsLocation::elementInformations() const
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void ElementsLocation::clearAcces()
|
||||||
@param location A standard element location
|
{
|
||||||
@return a hash identifying this location
|
acces =0;
|
||||||
*/
|
|
||||||
uint qHash(const ElementsLocation &location) {
|
|
||||||
return(qHash(location.toString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ElementsLocation::accesCount()
|
||||||
|
{
|
||||||
|
return acces;
|
||||||
|
}
|
||||||
|
|
||||||
|
///**
|
||||||
|
// @param location A standard element location
|
||||||
|
// @return a hash identifying this location
|
||||||
|
//*/
|
||||||
|
//uint qHash(const ElementsLocation &location) {
|
||||||
|
// return(qHash(location.toString()));
|
||||||
|
//}
|
||||||
|
|
||||||
QDebug operator<< (QDebug debug, const ElementsLocation &location)
|
QDebug operator<< (QDebug debug, const ElementsLocation &location)
|
||||||
{
|
{
|
||||||
QDebugStateSaver saver(debug);
|
QDebugStateSaver saver(debug);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2019 The QElectroTech Team
|
Copyright 2006-2019 The QElectroTech Team
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
@@ -24,6 +24,10 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
|
||||||
|
#ifndef Q_OS_LINUX
|
||||||
|
#include "sstream"
|
||||||
|
#endif
|
||||||
|
|
||||||
class QETProject;
|
class QETProject;
|
||||||
class XmlElementCollection;
|
class XmlElementCollection;
|
||||||
|
|
||||||
@@ -86,13 +90,18 @@ class ElementsLocation
|
|||||||
QString m_collection_path;
|
QString m_collection_path;
|
||||||
QString m_file_system_path;
|
QString m_file_system_path;
|
||||||
QETProject *m_project = nullptr;
|
QETProject *m_project = nullptr;
|
||||||
|
#ifndef Q_OS_LINUX
|
||||||
|
mutable std::stringstream m_string_stream;
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static int MetaTypeId; ///< Id of the corresponding Qt meta type
|
static int MetaTypeId; ///< Id of the corresponding Qt meta type
|
||||||
|
static void clearAcces();
|
||||||
|
static int accesCount();
|
||||||
};
|
};
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, const ElementsLocation &location);
|
QDebug operator<<(QDebug debug, const ElementsLocation &location);
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(ElementsLocation)
|
Q_DECLARE_METATYPE(ElementsLocation)
|
||||||
uint qHash(const ElementsLocation &);
|
//uint qHash(const ElementsLocation &);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -40,8 +40,10 @@ FileElementCollectionItem::FileElementCollectionItem()
|
|||||||
bool FileElementCollectionItem::setRootPath(const QString& path, bool set_data, bool hide_element)
|
bool FileElementCollectionItem::setRootPath(const QString& path, bool set_data, bool hide_element)
|
||||||
{
|
{
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
if (dir.exists()) {
|
if (dir.exists())
|
||||||
|
{
|
||||||
m_path = path;
|
m_path = path;
|
||||||
|
m_location.setPath(collectionPath());
|
||||||
populate(set_data, hide_element);
|
populate(set_data, hide_element);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -159,8 +161,8 @@ QString FileElementCollectionItem::localName()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (isElement()) {
|
else if (isElement()) {
|
||||||
ElementsLocation loc(collectionPath());
|
// ElementsLocation loc(collectionPath());
|
||||||
setText(loc.name());
|
setText(m_location.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
return text();
|
return text();
|
||||||
@@ -264,8 +266,8 @@ void FileElementCollectionItem::setUpData()
|
|||||||
|
|
||||||
//Set the local name and all informations of the element
|
//Set the local name and all informations of the element
|
||||||
//in the data Qt::UserRole+1, these data will be use for search.
|
//in the data Qt::UserRole+1, these data will be use for search.
|
||||||
ElementsLocation location(collectionPath());
|
// ElementsLocation location(collectionPath());
|
||||||
DiagramContext context = location.elementInformations();
|
DiagramContext context = m_location.elementInformations();
|
||||||
QStringList search_list;
|
QStringList search_list;
|
||||||
for (QString key : context.keys()) {
|
for (QString key : context.keys()) {
|
||||||
search_list.append(context.value(key).toString());
|
search_list.append(context.value(key).toString());
|
||||||
@@ -297,8 +299,8 @@ void FileElementCollectionItem::setUpIcon()
|
|||||||
if (isDir())
|
if (isDir())
|
||||||
setIcon(QET::Icons::Folder);
|
setIcon(QET::Icons::Folder);
|
||||||
else {
|
else {
|
||||||
ElementsLocation loc(collectionPath());
|
// ElementsLocation loc(collectionPath());
|
||||||
setIcon(loc.icon());
|
setIcon(m_location.icon());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -313,6 +315,7 @@ void FileElementCollectionItem::setUpIcon()
|
|||||||
void FileElementCollectionItem::setPathName(const QString& path_name, bool set_data, bool hide_element)
|
void FileElementCollectionItem::setPathName(const QString& path_name, bool set_data, bool hide_element)
|
||||||
{
|
{
|
||||||
m_path = path_name;
|
m_path = path_name;
|
||||||
|
m_location.setPath(collectionPath());
|
||||||
|
|
||||||
//This isn't an element, we create the childs
|
//This isn't an element, we create the childs
|
||||||
if (!path_name.endsWith(".elmt"))
|
if (!path_name.endsWith(".elmt"))
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#define FILEELEMENTCOLLECTIONITEM2_H
|
#define FILEELEMENTCOLLECTIONITEM2_H
|
||||||
|
|
||||||
#include "elementcollectionitem.h"
|
#include "elementcollectionitem.h"
|
||||||
|
#include "elementslocation.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The FileElementCollectionItem class
|
* @brief The FileElementCollectionItem class
|
||||||
@@ -59,6 +60,7 @@ class FileElementCollectionItem : public ElementCollectionItem
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_path;
|
QString m_path;
|
||||||
|
ElementsLocation m_location;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FILEELEMENTCOLLECTIONITEM2_H
|
#endif // FILEELEMENTCOLLECTIONITEM2_H
|
||||||
|
|||||||
Reference in New Issue
Block a user