File indexing completed on 2024-03-24 03:59:15
0001 /* 0002 SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef KNSQUICK_COMMENTSMODEL_H 0008 #define KNSQUICK_COMMENTSMODEL_H 0009 0010 #include <QQmlParserStatus> 0011 #include <QSortFilterProxyModel> 0012 #include <entry.h> 0013 0014 #include <memory> 0015 0016 namespace KNewStuffQuick 0017 { 0018 class CommentsModelPrivate; 0019 /** 0020 * @short Encapsulates a KNSCore::CommentsModel for use in Qt Quick 0021 * 0022 * This class takes care of initialisation of a KNSCore::CommentsModel when assigned an engine, 0023 * providerId and entryId. If the data is not yet cached, it will be requested from the provider, 0024 * and updated for display 0025 * @since 5.63 0026 */ 0027 class CommentsModel : public QSortFilterProxyModel, public QQmlParserStatus 0028 { 0029 Q_OBJECT 0030 Q_INTERFACES(QQmlParserStatus) 0031 /** 0032 * The KNewStufQuick::ItemsModel to interact with servers through 0033 */ 0034 Q_PROPERTY(QObject *itemsModel READ itemsModel WRITE setItemsModel NOTIFY itemsModelChanged) 0035 /** 0036 * The index in the model of the entry to fetch comments for 0037 */ 0038 Q_PROPERTY(KNSCore::Entry entry READ entry WRITE setEntry NOTIFY entryChanged) 0039 /** 0040 * Which types of comments should be included 0041 * @default AllComments 0042 * @since 5.65 0043 */ 0044 Q_PROPERTY(KNewStuffQuick::CommentsModel::IncludedComments includedComments READ includedComments WRITE setIncludedComments NOTIFY includedCommentsChanged) 0045 public: 0046 /** 0047 * The options which can be set for which comments to include 0048 * @since 5.65 0049 */ 0050 enum IncludedComments { 0051 IncludeAllComments = 0, //< All comments should be included 0052 IncludeOnlyReviews = 1, //< Only comments which have a rating (and thus is considered a review) should be included 0053 IncludeReviewsAndReplies = 2, //< Reviews (as OnlyReviews), except child comments are also included 0054 }; 0055 Q_ENUM(IncludedComments) 0056 0057 explicit CommentsModel(QObject *parent = nullptr); 0058 ~CommentsModel() override; 0059 void classBegin() override; 0060 void componentComplete() override; 0061 0062 QObject *itemsModel() const; 0063 void setItemsModel(QObject *newItemsModel); 0064 Q_SIGNAL void itemsModelChanged(); 0065 0066 KNSCore::Entry entry() const; 0067 void setEntry(const KNSCore::Entry &entry); 0068 Q_SIGNAL void entryChanged(); 0069 0070 /** 0071 * Which comments should be included 0072 * @since 5.65 0073 */ 0074 CommentsModel::IncludedComments includedComments() const; 0075 /** 0076 * Set which comments should be included 0077 * @since 5.65 0078 */ 0079 void setIncludedComments(CommentsModel::IncludedComments includedComments); 0080 /** 0081 * Fired when the value of includedComments changes 0082 * @since 5.65 0083 */ 0084 Q_SIGNAL void includedCommentsChanged(); 0085 0086 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; 0087 0088 private: 0089 const std::unique_ptr<CommentsModelPrivate> d; 0090 }; 0091 } 0092 0093 #endif // KNSQUICK_COMMENTSMODEL_H