Appendix B — QML Style Example

This annotated example demonstrates the approved QML coding style for a JASP analysis form. It covers variable assignment, grouped options, collapsible sections, radio buttons, and dropdowns.

// Every QML form has Form as its root element.
// Indent with tabs (4-space width), not spaces.
// Opening braces go on their own line, aligned with the closing brace.

import QtQuick
import QtQuick.Layouts
import JASP.Controls

Form
{
    // --- Variable assignment ---
    // VariablesForm creates the familiar drag-and-drop variable lists.
    VariablesForm
    {
        AvailableVariablesList { name: "availableVariables"                                              }
        AssignedVariablesList  { name: "dependent"; title: qsTr("Dependent Variable"); singleVariable: true;
                                 allowedColumns: ["scale"]                                               }
        AssignedVariablesList  { name: "variables"; title: qsTr("Covariates"); allowedColumns: ["scale"] }
        AssignedVariablesList  { name: "groupvar";  title: qsTr("Grouping Variable"); singleVariable: true;
                                 allowedColumns: ["nominal", "ordinal"]                                  }
    }

    // --- Grouped options ---
    // Group draws a titled box around related controls.
    Group
    {
        title: qsTr("Model")

        // Multiple properties: each on its own line, values aligned.
        IntegerField
        {
            name:           "polynomialDegree"
            label:          qsTr("Polynomial degree")
            defaultValue:   1
            min:            1
            max:            5
        }

        DropDown
        {
            name:           "method"
            label:          qsTr("Estimation method")
            indexDefaultValue: 0
            values:
            [
                { label: qsTr("OLS"),          value: "ols"  },
                { label: qsTr("Robust (HC3)"), value: "hc3"  },
                { label: qsTr("Bootstrap"),    value: "boot" }
            ]
        }
    }

    // --- Simple one-liners ---
    // Exception: elements with few short properties can be on one line.
    // Align values across stacked one-liners for visual consistency.
    Group
    {
        title: qsTr("Statistics")

        CheckBox { name: "meanDifference";    label: qsTr("Mean difference"); checked: true }
        CheckBox { name: "effectSize";        label: qsTr("Effect size")                    }
        CheckBox { name: "confidenceInterval"; label: qsTr("Confidence interval")            }

        // CIField appears only when its parent checkbox is enabled.
        CIField  { name: "confidenceIntervalLevel" }
    }

    // --- Collapsible section ---
    // Section creates a collapsible accordion in the UI.
    // Use it for secondary or advanced options to keep the form clean.
    Section
    {
        title: qsTr("Assumption Checks")

        CheckBox { name: "normalityTest";       label: qsTr("Normality test")        }
        CheckBox { name: "equalityOfVariances"; label: qsTr("Equality of variances") }
        CheckBox { name: "qqPlot";              label: qsTr("Q-Q plot")              }
    }

    // Sections can contain any combination of controls.
    Section
    {
        title: qsTr("Plots")

        CheckBox
        {
            name:   "residualPlot"
            label:  qsTr("Residuals vs. fitted")
        }

        // RadioButtonGroup gives mutually exclusive choices.
        RadioButtonGroup
        {
            name:   "colorScheme"
            title:  qsTr("Color scheme")

            RadioButton { value: "jasp";       label: qsTr("JASP");        checked: true }
            RadioButton { value: "colorblind"; label: qsTr("Colorblind")                 }
            RadioButton { value: "grayscale";  label: qsTr("Grayscale")                  }
        }
    }
}

B.0.1 Style rules summary

Rule Detail
Indentation Tabs (4-space width), never spaces
Braces Opening { on own line, vertically aligned with closing }
Multi-property elements Each property on own line, values aligned
One-liner exception Simple elements (CheckBox, VariablesList) with ≤ 3 short properties
One-liner alignment Align property values across stacked one-liners
Strings Wrap all user-visible text in qsTr()
Spacing One blank line between logical groups of controls
Sections Use Section for secondary/advanced options — keeps the main form compact
VariablesForm first Place the variable assignment block at the top of the form