Skip to content

Commit

Permalink
Remove DataPoint*Impl.qml files
Browse files Browse the repository at this point in the history
These were previously added as VeQuickItem came from Victron.Velib,
which could not be imported in the wasm build. However, VeQuickItem
is now in Victron.Veutil, so it can safely be used in all builds, and
DataPoint.qml can now use it directly inside a Component instead of
loading it from a separate file.
  • Loading branch information
blammit committed Aug 1, 2023
1 parent f824f62 commit 146ecfd
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 232 deletions.
111 changes: 111 additions & 0 deletions components/DataPoint.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
** Copyright (C) 2022 Victron Energy B.V.
*/

import QtQuick
import Victron.VenusOS
import Victron.Veutil

QtObject {
id: root

// Valid 'source' values are:
// - dbus paths, e.g. 'com.victronenergy.blah/path/to/value'
// - as above, but with as full dbus uid, e.g. 'dbus/com.victronenergy.blah/path/to/value'
// - full mqtt uid, e.g. 'mqtt/blah/device-id/path/to/value'
// Note that dbus and mqtt uids should only be used when the application is using their
// respective backend connection types. If a mqtt uid is used on a dbus connection, for
// example, the DataPoint would not produce a valid value.
property string source
property var sourceObject

readonly property var value: sourceObject ? sourceObject.value : undefined
readonly property bool valid: value !== undefined

property bool hasMin
property bool hasMax
readonly property var min: hasMin && sourceObject ? sourceObject.min : undefined
readonly property var max: hasMax && sourceObject ? sourceObject.max : undefined
property bool invalidate: true

property Component _dbusComponent : Component {
VeQuickItem {
uid: root.source.startsWith("dbus/") ? root.source : "dbus/" + root.source
invalidate: root.invalidate

onInvalidateChanged: root.invalidate = invalidate
}
}

property Component _mqttComponent : Component {
VeQuickItem {
readonly property string mqttUid: root.source.startsWith("mqtt/") ? root.source : _uidConverter.mqttUid

readonly property SingleUidHelper _uidConverter: SingleUidHelper {
dbusUid: root.source.length === 0 || root.source.startsWith("mqtt/")
? ""
: (root.source.startsWith("dbus/") ? root.source : "dbus/" + root.source)
}

uid: mqttUid
invalidate: root.invalidate

onInvalidateChanged: root.invalidate = invalidate
}
}

property Component _mockComponent : Component {
QtObject {
id: root

property string source: root.source
property var value: Global.mockDataSimulator ? Global.mockDataSimulator.mockDataValues[source] : undefined
property real min: 0
property real max: 100
property bool invalidate: root.invalidate

function setValue(v) {
value = v
}

onInvalidateChanged: root.invalidate = invalidate
}
}

function setValue(v) {
if (sourceObject) {
sourceObject.setValue(v)
} else {
console.warn("Set value() failed, no sourceObject for source", source)
}
}

function _reset() {
if (source.length === 0) {
return
}
if (sourceObject) {
sourceObject.destroy()
sourceObject = null
}
// TODO: maybe use incubateObject() in future if synchronous construction of sourceObject
// takes too long.
switch (BackendConnection.type) {
case BackendConnection.DBusSource:
sourceObject = _dbusComponent.createObject(root)
break
case BackendConnection.MqttSource:
sourceObject = _mqttComponent.createObject(root)
break
case BackendConnection.MockSource:
sourceObject = _mockComponent.createObject(root)
break
default:
console.warn("Unknown DataPoint source type:", BackendConnection.type)
break
}
}

onSourceChanged: _reset()
Component.onCompleted: _reset()
}
182 changes: 0 additions & 182 deletions components/datapoints/DataPoint.qml

This file was deleted.

11 changes: 0 additions & 11 deletions components/datapoints/DataPointDBusImpl.qml

This file was deleted.

20 changes: 0 additions & 20 deletions components/datapoints/DataPointMockImpl.qml

This file was deleted.

11 changes: 0 additions & 11 deletions components/datapoints/DataPointMqttImpl.qml

This file was deleted.

5 changes: 1 addition & 4 deletions qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<file>components/CommonWords.qml</file>
<file>components/ControlCard.qml</file>
<file>components/ControlValue.qml</file>
<file>components/DataPoint.qml</file>
<file>components/Device.qml</file>
<file>components/ElectricalQuantityLabel.qml</file>
<file>components/EnvironmentGauge.qml</file>
Expand Down Expand Up @@ -83,10 +84,6 @@
<file>components/controls/SpinBox.qml</file>
<file>components/controls/Switch.qml</file>
<file>components/controls/TextField.qml</file>
<file>components/datapoints/DataPoint.qml</file>
<file>components/datapoints/DataPointDBusImpl.qml</file>
<file>components/datapoints/DataPointMockImpl.qml</file>
<file>components/datapoints/DataPointMqttImpl.qml</file>
<file>components/dialogs/DateSelectorDialog.qml</file>
<file>components/dialogs/DialogShadow.qml</file>
<file>components/dialogs/VrmInstanceSwapDialog.qml</file>
Expand Down
6 changes: 2 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ void registerQmlTypes()
"Victron.VenusOS", 2, 0, "QuantityTableSummary");
qmlRegisterType(QUrl(QStringLiteral("qrc:/components/QuantityTable.qml")),
"Victron.VenusOS", 2, 0, "QuantityTable");
qmlRegisterType(QUrl(QStringLiteral("qrc:/components/DataPoint.qml")),
"Victron.VenusOS", 2, 0, "DataPoint");
qmlRegisterType(QUrl(QStringLiteral("qrc:/components/ElectricalQuantityLabel.qml")),
"Victron.VenusOS", 2, 0, "ElectricalQuantityLabel");
qmlRegisterType(QUrl(QStringLiteral("qrc:/components/FixedWidthLabel.qml")),
Expand Down Expand Up @@ -402,10 +404,6 @@ void registerQmlTypes()
qmlRegisterType(QUrl(QStringLiteral("qrc:/components/WeatherDetails.qml")),
"Victron.VenusOS", 2, 0, "WeatherDetails");

/* data points */
qmlRegisterType(QUrl(QStringLiteral("qrc:/components/datapoints/DataPoint.qml")),
"Victron.VenusOS", 2, 0, "DataPoint");

/* list items */
qmlRegisterType(QUrl(QStringLiteral("qrc:/components/listitems/ListLabel.qml")),
"Victron.VenusOS", 2, 0, "ListLabel");
Expand Down

0 comments on commit 146ecfd

Please sign in to comment.