From f7a29f3635af03bda58fefccf8c39e1007290377 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 29 Mar 2020 20:02:43 +0200 Subject: [PATCH] Fix units in dynamic graph view updates --- libnymea-app/models/logsmodelng.cpp | 19 +++++++++++-------- nymea-app/ui/customviews/GenericTypeGraph.qml | 7 ++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/libnymea-app/models/logsmodelng.cpp b/libnymea-app/models/logsmodelng.cpp index 1c032f5f..b1ae8359 100644 --- a/libnymea-app/models/logsmodelng.cpp +++ b/libnymea-app/models/logsmodelng.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "engine.h" #include "types/logentry.h" @@ -226,7 +227,7 @@ LogEntry *LogsModelNg::get(int index) const void LogsModelNg::logsReply(const QVariantMap &data) { -// qDebug() << "logs reply" << data; + qDebug() << "logs reply" << qUtf8Printable(QJsonDocument::fromVariant(data).toJson()); int offset = data.value("params").toMap().value("offset").toInt(); @@ -273,7 +274,7 @@ void LogsModelNg::logsReply(const QVariantMap &data) StateType *entryStateType = dev->deviceClass()->stateTypes()->getStateType(entry->typeId()); if (m_graphSeries) { - if (entryStateType->type() == "Bool") { + if (entryStateType->type().toLower() == "bool") { // We don't want bools painting triangles, add a toggle point to keep lines straight if (i > 0) { @@ -307,7 +308,7 @@ void LogsModelNg::logsReply(const QVariantMap &data) } else { - // Add a pint in the future to extend the graph (so it can scroll with time and the graph wouldn't end at the last known value) + // Add a point in the future to extend the graph (so it can scroll with time and the graph wouldn't end at the last known value) if (m_graphSeries->count() == 0) { m_graphSeries->append(QPointF(QDateTime::currentDateTime().addDays(1).toMSecsSinceEpoch(), Types::instance()->toUiValue(entry->value(), entryStateType->unit()).toReal())); } @@ -406,7 +407,7 @@ bool LogsModelNg::canFetchMore(const QModelIndex &parent) const void LogsModelNg::newLogEntryReceived(const QVariantMap &data) { - qDebug() << "***** model NG" << data << m_live; +// qDebug() << "***** model NG" << data << m_live; if (!m_live) { return; } @@ -434,10 +435,11 @@ void LogsModelNg::newLogEntryReceived(const QVariantMap &data) m_list.prepend(entry); if (m_graphSeries) { - Device *dev = m_engine->deviceManager()->devices()->getDevice(entry->deviceId()); - if (dev && dev->deviceClass()->stateTypes()->getStateType(entry->typeId())->type() == "Bool") { + StateType *entryStateType = dev->deviceClass()->stateTypes()->getStateType(entry->typeId()); + + if (dev && dev->deviceClass()->stateTypes()->getStateType(entry->typeId())->type().toLower() == "bool") { // First, remove the 2 rightmost (newest on the timeline) values. They're the ones in the future we added to extend the graph and making it end at 1 if (m_graphSeries->count() > 1) { m_graphSeries->removePoints(0, 2); @@ -464,10 +466,11 @@ void LogsModelNg::newLogEntryReceived(const QVariantMap &data) } // Add the actual value - m_graphSeries->insert(0, QPointF(entry->timestamp().toMSecsSinceEpoch(), entry->value().toReal())); + QVariant value = Types::instance()->toUiValue(entry->value(), entryStateType->unit()); + m_graphSeries->insert(0, QPointF(entry->timestamp().toMSecsSinceEpoch(), value.toReal())); // And add the "future" point again - m_graphSeries->insert(0, QPointF(entry->timestamp().addDays(1).toMSecsSinceEpoch(), entry->value().toReal())); + m_graphSeries->insert(0, QPointF(entry->timestamp().addDays(1).toMSecsSinceEpoch(), value.toReal())); } diff --git a/nymea-app/ui/customviews/GenericTypeGraph.qml b/nymea-app/ui/customviews/GenericTypeGraph.qml index 8d5d938a..b081db59 100644 --- a/nymea-app/ui/customviews/GenericTypeGraph.qml +++ b/nymea-app/ui/customviews/GenericTypeGraph.qml @@ -257,6 +257,11 @@ Item { lowerSeries: LineSeries { id: connectedLineSeries + onPointAdded: { + var newPoint = connectedLineSeries.at(index) + print("pointadded", newPoint.x, newPoint.y) + } + } color: "#55ff0000" borderWidth: 0 @@ -279,7 +284,7 @@ Item { id: lineSeries1 onPointAdded: { var newPoint = lineSeries1.at(index) - print("pointadded", newPoint.x, newPoint.y) +// print("pointadded", newPoint.x, newPoint.y) if (newPoint.x > lineSeries0.at(0).x) { lineSeries0.replace(0, newPoint.x, 0)