File indexing completed on 2024-05-19 16:38:21
0001 /* 0002 SPDX-FileCopyrightText: 2015, 2016 Ivan Cukic <ivan.cukic(at)kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef KACTIVITIES_STATS_RESULTMODEL_H 0008 #define KACTIVITIES_STATS_RESULTMODEL_H 0009 0010 // Qt 0011 #include <QAbstractListModel> 0012 #include <QObject> 0013 0014 // Local 0015 #include "query.h" 0016 0017 class QModelIndex; 0018 class QDBusPendingCallWatcher; 0019 0020 class KConfigGroup; 0021 0022 namespace KActivities 0023 { 0024 namespace Stats 0025 { 0026 class ResultModelPrivate; 0027 0028 /** 0029 * @class KActivities::Stats::ResultModel resultmodel.h <KActivities/Stats/ResultModel> 0030 * 0031 * Provides a model which displays the resources matching 0032 * the specified Query. 0033 */ 0034 class KACTIVITIESSTATS_EXPORT ResultModel : public QAbstractListModel 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 ResultModel(Query query, QObject *parent = nullptr); 0040 ResultModel(Query query, const QString &clientId, QObject *parent = nullptr); 0041 ~ResultModel() override; 0042 0043 enum Roles { 0044 ResourceRole = Qt::UserRole, 0045 TitleRole = Qt::UserRole + 1, 0046 ScoreRole = Qt::UserRole + 2, 0047 FirstUpdateRole = Qt::UserRole + 3, 0048 LastUpdateRole = Qt::UserRole + 4, 0049 LinkStatusRole = Qt::UserRole + 5, 0050 LinkedActivitiesRole = Qt::UserRole + 6, 0051 MimeType = Qt::UserRole + 7, // @since 5.77 0052 Agent = Qt::UserRole + 8, // @since 5.112 0053 }; 0054 0055 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0056 QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const override; 0057 QHash<int, QByteArray> roleNames() const override; 0058 0059 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0060 0061 void fetchMore(const QModelIndex &parent) override; 0062 bool canFetchMore(const QModelIndex &parent) const override; 0063 0064 void linkToActivity(const QUrl &resource, 0065 const Terms::Activity &activity = Terms::Activity(QStringList()), 0066 const Terms::Agent &agent = Terms::Agent(QStringList())); 0067 0068 void unlinkFromActivity(const QUrl &resource, 0069 const Terms::Activity &activity = Terms::Activity(QStringList()), 0070 const Terms::Agent &agent = Terms::Agent(QStringList())); 0071 0072 public Q_SLOTS: 0073 /** 0074 * Removes the specified resource from the history 0075 */ 0076 void forgetResource(const QString &resource); 0077 0078 /** 0079 * Removes specified list of resources from the history 0080 */ 0081 void forgetResources(const QList<QString> &resources); 0082 0083 /** 0084 * Removes the specified resource from the history 0085 */ 0086 void forgetResource(int row); 0087 0088 /** 0089 * Clears the history of all resources that match the current 0090 * model query 0091 */ 0092 void forgetAllResources(); 0093 0094 /** 0095 * Moves the resource to the specified position. 0096 * 0097 * Note that this only applies to the linked resources 0098 * since the recently/frequently used ones have 0099 * their natural order. 0100 * 0101 * @note This requires the clientId to be specified on construction. 0102 */ 0103 void setResultPosition(const QString &resource, int position); 0104 0105 /** 0106 * Sort the items by title. 0107 * 0108 * Note that this only affects the linked resources 0109 * since the recently/frequently used ones have 0110 * their natural order. 0111 * 0112 * @note This requires the clientId to be specified on construction. 0113 */ 0114 void sortItems(Qt::SortOrder sortOrder); 0115 0116 private: 0117 friend class ResultModelPrivate; 0118 ResultModelPrivate *const d; 0119 }; 0120 0121 } // namespace Stats 0122 } // namespace KActivities 0123 0124 #endif // KACTIVITIES_STATS_RESULTMODEL_H