KActivitiesStats 5.109.0
resultset.h
1/*
2 SPDX-FileCopyrightText: 2015, 2016 Ivan Cukic <ivan.cukic(at)kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#ifndef KACTIVITIES_STATS_RESULTSET
8#define KACTIVITIES_STATS_RESULTSET
9
10#include "query.h"
11
12#include <QDebug>
13
14namespace KActivities
15{
16namespace Stats
17{
18class ResultSetPrivate;
19class ResultSet_ResultPrivate;
20class ResultSet_IteratorPrivate;
21
43class KACTIVITIESSTATS_EXPORT ResultSet
44{
45public:
49 class Result
50 {
51 public:
52 Result();
53 ~Result();
54
55 Result(Result &&result);
56 Result(const Result &result);
57 Result &operator=(Result result);
58
59 enum LinkStatus {
60 NotLinked = 0,
61 Unknown = 1,
62 Linked = 2,
63 };
64
65 // TODO: KF6 rething the function names, and maybe their signature, perhaps leverage std::variant or std::optional to add semantics to the API
66 QString resource() const;
67 QUrl url() const;
68 QString title() const;
69 QString mimetype() const;
70 double score() const;
71 uint lastUpdate() const;
72 uint firstUpdate() const;
73 LinkStatus linkStatus() const;
74 QStringList linkedActivities() const;
75
76 void setResource(QString resource);
77 void setTitle(QString title);
78 void setMimetype(QString mimetype);
79 void setScore(double score);
80 void setLastUpdate(uint lastUpdate);
81 void setFirstUpdate(uint firstUpdate);
82 void setLinkStatus(LinkStatus linkedStatus);
83 void setLinkedActivities(QStringList activities);
84
85 private:
86 ResultSet_ResultPrivate *d;
87 };
88
94
99
100 ResultSet(ResultSet &&source);
101 ResultSet(const ResultSet &source);
102 ResultSet &operator=(ResultSet source);
103 ~ResultSet();
104
110 Result at(int index) const;
111
112 // Iterators
113
119 class const_iterator
120 {
121 public:
122 typedef std::random_access_iterator_tag iterator_category;
123 typedef int difference_type;
124
125 typedef const Result value_type;
126 typedef const Result &reference;
127 typedef const Result *pointer;
128
129 const_iterator();
130 const_iterator(const const_iterator &source);
131 const_iterator &operator=(const const_iterator &source);
132
133 ~const_iterator();
134
135 bool isSourceValid() const;
136
137 reference operator*() const;
138 pointer operator->() const;
139
140 // prefix
141 const_iterator &operator++();
142 // postfix
143 const_iterator operator++(int);
144
145 // prefix
146 const_iterator &operator--();
147 // postfix
148 const_iterator operator--(int);
149
150 const_iterator operator+(difference_type n) const;
151 const_iterator &operator+=(difference_type n);
152
153 const_iterator operator-(difference_type n) const;
154 const_iterator &operator-=(difference_type n);
155
156 reference operator[](difference_type n) const;
157
158 KACTIVITIESSTATS_EXPORT friend bool operator==(const const_iterator &left, const const_iterator &right);
159 KACTIVITIESSTATS_EXPORT friend bool operator!=(const const_iterator &left, const const_iterator &right);
160
161 KACTIVITIESSTATS_EXPORT friend bool operator<(const const_iterator &left, const const_iterator &right);
162 KACTIVITIESSTATS_EXPORT friend bool operator>(const const_iterator &left, const const_iterator &right);
163
164 KACTIVITIESSTATS_EXPORT friend bool operator<=(const const_iterator &left, const const_iterator &right);
165 KACTIVITIESSTATS_EXPORT friend bool operator>=(const const_iterator &left, const const_iterator &right);
166
167 KACTIVITIESSTATS_EXPORT friend difference_type operator-(const const_iterator &left, const const_iterator &right);
168
169 private:
170 const_iterator(const ResultSet *resultSet, int currentRow);
171
172 friend class ResultSet;
173
174 ResultSet_IteratorPrivate *const d;
175 };
176
182 const_iterator begin() const;
188 const_iterator end() const;
189
193 inline const_iterator cbegin() const
194 {
195 return begin();
196 }
200 inline const_iterator cend() const
201 {
202 return end();
203 }
204
208 inline const_iterator constBegin() const
209 {
210 return cbegin();
211 }
215 inline const_iterator constEnd() const
216 {
217 return cend();
218 }
219
220private:
221 friend class ResultSet_IteratorPrivate;
222 ResultSetPrivate *d;
223};
224
225bool KACTIVITIESSTATS_EXPORT operator==(const ResultSet::const_iterator &left, const ResultSet::const_iterator &right);
226bool KACTIVITIESSTATS_EXPORT operator!=(const ResultSet::const_iterator &left, const ResultSet::const_iterator &right);
227
228bool KACTIVITIESSTATS_EXPORT operator<(const ResultSet::const_iterator &left, const ResultSet::const_iterator &right);
229bool KACTIVITIESSTATS_EXPORT operator>(const ResultSet::const_iterator &left, const ResultSet::const_iterator &right);
230
231bool KACTIVITIESSTATS_EXPORT operator<=(const ResultSet::const_iterator &left, const ResultSet::const_iterator &right);
232bool KACTIVITIESSTATS_EXPORT operator>=(const ResultSet::const_iterator &left, const ResultSet::const_iterator &right);
233
234ResultSet::const_iterator::difference_type KACTIVITIESSTATS_EXPORT operator-(const ResultSet::const_iterator &left, const ResultSet::const_iterator &right);
235
236inline QDebug operator<<(QDebug out, const ResultSet::Result &result)
237{
238 return out << (result.linkStatus() == ResultSet::Result::Linked ? "⊤"
239 : result.linkStatus() == ResultSet::Result::NotLinked ? "⊥"
240 : "?")
241 << result.score() << (result.title() != result.resource() ? result.title() : QString()) << result.lastUpdate()
242 << QStringView(result.resource()).right(20);
243}
244
245} // namespace Stats
246} // namespace KActivities
247
248#endif // KACTIVITIES_STATS_RESULTSET
The activities system tracks resources (documents, contacts, etc.) that the user has used.
Definition query.h:54
Structure containing data of one of the results.
Definition resultset.h:50
uint lastUpdate() const
Timestamp of the last update.
double score() const
The score calculated based on the usage statistics.
QString mimetype() const
Mimetype of the resource, or URL if title is not known.
QUrl url() const
Url representation of a resource based on internal resource, readonly,.
QString title() const
Title of the resource, or URL if title is not known.
uint firstUpdate() const
Timestamp of the first update.
LinkStatus linkStatus() const
Differentiates between linked and non-linked resources in mixed queries.
QStringList linkedActivities() const
Contains the activities this resource is linked to for the queries that care about resource linking.
QString resource() const
String representation of resource (can represent an url or a path)
Class that can query the KActivities usage tracking mechanism for resources.
Definition resultset.h:44
const_iterator cend() const
Alias for end.
Definition resultset.h:200
Result value_type
ResultSet is a container.
Definition resultset.h:93
Result at(int index) const
const_iterator cbegin() const
Alias for begin.
Definition resultset.h:193
const_iterator end() const
const_iterator constBegin() const
Alias for begin.
Definition resultset.h:208
const_iterator begin() const
ResultSet(Query query)
Creates the ResultSet from the specified query.
const_iterator constEnd() const
Alias for end.
Definition resultset.h:215