[qet] [4542] Use multithreading for loading the element collection |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4542
Author: blacksun
Date: 2016-06-06 20:34:34 +0200 (Mon, 06 Jun 2016)
Log Message:
-----------
Use multithreading for loading the element collection
Modified Paths:
--------------
trunk/qelectrotech.pro
trunk/sources/ElementsCollection/elementcollectionitem.cpp
trunk/sources/ElementsCollection/elementcollectionitem.h
trunk/sources/ElementsCollection/elementscollectionwidget.cpp
trunk/sources/ElementsCollection/elementslocation.cpp
trunk/sources/elementdialog.cpp
Modified: trunk/qelectrotech.pro
===================================================================
--- trunk/qelectrotech.pro 2016-06-05 19:55:41 UTC (rev 4541)
+++ trunk/qelectrotech.pro 2016-06-06 18:34:34 UTC (rev 4542)
@@ -116,7 +116,7 @@
TRANSLATIONS += lang/qet_en.ts lang/qet_es.ts lang/qet_fr.ts lang/qet_ru.ts lang/qet_pt.ts lang/qet_cs.ts lang/qet_pl.ts lang/qet_de.ts lang/qet_ro.ts lang/qet_it.ts lang/qet_el.ts lang/qet_nl.ts lang/qet_be.ts
# Modules Qt utilises par l'application
-QT += xml svg network sql widgets printsupport
+QT += xml svg network sql widgets printsupport concurrent
# UI DESIGNER FILES AND GENERATION SOURCES FILES
FORMS += $$files(sources/richtext/*.ui) \
Modified: trunk/sources/ElementsCollection/elementcollectionitem.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementcollectionitem.cpp 2016-06-05 19:55:41 UTC (rev 4541)
+++ trunk/sources/ElementsCollection/elementcollectionitem.cpp 2016-06-06 18:34:34 UTC (rev 4542)
@@ -208,3 +208,8 @@
return list;
}
+
+void setUpData(ElementCollectionItem *eci)
+{
+ eci->setUpData();
+}
Modified: trunk/sources/ElementsCollection/elementcollectionitem.h
===================================================================
--- trunk/sources/ElementsCollection/elementcollectionitem.h 2016-06-05 19:55:41 UTC (rev 4541)
+++ trunk/sources/ElementsCollection/elementcollectionitem.h 2016-06-06 18:34:34 UTC (rev 4542)
@@ -56,4 +56,6 @@
QList<ElementCollectionItem *> items() const;
};
+void setUpData(ElementCollectionItem *eci);
+
#endif // ELEMENTCOLLECTIONITEM2_H
Modified: trunk/sources/ElementsCollection/elementscollectionwidget.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementscollectionwidget.cpp 2016-06-05 19:55:41 UTC (rev 4541)
+++ trunk/sources/ElementsCollection/elementscollectionwidget.cpp 2016-06-06 18:34:34 UTC (rev 4542)
@@ -35,6 +35,7 @@
#include <QDesktopServices>
#include <QUrl>
#include <QTimer>
+#include <QtConcurrent>
/**
* @brief ElementsCollectionWidget::ElementsCollectionWidget
@@ -447,12 +448,11 @@
new_model->addProject(project, false);
QList <ElementCollectionItem *> list = new_model->items();
- m_progress_bar->setMaximum(list.size());
- m_progress_bar->setValue(0);
- foreach (ElementCollectionItem *item, new_model->items())
- {
- item->setUpData();
- m_progress_bar->setValue(m_progress_bar->value() + 1);
+ QFuture<void> futur = QtConcurrent::map(list, setUpData);
+ m_progress_bar->setMinimum(futur.progressMinimum());
+ m_progress_bar->setMaximum(futur.progressMaximum());
+ while (futur.isRunning()) {
+ m_progress_bar->setValue(futur.progressValue());
}
m_tree_view->setModel(new_model);
Modified: trunk/sources/ElementsCollection/elementslocation.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementslocation.cpp 2016-06-05 19:55:41 UTC (rev 4541)
+++ trunk/sources/ElementsCollection/elementslocation.cpp 2016-06-06 18:34:34 UTC (rev 4542)
@@ -654,21 +654,21 @@
*/
QString ElementsLocation::name() const
{
- if (!m_project)
- {
- ElementsCollectionCache *cache = QETApp::collectionCache();
- ElementsLocation loc(*this); //Make a copy of this to keep this method const
- if (cache->fetchElement(loc))
- return cache->name();
- else
- return QString();
- }
- else
- {
+// if (!m_project)
+// {
+// ElementsCollectionCache *cache = QETApp::collectionCache();
+// ElementsLocation loc(*this); //Make a copy of this to keep this method const
+// if (cache->fetchElement(loc))
+// return cache->name();
+// else
+// return QString();
+// }
+// else
+// {
NamesList nl;
nl.fromXml(xml());
return nl.name(fileName());
- }
+// }
}
/**
Modified: trunk/sources/elementdialog.cpp
===================================================================
--- trunk/sources/elementdialog.cpp 2016-06-05 19:55:41 UTC (rev 4541)
+++ trunk/sources/elementdialog.cpp 2016-06-06 18:34:34 UTC (rev 4542)
@@ -20,6 +20,7 @@
#include <QTreeView>
#include <QDialogButtonBox>
#include <QPushButton>
+#include <QtConcurrent>
#include "elementdialog.h"
#include "qetapp.h"
@@ -86,12 +87,16 @@
m_tree_view = new QTreeView(this);
m_model = new ElementsCollectionModel(m_tree_view);
- if (m_mode == OpenElement) {m_model->addCommonCollection();}
- m_model->addCustomCollection();
- foreach (QETProject *project, QETApp::registeredProjects()) {
- m_model->addProject(project);
- }
+ if (m_mode == OpenElement)
+ m_model->addCommonCollection(false);
+ m_model->addCustomCollection(false);
+ foreach (QETProject *project, QETApp::registeredProjects())
+ m_model->addProject(project, false);
+
+ QList <ElementCollectionItem *> list = m_model->items();
+ QtConcurrent::blockingMap(list, setUpData);
+
m_tree_view->setModel(m_model);
m_tree_view->setHeaderHidden(true);
layout->addWidget(m_tree_view);