| 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 |
| 9 | |
| 10 | #include "quickitemsmodel.h" |
| 11 | |
| 12 | #include <entry.h> |
| 13 | |
| 14 | #include <QQmlParserStatus> |
| 15 | #include <QSortFilterProxyModel> |
| 16 | |
| 17 | #include <memory> |
| 18 | |
| 19 | namespace KNewStuffQuick |
| 20 | { |
| 21 | class ; |
| 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 | */ |
| 30 | class : 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) |
| 48 | public: |
| 49 | /** |
| 50 | * The options which can be set for which comments to include |
| 51 | * @since 5.65 |
| 52 | */ |
| 53 | enum { |
| 54 | = 0, //< All comments should be included |
| 55 | = 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 (QObject *parent = nullptr); |
| 61 | () override; |
| 62 | void () override; |
| 63 | void () override; |
| 64 | |
| 65 | ItemsModel *() const; |
| 66 | void (ItemsModel *newItemsModel); |
| 67 | Q_SIGNAL void (); |
| 68 | |
| 69 | KNSCore::Entry () const; |
| 70 | void (const KNSCore::Entry &entry); |
| 71 | Q_SIGNAL void (); |
| 72 | |
| 73 | /** |
| 74 | * Which comments should be included |
| 75 | * @since 5.65 |
| 76 | */ |
| 77 | CommentsModel::IncludedComments () const; |
| 78 | /** |
| 79 | * Set which comments should be included |
| 80 | * @since 5.65 |
| 81 | */ |
| 82 | void (CommentsModel::IncludedComments ); |
| 83 | /** |
| 84 | * Fired when the value of includedComments changes |
| 85 | * @since 5.65 |
| 86 | */ |
| 87 | Q_SIGNAL void (); |
| 88 | |
| 89 | bool (int sourceRow, const QModelIndex &sourceParent) const override; |
| 90 | |
| 91 | private: |
| 92 | const std::unique_ptr<CommentsModelPrivate> ; |
| 93 | }; |
| 94 | } |
| 95 | |
| 96 | #endif // KNSQUICK_COMMENTSMODEL_H |
| 97 | |