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 KNSQUICK_COMMENTSMODEL_H
8#define KNSQUICK_COMMENTSMODEL_H
9
10#include <QQmlParserStatus>
11#include <QSortFilterProxyModel>
12#include <entry.h>
13
14#include <memory>
15
16namespace KNewStuffQuick
17{
18class CommentsModelPrivate;
19/**
20 * @short Encapsulates a KNSCore::CommentsModel for use in Qt Quick
21 *
22 * This class takes care of initialisation of a KNSCore::CommentsModel when assigned an engine,
23 * providerId and entryId. If the data is not yet cached, it will be requested from the provider,
24 * and updated for display
25 * @since 5.63
26 */
27class CommentsModel : public QSortFilterProxyModel, public QQmlParserStatus
28{
29 Q_OBJECT
30 Q_INTERFACES(QQmlParserStatus)
31 /**
32 * The KNewStufQuick::ItemsModel to interact with servers through
33 */
34 Q_PROPERTY(QObject *itemsModel READ itemsModel WRITE setItemsModel NOTIFY itemsModelChanged)
35 /**
36 * The index in the model of the entry to fetch comments for
37 */
38 Q_PROPERTY(KNSCore::Entry entry READ entry WRITE setEntry NOTIFY entryChanged)
39 /**
40 * Which types of comments should be included
41 * @default AllComments
42 * @since 5.65
43 */
44 Q_PROPERTY(KNewStuffQuick::CommentsModel::IncludedComments includedComments READ includedComments WRITE setIncludedComments NOTIFY includedCommentsChanged)
45public:
46 /**
47 * The options which can be set for which comments to include
48 * @since 5.65
49 */
50 enum IncludedComments {
51 IncludeAllComments = 0, //< All comments should be included
52 IncludeOnlyReviews = 1, //< Only comments which have a rating (and thus is considered a review) should be included
53 IncludeReviewsAndReplies = 2, //< Reviews (as OnlyReviews), except child comments are also included
54 };
55 Q_ENUM(IncludedComments)
56
57 explicit CommentsModel(QObject *parent = nullptr);
58 ~CommentsModel() override;
59 void classBegin() override;
60 void componentComplete() override;
61
62 QObject *itemsModel() const;
63 void setItemsModel(QObject *newItemsModel);
64 Q_SIGNAL void itemsModelChanged();
65
66 KNSCore::Entry entry() const;
67 void setEntry(const KNSCore::Entry &entry);
68 Q_SIGNAL void entryChanged();
69
70 /**
71 * Which comments should be included
72 * @since 5.65
73 */
74 CommentsModel::IncludedComments includedComments() const;
75 /**
76 * Set which comments should be included
77 * @since 5.65
78 */
79 void setIncludedComments(CommentsModel::IncludedComments includedComments);
80 /**
81 * Fired when the value of includedComments changes
82 * @since 5.65
83 */
84 Q_SIGNAL void includedCommentsChanged();
85
86 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
87
88private:
89 const std::unique_ptr<CommentsModelPrivate> d;
90};
91}
92
93#endif // KNSQUICK_COMMENTSMODEL_H
94

source code of knewstuff/src/qtquick/commentsmodel.h