Skip to content
FactBitmask.qml 1.91 KiB
Newer Older
import QtQuick          2.3
import QtQuick.Controls 1.2
Don Gagne's avatar
Don Gagne committed

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
Flow {
Don Gagne's avatar
Don Gagne committed
    spacing: ScreenTools.defaultFontPixelWidth

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

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

    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
    Repeater {
        id:     repeater
        model:  fact ? fact.bitmaskStrings : []
Don Gagne's avatar
Don Gagne committed

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

            onClicked: {
                var i;
                var otherCheckbox;
Don Gagne's avatar
Don Gagne committed
                if (checked) {
                    if (firstEntryIsAll && index == 0) {
                        for (i = 1; i < repeater.count; i++) {
                            otherCheckbox = repeater.itemAt(i)
                            fact.value &= ~fact.bitmaskValues[i]
                            otherCheckbox.checked = false
                            otherCheckbox.enabled = false
                        }
                    }
Don Gagne's avatar
Don Gagne committed
                    fact.value |= fact.bitmaskValues[index]
                } else {
                    if (firstEntryIsAll && index == 0) {
                        for (i = 1; i < repeater.count; i++) {
                            otherCheckbox = repeater.itemAt(i)
                            otherCheckbox.enabled = true
                        }
                    }
Don Gagne's avatar
Don Gagne committed
                    fact.value &= ~fact.bitmaskValues[index]
                }
            }
        }
    }
}