1 | /* |
2 | SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <admin@leinir.dk> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | |
7 | #ifndef KNSCORE_COMMENTSMODEL_H |
8 | #define |
9 | |
10 | #include <QAbstractListModel> |
11 | #include <QDateTime> |
12 | |
13 | #include "enginebase.h" |
14 | |
15 | #include "knewstuffcore_export.h" |
16 | |
17 | #include <memory> |
18 | |
19 | namespace KNSCore |
20 | { |
21 | class Entry; |
22 | |
23 | struct { |
24 | QString ; |
25 | QString ; |
26 | QString ; |
27 | int = 0; |
28 | QString ; |
29 | QDateTime ; |
30 | int = 0; |
31 | std::shared_ptr<KNSCore::Comment> ; |
32 | }; |
33 | class ; |
34 | |
35 | /*! |
36 | * \class KNSCore::CommentsModel |
37 | * \inmodule KNewStuffCore |
38 | * |
39 | * \brief A model which takes care of the comments for a single Entry. |
40 | * |
41 | * \note This model should preferably be constructed by asking the Engine to give a model |
42 | * instance to you for a specific entry using the commentsForEntry function. If you |
43 | * insist, you can construct an instance yourself as well, but this is not recommended. |
44 | * |
45 | * \sa Engine::commentsForEntry(KNSCore::Entry) |
46 | * \since 5.63 |
47 | */ |
48 | class KNEWSTUFFCORE_EXPORT : public QAbstractListModel |
49 | { |
50 | Q_OBJECT |
51 | /*! |
52 | * \qmlproperty Entry CommentsModel::entry |
53 | * The Entry for which this model should handle comments |
54 | */ |
55 | /*! |
56 | * \property KNSCore::CommentsModel::entry |
57 | * The Entry for which this model should handle comments |
58 | */ |
59 | Q_PROPERTY(KNSCore::Entry entry READ entry WRITE setEntry NOTIFY entryChanged) |
60 | public: |
61 | /*! |
62 | * Construct a new CommentsModel instance. |
63 | * \note The class is intended to be constructed using the Engine::commentsForEntry function |
64 | * \sa Engine::commentsForEntry(KNSCore::Entry) |
65 | */ |
66 | explicit (EngineBase *parent = nullptr); |
67 | () override; |
68 | |
69 | /*! |
70 | * \enum KNSCore::CommentsModel::Roles |
71 | * |
72 | * \value SubjectRole |
73 | * \value IdRole |
74 | * \value TextRole |
75 | * \value ChildCountRole |
76 | * \value UsernameRole |
77 | * \value DateRole |
78 | * \value ScoreRole |
79 | * \value ParentIndexRole |
80 | * \value DepthRole |
81 | */ |
82 | enum { |
83 | = Qt::DisplayRole, |
84 | = Qt::UserRole + 1, |
85 | , |
86 | , |
87 | , |
88 | , |
89 | , |
90 | , |
91 | , |
92 | }; |
93 | Q_ENUM(Roles) |
94 | |
95 | QHash<int, QByteArray> () const override; |
96 | QVariant (const QModelIndex &index, int role = Qt::DisplayRole) const override; |
97 | int (const QModelIndex &parent = QModelIndex()) const override; |
98 | bool (const QModelIndex &parent) const override; |
99 | void (const QModelIndex &parent) override; |
100 | |
101 | const KNSCore::Entry &() const; |
102 | void (const KNSCore::Entry &newEntry); |
103 | Q_SIGNAL void (); |
104 | |
105 | private: |
106 | friend class CommentsModelPrivate; // For beginResetModel and beginInsertRows method calls |
107 | const std::unique_ptr<CommentsModelPrivate> ; |
108 | }; |
109 | } |
110 | |
111 | #endif // KNSCORE_COMMENTSMODEL_H |
112 | |