victronenergy / gui-v2

Other
24 stars 9 forks source link

Rework Device List model and delegates #1339

Open blammit opened 2 months ago

blammit commented 2 months ago

DeviceListPage should be reworked so that it:

We could load delegates in this manner:

  1. For each service type, create pages/settings/devicelist/delegates/DeviceListDelegate_<service-type>.qml.
  2. The DeviceListPage ListView has a delegate that is a Loader, that loads the correct delegate URI based on the service type.
  3. Have a base item DeviceListDelegate that can be extended for each delegate type.

This architecture will also make it easier to:

In terms of the model, that can be a VeQItemModel or similar that provides the required uids.

Example:

// DeviceListPage.qml
ListView {
    delegate: Loader {
        required property string uid
        Component.onCompleted: {
            const serviceType = BackendConnection.serviceTypeFromUid(uid)
            const uri = "/pages/settings/devicelist/delegates/DeviceListDelegate_%1.qml".arg(serviceType)
            setSource(uri, { serviceUid: uid } })
        }
    }
}

// DeviceListDelegate.qml
ListItem {
    required property string serviceUid
    readonly property Device device: Device { uid: serviceUid }

    text: device.name

    ListPressArea {
        anchors.fill: parent
        onClicked: Global.pageManager.pushPage(_displayInfo.url, _displayInfo.params)
    }
}

// DeviceListDelegate_vebus.qml
DeviceListDelegate {
    id: root

    content.children: [
        Label {
            text: Global.system.systemStateToText(state.value)
        }
    ]

    VeQuickItem {
        id: state
        uid: root.serviceUid + "/State"
    }
}
blammit commented 2 weeks ago

Note: this is a prerequisite for implementing https://github.com/victronenergy/gui-v2/issues/1400.