Canvas Toolkit
← Class index

CAbstractItemModel

Models and views · extends CObject

Abstract base class for models that expose data to item views.

import { CAbstractItemModel } from "canvas-toolkit-lib";

Declared members

readonly dataChanged: CSignal<[CModelIndex, CModelIndex]>;

Emitted when data in the inclusive index range has changed.

readonly modelReset: CSignal<[]>;

Emitted when the model has been reset.

readonly layoutAboutToBeChanged: CSignal<[]>;

Emitted immediately before indexes are rearranged.

readonly layoutChanged: CSignal<[CModelIndex[], CModelIndex[]]>;

Emitted after indexes have been rearranged.

readonly rowsAboutToBeInserted: CSignal<[CModelIndex, number, number]>;

Emitted immediately before a contiguous range of rows is inserted.

readonly rowsInserted: CSignal<[CModelIndex, number, number]>;

Emitted after a contiguous range of rows has been inserted.

readonly rowsAboutToBeRemoved: CSignal<[CModelIndex, number, number]>;

Emitted immediately before a contiguous range of rows is removed.

readonly rowsRemoved: CSignal<[CModelIndex, number, number]>;

Emitted after a contiguous range of rows has been removed.

constructor(parent?: CObject | null);

Creates an item model. @param parent Optional parent object.

abstract rowCount(parent?: CModelIndex): number;

Returns the number of rows below the optional parent index.

abstract columnCount(parent?: CModelIndex): number;

Returns the number of columns below the optional parent index.

abstract data(index: CModelIndex): unknown;

Returns the data associated with an index.

setItemData(_index: CModelIndex, _value: unknown): boolean;

Sets the data associated with an index. The base implementation does not modify the model. @returns `true` when the value was accepted.

applyTextEdits(_edits: readonly CItemTextEdit[]): CItemTextEditError | null;

Validates all pasted values before writing any of them. Return null on success or identify the rejected edit. Models opt in by overriding this method.

supportsTextEdits(): boolean;

Returns whether this model accepts batches of pasted text.

undoStack(): CUndoStack | null;

Returns the history of committed edits, if the model provides one.

isEditable(_index: CModelIndex): boolean;

Returns whether the item at an index can be edited. The base implementation returns `false`.

sort(_column: number, _order?: CSortOrder): void;

Sorts the model by a column in the requested order. The base implementation does not modify the model.

index(row: number, column: number, parent?: CModelIndex): CModelIndex;

Creates an index for an existing row and column. Returns an invalid index when the coordinates are outside the model.

parentIndex(_index: CModelIndex): CModelIndex;

Returns the parent index of an item. The base implementation represents a flat model and returns an invalid index.

headerData(section: number, _orientation: COrientation): string | number | null;

Returns display data for a header section. The default implementation returns a one-based section number.

protected createIndex(row: number, column: number, data?: unknown): CModelIndex;

Creates a model index owned by this model. @param row Zero-based row. @param column Zero-based column. @param data Optional internal data associated with the index.

canFetchMore(_parent?: CModelIndex): boolean;

Returns whether another block of rows can be fetched.

fetchMore(_parent?: CModelIndex): Promise<boolean>;

Fetches another block of rows. The base implementation does nothing.

protected emitDataChanged(topLeft: CModelIndex, bottomRight: CModelIndex): void;

Emits the dataChanged signal for the specified inclusive range.

protected resetModel(): void;

Resets the model and emits the modelReset signal.

protected beginLayoutChange(): void;

Announces that model indexes are about to be rearranged.

protected endLayoutChange(oldIndexes: CModelIndex[], newIndexes: CModelIndex[]): void;

Announces a completed index rearrangement.

protected beginInsertRows(parent: CModelIndex, first: number, last: number): void;

Announces that rows will be inserted before the model data changes.

protected endInsertRows(): void;

Announces that the previously declared rows have been inserted.

protected beginRemoveRows(parent: CModelIndex, first: number, last: number): void;

Announces that rows will be removed before the model data changes.

protected endRemoveRows(): void;

Announces that the previously declared rows have been removed.