initial take on QtCharts
This commit is contained in:
parent
c84cd88d76
commit
10cbc9941b
@ -15,7 +15,7 @@ include(../nymea-remoteproxy/libnymea-remoteproxyclient/libnymea-remoteproxyclie
|
|||||||
|
|
||||||
|
|
||||||
QT -= gui
|
QT -= gui
|
||||||
QT += network websockets bluetooth
|
QT += network websockets bluetooth charts
|
||||||
|
|
||||||
LIBS += -lssl -lcrypto
|
LIBS += -lssl -lcrypto
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,8 @@
|
|||||||
#include "types/logentry.h"
|
#include "types/logentry.h"
|
||||||
#include "logmanager.h"
|
#include "logmanager.h"
|
||||||
|
|
||||||
LogsModelNg::LogsModelNg(QObject *parent) : QAbstractListModel(parent)
|
LogsModelNg::LogsModelNg(QObject *parent) : QAbstractListModel(parent),
|
||||||
|
m_lineSeries(new QtCharts::QLineSeries(this))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -133,9 +134,19 @@ void LogsModelNg::setEndTime(const QDateTime &endTime)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QtCharts::QLineSeries *LogsModelNg::lineSeries() const
|
||||||
|
{
|
||||||
|
return m_lineSeries;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogsModelNg::setLineSeries(QtCharts::QLineSeries *lineSeries)
|
||||||
|
{
|
||||||
|
m_lineSeries = lineSeries;
|
||||||
|
}
|
||||||
|
|
||||||
void LogsModelNg::logsReply(const QVariantMap &data)
|
void LogsModelNg::logsReply(const QVariantMap &data)
|
||||||
{
|
{
|
||||||
qDebug() << "logs reply" << data;
|
// qDebug() << "logs reply" << data;
|
||||||
|
|
||||||
m_busy = false;
|
m_busy = false;
|
||||||
emit busyChanged();
|
emit busyChanged();
|
||||||
@ -170,6 +181,8 @@ void LogsModelNg::logsReply(const QVariantMap &data)
|
|||||||
beginInsertRows(QModelIndex(), offset, offset + newBlock.count() - 1);
|
beginInsertRows(QModelIndex(), offset, offset + newBlock.count() - 1);
|
||||||
for (int i = 0; i < newBlock.count(); i++) {
|
for (int i = 0; i < newBlock.count(); i++) {
|
||||||
m_list.insert(offset + i, newBlock.at(i));
|
m_list.insert(offset + i, newBlock.at(i));
|
||||||
|
qDebug() << "Adding line series point:" << i << newBlock.at(i)->timestamp().toSecsSinceEpoch() << newBlock.at(i)->value().toReal();
|
||||||
|
m_lineSeries->insert(offset + i, QPointF(newBlock.at(i)->timestamp().toSecsSinceEpoch(), newBlock.at(i)->value().toReal()));
|
||||||
}
|
}
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QLineSeries>
|
||||||
|
|
||||||
class LogEntry;
|
class LogEntry;
|
||||||
class Engine;
|
class Engine;
|
||||||
@ -20,6 +21,8 @@ class LogsModelNg : public QAbstractListModel
|
|||||||
Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged)
|
Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged)
|
||||||
Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged)
|
Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged)
|
||||||
|
|
||||||
|
Q_PROPERTY(QtCharts::QLineSeries *lineSeries READ lineSeries WRITE setLineSeries NOTIFY lineSeriesChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Roles {
|
enum Roles {
|
||||||
RoleTimestamp,
|
RoleTimestamp,
|
||||||
@ -56,6 +59,9 @@ public:
|
|||||||
QDateTime endTime() const;
|
QDateTime endTime() const;
|
||||||
void setEndTime(const QDateTime &endTime);
|
void setEndTime(const QDateTime &endTime);
|
||||||
|
|
||||||
|
QtCharts::QLineSeries *lineSeries() const;
|
||||||
|
void setLineSeries(QtCharts::QLineSeries *lineSeries);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void fetchMore(const QModelIndex &parent = QModelIndex()) override;
|
virtual void fetchMore(const QModelIndex &parent = QModelIndex()) override;
|
||||||
virtual bool canFetchMore(const QModelIndex &parent = QModelIndex()) const override;
|
virtual bool canFetchMore(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
@ -69,6 +75,7 @@ signals:
|
|||||||
void startTimeChanged();
|
void startTimeChanged();
|
||||||
void endTimeChanged();
|
void endTimeChanged();
|
||||||
void engineChanged();
|
void engineChanged();
|
||||||
|
void lineSeriesChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void newLogEntryReceived(const QVariantMap &data);
|
void newLogEntryReceived(const QVariantMap &data);
|
||||||
@ -89,6 +96,8 @@ private:
|
|||||||
int m_blockSize = 100;
|
int m_blockSize = 100;
|
||||||
bool m_canFetchMore = true;
|
bool m_canFetchMore = true;
|
||||||
|
|
||||||
|
QtCharts::QLineSeries *m_lineSeries = nullptr;
|
||||||
|
|
||||||
QList<QPair<QDateTime, bool> > m_fetchedPeriods;
|
QList<QPair<QDateTime, bool> > m_fetchedPeriods;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
* *
|
* *
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QApplication>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QtQml/QQmlContext>
|
#include <QtQml/QQmlContext>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
@ -58,7 +58,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
|
|
||||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
QGuiApplication application(argc, argv);
|
QApplication application(argc, argv);
|
||||||
application.setApplicationName("nymea-app");
|
application.setApplicationName("nymea-app");
|
||||||
application.setOrganizationName("nymea");
|
application.setOrganizationName("nymea");
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ int main(int argc, char *argv[])
|
|||||||
applicationFont.setCapitalization(QFont::MixedCase);
|
applicationFont.setCapitalization(QFont::MixedCase);
|
||||||
applicationFont.setPixelSize(16);
|
applicationFont.setPixelSize(16);
|
||||||
applicationFont.setWeight(QFont::Normal);
|
applicationFont.setWeight(QFont::Normal);
|
||||||
QGuiApplication::setFont(applicationFont);
|
QApplication::setFont(applicationFont);
|
||||||
|
|
||||||
QTranslator qtTranslator;
|
QTranslator qtTranslator;
|
||||||
qtTranslator.load("qt_" + QLocale::system().name(),
|
qtTranslator.load("qt_" + QLocale::system().name(),
|
||||||
|
|||||||
@ -2,7 +2,7 @@ TEMPLATE=app
|
|||||||
TARGET=nymea-app
|
TARGET=nymea-app
|
||||||
include(../config.pri)
|
include(../config.pri)
|
||||||
|
|
||||||
QT += network qml quick quickcontrols2 svg websockets bluetooth
|
QT += network qml quick quickcontrols2 svg websockets bluetooth charts
|
||||||
|
|
||||||
INCLUDEPATH += $$top_srcdir/libnymea-common \
|
INCLUDEPATH += $$top_srcdir/libnymea-common \
|
||||||
$$top_srcdir/libnymea-app-core
|
$$top_srcdir/libnymea-app-core
|
||||||
|
|||||||
58
nymea-app/ruletemplates/template.json
Normal file
58
nymea-app/ruletemplates/template.json
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
{
|
||||||
|
"templates": [
|
||||||
|
{
|
||||||
|
"interfaceName": "",
|
||||||
|
"description": "",
|
||||||
|
"ruleNameTemplate": "%0 ...",
|
||||||
|
"eventDescriptorTemplates": [ // optional
|
||||||
|
{
|
||||||
|
"interfaceName": "",
|
||||||
|
"interfaceEvent": "",
|
||||||
|
"selectionId": 0,
|
||||||
|
"params": [ // optional
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"value": "", //optional
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateEvaluatorTemplate": {
|
||||||
|
"stateDescriptorTemplate": {
|
||||||
|
"interfaceName": "",
|
||||||
|
"interfaceState": "",
|
||||||
|
"selectionId": 1,
|
||||||
|
"operator": "ValueOperatorEquals",
|
||||||
|
"value": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ruleActionTemplates": [
|
||||||
|
{
|
||||||
|
"interfaceName": "",
|
||||||
|
"interfaceAction": "",
|
||||||
|
"selectionId": 2,
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"value": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"ruleExitActionTemplates": [
|
||||||
|
{
|
||||||
|
"interfaceName": "",
|
||||||
|
"interfaceAction": "",
|
||||||
|
"selectionId": 2,
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"value": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
@ -4,6 +4,7 @@ import QtQuick.Layouts 1.1
|
|||||||
import Nymea 1.0
|
import Nymea 1.0
|
||||||
import "../components"
|
import "../components"
|
||||||
import "../customviews"
|
import "../customviews"
|
||||||
|
import QtCharts 2.2
|
||||||
|
|
||||||
Page {
|
Page {
|
||||||
id: root
|
id: root
|
||||||
@ -43,6 +44,7 @@ Page {
|
|||||||
deviceId: root.device.id
|
deviceId: root.device.id
|
||||||
typeIds: [root.stateType.id]
|
typeIds: [root.stateType.id]
|
||||||
live: true
|
live: true
|
||||||
|
lineSeries: lineSeries1
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
@ -58,6 +60,9 @@ Page {
|
|||||||
TabButton {
|
TabButton {
|
||||||
text: qsTr("Graph")
|
text: qsTr("Graph")
|
||||||
}
|
}
|
||||||
|
TabButton {
|
||||||
|
text: qsTr("Graph NG")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SwipeView {
|
SwipeView {
|
||||||
@ -163,6 +168,63 @@ Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Item {
|
||||||
|
width: swipeView.width
|
||||||
|
height: swipeView.height
|
||||||
|
|
||||||
|
ChartView {
|
||||||
|
id: chartView
|
||||||
|
anchors.fill: parent
|
||||||
|
ValueAxis {
|
||||||
|
id: yAxis
|
||||||
|
min: 0
|
||||||
|
max: 50
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueAxis {
|
||||||
|
id: xAxis
|
||||||
|
min: Math.floor(startTime.getTime() / 1000)
|
||||||
|
max: Math.floor(endTime.getTime() / 1000)
|
||||||
|
|
||||||
|
property date startTime: {
|
||||||
|
var date = new Date();
|
||||||
|
date.setHours(date.getHours() - 6);
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
property date endTime: new Date()
|
||||||
|
Component.onCompleted: print("creating axis:", startTime, endTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
LineSeries {
|
||||||
|
id: lineSeries1
|
||||||
|
axisX: xAxis
|
||||||
|
axisY: yAxis
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
property int lastX: 0
|
||||||
|
property int lastY: 0
|
||||||
|
onPressed: {
|
||||||
|
lastX = mouse.x
|
||||||
|
lastY = mouse.y
|
||||||
|
}
|
||||||
|
|
||||||
|
onPositionChanged: {
|
||||||
|
if (lastX !== mouse.x) {
|
||||||
|
chartView.scrollRight(lastX - mouse.x)
|
||||||
|
lastX = mouse.x
|
||||||
|
}
|
||||||
|
if (lastY !== mouse.y) {
|
||||||
|
chartView.scrollDown(lastY - mouse.y)
|
||||||
|
lastY = mouse.y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user