Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid rebuilding models for ListQuantityGroup and ListTextGroup #1903

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ set (VENUS_QML_MODULE_SOURCES
components/listitems/core/ListTemperature.qml
components/listitems/core/ListText.qml
components/listitems/core/ListTextField.qml
components/listitems/core/ListTextGroup.qml
components/listitems/core/ListTimeSelector.qml
components/listitems/core/PrimaryListLabel.qml
components/listitems/core/SecondaryListLabel.qml
Expand Down Expand Up @@ -703,6 +702,10 @@ list(APPEND VenusQMLModule_CPP_SOURCES
src/productinfo.h
src/quantityinfo.h
src/quantityinfo.cpp
src/quantityobject.h
src/quantityobject.cpp
src/quantityobjectmodel.h
src/quantityobjectmodel.cpp
src/qrangemodel_p.h
src/qrangemodel.h
src/qrangemodel.cpp
Expand Down
29 changes: 14 additions & 15 deletions components/InverterAcOutSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Column {

property string bindPrefix
readonly property bool isInverterCharger: isInverterChargerItem.value === 1
readonly property AcPhase acPhase: acPhaseNumber.value === 2 ? inverterData.phase3
: acPhaseNumber.value === 1 ? inverterData.phase2
: inverterData.phase1

width: parent ? parent.width : 0
spacing: Theme.geometry_gradientList_spacing
Expand All @@ -29,28 +32,24 @@ Column {
ListQuantityGroup {
text: CommonWords.ac_out
preferredVisible: !root.isInverterCharger
textModel: [
{ value: inverterData.phase1.voltage, unit: VenusOS.Units_Volt_AC },
{ value: inverterData.phase1.current, unit: VenusOS.Units_Amp },
{ value: inverterData.phase1.power, unit: VenusOS.Units_Watt },
]
model: QuantityObjectModel {
QuantityObject { object: inverterData.phase1; key: "voltage"; unit: VenusOS.Units_Volt_AC }
QuantityObject { object: inverterData.phase1; key: "current"; unit: VenusOS.Units_Amp }
QuantityObject { object: inverterData.phase1; key: "power"; unit: VenusOS.Units_Watt }
}
}

ListQuantityGroup {
readonly property AcPhase acPhase: acPhaseNumber.value === 2 ? inverterData.phase3
: acPhaseNumber.value === 1 ? inverterData.phase2
: inverterData.phase1

//: %1 = phase number (1-3)
//% "AC Out L%1"
text: qsTrId("inverter_ac-out_num").arg(acPhaseNumber.isValid ? acPhaseNumber.value + 1 : 1)
preferredVisible: root.isInverterCharger
textModel: [
{ value: acPhase.voltage, unit: VenusOS.Units_Volt_AC },
{ value: acPhase.current, unit: VenusOS.Units_Amp },
{ value: acPhase.power, unit: VenusOS.Units_Watt },
{ value: acPhase.frequency, unit: VenusOS.Units_Hertz },
]
model: QuantityObjectModel {
QuantityObject { object: root.acPhase; key: "voltage"; unit: VenusOS.Units_Volt_AC }
QuantityObject { object: root.acPhase; key: "current"; unit: VenusOS.Units_Amp }
QuantityObject { object: root.acPhase; key: "power"; unit: VenusOS.Units_Watt }
QuantityObject { object: root.acPhase; key: "frequency"; unit: VenusOS.Units_Hertz }
}

VeQuickItem {
id: acPhaseNumber
Expand Down
24 changes: 14 additions & 10 deletions components/PageGensetModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -158,28 +158,32 @@ VisibleItemModel {

model: root.nrOfPhases
delegate: ListQuantityGroup {
id: phaseDelegate

required property int index
readonly property string bindPrefix: `${root.bindPrefix}/Ac/L${index + 1}`

text: phaseRepeater.count === 1
//% "AC"
? qsTrId("ac-in-genset_ac")
: CommonWords.ac_phase_x.arg(model.index + 1)

textModel: [
{ value: phaseVoltage.value, unit: VenusOS.Units_Volt_AC },
{ value: phaseCurrent.value, unit: VenusOS.Units_Amp },
{ value: phasePower.value, unit: VenusOS.Units_Watt },
]
: CommonWords.ac_phase_x.arg(index + 1)
model: QuantityObjectModel {
QuantityObject { object: phaseVoltage; unit: VenusOS.Units_Volt_AC }
QuantityObject { object: phaseCurrent; unit: VenusOS.Units_Amp }
QuantityObject { object: phasePower; unit: VenusOS.Units_Watt }
}

VeQuickItem {
id: phaseVoltage
uid: root.bindPrefix + "/Ac/L" + (model.index + 1) + "/Voltage"
uid: phaseDelegate.bindPrefix + "/Voltage"
}
VeQuickItem {
id: phaseCurrent
uid: root.bindPrefix + "/Ac/L" + (model.index + 1) + "/Current"
uid: phaseDelegate.bindPrefix + "/Current"
}
VeQuickItem {
id: phasePower
uid: root.bindPrefix + "/Ac/L" + (model.index + 1) + "/Power"
uid: phaseDelegate.bindPrefix + "/Power"
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion components/QuantityLabel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ Item {

property alias value: quantityInfo.value
property alias unit: quantityInfo.unitType
readonly property alias quantityInfo: quantityInfo
property alias font: unitLabel.font
property alias valueColor: valueLabel.color
property alias unitColor: unitLabel.color
readonly property alias valueText: valueLabel.text
property alias valueText: valueLabel.text
readonly property alias unitText: unitLabel.text
property int alignment: Qt.AlignHCenter
property alias precision: quantityInfo.precision
property alias formatHints: quantityInfo.formatHints
property alias leftPadding: digitRow.leftPadding
property alias rightPadding: digitRow.rightPadding

implicitWidth: digitRow.width
implicitHeight: digitRow.height
Expand Down
75 changes: 28 additions & 47 deletions components/QuantityRow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,55 @@ import Victron.VenusOS
Row {
id: root

property alias model: quantityRepeater.model
property QuantityObjectModel model
property alias quantityMetrics: quantityMetrics
property bool showFirstSeparator

// In table mode, items are spaced out without separators between them.
// (TODO if not tableMode, then invalid items should be hidden, instead of showing them as "--".)
property bool tableMode

readonly property bool _showSeparators: !tableMode
readonly property int _textAlignment: tableMode ? Qt.AlignLeft : Qt.AlignHCenter

height: Theme.geometry_listItem_height

FontMetrics {
id: fontMetrics
font.pixelSize: Theme.font_size_body2
}

Repeater {
id: quantityRepeater

delegate: Row {
model: root.model
delegate: QuantityLabel {
id: quantityDelegate

// Visibility is determined by optional 'visible' property.
readonly property bool showValue: modelData.visible !== false
readonly property var dataValue: modelData.value
readonly property bool isStringValue: typeof(dataValue) === 'string'
required property int index
required property QuantityObject quantityObject
readonly property real horizontalPadding: quantityObject.textValue.length ? Theme.geometry_listItem_content_spacing : 0

width: quantityObject.textValue.length ? implicitWidth : quantityMetrics.columnWidth(unit)
height: root.height
leftPadding: verticalSeparator.width + horizontalPadding
rightPadding: horizontalPadding
alignment: root._textAlignment
font.pixelSize: Theme.font_size_body2
value: quantityObject.numberValue
unit: quantityObject.unit
precision: quantityObject.precision
valueText: quantityObject.textValue || quantityInfo.number
valueColor: Theme.color_quantityTable_quantityValue
unitColor: Theme.color_quantityTable_quantityUnit

Item {
Rectangle {
id: verticalSeparator
anchors.verticalCenter: parent.verticalCenter
width: Theme.geometry_listItem_separator_width + (Theme.geometry_listItem_content_spacing / 2)
height: textLabel.height
width: visible ? Theme.geometry_listItem_separator_width : 0
height: fontMetrics.height
visible: root._showSeparators
&& quantityDelegate.showValue
&& (model.index !== 0 || root.showFirstSeparator)

Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
width: Theme.geometry_listItem_separator_width
height: textLabel.height
color: Theme.color_listItem_separator
}
}

QuantityLabel {
id: quantityLabel
visible: quantityDelegate.showValue && !textLabel.visible
width: quantityMetrics.columnWidth(unit)
height: root.height
alignment: root._textAlignment
font.pixelSize: Theme.font_size_body2
unit: modelData.unit || VenusOS.Units_None
precision: modelData.precision || VenusOS.Units_Precision_Default
value: isNaN(quantityDelegate.dataValue) ? NaN : quantityDelegate.dataValue
valueColor: Theme.color_quantityTable_quantityValue
unitColor: Theme.color_quantityTable_quantityUnit
}

// Show a plain label instead of a QuantityLabel if modelData.value is a string instead of
// a number.
Label {
id: textLabel
anchors.verticalCenter: parent.verticalCenter
visible: quantityDelegate.showValue && quantityDelegate.isStringValue
leftPadding: Theme.geometry_listItem_content_spacing
rightPadding: Theme.geometry_listItem_content_spacing
text: visible ? quantityDelegate.dataValue : ""
horizontalAlignment: root._textAlignment
font.pixelSize: Theme.font_size_body2
color: Theme.color_quantityTable_quantityValue
&& (quantityDelegate.index > 0 || root.showFirstSeparator)
color: Theme.color_listItem_separator
}
}
}
Expand Down
1 change: 1 addition & 0 deletions components/QuantityTable.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import QtQuick
import Victron.VenusOS

// TODO change this to use QuantityObjectModel for the model
Column {
id: root

Expand Down
12 changes: 7 additions & 5 deletions components/listitems/ListDcInputQuantityGroup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ ListQuantityGroup {
//% "Input"
text: qsTrId("dc_input")
preferredVisible: inVoltage.isValid || inPower.isValid
textModel: [
{ value: inVoltage.value, unit: VenusOS.Units_Volt_DC, visible: inVoltage.isValid },
{ value: inCurrent.value, unit: VenusOS.Units_Amp, visible: inCurrent.isValid },
{ value: inPower.value, unit: VenusOS.Units_Watt, visible: inPower.isValid },
]
model: QuantityObjectModel {
filterType: QuantityObjectModel.HasValue

QuantityObject { object: inVoltage; unit: VenusOS.Units_Volt_DC }
QuantityObject { object: inCurrent; unit: VenusOS.Units_Amp }
QuantityObject { object: inPower; unit: VenusOS.Units_Watt }
}

VeQuickItem {
id: inVoltage
Expand Down
12 changes: 7 additions & 5 deletions components/listitems/ListDcOutputQuantityGroup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ ListQuantityGroup {
//: DC output measurement values
//% "Output"
text: qsTrId("dc_output")
textModel: [
{ value: dcVoltage.value, unit: VenusOS.Units_Volt_DC },
{ value: dcCurrent.value, unit: VenusOS.Units_Amp, visible: dcCurrent.isValid },
{ value: dcPower.value, unit: VenusOS.Units_Watt, visible: dcPower.isValid },
]
model: QuantityObjectModel {
filterType: QuantityObjectModel.HasValue

QuantityObject { object: dcVoltage; unit: VenusOS.Units_Volt_DC; defaultValue: "--" }
QuantityObject { object: dcCurrent; unit: VenusOS.Units_Amp }
QuantityObject { object: dcPower; unit: VenusOS.Units_Watt }
}

VeQuickItem {
id: dcVoltage
Expand Down
3 changes: 1 addition & 2 deletions components/listitems/core/ListQuantityGroup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import Victron.VenusOS
ListItem {
id: root

property alias textModel: quantityRow.model
property alias model: quantityRow.model

content.spacing: 0
content.children: [
QuantityRow {
id: quantityRow
Expand Down
42 changes: 0 additions & 42 deletions components/listitems/core/ListTextGroup.qml

This file was deleted.

10 changes: 5 additions & 5 deletions components/widgets/DcInputWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ OverviewWidget {
model: root.inputs
delegate: ListQuantityGroupNavigation {
text: model.device.name
quantityModel: [
{ value: model.device.voltage, unit: VenusOS.Units_Volt_DC },
{ value: model.device.current, unit: VenusOS.Units_Amp },
{ value: model.device.power, unit: VenusOS.Units_Watt },
]
tableMode: true
quantityModel: QuantityObjectModel {
QuantityObject { object: model.device; key: "voltage"; unit: VenusOS.Units_Volt_DC }
QuantityObject { object: model.device; key: "current"; unit: VenusOS.Units_Amp }
QuantityObject { object: model.device; key: "power"; unit: VenusOS.Units_Watt }
}

onClicked: {
Global.pageManager.pushPage(root.detailUrl, {
Expand Down
20 changes: 6 additions & 14 deletions components/widgets/DcLoadsWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,24 @@ OverviewWidget {
GradientListView {
model: Global.allDevicesModel.combinedDcLoadDevices

delegate: ListTextGroup {
delegate: ListQuantityGroupNavigation {
id: deviceDelegate

required property var device

text: device.name
textModel: [
Units.getCombinedDisplayText(VenusOS.Units_Volt_DC, dcDevice.voltage),
Units.getCombinedDisplayText(VenusOS.Units_Amp, dcDevice.current),
Units.getCombinedDisplayText(VenusOS.Units_Watt, dcDevice.power),
]
quantityModel: QuantityObjectModel {
QuantityObject { object: dcDevice; key: "voltage"; unit: VenusOS.Units_Volt_DC }
QuantityObject { object: dcDevice; key: "current"; unit: VenusOS.Units_Amp }
QuantityObject { object: dcDevice; key: "power"; unit: VenusOS.Units_Watt }
}

onClicked: root._showSettingsPage(device)

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

CP.ColorImage {
parent: deviceDelegate.content
anchors.verticalCenter: parent.verticalCenter
source: "qrc:/images/icon_arrow_32.svg"
rotation: 180
color: delegatePressArea.containsPress ? Theme.color_listItem_down_forwardIcon : Theme.color_listItem_forwardIcon
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions data/mock/PvInvertersImpl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ QtObject {
_productId.setValue(45058) // dummy value so that ProductId is not invalid, so PageAcIn.qml will show some content
_allowedRoles.setValue(Global.acInputs.roles.map((roleInfo) => { return roleInfo.role }))
_role.setValue("pvinverter")
Global.mockDataSimulator.setMockValue(serviceUid + "/Connected", 1)
}
}
}
Expand Down
Loading