aboutsummaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/qml/deltablue/Variable.qml
blob: 6b3411e520f7e04d028d07a680d14e1fd5fd6601 (plain)
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
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

pragma Strict
import QtQml

QtObject {
    property int value: 0
    property list<BaseConstraint> constraints
    property BaseConstraint determinedBy: null
    property int mark: 0
    property int walkStrength: Strength.WEAKEST
    property bool stay: true

    function addConstraint(c: BaseConstraint) {
        let l = constraints;
        l[l.length++] = c;
    }

    function removeConstraint(c: BaseConstraint) {
        let l = constraints;
        let index = 0;
        let skipped = 0;
        for (let i = 0, length = l.length; i < length; ++i) {
            let value = l[i] as BaseConstraint;
            if (value !== c) {
                if (index != i)
                    l[index] = value;
                ++index
            } else {
                ++skipped;
            }
        }

        l.length -= skipped;

        if (determinedBy === c)
            determinedBy = null;
    }

    function length(): int {
        return constraints.length
    }

    function constraint(i: int) : BaseConstraint {
        return constraints[i];
    }
}