redai/src/artmodel.h

46 lines
1.2 KiB
C
Raw Normal View History

2023-08-31 09:09:52 +02:00
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
//
// SPDX-License-Identifier: GPL-3.0-or-later
2023-03-27 12:49:53 -04:00
#pragma once
#include <QAbstractTableModel>
2023-08-31 13:39:00 +02:00
#include <QDir>
#include <QFutureWatcher>
#include <QImage>
2023-03-27 12:49:53 -04:00
#include <QJsonObject>
struct ArtPiece {
2023-08-31 13:39:59 +02:00
QString filename, jsonFilename;
QString title;
QJsonObject object;
2023-03-27 12:49:53 -04:00
2023-08-31 13:39:59 +02:00
QDate date;
QImage image, thumbnail;
2023-03-27 12:49:53 -04:00
2023-08-31 13:39:59 +02:00
bool hasAltText = false;
2023-03-27 12:49:53 -04:00
};
2023-08-31 13:39:59 +02:00
class ArtModel : public QAbstractTableModel
{
Q_OBJECT
2023-03-27 12:49:53 -04:00
public:
explicit ArtModel(const QDir &definitionDirectory, const QDir &assetDirectory, QObject *parent = nullptr);
2023-03-27 12:49:53 -04:00
2023-08-31 13:39:00 +02:00
[[nodiscard]] int rowCount(const QModelIndex &parent) const override;
2023-08-31 13:39:59 +02:00
[[nodiscard]] int columnCount(const QModelIndex &parent) const override;
2023-03-27 12:49:53 -04:00
2023-08-31 13:39:59 +02:00
[[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
[[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
2023-03-27 12:49:53 -04:00
private:
2023-08-31 13:39:59 +02:00
void loadData(ArtPiece &piece, const QString &filename, const QString &assetFilename);
2023-03-27 12:49:53 -04:00
2023-08-31 13:39:59 +02:00
void pieceFinished(int index);
void finished();
2023-08-31 13:39:59 +02:00
QFutureWatcher<ArtPiece> *piecesFuture;
2023-08-31 13:39:59 +02:00
QList<ArtPiece> m_artPieces;
2023-03-27 12:49:53 -04:00
};