C

Vehicle Properties Browser

Presents an editable list of available properties grouped by component using QML models.

"QtAA Vehicle Properties Browser Example Screenshot"

The example presents a list of available properties from the Vehicle Properties module. The properties are grouped by module, for example: HVAC, WindowControl and so on.

The first thing to do when using vehicle properties in QML is to import the Qt Vehicle Properties Module:

import QtIf.Android.VehicleProperties 1.0

The example provides two-way communication between the application and Android VHAL. Property modifications made to the app are visible in the Android VHAL. The reverse is true as well: changes made the Android VHAL are immediately reflected in the app. The available properties and the required metadata are collected under a single property defined in PropertiesModelDefinition.qml:

    readonly property var modulesModelData: [
        {
            name: 'QIfHvac',
            object: climateControl,
            properties: [
                {
                    name: 'powerOn',
                    property_id: 'HVAC_POWER_ON'
                },
                {
                    name: 'acOn',
                    property_id: 'HVAC_AC_ON'
                },
                {
                    name: 'maxAcOn',
                    property_id: 'HVAC_MAX_AC_ON'
                },
                {
                    name: 'dualOn',
                    property_id: 'HVAC_DUAL_ON'
                },
                {
                    name: 'autoOn',
                    property_id: 'HVAC_AUTO_ON'
                },
                {
                    name: 'fanDirection',
                    property_id: 'HVAC_FAN_DIRECTION',
                    values: ['FACE', 'FLOOR', 'DEFROST']
                },
                {
                    name: 'fanSpeed',
                    property_id: 'HVAC_FAN_SPEED'
                },
                {
                    name: 'recircOn',
                    property_id: 'HVAC_RECIRC_ON'
                },
                {
                    name: 'autoRecircOn',
                    property_id: 'HVAC_AUTO_RECIRC_ON'
                }
            ]
        },
        {
            name: 'QIfWindowControl',
            object: windowControl,
            properties: [
                {
                    name: 'windowLock',
                    property_id: 'WINDOW_LOCK',
                    readonly: true
                }
            ]
        }
    ]

Each top-level entry provides metadata for a single Vehicle Properties component and its properties. The instances of the components declared in the same file are also referenced through the object field.

    HVAC {
        id: climateControl
    }

    WindowControl {
        id: windowControl
    }

To create the QML model PropertiesModel.qml uses the properties' metadata and the component instances, defined in PropertiesModelDefinition.qml. Additionally, PropertiesModel.qml uses the Instantiator to create any bindings necessary to update the QML model whenever the data model of Android VHAL has changed:

    Instantiator {
        id: syncingInstantiator

        model: listModel

        delegate: Instantiator {
            id: propertiesInstantiator

            readonly property int moduleIndex: index

            model: properties

            delegate: Instantiator {
                id: zonesInstantiator

                model: zones
                readonly property string propertyName: name

                delegate: QtObject {
                    readonly property var propertyValue: {
                        const module = definitions.modulesModelData[moduleIndex]
                        const object = module.object
                        const zonedObject = internal.resolveZone(object, zone)

                        return zonedObject[zonesInstantiator.propertyName]
                    }

                    onPropertyValueChanged: {
                        zones.get(index).valueWrapper = { value: propertyValue }
                    }
                }
            }
        }
    }

Altering properties from the application level is possible using the following method:

    function updateProperty(moduleIndex, propertyIndex, zoneIndex, value) {
        const module = definitions.modulesModelData[moduleIndex]
        const property = module.properties[propertyIndex]
        const zones = property.zones || []
        const moduleObject = module.object
        const zonedObject = internal.resolveZone(moduleObject,
                                                 zones[zoneIndex] || '')
        zonedObject[property.name] = value
    }

The user interface consists of two components based on ListView: ModulesList and PropertiesList. These use the provided QML model. Finally, the visual representation of the property is rendered by ValueDelegate component which provides the appropriate controls depending on the property type and other metadata.

Known issues and limitations

Currently, the range of properties handled in this example is limited due to a bug in the Vehicle Properties module. When they are resolved, the application will be extended with the missing properties.

See also Qt IF Android Vehicle Properties Module, Qt for Android, and Qt IF.

Available under certain Qt licenses.
Find out more.