1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
pragma ComponentBehavior: Bound
pragma Strict
import QtQml
QtObject {
id: chainTest
property int length: 100
property Planner planner: Planner { id: planner }
property Plan plan: Plan { id: plan }
property Component variable: Variable {}
property list<Variable> variables: new Array(length)
property Variable first: variables[0]
property Variable last: variables[length - 1]
function setVariable(i: int, v: Variable) { variables[i] = v; }
property Component constraint: Constraint {}
property Constraint stayConstraint: Constraint {
id: stayConstraint
myOutput: chainTest.last
strength: Strength.STRONG_DEFAULT
}
property Constraint editConstraint: Constraint {
id: editConstraint
isInput: true
myOutput: chainTest.first
strength: Strength.PREFERRED
}
Component.onCompleted: {
for (let i = 0, end = length; i < end; ++i)
setVariable(i, variable.createObject(this, {objectName: "v" + i}) as Variable);
let v = variables;
let p = planner;
for (let i = 0, end = length - 1; i < end; ++i) {
p.incrementalAdd(constraint.createObject(this, {
myInput: v[i],
myOutput: v[i + 1],
strength: Strength.REQUIRED
}) as Constraint);
}
planner.incrementalAdd(stayConstraint)
planner.incrementalAdd(editConstraint)
}
function verify(i: int) {
if (last.value !== i)
console.error("Chain test failed.", last.value, i, first.value);
}
function run() {
planner.populatePlanFromConstraint(editConstraint, plan);
for (let i = 0; i < 100; ++i) {
first.value = i;
plan.execute();
verify(i);
}
}
}
|