FactBitmask.qml 1.9 KB
Newer Older
1 2
import QtQuick          2.3
import QtQuick.Controls 1.2
Don Gagne's avatar
Don Gagne committed
3 4 5 6 7 8

import QGroundControl.FactSystem    1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0

Don Gagne's avatar
Don Gagne committed
9
Flow {
Don Gagne's avatar
Don Gagne committed
10 11
    spacing: ScreenTools.defaultFontPixelWidth

12 13 14
    /// true: Checking the first entry will clear and disable all other entries
    property bool firstEntryIsAll: false

Don Gagne's avatar
Don Gagne committed
15 16
    property Fact fact: Fact { }

17 18 19 20 21 22 23 24 25
    Component.onCompleted: {
        if (firstEntryIsAll && repeater.itemAt(0).checked) {
            for (var i=1; i<repeater.count; i++) {
                var otherCheckbox = repeater.itemAt(i)
                otherCheckbox.enabled = false
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
26
    Repeater {
27 28
        id:     repeater
        model:  fact.bitmaskStrings
Don Gagne's avatar
Don Gagne committed
29 30

        QGCCheckBox {
31
            id:         checkbox
Don Gagne's avatar
Don Gagne committed
32 33 34 35
            text:       modelData
            checked:    fact.value & fact.bitmaskValues[index]

            onClicked: {
36 37
                var i;
                var otherCheckbox;
Don Gagne's avatar
Don Gagne committed
38
                if (checked) {
39
                    if (firstEntryIsAll && index == 0) {
40 41
                        for (i = 1; i < repeater.count; i++) {
                            otherCheckbox = repeater.itemAt(i)
42 43 44 45 46
                            fact.value &= ~fact.bitmaskValues[i]
                            otherCheckbox.checked = false
                            otherCheckbox.enabled = false
                        }
                    }
Don Gagne's avatar
Don Gagne committed
47 48
                    fact.value |= fact.bitmaskValues[index]
                } else {
49
                    if (firstEntryIsAll && index == 0) {
50 51
                        for (i = 1; i < repeater.count; i++) {
                            otherCheckbox = repeater.itemAt(i)
52 53 54
                            otherCheckbox.enabled = true
                        }
                    }
Don Gagne's avatar
Don Gagne committed
55 56 57 58 59 60
                    fact.value &= ~fact.bitmaskValues[index]
                }
            }
        }
    }
}