Use multithreading for loading the element collection

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4542 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun 2016-06-06 18:34:34 +00:00
parent e6c2ed8d5f
commit 2ec0278213
6 changed files with 36 additions and 24 deletions

View File

@ -116,7 +116,7 @@ RESOURCES += qelectrotech.qrc
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 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 # 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 # UI DESIGNER FILES AND GENERATION SOURCES FILES
FORMS += $$files(sources/richtext/*.ui) \ FORMS += $$files(sources/richtext/*.ui) \

View File

@ -208,3 +208,8 @@ QList<ElementCollectionItem *> ElementCollectionItem::items() const
return list; return list;
} }
void setUpData(ElementCollectionItem *eci)
{
eci->setUpData();
}

View File

@ -56,4 +56,6 @@ class ElementCollectionItem : public QStandardItem
QList<ElementCollectionItem *> items() const; QList<ElementCollectionItem *> items() const;
}; };
void setUpData(ElementCollectionItem *eci);
#endif // ELEMENTCOLLECTIONITEM2_H #endif // ELEMENTCOLLECTIONITEM2_H

View File

@ -35,6 +35,7 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QUrl> #include <QUrl>
#include <QTimer> #include <QTimer>
#include <QtConcurrent>
/** /**
* @brief ElementsCollectionWidget::ElementsCollectionWidget * @brief ElementsCollectionWidget::ElementsCollectionWidget
@ -447,12 +448,11 @@ void ElementsCollectionWidget::reload()
new_model->addProject(project, false); new_model->addProject(project, false);
QList <ElementCollectionItem *> list = new_model->items(); QList <ElementCollectionItem *> list = new_model->items();
m_progress_bar->setMaximum(list.size()); QFuture<void> futur = QtConcurrent::map(list, setUpData);
m_progress_bar->setValue(0); m_progress_bar->setMinimum(futur.progressMinimum());
foreach (ElementCollectionItem *item, new_model->items()) m_progress_bar->setMaximum(futur.progressMaximum());
{ while (futur.isRunning()) {
item->setUpData(); m_progress_bar->setValue(futur.progressValue());
m_progress_bar->setValue(m_progress_bar->value() + 1);
} }
m_tree_view->setModel(new_model); m_tree_view->setModel(new_model);

View File

@ -654,21 +654,21 @@ QIcon ElementsLocation::icon() const
*/ */
QString ElementsLocation::name() const QString ElementsLocation::name() const
{ {
if (!m_project) // if (!m_project)
{ // {
ElementsCollectionCache *cache = QETApp::collectionCache(); // ElementsCollectionCache *cache = QETApp::collectionCache();
ElementsLocation loc(*this); //Make a copy of this to keep this method const // ElementsLocation loc(*this); //Make a copy of this to keep this method const
if (cache->fetchElement(loc)) // if (cache->fetchElement(loc))
return cache->name(); // return cache->name();
else // else
return QString(); // return QString();
} // }
else // else
{ // {
NamesList nl; NamesList nl;
nl.fromXml(xml()); nl.fromXml(xml());
return nl.name(fileName()); return nl.name(fileName());
} // }
} }
/** /**

View File

@ -20,6 +20,7 @@
#include <QTreeView> #include <QTreeView>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QPushButton> #include <QPushButton>
#include <QtConcurrent>
#include "elementdialog.h" #include "elementdialog.h"
#include "qetapp.h" #include "qetapp.h"
@ -86,11 +87,15 @@ void ElementDialog::setUpWidget()
m_tree_view = new QTreeView(this); m_tree_view = new QTreeView(this);
m_model = new ElementsCollectionModel(m_tree_view); m_model = new ElementsCollectionModel(m_tree_view);
if (m_mode == OpenElement) {m_model->addCommonCollection();} if (m_mode == OpenElement)
m_model->addCustomCollection(); m_model->addCommonCollection(false);
foreach (QETProject *project, QETApp::registeredProjects()) { m_model->addCustomCollection(false);
m_model->addProject(project);
} 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->setModel(m_model);
m_tree_view->setHeaderHidden(true); m_tree_view->setHeaderHidden(true);