File indexing completed on 2026-07-12 13:30:34
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Han Young <hanyoung@protonmail.com> 0003 * SPDX-FileCopyrightText: 2020 Devin Lin <espidev@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QAbstractListModel> 0011 #include <QObject> 0012 0013 #include <KWeatherCore/LocationQuery> 0014 0015 class QTimer; 0016 class LocationQueryModel : public QAbstractListModel 0017 { 0018 Q_OBJECT 0019 Q_PROPERTY(bool loading READ loading NOTIFY propertyChanged) 0020 Q_PROPERTY(bool networkError READ networkError NOTIFY propertyChanged) 0021 0022 public: 0023 explicit LocationQueryModel(); 0024 enum Roles { 0025 NameRole = Qt::DisplayRole, 0026 }; 0027 0028 int rowCount(const QModelIndex &parent) const override; 0029 QVariant data(const QModelIndex &index, int role) const override; 0030 QHash<int, QByteArray> roleNames() const override; 0031 Q_INVOKABLE bool loading() const; 0032 Q_INVOKABLE bool networkError() const; 0033 Q_INVOKABLE void textChanged(QString query, int timeout = 2000); 0034 Q_INVOKABLE void addLocation(int index); 0035 Q_INVOKABLE KWeatherCore::LocationQueryResult get(int index); 0036 Q_INVOKABLE void clearResults(); 0037 void setQuery(); 0038 Q_SIGNALS: 0039 void propertyChanged(); 0040 void appendLocation(const KWeatherCore::LocationQueryResult &result); 0041 private Q_SLOTS: 0042 void handleQueryResults(const std::vector<KWeatherCore::LocationQueryResult> &results); 0043 0044 private: 0045 bool m_loading = false, m_networkError = false; 0046 std::vector<KWeatherCore::LocationQueryResult> m_results; 0047 KWeatherCore::LocationQuery m_querySource; 0048 QTimer *inputTimer = nullptr; 0049 QString m_text; 0050 };