Skip to content

Commit

Permalink
Use VeQuickItem::numberValue to reduce binding overheads
Browse files Browse the repository at this point in the history
  • Loading branch information
chriadam committed Jun 6, 2024
1 parent 24ee863 commit 11480f0
Show file tree
Hide file tree
Showing 27 changed files with 94 additions and 97 deletions.
8 changes: 4 additions & 4 deletions components/AcPhase.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ QtObject {
id: root

property string serviceUid
readonly property real frequency: _frequency.value === undefined ? NaN : _frequency.value
readonly property real current: _current.value === undefined ? NaN : _current.value
readonly property real voltage: _voltage.value === undefined ? NaN : _voltage.value
readonly property real power: _power.value === undefined ? NaN : _power.value
readonly property real frequency: _frequency.numberValue
readonly property real current: _current.numberValue
readonly property real voltage: _voltage.numberValue
readonly property real power: _power.numberValue
readonly property bool valid: !isNaN(frequency)
&& !isNaN(current)
&& !isNaN(voltage)
Expand Down
2 changes: 1 addition & 1 deletion components/listitems/ListQuantityField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Victron.VenusOS
ListTextField {
id: root

property real value: dataItem.isValid ? dataItem.value : NaN
property real value: dataItem.numberValue
property int unit: VenusOS.Units_None
property int decimals: Units.defaultUnitPrecision(unit)

Expand Down
2 changes: 1 addition & 1 deletion components/listitems/ListQuantityItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ListItem {

anchors.verticalCenter: parent.verticalCenter
font.pixelSize: Theme.font_size_body2
value: dataItem.value === undefined ? NaN : dataItem.value
value: dataItem.numberValue
}
]

Expand Down
2 changes: 1 addition & 1 deletion data/DcInputs.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ QtObject {

property real power: NaN
property real current: NaN
readonly property real maximumPower: _maximumPower.value === undefined ? NaN : _maximumPower.value
readonly property real maximumPower: _maximumPower.numberValue

property DeviceModel model: DeviceModel {
modelId: "dcInputs"
Expand Down
8 changes: 4 additions & 4 deletions data/System.qml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ QtObject {
property QtObject solar: QtObject {
readonly property real power: Units.sumRealNumbers(acPower, dcPower)
property real acPower: _pvMonitor.totalPower
property real dcPower: _dcPvPower.value === undefined ? NaN : _dcPvPower.value
readonly property real maximumPower: _maximumPower.value === undefined ? NaN : _maximumPower.value
property real dcPower: _dcPvPower.numberValue
readonly property real maximumPower: _maximumPower.numberValue

// In cases where the overall current cannot be determined, the value is NaN.
readonly property real current: {
Expand All @@ -46,7 +46,7 @@ QtObject {
}
return _pvMonitor.totalCurrent
} else if (Global.solarChargers.model.count > 0) {
return _dcPvCurrent.value === undefined ? NaN : _dcPvCurrent.value
return _dcPvCurrent.numberValue
}
return NaN
}
Expand All @@ -71,7 +71,7 @@ QtObject {

readonly property QtObject veBus: QtObject {
readonly property string serviceUid: BackendConnection.serviceUidFromName(_serviceName.value || "", _deviceInstance.value || 0)
readonly property real power: _power.value === undefined ? NaN : _power.value
readonly property real power: _power.numberValue

readonly property VeQuickItem _serviceName: VeQuickItem { uid: root.serviceUid + "/VebusService" }
readonly property VeQuickItem _deviceInstance: VeQuickItem { uid: root.serviceUid + "/VebusInstance" }
Expand Down
2 changes: 1 addition & 1 deletion data/SystemAc.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ QtObject {
property QtObject consumption: QtObject {
property real power: NaN
readonly property real current: phases.count === 1 ? _firstPhaseCurrent : NaN // multi-phase systems don't have a total current
readonly property real maximumCurrent: _maximumCurrent.value === undefined ? NaN : _maximumCurrent.value
readonly property real maximumCurrent: _maximumCurrent.numberValue
property real _firstPhaseCurrent: NaN

property ListModel phases: ListModel {}
Expand Down
2 changes: 1 addition & 1 deletion data/SystemDc.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ QtObject {
property real power: NaN
readonly property real current: (isNaN(power) || isNaN(voltage) || voltage === 0) ? NaN : power / voltage
property real voltage: NaN
readonly property real maximumPower: _maximumDcPower.value === undefined ? NaN : _maximumDcPower.value
readonly property real maximumPower: _maximumDcPower.numberValue

function reset() {
power = NaN
Expand Down
14 changes: 7 additions & 7 deletions data/common/AcData.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ QtObject {

property string bindPrefix

readonly property real voltage: _voltage.value === undefined ? NaN : _voltage.value
readonly property real current: _current.value === undefined ? NaN : _current.value
readonly property real frequency: _frequency.value === undefined ? NaN : _frequency.value
readonly property real voltage: _voltage.numberValue
readonly property real current: _current.numberValue
readonly property real frequency: _frequency.numberValue

// If the power is not reported, calculate the apparent power
readonly property real power: _reportedPower.value !== undefined ? _reportedPower.value
: _apparentPower.value !== undefined ? _apparentPower.value
: _voltage.value !== undefined && _current.value !== undefined ? _voltage.value * _current.value
readonly property real power: _reportedPower.isValid ? _reportedPower.numberValue
: _apparentPower.isValid ? _apparentPower.numberValue
: (_voltage.isValid && _current.isValid) ? _voltage.numberValue * _current.numberValue
: NaN
readonly property int powerUnit: _reportedPower.value !== undefined ? VenusOS.Units_Watt : VenusOS.Units_VoltAmpere
readonly property int powerUnit: _reportedPower.isValid ? VenusOS.Units_Watt : VenusOS.Units_VoltAmpere

property VeQuickItem _voltage: VeQuickItem {
uid: root.bindPrefix ? root.bindPrefix + "/V" : ""
Expand Down
16 changes: 9 additions & 7 deletions data/common/AcInputServiceLoader.qml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ Loader {
id: vebusComponent

QtObject {
readonly property real power: isNaN(_powerValue) ? NaN
readonly property real power: !_power.isValid ? _powerValue // Will be NaN.
: root._feedbackEnabled ? _powerValue
: _powerValue > 0 ? _powerValue // see AcInputs.clampMeasurement().
: 0.0
readonly property real currentLimit: _currentLimit.value === undefined ? NaN : _currentLimit.value
readonly property real _powerValue: _power.value === undefined ? NaN : _power.value
readonly property real currentLimit: _currentLimit.numberValue
readonly property real _powerValue: _power.numberValue

readonly property VeQuickItem _power: VeQuickItem {
uid: root.serviceUid + "/Ac/ActiveIn/P"
Expand All @@ -85,7 +85,7 @@ Loader {
id: multiComponent

QtObject {
readonly property real currentLimit: _currentLimit.value === undefined ? NaN : _currentLimit.value
readonly property real currentLimit: _currentLimit.numberValue

readonly property VeQuickItem _activeInput: VeQuickItem {
uid: root.serviceUid + "/Ac/ActiveIn/ActiveInput"
Expand All @@ -104,9 +104,11 @@ Loader {

QtObject {
readonly property bool _feedbackEnabled: Global.systemSettings.essFeedbackToGridEnabled
readonly property real power: _power.value === undefined ? NaN
: _feedbackEnabled ? _power.value
: Math.max(0, value) // See AcInputs.clampMeasurement().

readonly property real power: isNaN(_power.numberValue) ? _power.numberValue
: _feedbackEnabled ? _power.numberValue
: _power.numberValue > 0 ? _power.numberValue // See AcInputs.clampMeasurement().
: 0

// For these devices, there is no current limit.
readonly property real currentLimit: NaN
Expand Down
2 changes: 1 addition & 1 deletion data/common/AcInputSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ QtObject {
property string serviceUid
property int inputNumber: model.index + 1
readonly property int inputType: isNaN(_type.value) ? -1 : _type.value
readonly property real currentLimit: _currentLimit.value === undefined ? -1 : _currentLimit.value
readonly property real currentLimit: _currentLimit.isValid ? _currentLimit.numberValue : -1
readonly property bool currentLimitAdjustable: _currentLimitAdjustable.value === 1

property VeQuickItem _type: VeQuickItem {
Expand Down
16 changes: 9 additions & 7 deletions data/common/AcInputSystemInfo.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ QtObject {
readonly property string bindPrefix: Global.system.serviceUid + "/Ac/In/" + inputIndex
property bool isActiveInput
readonly property bool connected: _connected.value === 1
readonly property int deviceInstance: _deviceInstance.value === undefined ? -1 : _deviceInstance.value
readonly property int deviceInstance: _deviceInstance.isValid ? _deviceInstance.value : -1
readonly property string serviceType: _serviceType.value || "" // e.g. "vebus"
readonly property string serviceName: _serviceName.value || "" // e.g. com.victronenergy.vebus.ttyO, com.victronenergy.grid.ttyO
readonly property int source: _source.value === undefined ? VenusOS.AcInputs_InputSource_NotAvailable : _source.value
readonly property real minimumCurrent: _minimumCurrent.value === undefined ? NaN
: _feedbackEnabled ? _minimumCurrent.value
: Math.max(0, _minimumCurrent.value) // See AcInputs.clampMeasurement().
readonly property real maximumCurrent: _maximumCurrent.value === undefined ? NaN
: _feedbackEnabled ? _maximumCurrent.value
: Math.max(0, _maximumCurrent.value) // See AcInputs.clampMeasurement().
readonly property real minimumCurrent: !_minimumCurrent.isValid ? _minimumCurrent.numberValue // will be NaN if invalid.
: _feedbackEnabled ? _minimumCurrent.numberValue
: _minimumCurrent.numberValue > 0 ? _minimumCurrent.numberValue // See AcInputs.clampMeasurement().
: 0.0
readonly property real maximumCurrent: !_maximumCurrent.isValid ? _maximumCurrent.numberValue // will be NaN if invalid.
: _feedbackEnabled ? _maximumCurrent.numberValue
: _maximumCurrent.numberValue > 0 ? _maximumCurrent.numberValue // See AcInputs.clampMeasurement().
: 0.0

readonly property bool _feedbackEnabled: Global.systemSettings.essFeedbackToGridEnabled

Expand Down
12 changes: 6 additions & 6 deletions data/common/Battery.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import Victron.VenusOS
Device {
id: battery

readonly property real stateOfCharge: _stateOfCharge.value === undefined ? NaN : _stateOfCharge.value
readonly property real voltage: _voltage.value === undefined ? NaN : _voltage.value
readonly property real power: _power.value === undefined ? NaN : _power.value
readonly property real current: _current.value === undefined ? NaN : _current.value
readonly property real temperature: _temperature.value === undefined ? NaN : _temperature.value
readonly property real timeToGo: _timeToGo.value === undefined ? NaN : _timeToGo.value // in seconds
readonly property real stateOfCharge: _stateOfCharge.numberValue
readonly property real voltage: _voltage.numberValue
readonly property real power: _power.numberValue
readonly property real current: _current.numberValue
readonly property real temperature: _temperature.numberValue
readonly property real timeToGo: _timeToGo.numberValue // in seconds
readonly property string icon: !!Global.batteries ? Global.batteries.batteryIcon(battery) : ""
readonly property int mode: !!Global.batteries ? Global.batteries.batteryMode(battery) : -1

Expand Down
6 changes: 3 additions & 3 deletions data/common/DcDevice.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Victron.VenusOS
Device {
id: dcDevice

readonly property real voltage: _voltage.value === undefined ? NaN : _voltage.value
readonly property real current: _current.value === undefined ? NaN : _current.value
readonly property real power: _power.value === undefined ? NaN : _power.value
readonly property real voltage: _voltage.numberValue
readonly property real current: _current.numberValue
readonly property real power: _power.numberValue

readonly property VeQuickItem _voltage: VeQuickItem {
uid: dcDevice.serviceUid + "/Dc/0/Voltage"
Expand Down
2 changes: 1 addition & 1 deletion data/common/DcInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DcDevice {
id: input

readonly property int inputType: Global.dcInputs.inputType(serviceUid, monitorMode)
readonly property real temperature: _temperature.value === undefined ? NaN : _temperature.value
readonly property real temperature: _temperature.numberValue
readonly property int monitorMode: _monitorMode.value === undefined ? -1 : _monitorMode.value

property bool _completed
Expand Down
4 changes: 2 additions & 2 deletions data/common/EnvironmentInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Victron.VenusOS
Device {
id: input

readonly property real temperature: _temperature.value === undefined ? NaN : _temperature.value
readonly property real humidity: _humidity.value === undefined ? NaN : _humidity.value
readonly property real temperature: _temperature.numberValue
readonly property real humidity: _humidity.numberValue
readonly property int temperatureType: _temperatureType.value === undefined ? -1 : _temperatureType.value

readonly property VeQuickItem _temperature: VeQuickItem {
Expand Down
23 changes: 8 additions & 15 deletions data/common/EvCharger.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,16 @@ Device {
readonly property bool connected: _connected.value === 1
readonly property int chargingTime: _chargingTime.value || 0

readonly property real energy: _energy.value === undefined ? NaN : _energy.value
readonly property real power: _power.value === undefined ? NaN : _power.value
readonly property real current: _current.value === undefined ? NaN : _current.value
readonly property real maxCurrent: _maxCurrent.value === undefined ? NaN : _maxCurrent.value
readonly property real energy: _energy.numberValue
readonly property real power: _power.numberValue
readonly property real current: _current.numberValue
readonly property real maxCurrent: _maxCurrent.numberValue

readonly property ListModel phases: ListModel {
function setPower(index, value) {
if (index >= 0 && index < count) {
setProperty(index, "power", value === undefined ? NaN : value)
}
}

Component.onCompleted: {
const properties = [_phase1Power, _phase2Power, _phase3Power]
for (let i = 0; i < properties.length; ++i) {
const v = properties[i].value
append({ name: "L" + (i + 1), power: v === undefined ? NaN : v })
append({ name: "L" + (i + 1), power: properties[i].numberValue })
}
}
}
Expand All @@ -41,15 +34,15 @@ Device {

readonly property VeQuickItem _phase1Power: VeQuickItem {
uid: evCharger.serviceUid + "/Ac/L1/Power"
onValueChanged: phases.setPower(0, value)
onValueChanged: if (phases.count > 0) phases.setProperty(0, "power", numberValue)
}
readonly property VeQuickItem _phase2Power: VeQuickItem {
uid: evCharger.serviceUid + "/Ac/L2/Power"
onValueChanged: phases.setPower(1, value)
onValueChanged: if (phases.count > 1) phases.setProperty(1, "power", numberValue)
}
readonly property VeQuickItem _phase3Power: VeQuickItem {
uid: evCharger.serviceUid + "/Ac/L3/Power"
onValueChanged: phases.setPower(2, value)
onValueChanged: if (phases.count > 2) phases.setProperty(2, "power", numberValue)
}

readonly property VeQuickItem _power: VeQuickItem {
Expand Down
2 changes: 1 addition & 1 deletion data/common/InverterCharger.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Device {
readonly property int state: _state.value === undefined ? -1 : _state.value
readonly property int mode: _mode.value === undefined ? -1 : _mode.value
readonly property bool modeAdjustable: _modeAdjustable.value !== undefined && _modeAdjustable.value > 0
readonly property real nominalInverterPower: _nominalInverterPower.value === undefined ? NaN : _nominalInverterPower.value
readonly property real nominalInverterPower: _nominalInverterPower.numberValue

readonly property int numberOfAcInputs: _numberOfAcInputs.value === undefined ? NaN : _numberOfAcInputs.value
readonly property bool hasPassthroughSupport: _hasPassthroughSupport.value === 1
Expand Down
2 changes: 1 addition & 1 deletion data/common/MeteoDevice.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Victron.VenusOS
Device {
id: meteoDevice

readonly property real irradiance: _irradiance.value === undefined ? NaN : _irradiance.value
readonly property real irradiance: _irradiance.numberValue

readonly property VeQuickItem _irradiance: VeQuickItem {
uid: meteoDevice.serviceUid + "/Irradiance"
Expand Down
2 changes: 1 addition & 1 deletion data/common/MotorDrive.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Victron.VenusOS
Device {
id: motorDrive

readonly property real motorRpm: _motorRpm.value === undefined ? NaN : _motorRpm.value
readonly property real motorRpm: _motorRpm.numberValue

readonly property VeQuickItem _motorRpm: VeQuickItem {
uid: motorDrive.serviceUid + "/Motor/RPM"
Expand Down
8 changes: 4 additions & 4 deletions data/common/PvInverter.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Device {
readonly property int statusCode: _statusCode.value === undefined ? -1 : _statusCode.value
readonly property int errorCode: _errorCode.value === undefined ? -1 : _errorCode.value

readonly property real energy: _energy.value === undefined ? NaN : _energy.value
readonly property real current: phases.count === 1 && _current.value !== undefined ? _current.value : NaN // multi-phase systems don't have a total current
readonly property real power: _power.value === undefined ? NaN : _power.value
readonly property real voltage: _voltage.value === undefined ? NaN : _voltage.value
readonly property real energy: _energy.numberValue
readonly property real current: phases.count === 1 ? _current.numberValue : NaN // multi-phase systems don't have a total current
readonly property real power: _power.numberValue
readonly property real voltage: _voltage.numberValue

readonly property ListModel phases: ListModel {
function setPhaseProperty(phaseName, propertyName, value) {
Expand Down
8 changes: 4 additions & 4 deletions data/common/SolarCharger.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Device {
readonly property int state: _state.value === undefined ? -1 : _state.value
readonly property int errorCode: _errorCode.value === undefined ? -1 : _errorCode.value
readonly property ListModel trackers: ListModel {}
readonly property real power: _totalPower.value === undefined ? NaN : _totalPower.value
readonly property real power: _totalPower.numberValue
readonly property alias history: _history

readonly property real batteryVoltage: _batteryVoltage.value == undefined ? NaN : _batteryVoltage.value
readonly property real batteryCurrent: _batteryCurrent.value == undefined ? NaN : _batteryCurrent.value
readonly property real batteryTemperature: _batteryTemperature.value == undefined ? NaN : _batteryTemperature.value
readonly property real batteryVoltage: _batteryVoltage.numberValue
readonly property real batteryCurrent: _batteryCurrent.numberValue
readonly property real batteryTemperature: _batteryTemperature.numberValue

readonly property bool relayValid: _relay.value !== undefined
readonly property bool relayOn: _relay.value === 1
Expand Down
18 changes: 9 additions & 9 deletions data/common/SolarDailyHistory.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ QtObject {
// Prefix is: com.victronenergy.solarcharger.tty0/History/Daily/<day>
property string uidPrefix

readonly property real yieldKwh: _yieldKwh.value == undefined ? NaN : _yieldKwh.value
readonly property real maxPower: _maxPower.value == undefined ? NaN : _maxPower.value
readonly property real maxPvVoltage: _maxPvVoltage.value == undefined ? NaN : _maxPvVoltage.value
readonly property real yieldKwh: _yieldKwh.numberValue
readonly property real maxPower: _maxPower.numberValue
readonly property real maxPvVoltage: _maxPvVoltage.numberValue

readonly property real timeInFloat: _timeInFloat.value == undefined ? NaN : _timeInFloat.value
readonly property real timeInAbsorption: _timeInAbsorption.value == undefined ? NaN : _timeInAbsorption.value
readonly property real timeInBulk: _timeInBulk.value == undefined ? NaN : _timeInBulk.value
readonly property real timeInFloat: _timeInFloat.numberValue
readonly property real timeInAbsorption: _timeInAbsorption.numberValue
readonly property real timeInBulk: _timeInBulk.numberValue

readonly property real minBatteryVoltage: _minBatteryVoltage.value == undefined ? NaN : _minBatteryVoltage.value
readonly property real maxBatteryVoltage: _maxBatteryVoltage.value == undefined ? NaN : _maxBatteryVoltage.value
readonly property real maxBatteryCurrent: _maxBatteryCurrent.value == undefined ? NaN : _maxBatteryCurrent.value
readonly property real minBatteryVoltage: _minBatteryVoltage.numberValue
readonly property real maxBatteryVoltage: _maxBatteryVoltage.numberValue
readonly property real maxBatteryCurrent: _maxBatteryCurrent.numberValue

property SolarHistoryErrorModel errorModel: SolarHistoryErrorModel {
uidPrefix: root.uidPrefix
Expand Down
Loading

0 comments on commit 11480f0

Please sign in to comment.