IfSimulator QML Type

The global object for parsing simulation data inside a QIfSimulationEngine. More...

Properties

Methods

Detailed Description

The IfSimulator global object provides access to the simulation data of a QIfSimulationEngine and provides helper functions for parsing and checking boundaries.

Note: This object is only available inside a QIfSimulationEngine and cannot be accessed outside of it.

Data Format

The IfSimulator expects its data already in a parsed form. Usually this is done by the QIfSimulationEngine::loadSimulationData() function, which expects the file to be in the JSON format.

Interfaces

Because a simulation QML file can use multiple interfaces, the simulation data supports multiple data sets as well. These are identified by the interface name in a reverse DNS notation:

{
  "QIfClimateControl": {
    ...
  },
  "org.qt-project.QIfWindowControl": {
    ...
  }
}

The findData() method can be used to find the data for a specific interface.

Properties

The settings (e.g. boundaries) for every property of the interface are defined inside a data set.

{
  "QIfClimateControl": {
    "airConditioningEnabled": {
      "default": true
    },
    "steeringWheelHeater": {
      "minimum": 0,
      "default": 0
    },
    "fanSpeed": {
      "range": [0, 5]
    }
  }
}

For the interface named QIfClimateControl, there are settings defined for the properties airConditioningEnabled, steeringWheelHeater and fanSpeed.

The settings object can store multiple constraints which are called domains. The following domains are currently supported:

default Holds the default value the property should have when the frontend is connected.

minimum Every newly set value needs to be bigger than this value

maximum Every newly set value needs to be smaller than this value

range Every newly set value needs to be between the two values in this list

Note: The values in range always override the minimum and maximum domains

domain Every newly set value needs to be part of this list

unsupported Changing the property is not possible and will show an "unsupported" error message

The value for a specific domain can be loaded using the parseDomainValue() function or using defaultValue() when only the default domain is of interest.

Structures and Enums

As JSON is not typesafe, structures and enums need to be stored in a special format. An enum can be stored like this:

{
  "QIfClimateControl": {
    "recirculationMode": {
      "default": {
        "type": "enum",
        "value": "QtIfVehicleFunctionsModule::RecirculationOff"
      }
    }
  }
}

Structures can be stored in a similar fashion using the name of the structure as type:

{
  "AddressBook": {
    "contactList": {
      "default": [
        {
          "type": "Contact",
          "value": [
            "foo",
            23,
            true
          ]
        },
        {
          "type": "Contact",
          "value": [
            "bar",
            12,
            false
          ]
        }
      ]
    }
  },
  }
}

To correctly initialize the structure with these values, the structure needs to provide a constructor taking a QVariant as argument. For the given contact example this constructor can look like this:

Contact::Contact(const QVariant &variant)
    : Contact()
{
    QVariant value = qtif_convertFromJSON(variant);
    // First try to convert the values to a Map or a List
    // This is needed as it could also store a QStringList or a Hash
    if (value.canConvert(QMetaType::fromType<QVariantMap>()))
        value.convert(QMetaType::fromType<QVariantMap>());
    if (value.canConvert(QMetaType::fromType<QVariantList>()))
        value.convert(QMetaType::fromType<QVariantList>());

    if (value.type() == QVariant::Map) {
        QVariantMap map = value.toMap();
        if (map.contains(u"name"_s))
            d->m_name = map.value(u"name"_s).value<QString>();
        if (map.contains(u"age"_s))
            d->m_age = map.value(u"age"_s).value<int>();
        if (map.contains(u"isMarried"_s))
            d->m_isMarried = map.value(u"isMarried"_s).value<bool>();
    } else if (value.type() == QVariant::List) {
        QVariantList values = value.toList();
        d->m_name = values.value(0).value<QString>();
        d->m_age = values.value(1).value<int>();
        d->m_isMarried = values.value(2).value<bool>();
    }
}

Zones

For zoned interfaces, the supported zones are usually stored as list in the zones property:

{
  "QIfClimateControl": {
    "zones": [
      "FrontLeft",
      "FrontRight",
      "Rear"
    ]
  }
}

For every supported domain it is also possible to provide zone specific values e.g.:

{
  "QIfClimateControl": {
    "targetTemperature": {
      "maximum": 30.0,
      "default": {
        "FrontLeft": 21.0,
        "FrontRight": 22.5,
        "=": 0.0
      }
    }
  }
}

This defines that the maximum value for the targetTemperature property is 30, the default value is zone specific and is 21.5 for the FrontLeft zone, while it is 22.5 for the FrontRight zone. The unzoned targetTemperature temperature is initialized with 0.0.

Property Documentation

simulationData : object

Provides the simulation data parsed in QIfSimulationEngine::loadSimulationData()


Method Documentation

bool checkSettings(object data, var value, string zone)

Searches for all boundary settings in data for the given zone and returns whether the provided value meets this constraint.

To show meaningful error messages when the value is not within the boundaries, the constraint() function can be used.

See also constraint().


string constraint(object data, string zone)

Searches for all boundary settings in data for the given zone and returns the constraint (which is enforced for newly set values) in a human readable form.

This is useful for error messages in connection with checkSettings().

See also checkSettings().


var defaultValue(object data, string zone)

Provides the default value stored in data for the given zone. If zone is undefined or the data doesn't provide a default value for the given zone, it returns the unzoned default value if available.

This is just a convenience function calling parseDomainValue() with the domain default.


var findData(object data, string interface)

Searches for the key interface within data and returns the stored values. Returns undefined if no data was found for this interface.

If interface is a reverse NDS name, it first searches for the full string. If no key was found, it starts to search again with a reduced name until it finds a key with this name.

E.g. for the interface org.qt-project.ClimateControl it searches for keys in the following order:

  1. org.qt-project.ClimateControl
  2. qt-project.ClimateControl
  3. ClimateControl

void initializeDefault(object data, QObject*object)

Applies the default values read from data to object.

If object supports zoneing, the default value is only applied to the correct zone.


var parseDomainValue(object data, string domain, string zone)

Search for the domain in data for the given zone. If zone is undefined or the data doesn't provide this domain for the given zone, it returns the unzoned domain value if available.


© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.