Changeset View
Changeset View
Standalone View
Standalone View
lib/resultsmodel.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * This file is part of the KDE Milou Project | ||||
3 | * Copyright (C) 2019 Kai Uwe Broulik <kde@broulik.de> | ||||
4 | * | ||||
5 | * This library is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU Lesser General Public | ||||
7 | * License as published by the Free Software Foundation; either | ||||
8 | * version 2.1 of the License, or (at your option) version 3, or any | ||||
9 | * later version accepted by the membership of KDE e.V. (or its | ||||
10 | * successor approved by the membership of KDE e.V.), which shall | ||||
11 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
12 | * | ||||
13 | * This library is distributed in the hope that it will be useful, | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
16 | * Lesser General Public License for more details. | ||||
17 | * | ||||
18 | * You should have received a copy of the GNU Lesser General Public | ||||
19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
20 | * | ||||
21 | */ | ||||
22 | | ||||
23 | #pragma once | ||||
24 | | ||||
25 | #include <QIcon> | ||||
26 | #include <QSortFilterProxyModel> | ||||
27 | #include <QScopedPointer> | ||||
28 | | ||||
29 | #include "milou_export.h" | ||||
30 | | ||||
31 | namespace Milou { | ||||
32 | | ||||
33 | class MILOU_EXPORT ResultsModel : public QSortFilterProxyModel | ||||
34 | { | ||||
35 | Q_OBJECT | ||||
36 | | ||||
37 | /** | ||||
38 | * The query string to run | ||||
39 | */ | ||||
40 | Q_PROPERTY(QString queryString READ queryString WRITE setQueryString NOTIFY queryStringChanged) | ||||
41 | /** | ||||
42 | * The preferred maximum number of matches in the model | ||||
43 | * | ||||
44 | * If there are lots of results from different catergories, | ||||
45 | * the limit can be slightly exceeded. | ||||
46 | * | ||||
47 | * Default is 0, which means no limit. | ||||
48 | */ | ||||
49 | Q_PROPERTY(int limit READ limit WRITE setLimit RESET resetLimit NOTIFY limitChanged) | ||||
50 | /** | ||||
51 | * Whether the query is currently being run | ||||
52 | * | ||||
53 | * This can be used to show a busy indicator | ||||
54 | */ | ||||
55 | Q_PROPERTY(bool querying READ querying NOTIFY queryingChanged) | ||||
56 | | ||||
57 | /** | ||||
58 | * The single runner to use for querying in single runner mode | ||||
59 | * | ||||
60 | * Defaults to empty string which means all runners | ||||
61 | */ | ||||
62 | Q_PROPERTY(QString runner READ runner WRITE setRunner NOTIFY runnerChanged) | ||||
63 | // FIXME rename to singleModeRunnerName or something | ||||
64 | Q_PROPERTY(QString runnerName READ runnerName NOTIFY runnerChanged) | ||||
65 | Q_PROPERTY(QIcon runnerIcon READ runnerIcon NOTIFY runnerChanged) | ||||
66 | | ||||
67 | public: | ||||
68 | explicit ResultsModel(QObject *parent = nullptr); | ||||
69 | ~ResultsModel() override; | ||||
70 | | ||||
71 | enum Roles { | ||||
72 | IdRole = Qt::UserRole + 1, | ||||
73 | TypeRole, | ||||
74 | RelevanceRole, | ||||
75 | EnabledRole, | ||||
76 | CategoryRole, | ||||
77 | SubtextRole, | ||||
78 | DuplicateRole, | ||||
79 | ActionsRole | ||||
80 | }; | ||||
81 | Q_ENUM(Roles) | ||||
82 | | ||||
83 | QString queryString() const; | ||||
84 | void setQueryString(const QString &queryString); | ||||
85 | Q_SIGNAL void queryStringChanged(); | ||||
86 | | ||||
87 | int limit() const; | ||||
88 | void setLimit(int limit); | ||||
89 | void resetLimit(); | ||||
90 | Q_SIGNAL void limitChanged(); | ||||
91 | | ||||
92 | bool querying() const; | ||||
93 | Q_SIGNAL void queryingChanged(); | ||||
94 | | ||||
95 | QString runner() const; | ||||
96 | void setRunner(const QString &runner); | ||||
97 | Q_SIGNAL void runnerChanged(); | ||||
98 | | ||||
99 | QString runnerName() const; | ||||
100 | QIcon runnerIcon() const; | ||||
101 | | ||||
102 | QHash<int, QByteArray> roleNames() const override; | ||||
103 | | ||||
104 | /** | ||||
105 | * Clears the model content and resets the runner context, i.e. no new items will appear. | ||||
106 | */ | ||||
107 | Q_INVOKABLE void clear(); | ||||
108 | | ||||
109 | /** | ||||
110 | * Run the result at the given model index @p idx | ||||
111 | */ | ||||
112 | Q_INVOKABLE bool run(const QModelIndex &idx); | ||||
113 | /** | ||||
114 | * Run the action @p actionNumber at given model index @p idx | ||||
115 | */ | ||||
116 | Q_INVOKABLE bool runAction(const QModelIndex &idx, int actionNumber); | ||||
117 | | ||||
118 | /** | ||||
119 | * Get mime data for the result at given model index @p idx | ||||
120 | */ | ||||
121 | Q_INVOKABLE QMimeData *getMimeData(const QModelIndex &idx) const; | ||||
122 | | ||||
123 | Q_SIGNALS: | ||||
124 | /** | ||||
125 | * This signal is emitted when a an InformationalMatch is run, and it is advised | ||||
126 | * to update the search term, e.g. used for calculator runner results | ||||
127 | */ | ||||
128 | void queryStringChangeRequested(const QString &queryString, int pos); | ||||
129 | | ||||
130 | private: | ||||
131 | class Private; | ||||
132 | QScopedPointer<Private> d; | ||||
133 | | ||||
134 | }; | ||||
135 | | ||||
136 | } // namespace Milou |