File indexing completed on 2024-12-22 05:15:22
0001 /* 0002 SPDX-FileCopyrightText: 2012 Aurélien Gâteau <agateau@kde.org> 0003 SPDX-FileCopyrightText: 2014 Eike Hein <hein@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "abstractmodel.h" 0011 0012 #include <KRunner/QueryMatch> 0013 #include <KRunner/ResultsModel> 0014 #include <PlasmaActivities/Consumer> 0015 #include <optional> 0016 0017 namespace KRunner 0018 { 0019 class RunnerManager; 0020 } 0021 0022 class AbstractModel; 0023 0024 class RunnerMatchesModel : public KRunner::ResultsModel 0025 { 0026 Q_OBJECT 0027 0028 Q_PROPERTY(QString name READ name CONSTANT) 0029 Q_PROPERTY(int count READ count NOTIFY countChanged) 0030 Q_PROPERTY(QString description READ description CONSTANT) 0031 0032 Q_PROPERTY(AbstractModel *favoritesModel READ favoritesModel NOTIFY favoritesModelChanged) 0033 0034 public: 0035 explicit RunnerMatchesModel(const QString &runnerId, const std::optional<QString> &name, QObject *parent = nullptr); 0036 0037 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0038 0039 Q_INVOKABLE bool trigger(int row, const QString &actionId, const QVariant &argument); 0040 0041 QString name() const 0042 { 0043 return m_name; 0044 } 0045 QString description() const 0046 { 0047 return name(); 0048 } 0049 0050 AbstractModel *favoritesModel() const; 0051 void setFavoritesModel(AbstractModel *model); 0052 Q_SIGNAL void favoritesModelChanged(); 0053 0054 Q_SIGNAL void countChanged(); 0055 int count() const 0056 { 0057 return rowCount(); 0058 } 0059 0060 void setMatches(const QList<KRunner::QueryMatch> &matches); 0061 0062 QHash<int, QByteArray> roleNames() const override 0063 { 0064 return AbstractModel::staticRoleNames(); 0065 } 0066 0067 Q_SIGNAL void requestUpdateQueryString(const QString &term); 0068 0069 private: 0070 AbstractModel *m_favoritesModel = nullptr; 0071 const QString m_runnerId; 0072 QString m_name; 0073 KActivities::Consumer m_consumer; 0074 };