mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Dive pictures: Introduce thumbnailer class
Create a new class, which performs all thumbnailing code. This is mostly code reshuffling. Thumbnails are extracted either from a cache or thumbnail calculation is started in a worker thread. Since getHashedImage() is called from a worker thread it makes no sense to call subfunctions in yet another worker thread. Remove these calls. In contrast to the previous code, on error the background thread produces a failure image, but it is not yet shown. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f60343eebb
commit
3967b1fd4d
4 changed files with 141 additions and 68 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <QImage>
|
||||
#include <QFuture>
|
||||
#include <QNetworkReply>
|
||||
#include <QThreadPool>
|
||||
|
||||
class ImageDownloader : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -18,6 +19,31 @@ private:
|
|||
QString filename;
|
||||
};
|
||||
|
||||
class PictureEntry;
|
||||
class Thumbnailer : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static Thumbnailer *instance();
|
||||
|
||||
// Schedule a thumbnail for fetching or calculation.
|
||||
// Returns a placehlder thumbnail. The actual thumbnail will be sent
|
||||
// via a signal later.
|
||||
QImage fetchThumbnail(PictureEntry &entry, int size);
|
||||
|
||||
// If we change dive, clear all unfinished thumbnail creations
|
||||
void clearWorkQueue();
|
||||
signals:
|
||||
void thumbnailChanged(QString filename, QImage thumbnail);
|
||||
private:
|
||||
Thumbnailer();
|
||||
void processItem(QString filename, int size);
|
||||
|
||||
mutable QMutex lock;
|
||||
QThreadPool pool;
|
||||
|
||||
QMap<QString,QFuture<void>> workingOn;
|
||||
};
|
||||
|
||||
QImage getHashedImage(const QString &filename);
|
||||
|
||||
#endif // IMAGEDOWNLOADER_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue