Class Model<T>Abstract

Model is the interface for feeding dynamic data into .slint views.

A model is organized like a table with rows of data. The fields of the data type T behave like columns.

Type Parameters

  • T

    the type of the model's items.

    Example

    As an example let's see the implementation of ArrayModel

    export class ArrayModel<T> extends Model<T> {
    private a: Array<T>

    constructor(arr: Array<T>) {
    super();
    this.a = arr;
    }

    rowCount() {
    return this.a.length;
    }

    rowData(row: number) {
    return this.a[row];
    }

    setRowData(row: number, data: T) {
    this.a[row] = data;
    this.notifyRowDataChanged(row);
    }

    push(...values: T[]) {
    let size = this.a.length;
    Array.prototype.push.apply(this.a, values);
    this.notifyRowAdded(size, arguments.length);
    }

    remove(index: number, size: number) {
    let r = this.a.splice(index, size);
    this.notifyRowRemoved(index, size);
    }

    get length(): number {
    return this.a.length;
    }

    values(): IterableIterator<T> {
    return this.a.values();
    }

    entries(): IterableIterator<[number, T]> {
    return this.a.entries()
    }
    }

Hierarchy (view full)

Implements

  • Iterable<T>

Constructors

Methods

  • Returns Iterator<T, any, undefined>

  • Notifies the view that the complete data must be reload.

    Returns void

  • Notifies the view that multiple rows are added to the model.

    Parameters

    • row: number

      index of the first added row.

    • count: number

      the number of added items.

    Returns void

  • Notifies the view that the data of the current row is changed.

    Parameters

    • row: number

      index of the changed row.

    Returns void

  • Notifies the view that multiple rows are removed to the model.

    Parameters

    • row: number

      index of the first removed row.

    • count: number

      the number of removed items.

    Returns void

  • Implementations of this function must return the current number of rows.

    Returns number

  • Implementations of this function must return the data at the specified row.

    Parameters

    • row: number

      index in range 0..(rowCount() - 1).

    Returns T

    undefined if row is out of range otherwise the data.

  • Implementations of this function must store the provided data parameter in the model at the specified row.

    Parameters

    • _row: number

      index in range 0..(rowCount() - 1).

    • _data: T

      new data item to store on the given row index

    Returns void