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

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