KNewStuff

core/commentsmodel.h
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 KNSCORE_COMMENTSMODEL_H
9
10#include <QAbstractListModel>
11#include <QDateTime>
12
13#include "enginebase.h"
14
15#include "knewstuffcore_export.h"
16
17#include <memory>
18
19namespace KNSCore
20{
21class Entry;
22
23struct Comment {
24 QString id;
25 QString subject;
26 QString text;
27 int childCount = 0;
28 QString username;
29 QDateTime date;
30 int score = 0;
31 std::shared_ptr<KNSCore::Comment> parent;
32};
33class CommentsModelPrivate;
34
35/**
36 * @brief A model which takes care of the comments for a single Entry
37 *
38 * This model should preferably be constructed by asking the Engine to give a model
39 * instance to you for a specific entry using the commentsForEntry function. If you
40 * insist, you can construct an instance yourself as well, but this is not recommended.
41 *
42 * @see Engine::commentsForEntry(KNSCore::Entry)
43 * @since 5.63
44 */
46{
47 Q_OBJECT
48 /**
49 * The Entry for which this model should handle comments
50 */
51 Q_PROPERTY(KNSCore::Entry entry READ entry WRITE setEntry NOTIFY entryChanged)
52public:
53 /**
54 * Construct a new CommentsModel instance.
55 * @note The class is intended to be constructed using the Engine::commentsForEntry function
56 * @see Engine::commentsForEntry(KNSCore::Entry)
57 */
58 explicit CommentsModel(EngineBase *parent = nullptr);
59 ~CommentsModel() override;
60
61 enum Roles {
62 SubjectRole = Qt::DisplayRole,
63 IdRole = Qt::UserRole + 1,
64 TextRole,
65 ChildCountRole,
66 UsernameRole,
67 DateRole,
68 ScoreRole,
69 ParentIndexRole,
70 DepthRole,
71 };
72 Q_ENUM(Roles)
73
74 QHash<int, QByteArray> roleNames() const override;
75 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
76 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
77 bool canFetchMore(const QModelIndex &parent) const override;
78 void fetchMore(const QModelIndex &parent) override;
79
80 const KNSCore::Entry &entry() const;
81 void setEntry(const KNSCore::Entry &newEntry);
82 Q_SIGNAL void entryChanged();
83
84private:
85 friend class CommentsModelPrivate; // For beginResetModel and beginInsertRows method calls
86 const std::unique_ptr<CommentsModelPrivate> d;
87};
88}
89
90#endif // KNSCORE_COMMENTSMODEL_H
A model which takes care of the comments for a single Entry.
KNewStuff engine.
Definition enginebase.h:51
KNewStuff data entry container.
Definition entry.h:48
DisplayRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.