diff options
author | Mikko Gronoff <mikko.gronoff@qt.io> | 2018-08-24 11:10:54 +0300 |
---|---|---|
committer | Mikko Gronoff <mikko.gronoff@qt.io> | 2018-08-24 11:11:38 +0300 |
commit | 75addc77b361384b018ec28bde26e5880887c80f (patch) | |
tree | 38d58d5737dda597a6a69f2c931672575e5ed217 /basicsuite/ebike-ui/datastore.h | |
parent | 22cdfdd27aaa885ac5b7b450c8fb82b87853250d (diff) | |
parent | 1ff81b46a37550bb4430cc032b6d5504525af53f (diff) |
Merge remote-tracking branch 'origin/5.11' into dev
* origin/5.11:
1ff81b4 Merge remote-tracking branch 'origin/5.9' into 5.11
3594ea2 Fix scaling, video path & focusing issues on mediaplayer demo
e81384c Remove confusing highlighting on media player file browser
4aa85d7 Use QSettings for color definitions
a60eb67 Disable graphical effect from imx7 boards
83bffe9 Move color definitions to QSettings
57bc95f Fix qtquickcontrols2 demo image paths & controls theme
a5ba671 Doc: Bump version to 5.11.2
1510d96 Doc: bump version to 5.9.7
cc9de37 Fix mediaplayer slider color definitions
c20966f Move info button to mediaplayer-demo footer
0b0d77e Fix mediaplayer color definitions
a607978 Update Boot2Qt Launcher demo icons & doc images
773a661 Disable webbrowser demo from all imx7 boards
9f18bb7 Doc: Bump version to 5.11.1
4fa8854 Doc: remove outdate doc folder under qtquickcontrols2 example
054a2ea doc: add missing doc images for e-bike & quickcontrols2 demo
173d934 Update Boot2Qt demos appearing in QtCreator
a70868f Enable ebike demo
6ed3d30 Temporarily disable e-bike from the basicsuite demo set
28e9fdf Fix Media Player demo color definitions
6b5a6d0 Fix paths for demos.xml
783ca94 Doc: bump version to 5.9.6
d083365 Add new Ebike demo to basicsuite
da60352 Move common definitions to shared settings
e513aed Update QtWebBrowser demo to new UI theme
f5c4c3a Remove qtwebbrowser submodule
3fa5796 Replace existing controls demos with controls 2 gallery example
04e4798 Update Mediaplayer demo to new UI theme
2e8942f Update GraphicalEffects demo to new UI theme
e365074 Add new fonts
7c41444 Update Charts demo to new UI theme
2a50d49 Comment out 7 demos from demos.xml file
9e941af Doc: Bump version to 5.9.5
0909f9b Doc: Bump version to 5.11.0
55fee3b Doc: Bump version to 5.9.4
89033ce Doc: Bump version to 5.9.3
Change-Id: I17ac5f2e2ef94535458b07cf8db38688e25ca21c
Diffstat (limited to 'basicsuite/ebike-ui/datastore.h')
-rw-r--r-- | basicsuite/ebike-ui/datastore.h | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/basicsuite/ebike-ui/datastore.h b/basicsuite/ebike-ui/datastore.h new file mode 100644 index 0000000..20fa388 --- /dev/null +++ b/basicsuite/ebike-ui/datastore.h @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the E-Bike demo project. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DATASTORE_H +#define DATASTORE_H + +#include <QObject> +#include <QJsonObject> + +class SocketClient; +class TripDataModel; + +class DataStore: public QObject +{ + Q_OBJECT + + // Different measured properties + Q_PROPERTY(double speed READ speed NOTIFY speedChanged) + Q_PROPERTY(double topspeed READ topSpeed NOTIFY topspeedChanged) + Q_PROPERTY(double averagespeed READ averageSpeed NOTIFY currentTripChanged) + Q_PROPERTY(double odometer READ odometer NOTIFY odometerChanged) + Q_PROPERTY(double trip READ trip NOTIFY currentTripChanged) + Q_PROPERTY(double calories READ calories NOTIFY currentTripChanged) + Q_PROPERTY(double assistdistance READ assistDistance NOTIFY assistdistanceChanged) + Q_PROPERTY(double assistpower READ assistPower NOTIFY assistpowerChanged) + Q_PROPERTY(double batterylevel READ batteryLevel NOTIFY batterylevelChanged) + + // Toggles for lights and mode + Q_PROPERTY(bool lights READ lights WRITE setLights NOTIFY lightsChanged) + Q_PROPERTY(Mode mode READ mode WRITE setMode NOTIFY modeChanged) + + // Current units + Q_PROPERTY(Unit unit READ unit WRITE setUnit NOTIFY unitChanged) + Q_PROPERTY(QString smallUnit READ smallUnit NOTIFY smallUnitChanged) + + // Navigation + Q_PROPERTY(int arrow READ arrow NOTIFY arrowChanged) + Q_PROPERTY(double legdistance READ legDistance NOTIFY legdistanceChanged) + Q_PROPERTY(double tripremaining READ tripRemaining NOTIFY tripremainingChanged) + +public: + explicit DataStore(QObject *parent = nullptr); + + enum Mode { Cruise, Sport }; + Q_ENUM(Mode) + + enum Unit { Kmh, Mph }; + Q_ENUM(Unit) + +public: + // Getters + double speed() const; + double topSpeed() const; + double averageSpeed() const; + double odometer() const; + double trip() const; + double calories() const; + double assistDistance() const; + double assistPower() const; + double batteryLevel() const; + bool lights() const; + Mode mode() const; + Unit unit() const; + int arrow() const; + double legDistance() const; + double tripRemaining() const; + QString smallUnit() const; + + // Setters + void setLights(bool lights); + void setMode(Mode mode); + void setUnit(Unit unit); + + // Get trip data model + TripDataModel *tripDataModel() const { return m_trips; } + + // Convert speed and distance to proper units + Q_INVOKABLE double convertSpeed(double speed) const; + Q_INVOKABLE double convertDistance(double distance) const; + Q_INVOKABLE double convertSmallDistance(double distance) const; + Q_INVOKABLE QString getSmallUnit() const; + + // Split and convert distance and duration to value and unit + Q_INVOKABLE QJsonObject splitDistance(double distance, bool round=false) const; + Q_INVOKABLE QJsonObject splitDuration(double duration) const; + +private: + void emitByName(const QString &valuename); + +signals: + void speedChanged(); + void topspeedChanged(); + void averagespeedChanged(); + void odometerChanged(); + void tripChanged(); + void caloriesChanged(); + void assistdistanceChanged(); + void assistpowerChanged(); + void batterylevelChanged(); + void lightsChanged(); + void modeChanged(); + void unitChanged(); + void arrowChanged(); + void legdistanceChanged(); + void tripremainingChanged(); + void currentTripChanged(); + void smallUnitChanged(QString smallUnit); + void demoReset(); + +public slots: + void connectToServer(const QString &servername); + void getTrips(); + void endTrip(); + void toggleMode(); + void resetDemo(); + +private slots: + void requestStatus(); + void parseMessage(const QJsonObject &message); + +private: + SocketClient *m_client; + QJsonObject m_properties; + QJsonObject m_current; + Unit m_unit; + TripDataModel *m_trips; + int m_smallUnit; +}; + +#endif // DATASTORE_H |