mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Clean code
This commit is contained in:
@@ -25,7 +25,6 @@
|
|||||||
#include "elementcollectionhandler.h"
|
#include "elementcollectionhandler.h"
|
||||||
|
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
#include <QFutureWatcher>
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -238,23 +237,17 @@ void ElementsCollectionModel::loadCollections(bool common_collection, bool custo
|
|||||||
list.append(items());
|
list.append(items());
|
||||||
|
|
||||||
|
|
||||||
foreach (QETProject *project, projects) {
|
for (QETProject *project : projects)
|
||||||
|
{
|
||||||
addProject(project, false);
|
addProject(project, false);
|
||||||
list.append(projectItems(project));
|
list.append(projectItems(project));
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementsLocation::clearAcces();
|
emit loadingMaxValue(list.size());
|
||||||
qDebug() << "acces count " << ElementsLocation::accesCount();
|
QFuture<void> future = QtConcurrent::map(list, setUpData);
|
||||||
QTime t;
|
while (future.isRunning()) {
|
||||||
t.start();
|
emit loadingProgressValue(future.progressValue());
|
||||||
QFuture<void> futur = QtConcurrent::map(list, setUpData);
|
|
||||||
emit loadingMaxValue(futur.progressMaximum());
|
|
||||||
while (futur.isRunning()) {
|
|
||||||
emit loadingProgressValue(futur.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 "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");
|
||||||
|
|
||||||
@@ -539,7 +538,6 @@ 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))
|
||||||
@@ -583,7 +581,6 @@ pugi::xml_document ElementsLocation::pugiXml() const
|
|||||||
#endif
|
#endif
|
||||||
if (!m_project)
|
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()))
|
||||||
{
|
{
|
||||||
@@ -695,25 +692,12 @@ QUuid ElementsLocation::uuid() const
|
|||||||
return QUuid();
|
return QUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSettings set;
|
|
||||||
if(set.value("use_pugixml").toBool())
|
|
||||||
{
|
|
||||||
auto document = pugiXml();
|
auto document = pugiXml();
|
||||||
auto uuid_node = document.document_element().child("uuid");
|
auto uuid_node = document.document_element().child("uuid");
|
||||||
if (uuid_node.empty()) {
|
if (uuid_node.empty()) {
|
||||||
return QUuid();
|
return QUuid();
|
||||||
}
|
}
|
||||||
return QUuid(uuid_node.attribute("uuid").as_string());
|
return QUuid(uuid_node.attribute("uuid").as_string());
|
||||||
}
|
|
||||||
|
|
||||||
//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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -744,14 +728,7 @@ QIcon ElementsLocation::icon() const
|
|||||||
QString ElementsLocation::name() const
|
QString ElementsLocation::name() const
|
||||||
{
|
{
|
||||||
NamesList nl;
|
NamesList nl;
|
||||||
|
|
||||||
QSettings set;
|
|
||||||
if(set.value("use_pugixml").toBool()) {
|
|
||||||
nl.fromXml(pugiXml().document_element());
|
nl.fromXml(pugiXml().document_element());
|
||||||
} else {
|
|
||||||
nl.fromXml(xml());
|
|
||||||
}
|
|
||||||
|
|
||||||
return nl.name(fileName());
|
return nl.name(fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -784,37 +761,10 @@ DiagramContext ElementsLocation::elementInformations() const
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSettings set;
|
|
||||||
if (set.value("use_pugixml").toBool())
|
|
||||||
{
|
|
||||||
context.fromXml(pugiXml().document_element().child("elementInformations"), "elementInformation");
|
context.fromXml(pugiXml().document_element().child("elementInformations"), "elementInformation");
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QDomElement dom = this->xml().firstChildElement("elementInformations");
|
|
||||||
context.fromXml(dom, "elementInformation");
|
|
||||||
}
|
|
||||||
return context;
|
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)
|
QDebug operator<< (QDebug debug, const ElementsLocation &location)
|
||||||
{
|
{
|
||||||
QDebugStateSaver saver(debug);
|
QDebugStateSaver saver(debug);
|
||||||
|
|||||||
@@ -96,8 +96,6 @@ class ElementsLocation
|
|||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -123,9 +123,6 @@ QString FileElementCollectionItem::localName()
|
|||||||
setText(QObject::tr("Collection inconnue"));
|
setText(QObject::tr("Collection inconnue"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
QSettings set;
|
|
||||||
if (set.value("use_pugixml").toBool())
|
|
||||||
{
|
{
|
||||||
QString str(fileSystemPath() + "/qet_directory");
|
QString str(fileSystemPath() + "/qet_directory");
|
||||||
pugi::xml_document docu;
|
pugi::xml_document docu;
|
||||||
@@ -139,29 +136,8 @@ QString FileElementCollectionItem::localName()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (isElement()) {
|
else if (isElement()) {
|
||||||
// ElementsLocation loc(collectionPath());
|
|
||||||
setText(m_location.name());
|
setText(m_location.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +242,6 @@ 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());
|
|
||||||
DiagramContext context = m_location.elementInformations();
|
DiagramContext context = m_location.elementInformations();
|
||||||
QStringList search_list;
|
QStringList search_list;
|
||||||
for (QString key : context.keys()) {
|
for (QString key : context.keys()) {
|
||||||
@@ -295,11 +270,11 @@ void FileElementCollectionItem::setUpIcon()
|
|||||||
else
|
else
|
||||||
setIcon(QIcon(":/ico/16x16/go-home.png"));
|
setIcon(QIcon(":/ico/16x16/go-home.png"));
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if (isDir())
|
{
|
||||||
|
if (isDir()) {
|
||||||
setIcon(QET::Icons::Folder);
|
setIcon(QET::Icons::Folder);
|
||||||
else {
|
} else {
|
||||||
// ElementsLocation loc(collectionPath());
|
|
||||||
setIcon(m_location.icon());
|
setIcon(m_location.icon());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,8 +127,6 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) :
|
|||||||
ui->m_custom_tbt_path_cb->blockSignals(false);
|
ui->m_custom_tbt_path_cb->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->m_use_pugi_xml->setChecked(settings.value("use_pugixml").toBool());
|
|
||||||
|
|
||||||
fillLang();
|
fillLang();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,8 +234,6 @@ void GeneralConfigurationPage::applyConf()
|
|||||||
if (path != settings.value("elements-collections/custom-tbt-path").toString()) {
|
if (path != settings.value("elements-collections/custom-tbt-path").toString()) {
|
||||||
QETApp::resetUserElementsDir();
|
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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="tab_6">
|
<widget class="QWidget" name="tab_6">
|
||||||
|
|||||||
Reference in New Issue
Block a user