File: ProjectionTest.qml

package info (click to toggle)
qt6-declarative 6.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 308,920 kB
  • sloc: cpp: 775,911; javascript: 514,247; xml: 10,855; python: 2,806; ansic: 2,253; java: 810; sh: 262; makefile: 41; php: 27
file content (112 lines) | stat: -rw-r--r-- 3,333 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// 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: projectionTest
    property int length: 100

    property Planner planner: Planner {
        id: planner
    }

    property Variable scale: Variable {
        id: scaleVariable
        objectName: "scale"
        value: 10
    }

    property Variable offset: Variable {
        id: offsetVariable
        objectName: "offset"
        value: 1000
    }

    property Component variable: Variable {}

    property list<Variable> sources: new Array(length)
    property Variable src: sources[length - 1]
    function setSource(i: int, v: Variable) { sources[i] = v; }

    property list<Variable> destinations: new Array(length)
    property Variable dst: destinations[length - 1]
    function setDestination(i: int, v: Variable) { destinations[i] = v; }

    property Component constraint: Constraint {}

    Component.onCompleted: {
        let p = planner;
        for (let i = 0, end = length; i < end; ++i) {
            let source = variable.createObject(this, {
                objectName: "src" + i,
                value: i
            }) as Variable;
            setSource(i, source);

            let destination = variable.createObject(this, {
                objectName: "dst" + i,
                value: i
            }) as Variable;
            setDestination(i, destination);

            p.incrementalAdd(constraint.createObject(this, {
                myOutput: source,
                strength: Strength.NORMAL
            }) as Constraint);

            p.incrementalAdd(constraint.createObject(this, {
                myInput: source,
                myOutput: destination,
                scale: scaleVariable,
                offset: offsetVariable,
                strength: Strength.REQUIRED
            }) as Constraint);
        }
    }

    component Changer : Constraint {
        id: editConstraint
        isInput: true

        strength: Strength.PREFERRED

        property Plan plan: Plan {}

        function run(v: Variable, newValue: int) {
            myOutput = v;
            planner.incrementalAdd(editConstraint);
            planner.populatePlanFromConstraint(editConstraint, plan);
            for (let i = 0; i < 10; ++i) {
                v.value = newValue;
                plan.execute();
            }
            planner.incrementalRemove(editConstraint);
        }
    }

    property Changer changer: Changer { id: changer }

    function run() {
        changer.run(src, 17);
        if (dst.value !== 1170)
            console.error("Projection 1 failed", dst.value, offsetVariable.value);
        changer.run(dst, 1050);
        if (src.value !== 5)
            console.error("Projection 2 failed", src.value, offsetVariable.value);
        changer.run(scaleVariable, 5);

        let d = destinations;
        for (let i = 0, end = length - 1; i < end; ++i) {
            if (d[i].value !== i * 5 + 1000)
                console.error("Projection 3 failed");
        }
        changer.run(offsetVariable, 2000);
        for (let i = 0, end = length - 1; i < end; ++i) {
            if (d[i].value !== i * 5 + 2000)
                console.error("Projection 4 failed");
        }
    }
}