Skip to content

Commit

Permalink
Destroy closed dialogs
Browse files Browse the repository at this point in the history
- Move QML component handling outside the pages that show dialogs
  • Loading branch information
jpetrell committed Feb 8, 2024
1 parent 76fd1e7 commit 361abf2
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 129 deletions.
8 changes: 2 additions & 6 deletions components/InverterModeDialogLauncher.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ QtObject {
? Global.inverterChargers.inverterChargerModeToText(_modeItem.value)
: Global.inverterChargers.inverterModeToText(_modeItem.value)

property var _modeDialog

property VeQuickItem _isInverterChargerItem: VeQuickItem {
uid: root.serviceUid + "/IsInverterCharger"
}
Expand All @@ -40,12 +38,10 @@ QtObject {
function openDialog() {
if (!_modeDialog) {
if (_isInverterChargerItem.value === 1) {
_modeDialog = _inverterChargerModeDialogComponent.createObject(Global.dialogLayer)
Global.dialogLayer.open(_inverterChargerModeDialogComponent)
} else {
_modeDialog = _inverterModeDialogComponent.createObject(Global.dialogLayer)
Global.dialogLayer.open(_inverterModeDialogComponent)
}
}
_modeDialog.mode = _modeItem.value
_modeDialog.open()
}
}
7 changes: 2 additions & 5 deletions components/SolarHistoryChart.qml
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,8 @@ Item {
height: parent.height

onClicked: {
if (!root._dailyHistoryDialog) {
root._dailyHistoryDialog = dailyHistoryDialogComponent.createObject(Global.dialogLayer)
}
root._dailyHistoryDialog.day = yieldModel.dayRange[0] + model.index
root._dailyHistoryDialog.open()
Global.dialogLayer.open(dailyHistoryDialogComponent,
{day: yieldModel.dayRange[0] + model.index})
}

Rectangle {
Expand Down
10 changes: 1 addition & 9 deletions components/listitems/ListDateSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@ ListButton {
// data value is assumed to be in seconds
property var date: dataItem.isValid ? new Date(dataItem.value * 1000) : null

property var _dateSelector

button.text: date == null ? "--" : Qt.formatDate(date, "yyyy-MM-dd")
enabled: dataItem.uid === "" || dataItem.isValid

onClicked: {
if (!_dateSelector) {
_dateSelector = dateSelectorComponent.createObject(Global.dialogLayer)
}
_dateSelector.date = date
_dateSelector.open()
}
onClicked: Global.dialogLayer.open(dateSelectorComponent, {date: date})

Component {
id: dateSelectorComponent
Expand Down
8 changes: 1 addition & 7 deletions components/listitems/ListSpinBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ ListButton {
button.text: value === undefined ? "--" : value.toFixed(decimals) + root.suffix
enabled: dataItem.uid === "" || dataItem.isValid

onClicked: {
if (!_numberSelector) {
_numberSelector = numberSelectorComponent.createObject(Global.dialogLayer)
}
_numberSelector.value = value
_numberSelector.open()
}
onClicked: Global.dialogLayer.open(numberSelectorComponent, {value: value})

Component {
id: numberSelectorComponent
Expand Down
11 changes: 1 addition & 10 deletions components/listitems/ListTimeSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,10 @@ ListButton {
// total value, in seconds (data value is assumed to be in seconds)
property real value: !dataItem.isValid ? 0 : dataItem.value

property var _timeSelector

button.text: hour < 0 || minute < 0 ? "--" : ClockTime.formatTime(hour, minute)
enabled: dataItem.uid === "" || dataItem.isValid

onClicked: {
if (!_timeSelector) {
_timeSelector = timeSelectorComponent.createObject(Global.dialogLayer)
}
_timeSelector.hour = hour
_timeSelector.minute = minute
_timeSelector.open()
}
onClicked: Global.dialogLayer.open(timeSelectorComponent, {hour: hour, minute: minute})

Component {
id: timeSelectorComponent
Expand Down
30 changes: 6 additions & 24 deletions pages/DialogLayer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,13 @@ import Victron.VenusOS
Item {
id: root

property ModalWarningDialog _rebootDialog

function showRebootDialog() {
if (!_rebootDialog) {
_rebootDialog = rebootDialogComponent.createObject(root)
}
_rebootDialog.open()
function open(dialogComponent, properties) {
const dialog = dialogComponent.createObject(Global.dialogLayer, properties)
dialog.closed.connect(function() {
dialog.destroy()
})
dialog.open()
}

anchors.fill: parent

Component {
id: rebootDialogComponent

ModalWarningDialog {
title: BackendConnection.type === BackendConnection.DBusSource
//% "Rebooting..."
? qsTrId("dialoglayer_rebooting")
//% "Device has been rebooted."
: qsTrId("dialoglayer_rebooted")

// On device, dialog cannot be dismissed; just wait until device is rebooted.
dialogDoneOptions: VenusOS.ModalDialog_DoneOptions_OkOnly
footer.enabled: BackendConnection.type !== BackendConnection.DBusSource
footer.opacity: footer.enabled ? 1 : 0
}
}
}
9 changes: 1 addition & 8 deletions pages/controlcards/ESSCard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,14 @@ ControlCard {
ButtonControlValue {
id: minimumSocRow

property var _minSocDialog

//% "Minimum SOC"
label.text: qsTrId("ess_card_minimum_soc")
//: State of charge as a percentage value
//% "%1%"
button.text: qsTrId("ess_card_minimum_soc_value").arg(Global.ess.minimumStateOfCharge)
separator.visible: warningRow.visible

onClicked: {
if (!_minSocDialog) {
_minSocDialog = minSocDialogComponent.createObject(Global.dialogLayer)
}
_minSocDialog.open()
}
onClicked: Global.dialogLayer.open(minSocDialogComponent)

Component {
id: minSocDialogComponent
Expand Down
17 changes: 3 additions & 14 deletions pages/controlcards/GeneratorCard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ ControlCard {
root.generator.setAutoStart(false)
} else {
// check if they really want to disable
if (!autostartSwitch._confirmationDialog) {
autostartSwitch._confirmationDialog = confirmationDialogComponent.createObject(Global.dialogLayer)
}
autostartSwitch._confirmationDialog.open()
Global.dialogLayer.open(confirmationDialogComponent)
}
}
}
Expand Down Expand Up @@ -97,8 +94,6 @@ ControlCard {
Button {
id: startStopButton

property GeneratorStartDialog _startDialog
property GeneratorStopDialog _stopDialog
property int _generatorStateBeforeDialogOpen: -1

anchors {
Expand Down Expand Up @@ -131,15 +126,9 @@ ControlCard {
onClicked: {
_generatorStateBeforeDialogOpen = root.generator.state
if (root.generator.state === VenusOS.Generators_State_Running) {
if (!_stopDialog) {
_stopDialog = generatorStopDialogComponent.createObject(Global.dialogLayer)
}
_stopDialog.open()
Global.dialogLayer.open(generatorStopDialogComponent)
} else {
if (!_startDialog) {
_startDialog = generatorStartDialogComponent.createObject(Global.dialogLayer)
}
_startDialog.open()
Global.dialogLayer.open(generatorStartDialogComponent)
}
}

Expand Down
5 changes: 1 addition & 4 deletions pages/settings/PageSettingsDisplay.qml
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,12 @@ Page {
popDestination: undefined // don't pop page automatically.
updateOnClick: false // handle option clicked manually.

property var pleaseWaitDialog

onOptionClicked: function(index) {
// The SystemSettings data point listener will trigger retranslateUi()
// It may take a few seconds for the backend to deliver the value
// change to the other data point. So, display a message to the user.
languageDataItem.setValue(Language.toCode(optionModel.languageAt(index)))
pleaseWaitDialog = changingLanguageDialog.createObject(Global.dialogLayer)
pleaseWaitDialog.open()
Global.dialogLayer.open(changingLanguageDialog)
}

LanguageModel {
Expand Down
19 changes: 18 additions & 1 deletion pages/settings/PageSettingsGeneral.qml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,24 @@ Page {
writeAccessLevel: VenusOS.User_AccessType_User
onClicked: {
Global.venusPlatform.reboot()
Global.dialogLayer.showRebootDialog()
Global.dialogLayer.open(rebootDialogComponent)
}

Component {
id: rebootDialogComponent

ModalWarningDialog {
title: BackendConnection.type === BackendConnection.DBusSource
//% "Rebooting..."
? qsTrId("dialoglayer_rebooting")
//% "Device has been rebooted."
: qsTrId("dialoglayer_rebooted")

// On device, dialog cannot be dismissed; just wait until device is rebooted.
dialogDoneOptions: VenusOS.ModalDialog_DoneOptions_OkOnly
footer.enabled: BackendConnection.type !== BackendConnection.DBusSource
footer.opacity: footer.enabled ? 1 : 0
}
}
}

Expand Down
9 changes: 1 addition & 8 deletions pages/settings/PageSettingsHub4.qml
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,13 @@ Page {
ListButton {
id: minSocLimit

property var _minSocDialog

//% "Minimum SOC (unless grid fails)"
text: qsTrId("settings_ess_min_soc")
button.text: Global.ess.minimumStateOfCharge + "%"
visible: defaultVisible
&& essMode.value !== VenusOS.Ess_Hub4ModeState_Disabled
&& batteryLifeState.dataItem.value !== VenusOS.Ess_BatteryLifeState_KeepCharged
onClicked: {
if (!_minSocDialog) {
_minSocDialog = minSocDialogComponent.createObject(Global.dialogLayer)
}
_minSocDialog.open()
}
onClicked: Global.dialogLayer.open(minSocDialogComponent)

Component {
id: minSocDialogComponent
Expand Down
8 changes: 1 addition & 7 deletions pages/settings/PageSettingsTcpIp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Page {
readonly property bool _wifi: technologyType === "wifi"
property string _agentPath: "/com/victronenergy/ccgx"
property CmAgent _agent
property var _forgetNetworkDialog

function _getIpv4Property(name) {
if (!service) {
Expand Down Expand Up @@ -171,12 +170,7 @@ Page {
button.text: qsTrId("settings_tcpip_forget")
visible: root.service && root._wifi && root.service.favorite
writeAccessLevel: VenusOS.User_AccessType_User
onClicked: {
if (!root._forgetNetworkDialog) {
root._forgetNetworkDialog = forgetNetworkDialogComponent.createObject(Global.dialogLayer)
}
root._forgetNetworkDialog.open()
}
onClicked: Global.dialogLayer.open(forgetNetworkDialogComponent)

Component {
id: forgetNetworkDialogComponent
Expand Down
6 changes: 1 addition & 5 deletions pages/settings/PageSettingsWifiWithAccessPoint.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Page {
id: root

property CmTechnology _tech: Connman.getTechnology("wifi")
property var _confirmApDialog

GradientListView {
id: settingsListView
Expand All @@ -24,10 +23,7 @@ Page {

onClicked: {
if (checked) {
if (!root._confirmApDialog) {
root._confirmApDialog = confirmApDialogComponent.createObject(Global.dialogLayer)
}
root._confirmApDialog.open()
Global.dialogLayer.open(confirmApDialogComponent)
} else {
accessPoint.setValue(1)
}
Expand Down
8 changes: 1 addition & 7 deletions pages/settings/PageTzInfo.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Page {
id: root

property var _timeZoneModels: [ tzAfrica, tzAmerica, tzAntartica, tzArtic, tzAsia, tzAtlantic, tzAustralia, tzEurope, tzIndian, tzPacific, tzEtc ]
property var _timeSelector

function _findTimeZoneName(region, city) {
if (city === "UTC") {
Expand All @@ -32,13 +31,8 @@ Page {
}

function _openTimeSelector() {
if (!_timeSelector) {
_timeSelector = timeSelectorComponent.createObject(Global.dialogLayer)
}
const dt = ClockTime.currentDateTime
_timeSelector.hour = dt.getHours()
_timeSelector.minute = dt.getMinutes()
_timeSelector.open()
Global.dialogLayer.open(timeSelectorComponent, {hour: dt.getHours(), minute: dt.getMinutes()})
}

// Ensure time is up-to-date while this page is open.
Expand Down
9 changes: 1 addition & 8 deletions pages/settings/devicelist/battery/PageBatterySettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,12 @@ Page {
}

ListButton {
property var _confirmationDialog

//% "Restore factory defaults"
text: qsTrId("batterysettings_restore_factory_defaults")
//% "Press to restore"
secondaryText: qsTrId("batterysettings_press_to_restore")
visible: defaultVisible && restoreDefaults.isValid
onClicked: {
if (!_confirmationDialog) {
_confirmationDialog = confirmationDialogComponent.createObject(Global.dialogLayer)
}
_confirmationDialog.open()
}
onClicked: Global.dialogLayer.open(confirmationDialogComponent)

Component {
id: confirmationDialogComponent
Expand Down
7 changes: 1 addition & 6 deletions pages/vebusdevice/VeBusDeviceModeButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Loader {

property var veBusDevice
readonly property bool isMulti: veBusDevice.numberOfAcInputs > 0
property var _modeDialog

//% "This setting is disabled when a Digital Multi Control is connected."
readonly property string noAdjustableByDmc: qsTrId("vebus_no_adjustable_by_dmc")
Expand Down Expand Up @@ -53,11 +52,7 @@ Loader {
return
}

if (!_modeDialog) {
_modeDialog = modeDialogComponent.createObject(Global.dialogLayer)
}
_modeDialog.mode = root.veBusDevice.mode
_modeDialog.open()
Global.dialogLayer.open(modeDialogComponent, {mode: root.veBusDevice.mode})
}
}

Expand Down

0 comments on commit 361abf2

Please sign in to comment.