| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2014 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef BALOO_QUERYRESULTSMODEL_H |
| 8 | #define BALOO_QUERYRESULTSMODEL_H |
| 9 | |
| 10 | #include <QAbstractListModel> |
| 11 | #include <QString> |
| 12 | #include <qqmlregistration.h> |
| 13 | |
| 14 | class Query : public QObject |
| 15 | { |
| 16 | Q_OBJECT |
| 17 | QML_ELEMENT |
| 18 | Q_PROPERTY(QString searchString READ searchString WRITE setSearchString NOTIFY searchStringChanged) |
| 19 | Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged) |
| 20 | |
| 21 | public: |
| 22 | explicit Query(QObject *parent = nullptr); |
| 23 | ~Query(); |
| 24 | |
| 25 | void setSearchString(const QString &searchString); |
| 26 | QString searchString() const; |
| 27 | |
| 28 | void setLimit(const int &limit); |
| 29 | int limit() const; |
| 30 | |
| 31 | Q_SIGNALS: |
| 32 | void searchStringChanged(); |
| 33 | void limitChanged(); |
| 34 | |
| 35 | private: |
| 36 | QString m_searchString; |
| 37 | int m_limit; |
| 38 | |
| 39 | }; |
| 40 | |
| 41 | class QueryResultsModel : public QAbstractListModel |
| 42 | { |
| 43 | Q_OBJECT |
| 44 | QML_ELEMENT |
| 45 | Q_PROPERTY(Query* query READ query WRITE setQuery NOTIFY queryChanged) |
| 46 | |
| 47 | public: |
| 48 | explicit QueryResultsModel(QObject *parent = nullptr); |
| 49 | ~QueryResultsModel(); |
| 50 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 51 | |
| 52 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 53 | |
| 54 | QHash<int, QByteArray> roleNames() const override; |
| 55 | |
| 56 | enum Roles { |
| 57 | UrlRole = Qt::UserRole + 1, |
| 58 | }; |
| 59 | |
| 60 | void setQuery(Query *query); |
| 61 | Query* query() const; |
| 62 | |
| 63 | Q_SIGNALS: |
| 64 | void queryChanged(); |
| 65 | |
| 66 | private Q_SLOTS: |
| 67 | void populateModel(); |
| 68 | |
| 69 | private: |
| 70 | QStringList m_balooEntryList; |
| 71 | Query *m_query; |
| 72 | }; |
| 73 | |
| 74 | #endif |
| 75 | |