git repos / SagoImageBrowser

blame: imagemodel.h

normal view · raw

032aa1e1 Poul Sander 2026-02-19 18:55 1
#pragma once
032aa1e1 Poul Sander 2026-02-19 18:55 2
032aa1e1 Poul Sander 2026-02-19 18:55 3
#include <QAbstractListModel>
032aa1e1 Poul Sander 2026-02-19 18:55 4
#include <QPixmap>
032aa1e1 Poul Sander 2026-02-19 18:55 5
#include <QVector>
cec3b5da Poul Sander 2026-02-19 19:17 6
#include <QThreadPool>
6fcd6c90 Poul Sander 2026-02-19 21:12 7
#include <QSet>
6fcd6c90 Poul Sander 2026-02-19 21:12 8
#include <atomic>
cec3b5da Poul Sander 2026-02-19 19:17 9
cec3b5da Poul Sander 2026-02-19 19:17 10
class ThumbnailWorker;
032aa1e1 Poul Sander 2026-02-19 18:55 11
032aa1e1 Poul Sander 2026-02-19 18:55 12
class ImageModel : public QAbstractListModel
032aa1e1 Poul Sander 2026-02-19 18:55 13
{
032aa1e1 Poul Sander 2026-02-19 18:55 14
    Q_OBJECT
032aa1e1 Poul Sander 2026-02-19 18:55 15
032aa1e1 Poul Sander 2026-02-19 18:55 16
public:
032aa1e1 Poul Sander 2026-02-19 18:55 17
    explicit ImageModel(QObject *parent = nullptr);
cec3b5da Poul Sander 2026-02-19 19:17 18
    ~ImageModel();
032aa1e1 Poul Sander 2026-02-19 18:55 19
032aa1e1 Poul Sander 2026-02-19 18:55 20
    void setDirectory(const QString &path);
032aa1e1 Poul Sander 2026-02-19 18:55 21
    QString filePath(const QModelIndex &index) const;
032aa1e1 Poul Sander 2026-02-19 18:55 22
6fcd6c90 Poul Sander 2026-02-19 21:12 23
    void requestThumbnails(int firstRow, int lastRow);
6fcd6c90 Poul Sander 2026-02-19 21:12 24
032aa1e1 Poul Sander 2026-02-19 18:55 25
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
032aa1e1 Poul Sander 2026-02-19 18:55 26
    QVariant data(const QModelIndex &index, int role) const override;
032aa1e1 Poul Sander 2026-02-19 18:55 27
6fcd6c90 Poul Sander 2026-02-19 21:12 28
    void thumbnailReady(int row, const QImage &image);
cec3b5da Poul Sander 2026-02-19 19:17 29
032aa1e1 Poul Sander 2026-02-19 18:55 30
private:
032aa1e1 Poul Sander 2026-02-19 18:55 31
    struct Item
032aa1e1 Poul Sander 2026-02-19 18:55 32
    {
032aa1e1 Poul Sander 2026-02-19 18:55 33
        QString path;
032aa1e1 Poul Sander 2026-02-19 18:55 34
        QPixmap thumbnail;
cec3b5da Poul Sander 2026-02-19 19:17 35
        bool loaded = false;
032aa1e1 Poul Sander 2026-02-19 18:55 36
    };
032aa1e1 Poul Sander 2026-02-19 18:55 37
6fcd6c90 Poul Sander 2026-02-19 21:12 38
    void queueRow(int row);
6fcd6c90 Poul Sander 2026-02-19 21:12 39
032aa1e1 Poul Sander 2026-02-19 18:55 40
    QVector<Item> m_items;
cec3b5da Poul Sander 2026-02-19 19:17 41
    QThreadPool m_threadPool;
cec3b5da Poul Sander 2026-02-19 19:17 42
    QPixmap m_placeholder;
6fcd6c90 Poul Sander 2026-02-19 21:12 43
6fcd6c90 Poul Sander 2026-02-19 21:12 44
    QSet<int> m_pendingRows;
6fcd6c90 Poul Sander 2026-02-19 21:12 45
    std::atomic_bool m_cancelFlag{false};
032aa1e1 Poul Sander 2026-02-19 18:55 46
};
1970-01-01 00:00 47