File indexing completed on 2024-05-19 05:29:58
0001 /* 0002 * SPDX-FileCopyrightText: 2015 David Edmundson <david@davidedmundson.co.uk> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 * 0006 */ 0007 0008 #ifndef STATISTICSPROVIDER_H 0009 #define STATISTICSPROVIDER_H 0010 0011 #include <QObject> 0012 #include <QPointF> 0013 #include <QQmlParserStatus> 0014 0015 struct HistoryReply { 0016 public: 0017 uint time = 0; 0018 double value = 0.0; 0019 uint charging = 0; 0020 }; 0021 0022 Q_DECLARE_METATYPE(HistoryReply) 0023 0024 class StatisticsProvider : public QObject, public QQmlParserStatus 0025 { 0026 Q_OBJECT 0027 Q_INTERFACES(QQmlParserStatus) 0028 0029 Q_PROPERTY(QString device MEMBER m_device WRITE setDevice NOTIFY deviceChanged) 0030 Q_PROPERTY(uint duration MEMBER m_duration WRITE setDuration NOTIFY durationChanged) 0031 Q_PROPERTY(HistoryType type MEMBER m_type WRITE setType NOTIFY typeChanged) 0032 0033 Q_PROPERTY(QVariantList points READ asPoints NOTIFY dataChanged) 0034 Q_PROPERTY(int count READ count NOTIFY dataChanged) 0035 Q_PROPERTY(int firstDataPointTime READ firstDataPointTime NOTIFY dataChanged) 0036 Q_PROPERTY(int lastDataPointTime READ lastDataPointTime NOTIFY dataChanged) 0037 Q_PROPERTY(int largestValue READ largestValue NOTIFY dataChanged) 0038 0039 public: 0040 enum HistoryType { 0041 RateType, 0042 ChargeType, 0043 }; 0044 Q_ENUM(HistoryType) 0045 0046 enum HistoryRoles { 0047 TimeRole = Qt::UserRole + 1, 0048 ValueRole, 0049 ChargingRole, 0050 }; 0051 0052 explicit StatisticsProvider(QObject *parent = nullptr); 0053 0054 void setDevice(const QString &device); 0055 void setDuration(uint duration); 0056 void setType(HistoryType type); 0057 0058 void load(); 0059 0060 void classBegin() override; 0061 void componentComplete() override; 0062 0063 QVariantList asPoints() const; 0064 int count() const; 0065 0066 int firstDataPointTime() const; 0067 int lastDataPointTime() const; 0068 int largestValue() const; 0069 0070 Q_SIGNALS: 0071 void deviceChanged(); 0072 void typeChanged(); 0073 void durationChanged(); 0074 0075 void dataChanged(); 0076 0077 public Q_SLOTS: 0078 void refresh(); 0079 0080 private: 0081 QString m_device; 0082 HistoryType m_type; 0083 uint m_duration; // in seconds 0084 0085 QList<HistoryReply> m_values; 0086 bool m_isComplete = false; 0087 }; 0088 0089 #endif // STATISTICSPROVIDER_H