mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Clean code
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
#include "elementcollectionhandler.h"
|
||||
|
||||
#include <QtConcurrent>
|
||||
#include <QFutureWatcher>
|
||||
#include <QMessageBox>
|
||||
|
||||
/**
|
||||
@@ -238,23 +237,17 @@ void ElementsCollectionModel::loadCollections(bool common_collection, bool custo
|
||||
list.append(items());
|
||||
|
||||
|
||||
foreach (QETProject *project, projects) {
|
||||
for (QETProject *project : projects)
|
||||
{
|
||||
addProject(project, false);
|
||||
list.append(projectItems(project));
|
||||
}
|
||||
|
||||
ElementsLocation::clearAcces();
|
||||
qDebug() << "acces count " << ElementsLocation::accesCount();
|
||||
QTime t;
|
||||
t.start();
|
||||
QFuture<void> futur = QtConcurrent::map(list, setUpData);
|
||||
emit loadingMaxValue(futur.progressMaximum());
|
||||
while (futur.isRunning()) {
|
||||
emit loadingProgressValue(futur.progressValue());
|
||||
emit loadingMaxValue(list.size());
|
||||
QFuture<void> future = QtConcurrent::map(list, setUpData);
|
||||
while (future.isRunning()) {
|
||||
emit loadingProgressValue(future.progressValue());
|
||||
}
|
||||
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 %2 acces").arg(ms).arg(ElementsLocation::accesCount()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "qetxml.h"
|
||||
#include <QPicture>
|
||||
|
||||
static int acces;
|
||||
// make this class usable with QVariant
|
||||
int ElementsLocation::MetaTypeId = qRegisterMetaType<ElementsLocation>("ElementsLocation");
|
||||
|
||||
@@ -539,7 +538,6 @@ QDomElement ElementsLocation::xml() const
|
||||
{
|
||||
if (!m_project)
|
||||
{
|
||||
++acces;
|
||||
QFile file (m_file_system_path);
|
||||
QDomDocument docu;
|
||||
if (docu.setContent(&file))
|
||||
@@ -583,7 +581,6 @@ pugi::xml_document ElementsLocation::pugiXml() const
|
||||
#endif
|
||||
if (!m_project)
|
||||
{
|
||||
++acces;
|
||||
pugi::xml_document docu;
|
||||
if (docu.load_file(m_file_system_path.toStdString().c_str()))
|
||||
{
|
||||
@@ -695,25 +692,12 @@ QUuid ElementsLocation::uuid() const
|
||||
return QUuid();
|
||||
}
|
||||
|
||||
QSettings set;
|
||||
if(set.value("use_pugixml").toBool())
|
||||
{
|
||||
auto document = pugiXml();
|
||||
auto uuid_node = document.document_element().child("uuid");
|
||||
if (uuid_node.empty()) {
|
||||
return QUuid();
|
||||
}
|
||||
return QUuid(uuid_node.attribute("uuid").as_string());
|
||||
auto document = pugiXml();
|
||||
auto uuid_node = document.document_element().child("uuid");
|
||||
if (uuid_node.empty()) {
|
||||
return QUuid();
|
||||
}
|
||||
|
||||
//Get the uuid of element
|
||||
QList<QDomElement> list_ = QET::findInDomElement(xml(), "uuid");
|
||||
|
||||
if (!list_.isEmpty())
|
||||
return QUuid(list_.first().attribute("uuid"));
|
||||
|
||||
return QUuid();
|
||||
//Get the uuid of element
|
||||
return QUuid(uuid_node.attribute("uuid").as_string());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -744,14 +728,7 @@ QIcon ElementsLocation::icon() const
|
||||
QString ElementsLocation::name() const
|
||||
{
|
||||
NamesList nl;
|
||||
|
||||
QSettings set;
|
||||
if(set.value("use_pugixml").toBool()) {
|
||||
nl.fromXml(pugiXml().document_element());
|
||||
} else {
|
||||
nl.fromXml(xml());
|
||||
}
|
||||
|
||||
nl.fromXml(pugiXml().document_element());
|
||||
return nl.name(fileName());
|
||||
}
|
||||
|
||||
@@ -783,38 +760,11 @@ DiagramContext ElementsLocation::elementInformations() const
|
||||
if (isDirectory()) {
|
||||
return context;
|
||||
}
|
||||
|
||||
QSettings set;
|
||||
if (set.value("use_pugixml").toBool())
|
||||
{
|
||||
context.fromXml(pugiXml().document_element().child("elementInformations"), "elementInformation");
|
||||
}
|
||||
else
|
||||
{
|
||||
QDomElement dom = this->xml().firstChildElement("elementInformations");
|
||||
context.fromXml(dom, "elementInformation");
|
||||
}
|
||||
|
||||
context.fromXml(pugiXml().document_element().child("elementInformations"), "elementInformation");
|
||||
return context;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -96,8 +96,6 @@ class ElementsLocation
|
||||
|
||||
public:
|
||||
static int MetaTypeId; ///< Id of the corresponding Qt meta type
|
||||
static void clearAcces();
|
||||
static int accesCount();
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug debug, const ElementsLocation &location);
|
||||
|
||||
@@ -124,44 +124,20 @@ QString FileElementCollectionItem::localName()
|
||||
}
|
||||
else
|
||||
{
|
||||
QSettings set;
|
||||
if (set.value("use_pugixml").toBool())
|
||||
QString str(fileSystemPath() + "/qet_directory");
|
||||
pugi::xml_document docu;
|
||||
if(docu.load_file(str.toStdString().c_str()))
|
||||
{
|
||||
QString str(fileSystemPath() + "/qet_directory");
|
||||
pugi::xml_document docu;
|
||||
if(docu.load_file(str.toStdString().c_str()))
|
||||
if (QString(docu.document_element().name()) == "qet-directory")
|
||||
{
|
||||
if (QString(docu.document_element().name()) == "qet-directory")
|
||||
{
|
||||
NamesList nl;
|
||||
nl.fromXml(docu.document_element());
|
||||
setText(nl.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Open the qet_directory file, to get the traductions name of this dir
|
||||
QFile dir_conf(fileSystemPath() + "/qet_directory");
|
||||
|
||||
if (dir_conf.exists() && dir_conf.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
|
||||
//Get the content of the file
|
||||
QDomDocument document;
|
||||
if (document.setContent(&dir_conf)) {
|
||||
QDomElement root = document.documentElement();
|
||||
if (root.tagName() == "qet-directory") {
|
||||
NamesList nl;
|
||||
nl.fromXml(root);
|
||||
setText(nl.name());
|
||||
}
|
||||
}
|
||||
NamesList nl;
|
||||
nl.fromXml(docu.document_element());
|
||||
setText(nl.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (isElement()) {
|
||||
// ElementsLocation loc(collectionPath());
|
||||
setText(m_location.name());
|
||||
}
|
||||
|
||||
@@ -266,7 +242,6 @@ 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 = m_location.elementInformations();
|
||||
QStringList search_list;
|
||||
for (QString key : context.keys()) {
|
||||
@@ -295,11 +270,11 @@ void FileElementCollectionItem::setUpIcon()
|
||||
else
|
||||
setIcon(QIcon(":/ico/16x16/go-home.png"));
|
||||
}
|
||||
else {
|
||||
if (isDir())
|
||||
else
|
||||
{
|
||||
if (isDir()) {
|
||||
setIcon(QET::Icons::Folder);
|
||||
else {
|
||||
// ElementsLocation loc(collectionPath());
|
||||
} else {
|
||||
setIcon(m_location.icon());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,8 +126,6 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) :
|
||||
ui->m_custom_tbt_path_cb->setItemData(1, path, Qt::DisplayRole);
|
||||
ui->m_custom_tbt_path_cb->blockSignals(false);
|
||||
}
|
||||
|
||||
ui->m_use_pugi_xml->setChecked(settings.value("use_pugixml").toBool());
|
||||
|
||||
fillLang();
|
||||
}
|
||||
@@ -236,8 +234,6 @@ void GeneralConfigurationPage::applyConf()
|
||||
if (path != settings.value("elements-collections/custom-tbt-path").toString()) {
|
||||
QETApp::resetUserElementsDir();
|
||||
}
|
||||
|
||||
settings.setValue("use_pugixml", ui->m_use_pugi_xml->isChecked()? true : false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -325,13 +325,6 @@ Vous pouvez spécifier ici la valeur par défaut de ce champ pour les éléments
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="m_use_pugi_xml">
|
||||
<property name="text">
|
||||
<string>Utiliser pugi xml pour le chargement des collections.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_6">
|
||||
|
||||
Reference in New Issue
Block a user