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 | #include "commentsmodel.h" |
8 | |
9 | #include "quickitemsmodel.h" |
10 | |
11 | #include "core/commentsmodel.h" |
12 | |
13 | namespace KNewStuffQuick |
14 | { |
15 | class |
16 | { |
17 | public: |
18 | (CommentsModel *qq) |
19 | : q(qq) |
20 | { |
21 | } |
22 | CommentsModel *; |
23 | ItemsModel *{nullptr}; |
24 | KNSCore::Entry ; |
25 | bool {false}; |
26 | CommentsModel::IncludedComments {CommentsModel::IncludeAllComments}; |
27 | |
28 | QSharedPointer<KNSCore::Provider> ; |
29 | void () |
30 | { |
31 | if (componentCompleted && itemsModel) { |
32 | q->setSourceModel(qobject_cast<QAbstractListModel *>( |
33 | object: itemsModel->data(index: itemsModel->index(row: itemsModel->indexOfEntry(e: entry)), role: ItemsModel::CommentsModelRole).value<QObject *>())); |
34 | } |
35 | } |
36 | |
37 | bool (const QModelIndex &index, bool checkParents = false) |
38 | { |
39 | bool result{false}; |
40 | if (q->sourceModel()) { |
41 | if (q->sourceModel()->data(index, role: KNSCore::CommentsModel::ScoreRole).toInt() > 0) { |
42 | result = true; |
43 | } |
44 | if (result == false && checkParents) { |
45 | QModelIndex parentIndex = q->sourceModel()->index(row: q->sourceModel()->data(index, role: KNSCore::CommentsModel::ParentIndexRole).toInt(), column: 0); |
46 | if (parentIndex.isValid()) { |
47 | result = hasReview(index: parentIndex, checkParents: true); |
48 | } |
49 | } |
50 | } |
51 | return result; |
52 | } |
53 | }; |
54 | } |
55 | |
56 | using namespace KNewStuffQuick; |
57 | |
58 | CommentsModel::(QObject *parent) |
59 | : QSortFilterProxyModel(parent) |
60 | , d(new CommentsModelPrivate(this)) |
61 | { |
62 | } |
63 | |
64 | CommentsModel::() = default; |
65 | |
66 | void KNewStuffQuick::CommentsModel::() |
67 | { |
68 | } |
69 | |
70 | void KNewStuffQuick::CommentsModel::() |
71 | { |
72 | d->componentCompleted = true; |
73 | d->resetConnections(); |
74 | } |
75 | |
76 | QObject *CommentsModel::() const |
77 | { |
78 | return d->itemsModel; |
79 | } |
80 | |
81 | void CommentsModel::(QObject *newItemsModel) |
82 | { |
83 | if (d->itemsModel != newItemsModel) { |
84 | d->itemsModel = qobject_cast<ItemsModel *>(object: newItemsModel); |
85 | d->resetConnections(); |
86 | Q_EMIT itemsModelChanged(); |
87 | } |
88 | } |
89 | |
90 | KNSCore::Entry CommentsModel::() const |
91 | { |
92 | return d->entry; |
93 | } |
94 | |
95 | void CommentsModel::(const KNSCore::Entry &entry) |
96 | { |
97 | d->entry = entry; |
98 | d->resetConnections(); |
99 | Q_EMIT entryChanged(); |
100 | } |
101 | |
102 | CommentsModel::IncludedComments KNewStuffQuick::CommentsModel::() const |
103 | { |
104 | return d->includedComments; |
105 | } |
106 | |
107 | void KNewStuffQuick::CommentsModel::(CommentsModel::IncludedComments ) |
108 | { |
109 | if (d->includedComments != includedComments) { |
110 | d->includedComments = includedComments; |
111 | invalidateFilter(); |
112 | Q_EMIT includedCommentsChanged(); |
113 | } |
114 | } |
115 | |
116 | bool KNewStuffQuick::CommentsModel::(int sourceRow, const QModelIndex &sourceParent) const |
117 | { |
118 | bool result{false}; |
119 | switch (d->includedComments) { |
120 | case IncludeOnlyReviews: |
121 | result = d->hasReview(index: sourceModel()->index(row: sourceRow, column: 0, parent: sourceParent)); |
122 | break; |
123 | case IncludeReviewsAndReplies: |
124 | result = d->hasReview(index: sourceModel()->index(row: sourceRow, column: 0, parent: sourceParent), checkParents: true); |
125 | break; |
126 | case IncludeAllComments: |
127 | default: |
128 | result = true; |
129 | break; |
130 | } |
131 | return result; |
132 | } |
133 | |
134 | #include "moc_commentsmodel.cpp" |
135 | |