Warning, file /plasma/kdeplasma-addons/applets/weather/plugin/locationlistmodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Friedrich W. H. Kossebau <kossebau@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef LOCATIONLISTMODEL_H 0008 #define LOCATIONLISTMODEL_H 0009 0010 #include <Plasma/DataEngine> 0011 #include <Plasma/DataEngineConsumer> 0012 0013 #include <QAbstractListModel> 0014 #include <QMap> 0015 #include <QVector> 0016 0017 class WeatherValidator : public QObject 0018 { 0019 Q_OBJECT 0020 public: 0021 WeatherValidator(Plasma::DataEngine *weatherDataengine, const QString &ionName, QObject *parent = nullptr); 0022 ~WeatherValidator() override; 0023 0024 /** 0025 * @param location the name of the location to find 0026 */ 0027 void validate(const QString &location); 0028 0029 Q_SIGNALS: 0030 /** 0031 * Emitted when an error in validation occurs 0032 **/ 0033 void error(const QString &message); 0034 0035 /** 0036 * Emitted when validation is done 0037 * @param sources a mapping of user-friendly names to the DataEngine source 0038 **/ 0039 void finished(const QMap<QString, QString> &sources); 0040 0041 public Q_SLOTS: // callback for the weather dataengine 0042 void dataUpdated(const QString &source, const Plasma::DataEngine::Data &data); 0043 0044 private: 0045 Plasma::DataEngine *m_weatherDataEngine; 0046 QString m_ionName; 0047 }; 0048 0049 class LocationItem 0050 { 0051 public: 0052 LocationItem() 0053 { 0054 } 0055 LocationItem(const QString &_weatherStation, const QString &_weatherService, const QString &_value) 0056 : weatherStation(_weatherStation) 0057 , weatherService(_weatherService) 0058 , value(_value) 0059 { 0060 } 0061 0062 QString weatherStation; 0063 QString weatherService; 0064 QString value; 0065 }; 0066 0067 Q_DECLARE_METATYPE(LocationItem) 0068 Q_DECLARE_TYPEINFO(LocationItem, Q_MOVABLE_TYPE); 0069 0070 class LocationListModel : public QAbstractListModel, public Plasma::DataEngineConsumer 0071 { 0072 Q_OBJECT 0073 Q_PROPERTY(bool validatingInput READ isValidatingInput NOTIFY validatingInputChanged) 0074 0075 public: 0076 explicit LocationListModel(QObject *parent = nullptr); 0077 0078 public: // QAbstractListModel API 0079 QVariant data(const QModelIndex &index, int role) const override; 0080 int rowCount(const QModelIndex &index) const override; 0081 0082 public: 0083 bool isValidatingInput() const; 0084 0085 public: 0086 Q_INVOKABLE QString nameForListIndex(int listIndex) const; 0087 Q_INVOKABLE QString valueForListIndex(int listIndex) const; 0088 Q_INVOKABLE void searchLocations(const QString &searchString, const QStringList &services); 0089 Q_INVOKABLE void clear(); 0090 0091 Q_SIGNALS: 0092 void validatingInputChanged(bool validatingInput); 0093 void locationSearchDone(bool success, const QString &searchString); 0094 0095 private: 0096 void addSources(const QMap<QString, QString> &sources); 0097 void validatorError(const QString &error); 0098 void completeSearch(); 0099 0100 private: 0101 QVector<LocationItem> m_locations; 0102 0103 bool m_validatingInput; 0104 QString m_searchString; 0105 int m_checkedInCount; 0106 QVector<WeatherValidator *> m_validators; 0107 0108 QMap<QString, QString> m_serviceCodeToDisplayName; 0109 }; 0110 0111 #endif // LOCATIONLISTMODEL_H