TransformList
Description
The TransformList object is a PropertyModifier object which transforms a source list into a target list using an arbitrary expression. The expression is evaluated for each element in the source list and the result is written to the corresponding element in the target list. ReduceList manages strong bindings between elements in the source list, the expression and the target list, i.e. whenever either an element in the source list or other variable parts of the evaluated expression change the target list is being updated instantly.
TransformList primarily is designed to use with DataObject lists. TransformList replaces traditional for loops in a declarative manner. This not only reduces the code complexity but also improves performance. When only a few elements in the source list are changed, TransformList will only update the corresponding elements of the target list. This saves unnecessary expression evaluations and further processings caused by the updates.
- › Inherits:
Overview
Properties
Methods
Signals
Enumerations
Properties
error
This property holds the most recently occurred error or TransformList.NoError if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() signal to detect multiple occurrences of the same error.
- › Type:
- › Signal:
errorChanged()
- › Attributes:
Readonly
errorString
This property holds the current human readable error string corresponding to the current value in the error property. It may include additional information such as failure reasons or locations.
- › Type:
String
- › Signal:
errorStringChanged()
- › Attributes:
Readonly
eval
This property holds an expression which is evaluated for each element in the source list. The respective source list element is available in a local item property inside the expression. The result of the expression is written to the corresponding element in the target list. The expression is reevaluated whenever the source list element or other parts of the expression change. The target list therefore always contains an up-to-date representation of the transformed data.
- › Type:
<QML expression>
- › Signal:
evalChanged()
- › Attributes:
Writable
source
This property holds a list of elements to transform, i.e. a List object or a reference to it.
- › Type:
Variant
- › Signal:
sourceChanged()
- › Attributes:
Writable
Signals
errorOccurred()
This signal is emitted whenever an error has occurred, regardless of whether the error property has changed or not. In contrast to the change notification signal of the error property this signal is also emitted several times if a certain error occurs several times in succession.
Enumerations
Error
This enumeration describes all errors which can occur in TransformList objects. The most recently occurred error is stored in the error property.
Name |
Value |
Description |
|---|---|---|
|
|
No error occurred or was detected. |
|
|
TransformList not supported for non-list property “”. |
|
|
TransformList not supported for readonly property “”. |
|
|
Can’t add incompatible object to property “”. |
|
|
Error inserting object to property “”. |
|
|
Error while evaluating expression: <Unknown File>: . |
Example
import InCore.Foundation 2.5
Application {
MeasurementGroup {
id: randomNegativeMeasurements
Measurement { data: -Math.random() }
Measurement { data: -Math.random() }
Measurement { data: -Math.random() }
Measurement { data: -Math.random() }
Measurement { data: -Math.random() }
}
// create a second MeasurementGroup which contains identical measurements except for data being transformed
MeasurementGroup {
id: absoluteMeasurements
TransformList on objects {
source: randomNegativeMeasurements.objects
eval: Math.abs(item.data)
}
onObjectsDataChanged: console.log(index, objects[index].data)
}
// wrap value array into List object
List {
id: simpleValueList
items: [ 1, 2, 3 ]
}
// create a List which contains transformed items
List {
TransformList on items {
source: simpleValueList
eval: item*5
}
onItemsChanged: console.log(items)
}
onCompleted: {
// update a value and observe an automatic update of the list above
simpleValueList.setItem( 1, 123 )
}
}