Skip to content

Commit

Permalink
Remove Global.dcLoads and DcLoad.qml
Browse files Browse the repository at this point in the history
Global.dcLoads does nothing except provide a global model, so move
this model into AllDevicesModel. DcLoad.qml is not needed as the
Device List delegate does not need the individual DcLoad properties.

Part of #1400
  • Loading branch information
blammit committed Dec 9, 2024
1 parent e29d518 commit c47c72a
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 178 deletions.
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ set (VENUS_QML_MODULE_SOURCES
components/Led.qml
components/LoadGraph.qml
components/LoadGraphShapePath.qml
components/MultiServiceDeviceModel.qml
components/NavBar.qml
components/NavButton.qml
components/NotificationDelegate.qml
Expand All @@ -238,6 +239,7 @@ set (VENUS_QML_MODULE_SOURCES
components/SegmentedButtonRow.qml
components/SeparatorBar.qml
components/ServiceDeviceModel.qml
components/ServiceModelLoader.qml
components/SettingsRangeSlider.qml
components/SettingsSlider.qml
components/ShinyProgressArc.qml
Expand Down Expand Up @@ -380,7 +382,6 @@ set (VENUS_QML_MODULE_SOURCES
data/Batteries.qml
data/DataManager.qml
data/DcInputs.qml
data/DcLoads.qml
data/DigitalInputs.qml
data/EnvironmentInputs.qml
data/Ess.qml
Expand All @@ -405,7 +406,6 @@ set (VENUS_QML_MODULE_SOURCES
data/common/AcInput.qml
data/common/DcDevice.qml
data/common/DcInput.qml
data/common/DcLoad.qml
data/common/DeviceModel.qml
data/common/EnvironmentInput.qml
data/common/EssData.qml
Expand Down Expand Up @@ -783,7 +783,6 @@ endif()
set(Dbus_QML_MODULE_SOURCES
data/dbus/DBusDataManager.qml
data/dbus/DcInputsImpl.qml
data/dbus/DcLoadsImpl.qml
data/dbus/EnvironmentInputsImpl.qml
data/dbus/EssImpl.qml
data/dbus/EvChargersImpl.qml
Expand Down Expand Up @@ -902,7 +901,6 @@ endif()
# Mqtt_QML_MODULE
set(Mqtt_QML_MODULE_SOURCES
data/mqtt/DcInputsImpl.qml
data/mqtt/DcLoadsImpl.qml
data/mqtt/EnvironmentInputsImpl.qml
data/mqtt/EssImpl.qml
data/mqtt/EvChargersImpl.qml
Expand Down
2 changes: 0 additions & 2 deletions Global.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ QtObject {
property var acInputs
property var batteries
property var dcInputs
property var dcLoads
property var digitalInputs
property var environmentInputs
property var ess
Expand Down Expand Up @@ -103,7 +102,6 @@ QtObject {
acInputs = null
batteries = null
dcInputs = null
dcLoads = null
digitalInputs = null
environmentInputs = null
ess = null
Expand Down
7 changes: 6 additions & 1 deletion components/AllDevicesModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ AggregateDeviceModel {
sourceModels: [
batteryDevices,
Global.dcInputs.model,
Global.dcLoads.model,
combinedDcLoadsModel,
digitalInputDevices,
Global.environmentInputs.model,
Global.evChargers.model,
Expand Down Expand Up @@ -40,6 +40,11 @@ AggregateDeviceModel {
modelId: "battery"
}

readonly property MultiServiceDeviceModel combinedDcLoadsModel: MultiServiceDeviceModel {
serviceTypes: ["dcload", "dcsystem", "dcdc"]
modelId: "combinedDcloads"
}

readonly property ServiceDeviceModel digitalInputDevices: ServiceDeviceModel {
serviceType: "digitalinput"
modelId: "digitalinput"
Expand Down
40 changes: 40 additions & 0 deletions components/MultiServiceDeviceModel.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
** Copyright (C) 2024 Victron Energy B.V.
** See LICENSE.txt for license information.
*/

import QtQuick
import Victron.VenusOS

// Provides a generic DeviceModel for a set of service types.
//
// All services found for the specified types will be added and removed as Device objects.

DeviceModel {
id: root

required property var serviceTypes

readonly property Instantiator _serviceObjects: Instantiator {
model: root.serviceTypes
delegate: Instantiator {
required property string modelData
readonly property ServiceModelLoader modelLoader: ServiceModelLoader {
serviceType: modelData
}

model: modelLoader.item
delegate: Device {
id: device
serviceUid: model.uid
onValidChanged: {
if (valid) {
root.addDevice(device)
} else {
root.removeDevice(device.serviceUid)
}
}
}
}
}
}
21 changes: 2 additions & 19 deletions components/ServiceDeviceModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,7 @@ DeviceModel {
}
}

readonly property Loader modelLoader: Loader {
sourceComponent: BackendConnection.type === BackendConnection.MqttSource ? _mqttModelComponent
: _dbusOrMockModelComponent
}

readonly property Component _dbusOrMockModelComponent: Component {
VeQItemSortTableModel {
dynamicSortFilter: true
filterRole: VeQItemTableModel.UniqueIdRole
filterRegExp: "^%1/com\.victronenergy\.%2\.".arg(BackendConnection.uidPrefix()).arg(root.serviceType)
model: Global.dataServiceModel
}
}

readonly property Component _mqttModelComponent: Component {
VeQItemTableModel {
uids: [ "mqtt/" + root.serviceType ]
flags: VeQItemTableModel.AddChildren | VeQItemTableModel.AddNonLeaves | VeQItemTableModel.DontAddItem
}
readonly property ServiceModelLoader modelLoader: ServiceModelLoader {
serviceType: root.serviceType
}
}
32 changes: 32 additions & 0 deletions components/ServiceModelLoader.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
** Copyright (C) 2024 Victron Energy B.V.
** See LICENSE.txt for license information.
*/

import QtQuick
import Victron.VenusOS

Loader {
id: root

required property string serviceType

sourceComponent: BackendConnection.type === BackendConnection.MqttSource ? _mqttModelComponent
: _dbusOrMockModelComponent

readonly property Component _dbusOrMockModelComponent: Component {
VeQItemSortTableModel {
dynamicSortFilter: true
filterRole: VeQItemTableModel.UniqueIdRole
filterRegExp: "^%1/com\.victronenergy\.%2\.".arg(BackendConnection.uidPrefix()).arg(root.serviceType)
model: Global.dataServiceModel
}
}

readonly property Component _mqttModelComponent: Component {
VeQItemTableModel {
uids: [ "mqtt/" + root.serviceType ]
flags: VeQItemTableModel.AddChildren | VeQItemTableModel.AddNonLeaves | VeQItemTableModel.DontAddItem
}
}
}
19 changes: 12 additions & 7 deletions components/widgets/DcLoadsWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ OverviewWidget {
title: qsTrId("overview_widget_dcloads_title")
icon.source: "qrc:/images/dcloads.svg"
type: VenusOS.OverviewWidget_Type_DcLoads
enabled: Global.dcLoads.model.count > 0
enabled: Global.allDevicesModel.combinedDcLoadsModel.count > 0

quantityLabel.dataObject: Global.system.dc

onClicked: {
if (Global.dcLoads.model.count > 1) {
if (Global.allDevicesModel.combinedDcLoadsModel.count > 1) {
Global.pageManager.pushPage(deviceListPageComponent, { "title": root.title })
} else {
root._showSettingsPage(Global.dcLoads.model.firstObject)
root._showSettingsPage(Global.allDevicesModel.combinedDcLoadsModel.firstObject)
}
}

Expand All @@ -41,7 +41,7 @@ OverviewWidget {

Page {
GradientListView {
model: Global.dcLoads.model
model: Global.allDevicesModel.combinedDcLoadsModel

delegate: ListTextGroup {
id: deviceDelegate
Expand All @@ -50,11 +50,16 @@ OverviewWidget {

text: device.name
textModel: [
Units.getCombinedDisplayText(VenusOS.Units_Volt_DC, device.voltage),
Units.getCombinedDisplayText(VenusOS.Units_Amp, device.current),
Units.getCombinedDisplayText(VenusOS.Units_Watt, device.power),
Units.getCombinedDisplayText(VenusOS.Units_Volt_DC, dcDevice.voltage),
Units.getCombinedDisplayText(VenusOS.Units_Amp, dcDevice.current),
Units.getCombinedDisplayText(VenusOS.Units_Watt, dcDevice.power),
]

DcDevice {
id: dcDevice
serviceUid: deviceDelegate.device.serviceUid
}

ListPressArea {
id: delegatePressArea

Expand Down
2 changes: 0 additions & 2 deletions data/DataManager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Item {
&& !!Global.acInputs
&& !!Global.batteries
&& !!Global.dcInputs
&& !!Global.dcLoads
&& !!Global.digitalInputs
&& !!Global.environmentInputs
&& !!Global.ess
Expand Down Expand Up @@ -96,7 +95,6 @@ Item {
AcInputs {}
Batteries {}
DcInputs {}
DcLoads {}
DigitalInputs {}
EnvironmentInputs {}
Ess {}
Expand Down
17 changes: 0 additions & 17 deletions data/DcLoads.qml

This file was deleted.

21 changes: 0 additions & 21 deletions data/common/DcLoad.qml

This file was deleted.

1 change: 0 additions & 1 deletion data/dbus/DBusDataManager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ QtObject {
id: root

property var dcInputs: DcInputsImpl { }
property var dcLoads: DcLoadsImpl { }
property var environmentInputs: EnvironmentInputsImpl { }
property var ess: EssImpl { }
property var evChargers: EvChargersImpl { }
Expand Down
50 changes: 0 additions & 50 deletions data/dbus/DcLoadsImpl.qml

This file was deleted.

14 changes: 7 additions & 7 deletions data/mock/DcLoadsImpl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ QtObject {
}

property Timer updateDcValues: Timer {
running: Global.mockDataSimulator.timersActive
interval: 1000
running: Global.mockDataSimulator.timersActive && !!(Global.allDevicesModel?.combinedDcLoadsModel)
interval: 500
repeat: true
triggeredOnStart: true

onTriggered: {
let totalPower = NaN
for (let i = 0; i < Global.dcLoads.model.count; ++i) {
const dcLoad = Global.dcLoads.model.deviceAt(i)
totalPower = Units.sumRealNumbers(totalPower, dcLoad.power)
for (let i = 0; i < Global.allDevicesModel.combinedDcLoadsModel.count; ++i) {
const dcLoad = Global.allDevicesModel.combinedDcLoadsModel.deviceAt(i)
const power = Global.mockDataSimulator.mockValue(dcLoad.serviceUid + "/Dc/0/Power")
totalPower = Units.sumRealNumbers(totalPower, power)
}

Global.mockDataSimulator.setMockValue("com.victronenergy.system/Dc/System/Power", totalPower)
Expand All @@ -83,7 +83,7 @@ QtObject {
}

property Component dcLoadComponent: Component {
DcLoad {
Device {
id: dcLoad

property string serviceType
Expand Down
Loading

0 comments on commit c47c72a

Please sign in to comment.