1/*
2 * This file is part of the KDE Milou Project
3 * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@broulik.de>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 *
7 */
8
9#pragma once
10
11#include <KConfigGroup>
12#include <QAbstractItemModel>
13#include <QHash>
14#include <QString>
15
16#include <KRunner/QueryMatch>
17
18namespace KRunner
19{
20class RunnerManager;
21}
22
23namespace KRunner
24{
25class RunnerResultsModel : public QAbstractItemModel
26{
27 Q_OBJECT
28
29public:
30 explicit RunnerResultsModel(const KConfigGroup &configGroup, const KConfigGroup &stateConfigGroup, QObject *parent = nullptr);
31
32 QString queryString() const;
33 void setQueryString(const QString &queryString, const QString &runner);
34 Q_SIGNAL void queryStringChanged(const QString &queryString);
35
36 bool querying() const;
37 Q_SIGNAL void queryingChanged();
38
39 /**
40 * Clears the model content and resets the runner context, i.e. no new items will appear.
41 */
42 void clear();
43
44 bool run(const QModelIndex &idx);
45 bool runAction(const QModelIndex &idx, int actionNumber);
46
47 int columnCount(const QModelIndex &parent) const override;
48 int rowCount(const QModelIndex &parent) const override;
49
50 QVariant data(const QModelIndex &index, int role) const override;
51
52 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
53 QModelIndex parent(const QModelIndex &child) const override;
54
55 KRunner::RunnerManager *runnerManager() const;
56 KRunner::QueryMatch fetchMatch(const QModelIndex &idx) const;
57
58 QStringList m_favoriteIds;
59Q_SIGNALS:
60 void queryStringChangeRequested(const QString &queryString, int pos);
61
62 void matchesChanged();
63
64private:
65 void setQuerying(bool querying);
66
67 void onMatchesChanged(const QList<KRunner::QueryMatch> &matches);
68
69 KRunner::RunnerManager *m_manager;
70
71 QString m_queryString;
72 bool m_querying = false;
73
74 QString m_prevRunner;
75
76 bool m_hasMatches = false;
77
78 QStringList m_categories;
79 QHash<QString /*category*/, QList<KRunner::QueryMatch>> m_matches;
80};
81
82} // namespace Milou
83

source code of krunner/src/model/runnerresultsmodel_p.h