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

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 36
            text:       modelData
            checked:    fact.value & fact.bitmaskValues[index]

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