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#include <QList>
27
28class ElementsModel : public QAbstractListModel
29{
30 Q_OBJECT
31
32public:
33 enum Roles {
34 ThumbnailRole = Qt::UserRole + 1,
35 FilePathRole,
36 HasAnimationRole,
37 };
38
39 explicit ElementsModel(QObject *parent = nullptr);
40 explicit ElementsModel(const QDir &dir, QObject *parent = nullptr);
41
42 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
43 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
44 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
45 Qt::ItemFlags flags(const QModelIndex &index) const override;
46
48 void updateThumbnail(const QString &filePath, QImage &image, const QModelIndex &persistentIndex);
49
51 void setDir(const QDir &dir);
52
54 void setDirs(const QList<QDir> &dirs);
55
56private:
57 QDir m_dir;
58 QList<QFileInfo> m_files;
59 QHash<int, QImage> m_overrideThumbnails;
60};
61
62#endif // ELEMENTSMODEL_H