← Back to Docs
  • index.html
  • Clayground
  • Clayground.Lab
  • ModelState
  • Clayground 2026.14
  • ModelState QML Type

    The part of a lab's state only its model knows, for Lab.snapshot(). More...

    Import Statement: import Clayground.Lab

    Properties

    Detailed Description

    Lab::snapshot() holds the clock, the random numbers, the parameters and the probe samples by itself. What it cannot know is what the model has built up while time ran - the cars on the roads, the filter's estimate, a sensor's next due time. A ModelState hands that over: one per object that keeps such state, auto-registered with Lab like a Probe.

    Two ways to say what the state is. A target with a list of properties is enough for an object whose state is a few of its own properties:

    import Clayground.Lab
    
    ModelState {
        name: "odometry"; target: odo
        properties: ["estX", "estY", "headingErr", "_lastT", "_lastTrue"]
    }

    A model held in one plain object, or one that has to rebuild something when its state comes back, gives save and load instead:

    ModelState {
        name: "traffic"
        save: () => ({ plan: root.planState(), sim: root.simState })
        load: (s) => { root.loadPlan(s.plan); root.simState = s.sim }
    }

    The state must be plain data: numbers, strings, booleans, null, arrays and objects of them - what survives being written to a file. A snapshot copies it, so save may return the live object, and load is handed a copy of its own that it may keep. A property listed in properties that is bound loses its binding when the state comes back; list only properties the model assigns.

    See also Lab::snapshot and Lab::restore.

    Property Documentation

    load : var

    Function taking what save returned and putting it back.


    name : string

    Unique name the state is filed under in a snapshot.

    A snapshot restores into a lab only when that lab offers the same names, so name what the state is of ("traffic", "gps"), not where it happens to live.


    properties : string

    Names of target's properties that make up the state.


    save : var

    Function returning the state as plain data; overrides properties.


    target : QtObject

    The object whose properties are the state.