// SPDX-FileCopyrightText: 2020 Han Young // SPDX-FileCopyrightText: 2020-2022 Devin Lin // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include #include #include #include #include "weatherlocation.h" class WeatherLocationListModel : public QAbstractListModel { Q_OBJECT QML_ELEMENT QML_SINGLETON Q_PROPERTY(int count READ count NOTIFY locationsChanged) Q_PROPERTY(QList locations READ locations NOTIFY locationsChanged) public: enum Roles { LocationRole = Qt::UserRole }; static WeatherLocationListModel *inst(); static WeatherLocationListModel *create(QQmlEngine *, QJSEngine *); void load(); void saveOrder(); int count() const; int rowCount(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override; QHash roleNames() const override; Q_INVOKABLE void insert(int index, WeatherLocation *weatherLocation); Q_INVOKABLE void remove(int index); Q_INVOKABLE void move(int oldIndex, int newIndex); Q_INVOKABLE void requestCurrentLocation(); // invoked by UI QList &locations(); public Q_SLOTS: void addLocation(const KWeatherCore::LocationQueryResult &ret); Q_SIGNALS: void locationsChanged(); void networkErrorCreating(); // error creating a location void networkErrorCreatingDefault(); // error getting current location void successfullyCreatedDefault(); // successful in getting current location protected: explicit WeatherLocationListModel(QObject *parent = nullptr); private Q_SLOTS: void addCurrentLocation(const KWeatherCore::LocationQueryResult &ret); private: QList m_locations; };