<commit_before>import QtQuick 2.4

/*! \qmltype ConditionalLayout
    \inqmlmodule Mut.Layout 0.1

    \brief Provides a layout that could change dinamically.

    ConditionalLayout uses a \l {QtQuick::Loader} that loads a layout
    dinamically according to the following properties:
    * `layouts`: contains a list of possible layouts that should be defined as a {QtQuick::Component}.
    * `when`: is a condition that should return the `layouts` index for the chosen layout

    ConditionalLayout provides a fallback system that chooses the nearest available layout
    so if the `when` property is set to 5 but `layouts` contains only 3 layouts, the
    rightmost element of the array will be used.

    \qml
    import QtQuick 2.4
    import Mut 0.1
    import Mut.Layouts 0.1

    Component {
        id: first_layout
        RowLayout {
            ...
        }
    }

    Component {
        id: second_layout
        ColumnLayout {
            ...
        }
    }

    ConditionalLayout {
        when: aReallyLongCondition ? 0 : 1
        layouts: [
            first_layout,
            second_layout
        ]

    }
    \endqml
*/
FocusScope {
    id: root

    property list<Component> layouts
    property int when: -1

    property alias activeComponent: __layoutLoader.sourceComponent
    property alias activeLayout: __layoutLoader.item

    Loader {
        id: __layoutLoader
        anchors.fill: parent
        sourceComponent: layoutSelection()
    }

    function layoutSelection () {
        var index = root.when;
        var layout;

        // manages layouts fallback
        while (typeof root.layouts[index] === 'undefined' && index > -1) {
            index -= 1;
        }

        // chooses the most similar layout available,
        // 'empty' otherwise (no layout will be loaded)
        if (index === -1) {
            layout = undefined;<commit_msg>tied loader's active property to the when condition<commit_after>import QtQuick 2.4

/*! \qmltype ConditionalLayout
    \inqmlmodule Mut.Layout 0.1

    \brief Provides a layout that could change dinamically.

    ConditionalLayout uses a \l {QtQuick::Loader} that loads a layout
    dinamically according to the following properties:
    * `layouts`: contains a list of possible layouts that should be defined as a {QtQuick::Component}.
    * `when`: is a condition that should return the `layouts` index for the chosen layout

    ConditionalLayout provides a fallback system that chooses the nearest available layout
    so if the `when` property is set to 5 but `layouts` contains only 3 layouts, the
    rightmost element of the array will be used.

    \qml
    import QtQuick 2.4
    import Mut 0.1
    import Mut.Layouts 0.1

    Component {
        id: first_layout
        RowLayout {
            ...
        }
    }

    Component {
        id: second_layout
        ColumnLayout {
            ...
        }
    }

    ConditionalLayout {
        when: aReallyLongCondition ? 0 : 1
        layouts: [
            first_layout,
            second_layout
        ]

    }
    \endqml
*/
FocusScope {
    id: root

    property list<Component> layouts
    property int when: -1

    property alias activeComponent: __layoutLoader.sourceComponent
    property alias activeLayout: __layoutLoader.item

    Loader {
        id: __layoutLoader
        anchors.fill: parent
        active: root.when >= 0
        sourceComponent: layoutSelection()
    }

    function layoutSelection () {
        var index = root.when;
        var layout;

        // manages layouts fallback
        while (typeof root.layouts[index] === 'undefined' && index > -1) {
            index -= 1;
        }

        // chooses the most similar layout available,
        // 'empty' otherwise (no layout will be loaded)
        if (index === -1) {
            layout = undefined;
{'fraction_non_alphanumeric': 0.0724863600935308, 'fraction_numerical': 0.009612886464016628, 'mean_word_length': 2.0677290836653386, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1874294', 'n_tokens_mistral': 1071, 'n_tokens_neox': 997, 'n_words': 373}