CuteLogger
Fast and simple logging solution for Qt based applications
elementsmodel.h
1/*
2 * Copyright (c) 2026 Meltytech, LLC
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef ELEMENTSMODEL_H
19#define ELEMENTSMODEL_H
20
21#include <QAbstractListModel>
22#include <QDir>
23#include <QFileInfo>
24#include <QHash>
25#include <QImage>
26
27class ElementsModel : public QAbstractListModel
28{
29 Q_OBJECT
30
31public:
32 enum Roles {
33 ThumbnailRole = Qt::UserRole + 1,
34 FilePathRole,
35 HasAnimationRole,
36 };
37
38 explicit ElementsModel(const QDir &dir, QObject *parent = nullptr);
39
40 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
41 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
42 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
43 Qt::ItemFlags flags(const QModelIndex &index) const override;
44
46 void updateThumbnail(const QString &filePath, QImage &image, const QModelIndex &persistentIndex);
47
49 void setDir(const QDir &dir);
50
51private:
52 QDir m_dir;
53 QList<QFileInfo> m_files;
54 QHash<int, QImage> m_overrideThumbnails;
55};
56
57#endif // ELEMENTSMODEL_H