1 | /* |
2 | SPDX-FileCopyrightText: 2017 René J.V. Bertin <rjvbertin@gmail.com> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef DIFFLISTMODEL_H |
8 | #define DIFFLISTMODEL_H |
9 | |
10 | #include <QAbstractListModel> |
11 | #include <QHash> |
12 | #include <QList> |
13 | |
14 | class KJob; |
15 | class QTemporaryDir; |
16 | |
17 | class DiffListModel : public QAbstractListModel |
18 | { |
19 | Q_OBJECT |
20 | Q_PROPERTY(QString status READ status WRITE setStatus) |
21 | public: |
22 | DiffListModel(QObject *parent = nullptr); |
23 | |
24 | void refresh(); |
25 | |
26 | QHash<int, QByteArray> roleNames() const override; |
27 | QVariant data(const QModelIndex &idx, int role) const override; |
28 | int rowCount(const QModelIndex &parent) const override; |
29 | |
30 | QString status() const |
31 | { |
32 | return m_status; |
33 | } |
34 | |
35 | void setStatus(const QString &status); |
36 | |
37 | void receivedDiffRevs(KJob *job); |
38 | Q_SCRIPTABLE QVariant get(int row, const QByteArray &role); |
39 | |
40 | private: |
41 | struct Value { |
42 | QVariant summary; |
43 | QVariant id; |
44 | QVariant status; |
45 | #ifndef QT_NO_DEBUG_STREAM |
46 | operator QString() const |
47 | { |
48 | QString ret = QStringLiteral("DiffListModel::Value{summary=\"%1\" id=\"%2\" status=\"%3\"}" ); |
49 | return ret.arg(a: this->summary.toString()).arg(a: this->id.toString()).arg(a: this->status.toInt()); |
50 | } |
51 | #endif |
52 | }; |
53 | QList<Value> m_values; |
54 | |
55 | QString m_status; |
56 | QString m_initialDir; |
57 | QTemporaryDir *m_tempDir; |
58 | }; |
59 | |
60 | #endif |
61 | |