Clean code

This commit is contained in:
Claveau Joshua
2020-01-17 19:33:13 +01:00
parent 32c135a7e5
commit dca44566e8
6 changed files with 25 additions and 120 deletions

View File

@@ -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()));
}
/**

View File

@@ -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,9 +692,6 @@ 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()) {
@@ -706,16 +700,6 @@ QUuid ElementsLocation::uuid() const
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
}
/**
* @brief ElementLocation::icon
* @return The icon of the represented element.
@@ -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());
}
return nl.name(fileName());
}
@@ -784,37 +761,10 @@ DiagramContext ElementsLocation::elementInformations() const
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");
}
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);

View File

@@ -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);

View File

@@ -123,9 +123,6 @@ QString FileElementCollectionItem::localName()
setText(QObject::tr("Collection inconnue"));
}
else
{
QSettings set;
if (set.value("use_pugixml").toBool())
{
QString str(fileSystemPath() + "/qet_directory");
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()) {
// 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());
}
}

View File

@@ -127,8 +127,6 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) :
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);
}
/**

View File

@@ -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">