mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-01 00:13:24 +00:00
Don't call UI functions from helper code
This may seem much more complicated but actually is much cleaner. Add each thread we start to the list of future results and add a new UI function that updates the UI once all of the threads have finished. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
44b55bd1a2
commit
1e3700c11f
4 changed files with 14 additions and 4 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "divelist.h"
|
||||
#include <QtConcurrentMap>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QFuture>
|
||||
#include <QDir>
|
||||
#include <QCryptographicHash>
|
||||
#include <mainwindow.h>
|
||||
|
@ -53,6 +54,14 @@ SPixmap scaleImages(picturepointer picture)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void DivePictureModel::updateDivePicturesWhenDone(QList<QFuture<void> > futures)
|
||||
{
|
||||
Q_FOREACH (QFuture<void> f, futures) {
|
||||
f.waitForFinished();
|
||||
}
|
||||
updateDivePictures();
|
||||
}
|
||||
|
||||
void DivePictureModel::updateDivePictures()
|
||||
{
|
||||
if (numberOfPictures != 0) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QAbstractTableModel>
|
||||
#include <QListView>
|
||||
#include <QThread>
|
||||
#include <QFuture>
|
||||
|
||||
typedef QPair<QString, QByteArray> SHashedFilename;
|
||||
|
||||
|
@ -25,6 +26,7 @@ public:
|
|||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
void updateDivePictures();
|
||||
void updateDivePicturesWhenDone(QList<QFuture<void> >);
|
||||
void removePicture(const QString& fileUrl);
|
||||
|
||||
private:
|
||||
|
|
|
@ -327,14 +327,15 @@ void MainWindow::on_actionHash_images_triggered()
|
|||
dialog.setLabelText(QFileDialog::Accept, tr("Scan"));
|
||||
dialog.setLabelText(QFileDialog::Reject, tr("Cancel"));
|
||||
QStringList dirnames;
|
||||
QList<QFuture<void> > futures;
|
||||
if (dialog.exec())
|
||||
dirnames = dialog.selectedFiles();
|
||||
if (dirnames.isEmpty())
|
||||
return;
|
||||
foreach (QString dir, dirnames) {
|
||||
QtConcurrent::run(learnImages, QDir(dir), 10, false);
|
||||
futures << QtConcurrent::run(learnImages, QDir(dir), 10, false);
|
||||
}
|
||||
|
||||
DivePictureModel::instance()->updateDivePicturesWhenDone(futures);
|
||||
}
|
||||
|
||||
ProfileWidget2 *MainWindow::graphics() const
|
||||
|
|
|
@ -870,6 +870,4 @@ void learnImages(const QDir dir, int max_recursions, bool recursed)
|
|||
}
|
||||
|
||||
QtConcurrent::blockingMap(files, hashFile);
|
||||
if (!recursed)
|
||||
DivePictureModel::instance()->updateDivePictures();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue