radioviz.views.item_model

Module for managing item models in the radioviz application.

This module provides the ItemModel class which implements the QAbstractTableModel interface to display items from an ItemStore in a Qt table view.

Classes

ItemModel(store[, parent])

Abstract table model for displaying items from an item store.

class radioviz.views.item_model.ItemModel(store: ItemStore[T], parent: QObject | None = None)[source]

Bases: QAbstractTableModel, Generic[T]

Abstract table model for displaying items from an item store.

This class provides a generic implementation of a Qt table model that displays items from an ItemStore. It automatically updates the view when the underlying store changes.

Variables:

headers (list[str]) – List of column headers for the table model

Initialize the item model with a data store.

Parameters:
  • store (ItemStore[T]) – The item store to display in the model

  • parent (QObject or None) – Parent object for the model

columnCount(parent: ~PySide6.QtCore.QModelIndex | ~PySide6.QtCore.QPersistentModelIndex = <PySide6.QtCore.QModelIndex(-1, -1, 0x0, QObject(0x0))>) int[source]

Return the number of columns in the model.

Parameters:

parent (QModelIndex or QPersistentModelIndex) – Parent index (unused)

Returns:

Number of headers

Return type:

int

data(index: QModelIndex | QPersistentModelIndex, role: int = ItemDataRole.DisplayRole) Any[source]

Return the data for the given index and role.

Parameters:
  • index (QModelIndex or QPersistentModelIndex) – The model index

  • role (int) – The data role

Returns:

Data for the cell or None

Return type:

Any

data_for(item: T, column: int, role: int = ItemDataRole.DisplayRole) Any[source]

Return the data for a specific item and column.

This method must be implemented by subclasses to provide the actual data display logic for each cell.

Parameters:
  • item (T) – The item to get data for

  • column (int) – The column index

  • role (int) – The data role

Returns:

Data for the cell

Return type:

Any

Raises:

NotImplementedError – Always raised as this is an abstract method

headerData(section: int, orientation: Orientation, role: int = ItemDataRole.DisplayRole) Any[source]

Return the header data for the given section and orientation.

Parameters:
  • section (int) – The section index

  • orientation (Qt.Orientation) – The orientation of the header

  • role (int) – The data role

Returns:

Header data or None

Return type:

str or None

on_store_change(event: StoreEvent, data: T | None = None, index: int = 0) None[source]

Handle changes in the underlying store.

This method is called when the store emits a change event and updates the model accordingly.

Parameters:
  • event (StoreEvent) – The type of store event

  • data (T) – The data associated with the event

  • index (int) – The index where the event occurred

rowCount(parent: ~PySide6.QtCore.QModelIndex | ~PySide6.QtCore.QPersistentModelIndex = <PySide6.QtCore.QModelIndex(-1, -1, 0x0, QObject(0x0))>) int[source]

Return the number of rows in the model.

Parameters:

parent (QModelIndex or QPersistentModelIndex) – Parent index (unused)

Returns:

Number of items in the store

Return type:

int

setData(index: QModelIndex | QPersistentModelIndex, value: Any, role: int = ItemDataRole.DisplayRole) bool[source]

Set the data for the given index and role.

Parameters:
  • index (QModelIndex or QPersistentModelIndex) – The model index

  • value (Any) – The value to set

  • role (int) – The data role

Returns:

True if the data was set successfully, False otherwise

Return type:

bool

set_data_for(item: T, column: int, value: Any, role: int = ItemDataRole.DisplayRole) bool[source]

Set the data for a specific item and column.

This method must be implemented by subclasses to provide the actual data setting logic for each cell.

Parameters:
  • item (T) – The item to set data for

  • column (int) – The column index

  • value (Any) – The value to set

  • role (int) – The data role

Returns:

True if the data was set successfully, False otherwise

Return type:

bool

Raises:

NotImplementedError – Always raised as this is an abstract method