spinetoolbox.mvcmodels.compound_table_model

Models that vertically concatenate two or more table models.

Module Contents

Classes

CompoundTableModel

A model that concatenates several sub table models vertically.

CompoundWithEmptyTableModel

A compound parameter table model where the last model is an empty row model.

class spinetoolbox.mvcmodels.compound_table_model.CompoundTableModel(parent=None, header=None)[source]

Bases: spinetoolbox.mvcmodels.minimal_table_model.MinimalTableModel

A model that concatenates several sub table models vertically.

Initializes model.

Parameters
  • parent (QObject, optional) – the parent object

  • header (list of str, optional) – header labels

refreshed[source]
map_to_sub(index)[source]

Returns an equivalent submodel index.

Parameters

index (QModelIndex) – the compound model index.

Returns

the equivalent index in one of the submodels

Return type

QModelIndex

map_from_sub(sub_model, sub_index)[source]

Returns an equivalent compound model index.

Parameters
  • sub_model (MinimalTableModel) – the submodel

  • sub_index (QModelIndex) – the submodel index.

Returns

the equivalent index in the compound model

Return type

QModelIndex

item_at_row(row)[source]

Returns the item at given row.

Parameters

row (int) –

Returns

object

sub_model_at_row(row)[source]

Returns the submodel corresponding to the given row in the compound model.

Parameters

row (int) –

Returns

MinimalTableModel

sub_model_row(row)[source]

Calculates sub model row.

Parameters

row (int) – row in compound model

Returns

row in sub model

Return type

int

refresh()[source]

Refreshes the layout by computing a new row map.

_do_refresh()[source]

Recomputes the row and inverse row maps.

_append_row_map(row_map)[source]

Appends given row map to the tail of the model.

Parameters

row_map (list) – tuples (model, row number)

_row_map_iterator_for_model(model)[source]

Yields row map for given model. The base class implementation just yields all model rows.

Parameters

model (MinimalTableModel) –

Yields

tuple – (model, row number)

_row_map_for_model(model)[source]

Returns row map for given model. The base class implementation just returns all model rows.

Parameters

model (MinimalTableModel) –

Returns

tuples (model, row number)

Return type

list

canFetchMore(parent)[source]

Returns True if any of the submodels that haven’t been fetched yet can fetch more.

fetchMore(parent)[source]

Fetches the next sub model and increments the fetched counter.

flags(index)[source]

Return index flags.

data(index, role=Qt.ItemDataRole.DisplayRole)[source]

Returns the data stored under the given role for the item referred to by the index.

Parameters
  • index (QModelIndex) – Index of item

  • role (int) – Data role

Returns

Item data for given role.

rowCount(parent=QModelIndex())[source]

Returns the sum of rows in all models.

batch_set_data(indexes, data)[source]

Sets data for indexes in batch. Distributes indexes and values among the different submodels and calls batch_set_data on each of them.

insertRows(row, count, parent=QModelIndex())[source]

Inserts count rows after the given row under the given parent. Localizes the appropriate submodel and calls insertRows on it.

removeRows(row, count, parent=QModelIndex())[source]

Removes count rows starting with the given row under parent. Localizes the appropriate submodels and calls removeRows on it.

class spinetoolbox.mvcmodels.compound_table_model.CompoundWithEmptyTableModel(parent=None, header=None)[source]

Bases: CompoundTableModel

A compound parameter table model where the last model is an empty row model.

Initializes model.

Parameters
  • parent (QObject, optional) – the parent object

  • header (list of str, optional) – header labels

property single_models[source]
property empty_model[source]
abstract _create_empty_model()[source]

Creates and returns an empty model.

Returns

model

Return type

EmptyRowModel

init_model()[source]

Initializes the compound model.

Basically populates the sub_models list attribute with the result of _create_empty_model.

_connect_single_model(model)[source]

Connects signals so changes in the submodels are acknowledged by the compound.

_recompute_empty_row_map()[source]

Recomputes the part of the row map corresponding to the empty model.

_handle_empty_rows_removed(parent, empty_first, empty_last)[source]

Updates row_map when rows are removed from the empty model.

_handle_empty_rows_inserted(parent, empty_first, empty_last)[source]

Runs when rows are inserted to the empty model. Updates row_map, then emits rowsInserted so the new rows become visible.

_handle_single_model_about_to_be_reset(model)[source]

Runs when given model is about to reset.

_handle_single_model_reset(model)[source]

Runs when given model is reset.

_refresh_single_model(model)[source]
_get_insert_position(model)[source]
_insert_single_model(model)[source]
_get_row_for_insertion(pos)[source]
_insert_row_map(pos, single_row_map)[source]
clear_model()[source]

Clears the model.