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