Commit 79c2de26 authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Use the new dialog for replacing missing sensors

When a page is missing sensors, it may end up not displaying correctly.
This can happen because we have certain sensors that are bound to
physical hardware, which disappear or do not exist when we use a page
from the store.

Rather than trying to do a difficult (probably impossible) mapping
between sensors or trying to prevent uploading pages with
hardware-dependent sensors, provide a UI so this situation can be
resolved by the user.
parent 9bae791a
Pipeline #190982 passed with stage
in 1 minute and 27 seconds
......@@ -17,6 +17,12 @@ Container {
property PageDataObject columnData
function replaceSensors(replacement) {
for (let i = 0; i < repeater.count; ++i) {
repeater.itemAt(i).replaceSensors(replacement)
}
}
Kirigami.AbstractCard {
parent: control.background
anchors.fill: parent
......@@ -100,6 +106,7 @@ Container {
onAddSeparator: control.addSeparator(index + 1)
onRemove: control.columnData.removeChild(index)
onMove: control.columnData.moveChild(from, to)
onMissingSensorsChanged: control.missingSensorsChanged(id, title, sensors)
}
}
......
......@@ -222,6 +222,18 @@ Kirigami.ScrollablePage {
}
}
DialogLoader {
id: missingSensorsDialog
sourceComponent: MissingSensorsDialog {
missingSensors: contentLoader.item ? contentLoader.item.missingSensors : []
onSensorReplacementChanged: {
contentLoader.item.replaceSensors(sensorReplacement)
}
}
}
Rectangle {
id: loadOverlay
......@@ -265,5 +277,13 @@ Kirigami.ScrollablePage {
loadOverlay.opacity = 0
}
}
Connections {
target: contentLoader.item
function onShowMissingSensors() {
missingSensorsDialog.open()
}
}
}
}
......@@ -18,6 +18,23 @@ Container {
property alias dataObject: loader.dataObject
function replaceSensors(replacement) {
let changed = false
for (let entry of replacement) {
if (entry.face != dataObject.face) {
continue
}
loader.controller.replaceSensors(entry.sensor, entry.replacement)
changed = true
}
if (changed) {
loader.controller.reloadConfig()
}
}
topPadding: 0
bottomPadding: 0
leftPadding: 0
......
......@@ -21,6 +21,29 @@ ColumnLayout {
property var actionsFace
property var missingSensors: []
property var faceMapping: new Object()
signal showMissingSensors()
function replaceSensors(replacement) {
if (!replacement) {
return
}
missingSensors = []
let modifiedControllers = []
for (let entry of replacement) {
let controller = faceMapping[entry.face].controller
controller.replaceSensors(entry.sensor, entry.replacement)
modifiedControllers.push(controller)
}
for (let c of modifiedControllers) {
c.reloadConfig()
}
}
spacing: rowSpacing // From parent Loader
......@@ -76,6 +99,11 @@ ColumnLayout {
type: Kirigami.MessageType.Error
text: i18n("This page is missing some sensors and will not display correctly.");
actions: Kirigami.Action {
icon.name: "document-edit"
text: i18nc("@action:button", "Fix…")
onTriggered: root.showMissingSensors()
}
}
Repeater {
......@@ -235,6 +263,10 @@ ColumnLayout {
}
root.missingSensorsChanged()
}
Component.onCompleted: {
root.faceMapping[modelData.data.face] = loader
}
}
Component.onCompleted: {
......
......@@ -21,6 +21,8 @@ Column {
property var actionsFace
property var missingSensors: []
signal showMissingSensors()
spacing: rowSpacing // From parent loader
move: Transition {
......@@ -104,6 +106,18 @@ Column {
missingSensorsChanged()
}
function replaceSensors(replacement) {
if (!replacement) {
return
}
missingSensors = []
for (let i = 0; i < repeater.count; ++i) {
repeater.itemAt(i).replaceSensors(replacement)
}
}
onWidthChanged: Qt.callLater(relayout)
onHeightChanged: Qt.callLater(relayout)
......@@ -116,6 +130,11 @@ Column {
type: Kirigami.MessageType.Error
text: i18n("This page is missing some sensors and will not display correctly.");
actions: Kirigami.Action {
icon.name: "document-edit"
text: i18nc("@action:button", "Fix…")
onTriggered: root.showMissingSensors()
}
}
Repeater {
......@@ -146,6 +165,7 @@ Column {
onRemove: pageData.removeChild(index)
onMove: pageData.moveChild(from, to)
onMissingSensorsChanged: root.updateMissingSensors(id, title, sensors)
}
}
......
......@@ -56,6 +56,12 @@ Container {
minimumHeight = minHeight + control.topPadding + control.bottomPadding
}
function replaceSensors(replacement) {
for (let i = 0; i < repeater.count; ++i) {
repeater.itemAt(i).replaceSensors(replacement)
}
}
onTopPaddingChanged: Qt.callLater(updateMinimumHeight)
onBottomPaddingChanged: Qt.callLater(updateMinimumHeight)
......@@ -111,6 +117,7 @@ Container {
onSelect: control.select(item)
onRemove: control.rowData.removeChild(index)
onMove: control.rowData.moveChild(from, to)
onMissingSensorsChanged: control.missingSensorsChanged(id, title, sensors)
}
}
......
......@@ -20,6 +20,10 @@ Container {
signal addSection()
signal addSeparator()
function replaceSensors(replacement) {
contentItem.replaceSensors(replacement)
}
implicitWidth: (sectionData.isSeparator ? toolbar.Layout.minimumWidth : 0) + leftPadding + rightPadding
Kirigami.Separator {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment