Separate thumnail loading to different pool

This commit is contained in:
2022-04-18 09:55:47 +02:00
parent cba8a0bb9c
commit fabf3f0c1a
2 changed files with 11 additions and 5 deletions
+8 -4
View File
@@ -30,10 +30,10 @@ void Image::load()
emit pixmapLoaded(this); emit pixmapLoaded(this);
} }
void Image::loadThumbnail() void Image::loadThumbnail(QThreadPool *pool)
{ {
if(!m_thumbnail) if(!m_thumbnail)
QThreadPool::globalInstance()->start(new LoadRunable(m_name, this, AnalyzeLevel::None, true)); pool->start(new LoadRunable(m_name, this, AnalyzeLevel::None, true));
else else
emit thumbnailLoaded(this); emit thumbnailLoaded(this);
} }
@@ -102,12 +102,16 @@ ImageRingList::ImageRingList(QObject *parent) : QAbstractItemModel(parent)
, m_analyzeLevel(None) , m_analyzeLevel(None)
{ {
connect(&m_fileSystemWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(dirChanged(QString))); connect(&m_fileSystemWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(dirChanged(QString)));
m_thumbPool = new QThreadPool(this);
} }
ImageRingList::~ImageRingList() ImageRingList::~ImageRingList()
{ {
QThreadPool::globalInstance()->clear(); QThreadPool::globalInstance()->clear();
m_thumbPool->clear();
QThreadPool::globalInstance()->waitForDone(); QThreadPool::globalInstance()->waitForDone();
m_thumbPool->waitForDone();
} }
bool ImageRingList::setDir(const QString path, const QString &currentFile) bool ImageRingList::setDir(const QString path, const QString &currentFile)
@@ -239,13 +243,13 @@ void ImageRingList::loadThumbnails()
{ {
for(auto &img : m_images) for(auto &img : m_images)
{ {
img->loadThumbnail(); img->loadThumbnail(m_thumbPool);
} }
} }
void ImageRingList::stopLoading() void ImageRingList::stopLoading()
{ {
QThreadPool::globalInstance()->clear(); m_thumbPool->clear();
} }
int ImageRingList::imageCount() const int ImageRingList::imageCount() const
+3 -1
View File
@@ -10,6 +10,7 @@
#include "rawimage.h" #include "rawimage.h"
class ImageRingList; class ImageRingList;
class QThreadPool;
class Image : public QObject class Image : public QObject
{ {
@@ -26,7 +27,7 @@ class Image : public QObject
public: public:
explicit Image(const QString name, int number, ImageRingList *ringList); explicit Image(const QString name, int number, ImageRingList *ringList);
void load(); void load();
void loadThumbnail(); void loadThumbnail(QThreadPool *pool);
void release(); void release();
QString name() const; QString name() const;
RawImage* rawImage(); RawImage* rawImage();
@@ -55,6 +56,7 @@ class ImageRingList : public QAbstractItemModel
QFileSystemWatcher m_fileSystemWatcher; QFileSystemWatcher m_fileSystemWatcher;
bool m_liveMode; bool m_liveMode;
AnalyzeLevel m_analyzeLevel; AnalyzeLevel m_analyzeLevel;
QThreadPool *m_thumbPool;
public: public:
explicit ImageRingList(QObject *parent = 0); explicit ImageRingList(QObject *parent = 0);
~ImageRingList(); ~ImageRingList();