mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Improve file access on windows and mac OSX
This commit is contained in:
parent
3492540d53
commit
3d051419a5
@ -243,6 +243,8 @@ void ElementsCollectionModel::loadCollections(bool common_collection, bool custo
|
||||
list.append(projectItems(project));
|
||||
}
|
||||
|
||||
ElementsLocation::clearAcces();
|
||||
qDebug() << "acces count " << ElementsLocation::accesCount();
|
||||
QTime t;
|
||||
t.start();
|
||||
QFuture<void> futur = QtConcurrent::map(list, setUpData);
|
||||
@ -252,7 +254,7 @@ void ElementsCollectionModel::loadCollections(bool common_collection, bool custo
|
||||
}
|
||||
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
|
||||
This file is part of QElectroTech.
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include "qetxml.h"
|
||||
#include <QPicture>
|
||||
|
||||
static int acces;
|
||||
// make this class usable with QVariant
|
||||
int ElementsLocation::MetaTypeId = qRegisterMetaType<ElementsLocation>("ElementsLocation");
|
||||
|
||||
@ -538,6 +539,7 @@ QDomElement ElementsLocation::xml() const
|
||||
{
|
||||
if (!m_project)
|
||||
{
|
||||
++acces;
|
||||
QFile file (m_file_system_path);
|
||||
QDomDocument docu;
|
||||
if (docu.setContent(&file))
|
||||
@ -568,11 +570,28 @@ QDomElement ElementsLocation::xml() 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;
|
||||
if (docu.load_file(m_file_system_path.toStdString().c_str()))
|
||||
{
|
||||
#ifndef Q_OS_LINUX
|
||||
docu.save(m_string_stream);
|
||||
#endif
|
||||
return docu;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -778,14 +797,24 @@ DiagramContext ElementsLocation::elementInformations() const
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
@param location A standard element location
|
||||
@return a hash identifying this location
|
||||
*/
|
||||
uint qHash(const ElementsLocation &location) {
|
||||
return(qHash(location.toString()));
|
||||
void ElementsLocation::clearAcces()
|
||||
{
|
||||
acces =0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
QDebugStateSaver saver(debug);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
Copyright 2006-2019 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
@ -24,6 +24,10 @@
|
||||
#include <QString>
|
||||
#include <QIcon>
|
||||
|
||||
#ifndef Q_OS_LINUX
|
||||
#include "sstream"
|
||||
#endif
|
||||
|
||||
class QETProject;
|
||||
class XmlElementCollection;
|
||||
|
||||
@ -86,13 +90,18 @@ class ElementsLocation
|
||||
QString m_collection_path;
|
||||
QString m_file_system_path;
|
||||
QETProject *m_project = nullptr;
|
||||
#ifndef Q_OS_LINUX
|
||||
mutable std::stringstream m_string_stream;
|
||||
#endif
|
||||
|
||||
public:
|
||||
static int MetaTypeId; ///< Id of the corresponding Qt meta type
|
||||
static void clearAcces();
|
||||
static int accesCount();
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug debug, const ElementsLocation &location);
|
||||
|
||||
Q_DECLARE_METATYPE(ElementsLocation)
|
||||
uint qHash(const ElementsLocation &);
|
||||
//uint qHash(const ElementsLocation &);
|
||||
#endif
|
||||
|
@ -40,8 +40,10 @@ FileElementCollectionItem::FileElementCollectionItem()
|
||||
bool FileElementCollectionItem::setRootPath(const QString& path, bool set_data, bool hide_element)
|
||||
{
|
||||
QDir dir(path);
|
||||
if (dir.exists()) {
|
||||
if (dir.exists())
|
||||
{
|
||||
m_path = path;
|
||||
m_location.setPath(collectionPath());
|
||||
populate(set_data, hide_element);
|
||||
return true;
|
||||
}
|
||||
@ -159,8 +161,8 @@ QString FileElementCollectionItem::localName()
|
||||
}
|
||||
}
|
||||
else if (isElement()) {
|
||||
ElementsLocation loc(collectionPath());
|
||||
setText(loc.name());
|
||||
// ElementsLocation loc(collectionPath());
|
||||
setText(m_location.name());
|
||||
}
|
||||
|
||||
return text();
|
||||
@ -264,8 +266,8 @@ void FileElementCollectionItem::setUpData()
|
||||
|
||||
//Set the local name and all informations of the element
|
||||
//in the data Qt::UserRole+1, these data will be use for search.
|
||||
ElementsLocation location(collectionPath());
|
||||
DiagramContext context = location.elementInformations();
|
||||
// ElementsLocation location(collectionPath());
|
||||
DiagramContext context = m_location.elementInformations();
|
||||
QStringList search_list;
|
||||
for (QString key : context.keys()) {
|
||||
search_list.append(context.value(key).toString());
|
||||
@ -297,8 +299,8 @@ void FileElementCollectionItem::setUpIcon()
|
||||
if (isDir())
|
||||
setIcon(QET::Icons::Folder);
|
||||
else {
|
||||
ElementsLocation loc(collectionPath());
|
||||
setIcon(loc.icon());
|
||||
// ElementsLocation loc(collectionPath());
|
||||
setIcon(m_location.icon());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -313,6 +315,7 @@ void FileElementCollectionItem::setUpIcon()
|
||||
void FileElementCollectionItem::setPathName(const QString& path_name, bool set_data, bool hide_element)
|
||||
{
|
||||
m_path = path_name;
|
||||
m_location.setPath(collectionPath());
|
||||
|
||||
//This isn't an element, we create the childs
|
||||
if (!path_name.endsWith(".elmt"))
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define FILEELEMENTCOLLECTIONITEM2_H
|
||||
|
||||
#include "elementcollectionitem.h"
|
||||
#include "elementslocation.h"
|
||||
|
||||
/**
|
||||
* @brief The FileElementCollectionItem class
|
||||
@ -59,6 +60,7 @@ class FileElementCollectionItem : public ElementCollectionItem
|
||||
|
||||
private:
|
||||
QString m_path;
|
||||
ElementsLocation m_location;
|
||||
};
|
||||
|
||||
#endif // FILEELEMENTCOLLECTIONITEM2_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user