File indexing completed on 2024-05-19 15:40:35

0001 // SPDX-FileCopyrightText: 2024 Carl Schwan <carlschwan@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003 
0004 #pragma once
0005 
0006 #include <QAbstractListModel>
0007 #include <QQmlEngine>
0008 
0009 class ConsoleLog : public QAbstractListModel
0010 {
0011     Q_OBJECT
0012     QML_ELEMENT
0013     QML_SINGLETON
0014 
0015 public:
0016     enum ExtraRoles {
0017         OutputRole = Qt::UserRole + 1,
0018         ImagePathRole,
0019         ImageNameRole,
0020     };
0021 
0022     explicit ConsoleLog(QObject *parent = nullptr);
0023 
0024     QVariant data(const QModelIndex &index, int role) const override;
0025     int rowCount(const QModelIndex &parent = {}) const override;
0026     QHash<int, QByteArray> roleNames() const override;
0027 
0028     void addConsoleEntry(const QString &output, const QString &imagePath);
0029 
0030 private:
0031     struct LogEntry {
0032         QString output;
0033         QString imagePath;
0034     };
0035 
0036     std::vector<LogEntry> m_logEntries;
0037 };