C
车辆属性浏览器
使用 QML 模型按组件分组显示可用的属性的可编辑列表。
构建和部署示例
请参阅有关构建和部署 Qt for Android Automotive 示例的具体步骤。
概述
该示例展示了一个来自车辆属性库的可用属性列表。属性根据QFace
模块分组,例如:HVAC
、WindowControl
等。
在使用 QML 中的车辆属性时,首先要做的是导入 Qt 车辆属性前端
import QtIf.Android.VehicleProperties
通信
该示例提供了应用程序和 Android VHAL 之间的双向通信。对应用程序所做的属性修改在 Android VHAL 中可见。反之亦然:在 Android VHAL 中所做的更改将立即反映在应用程序中。可用的属性和所需的元数据都收集在一个在 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: 'temperatureSet', property_id: 'HVAC_TEMPERATURE_SET', zones: ['DriverSide', 'PassengerSide'] }, { name: 'fanDirection', property_id: 'HVAC_FAN_DIRECTION', values: ['FACE', 'FLOOR', 'DEFROST'] }, { name: 'fanSpeed', property_id: 'HVAC_FAN_SPEED' }, { name: 'defroster', property_id: 'HVAC_DEFROSTER', zones: ['FrontWindshield', 'RearWindshield'] }, { name: 'recircOn', property_id: 'HVAC_RECIRC_ON' }, { name: 'autoRecircOn', property_id: 'HVAC_AUTO_RECIRC_ON' }, { name: 'seatVentilation', property_id: 'HVAC_SEAT_VENTILATION', zones: [ 'Driver', 'Passenger' ] }, { name: 'maxDefrostOn', property_id: 'HVAC_MAX_DEFROST_ON' }, { name: 'seatTemperature', property_id: 'HVAC_SEAT_TEMPERATURE', zones: [ 'Driver', 'Passenger' ] }, { name: 'steeringWheelHeat', property_id: 'HVAC_STEERING_WHEEL_HEAT', zones: [ 'Global' ] }, { name: 'temperatureDisplayUnits', property_id: 'HVAC_TEMPERATURE_DISPLAY_UNITS', values: ['CELSIUS', 'FAHRENHEIT'], zones: [ 'Global' ], exclusive: true } ] }, { name: 'QIfWindowControl', object: windowControl, properties: [ { name: 'windowPos', property_id: 'WINDOW_POS', zones: [ 'Driver', 'Passenger', 'PassengerRow2Left', 'PassengerRow2Right', 'Roof1' ] }, { name: 'windowLock', property_id: 'WINDOW_LOCK', readonly: true } ] }, { name: 'QIfCarInfo', object: carInfo, properties: [ { name: 'infoFuelCapacity', property_id: 'INFO_FUEL_CAPACITY', readonly: true }, { name: 'infoEvBatteryCapacity', property_id: 'INFO_EV_BATTERY_CAPACITY', readonly: true }, { name: 'infoFuelDoorLocation', property_id: 'INFO_FUEL_DOOR_LOCATION', readonly: true }, { name: 'infoEvPortLocation', property_id: 'INFO_EV_PORT_LOCATION', readonly: true }, { name: 'infoDriverSeat', property_id: 'INFO_DRIVER_SEAT', readonly: true } ] }, { name: 'QIfTireControl', object: tireControl, properties: [ { name: 'tirePressure', property_id: 'TIRE_PRESSURE', zones: [ 'RightFront', 'LeftFront', 'RightRear', 'LeftRear' ], readonly: true } ] }, { name: 'QIfLightsControl', object: lightsControl, properties: [ { name: 'headlightsState', property_id: 'HEADLIGHTS_STATE', readonly: true }, { name: 'highbeamLightsState', property_id: 'HIGH_BEAM_LIGHTS_STATE', readonly: true }, { name: 'fogLightsState', property_id: 'FOG_LIGHTS_STATE', readonly: true }, { name: 'hazardLightsState', property_id: 'HAZARD_LIGHTS_STATE', readonly: true }, { name: 'headlightsSwitch', property_id: 'HEADLIGHTS_SWITCH', readonly: false }, { name: 'highbeamLightsSwitch', property_id: 'HIGH_BEAM_LIGHTS_SWITCH', readonly: false }, { name: 'fogLightsSwitch', property_id: 'FOG_LIGHTS_SWITCH', readonly: false }, { name: 'hazardLightsSwitch', property_id: 'HAZARD_LIGHTS_SWITCH', readonly: false }, { name: 'nightMode', property_id: 'NIGHT_MODE', readonly: true } ] }, { name: 'QIfFuelControl', object: fuelControl, properties: [ { name: 'fuelLevel', property_id: 'FUEL_LEVEL', readonly: true }, { name: 'fuelLevelLow', property_id: 'FUEL_LEVEL_LOW', readonly: true }, { name: 'fuelDoorOpen', property_id: 'FUEL_DOOR_OPEN', readonly: false }, { name: 'evBatteryInstantaneousChargeRate', property_id: 'EV_BATTERY_INSTANTANEOUS_CHARGE_RATE', readonly: true }, { name: 'evBatteryLevel', property_id: 'EV_BATTERY_LEVEL', readonly: true }, { name: 'evChargePortConnected', property_id: 'EV_CHARGE_PORT_CONNECTED', readonly: true }, { name: 'evChargePortOpen', property_id: 'EV_CHARGE_PORT_OPEN', readonly: true }, { name: 'rangeRemaining', property_id: 'RANGE_REMAINING', readonly: true } ] }, { name: 'QIfDoorControl', object: doorControl, properties: [ { name: 'doorPos', property_id: 'DOOR_POS', zones:['Row1Left', 'Row1Right', 'Row2Left', 'Row2Right', 'Rear'], readonly: false }, { name: 'doorLock', zones:['Row1Left', 'Row1Right', 'Row2Left', 'Row2Right'], property_id: 'DOOR_LOCK', readonly: false } ] }, { name: 'QIfDriveInfo', object: driveInfo, properties: [ { name: 'perfOdometer', property_id: 'PERF_ODOMETER', readonly: true }, { name: 'perfVehicleSpeed', property_id: 'PERF_VEHICLE_SPEED', readonly: true }, { name: 'gearSelection', property_id: 'GEAR_SELECTION', readonly: true }, { name: 'currentGear', property_id: 'CURRENT_GEAR', readonly: true }, { name: 'parkingBrakeOn', property_id: 'PARKING_BRAKE_ON', readonly: true }, { name: 'ignitionState', property_id: 'IGNITION_STATE', readonly: true }, { name: 'absActive', property_id: 'ABS_ACTIVE', readonly: true }, { name: 'tractionControlActive', property_id: 'TRACTION_CONTROL_ACTIVE', readonly: true }, { name: 'distanceDisplayUnits', property_id: 'DISTANCE_DISPLAY_UNITS', readonly: false }, { name: 'envOutsideTemperature', property_id: 'ENV_OUTSIDE_TEMPERATURE', readonly: true } ] }, { name: 'QIfEngineInfo', object: engineInfo, properties: [ { name: 'engineOilLevel', property_id: 'ENGINE_OIL_LEVEL', readonly: true }, { name: 'engineOilTemp', property_id: 'ENGINE_OIL_TEMP', readonly: true }, { name: 'engineRpm', property_id: 'ENGINE_RPM', readonly: true } ] } ]
每个顶级条目提供了一个车辆属性组件及其属性的确切元数据。在同一文件中声明的组件实例还通过 object
字段引用。
HVAC { id: climateControl } WindowControl { id: windowControl }
QML 模型
QML 模型在 PropertiesModel.qml
中定义。它使用属性元数据和组件实例,这些在 PropertiesModelDefinition.qml
中定义。使用 Instantiator 创建任何必要的绑定,以便在 Android VHAL 的数据模型更改时更新 QML 模型。
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) const ret = zonedObject[zonesInstantiator.propertyName] if (typeof ret === 'number' && !Number.isInteger(ret)) return ret.toFixed(2) return ret } onPropertyValueChanged: { zones.get(index).valueWrapper = { value: propertyValue } } } } } }
更改属性
从应用程序级别更改属性的操作如下
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 }
用户界面
用户界面由基于 ListView 的两个组件组成:ModulesList
和 PropertiesList
。它们使用提供的 QML 模型。最后,通过提供相应的控件(取决于属性类型和其他元数据)的 ValueDelegate
组件来渲染属性的视觉表示。
另请参阅Qt IF Android 车辆属性、Qt for Android 和 Qt 接口框架。
在特定 Qt 许可证下提供。
了解更多信息。