PlasmaActivitiesStats

resultmodel.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_RESULTMODEL_H
8#define KACTIVITIES_STATS_RESULTMODEL_H
9
10// Qt
11#include <QAbstractListModel>
12#include <QObject>
13
14// Local
15#include "query.h"
16
17class QModelIndex;
19
20class KConfigGroup;
21
22namespace KActivities
23{
24namespace Stats
25{
26class ResultModelPrivate;
27
28/**
29 * @class KActivities::Stats::ResultModel resultmodel.h <KActivities/Stats/ResultModel>
30 *
31 * Provides a model which displays the resources matching
32 * the specified Query.
33 */
34class PLASMAACTIVITIESSTATS_EXPORT ResultModel : public QAbstractListModel
35{
37
38public:
39 ResultModel(Query query, QObject *parent = nullptr);
40 ResultModel(Query query, const QString &clientId, QObject *parent = nullptr);
41 ~ResultModel() override;
42
43 enum Roles {
44 ResourceRole = Qt::UserRole,
45 TitleRole = Qt::UserRole + 1,
46 ScoreRole = Qt::UserRole + 2,
47 FirstUpdateRole = Qt::UserRole + 3,
48 LastUpdateRole = Qt::UserRole + 4,
49 LinkStatusRole = Qt::UserRole + 5,
50 LinkedActivitiesRole = Qt::UserRole + 6,
51 MimeType = Qt::UserRole + 7, // @since 5.77
52 Agent = Qt::UserRole + 8, // @since 6.0
53 };
54
55 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
56 QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const override;
57 QHash<int, QByteArray> roleNames() const override;
58
59 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
60
61 void fetchMore(const QModelIndex &parent) override;
62 bool canFetchMore(const QModelIndex &parent) const override;
63
64 void linkToActivity(const QUrl &resource,
65 const Terms::Activity &activity = Terms::Activity(QStringList()),
66 const Terms::Agent &agent = Terms::Agent(QStringList()));
67
68 void unlinkFromActivity(const QUrl &resource,
69 const Terms::Activity &activity = Terms::Activity(QStringList()),
70 const Terms::Agent &agent = Terms::Agent(QStringList()));
71
72public Q_SLOTS:
73 /**
74 * Removes the specified resource from the history
75 */
76 void forgetResource(const QString &resource);
77
78 /**
79 * Removes specified list of resources from the history
80 */
81 void forgetResources(const QList<QString> &resources);
82
83 /**
84 * Removes the specified resource from the history
85 */
86 void forgetResource(int row);
87
88 /**
89 * Clears the history of all resources that match the current
90 * model query
91 */
92 void forgetAllResources();
93
94 /**
95 * Moves the resource to the specified position.
96 *
97 * Note that this only applies to the linked resources
98 * since the recently/frequently used ones have
99 * their natural order.
100 *
101 * @note This requires the clientId to be specified on construction.
102 */
103 void setResultPosition(const QString &resource, int position);
104
105 /**
106 * Sort the items by title.
107 *
108 * Note that this only affects the linked resources
109 * since the recently/frequently used ones have
110 * their natural order.
111 *
112 * @note This requires the clientId to be specified on construction.
113 */
114 void sortItems(Qt::SortOrder sortOrder);
115
116private:
117 friend class ResultModelPrivate;
118 ResultModelPrivate *const d;
119};
120
121} // namespace Stats
122} // namespace KActivities
123
124#endif // KACTIVITIES_STATS_RESULTMODEL_H
The activities system tracks resources (documents, contacts, etc.) that the user has used.
Definition query.h:54
void sortItems(Qt::SortOrder sortOrder)
Sort the items by title.
void forgetResource(const QString &resource)
Removes the specified resource from the history.
void setResultPosition(const QString &resource, int position)
Moves the resource to the specified position.
void forgetResources(const QList< QString > &resources)
Removes specified list of resources from the history.
void forgetAllResources()
Clears the history of all resources that match the current model query.
virtual QModelIndex parent(const QModelIndex &index) const const=0
QAbstractListModel(QObject *parent)
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
UserRole
Orientation
SortOrder
Term to filter the resources according the activity in which they were accessed.
Definition terms.h:139
Term to filter the resources according the agent (application) which accessed it.
Definition terms.h:106
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 12:01:02 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.