Warning, file /frameworks/kactivities-stats/src/resultmodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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     };
0053 
0054     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0055     QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const override;
0056     QHash<int, QByteArray> roleNames() const override;
0057 
0058     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0059 
0060     void fetchMore(const QModelIndex &parent) override;
0061     bool canFetchMore(const QModelIndex &parent) const override;
0062 
0063     void linkToActivity(const QUrl &resource,
0064                         const Terms::Activity &activity = Terms::Activity(QStringList()),
0065                         const Terms::Agent &agent = Terms::Agent(QStringList()));
0066 
0067     void unlinkFromActivity(const QUrl &resource,
0068                             const Terms::Activity &activity = Terms::Activity(QStringList()),
0069                             const Terms::Agent &agent = Terms::Agent(QStringList()));
0070 
0071 public Q_SLOTS:
0072     /**
0073      * Removes the specified resource from the history
0074      */
0075     void forgetResource(const QString &resource);
0076 
0077     /**
0078      * Removes specified list of resources from the history
0079      */
0080     void forgetResources(const QList<QString> &resources);
0081 
0082     /**
0083      * Removes the specified resource from the history
0084      */
0085     void forgetResource(int row);
0086 
0087     /**
0088      * Clears the history of all resources that match the current
0089      * model query
0090      */
0091     void forgetAllResources();
0092 
0093     /**
0094      * Moves the resource to the specified position.
0095      *
0096      * Note that this only applies to the linked resources
0097      * since the recently/frequently used ones have
0098      * their natural order.
0099      *
0100      * @note This requires the clientId to be specified on construction.
0101      */
0102     void setResultPosition(const QString &resource, int position);
0103 
0104     /**
0105      * Sort the items by title.
0106      *
0107      * Note that this only affects the linked resources
0108      * since the recently/frequently used ones have
0109      * their natural order.
0110      *
0111      * @note This requires the clientId to be specified on construction.
0112      */
0113     void sortItems(Qt::SortOrder sortOrder);
0114 
0115 private:
0116     friend class ResultModelPrivate;
0117     ResultModelPrivate *const d;
0118 };
0119 
0120 } // namespace Stats
0121 } // namespace KActivities
0122 
0123 #endif // KACTIVITIES_STATS_RESULTMODEL_H