spinetoolbox.spine_db_editor.mvcmodels.compound_models

Compound models. These models concatenate several ‘single’ models and one ‘empty’ model.

Module Contents

Classes

CompoundModelBase

A base model for all models that show data in stacked format.

FilterEntityAlternativeMixin

Provides the interface to filter by entity and alternative.

EditParameterValueMixin

Provides the interface to edit values via ParameterValueEditor.

CompoundParameterDefinitionModel

A model that concatenates several single parameter_definition models and one empty parameter_definition model.

CompoundParameterValueModel

A model that concatenates several single parameter_value models and one empty parameter_value model.

CompoundEntityAlternativeModel

Provides the interface to filter by entity and alternative.

class spinetoolbox.spine_db_editor.mvcmodels.compound_models.CompoundModelBase(parent, db_mngr, *db_maps)[source]

Bases: spinetoolbox.mvcmodels.compound_table_model.CompoundWithEmptyTableModel

A base model for all models that show data in stacked format.

Parameters:
  • parent (SpineDBEditor) – the parent object

  • db_mngr (SpineDBManager) – the database manager

  • *db_maps (DatabaseMapping) – the database maps included in the model

property field_map[source]
abstract property item_type[source]

Returns the DB item type, e.g., ‘parameter_value’.

Returns:

str

abstract property _single_model_type[source]

Returns a constructor for the single models.

Returns:

SingleParameterModel

abstract property _empty_model_type[source]

Returns a constructor for the empty model.

Returns:

EmptyParameterModel

abstract _make_header()[source]
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.

shows_item(item, db_map)[source]
reset_db_maps(db_maps)[source]
init_model()[source]

Initializes the model.

get_auto_filter_menu(logical_index)[source]

Returns auto filter menu for given logical index from header view.

Parameters:

logical_index (int)

Returns:

AutoFilterMenu

_make_auto_filter_menu(field)[source]
headerData(section, orientation=Qt.Orientation.Horizontal, role=Qt.ItemDataRole.DisplayRole)[source]

Returns an italic font in case the given column has an autofilter installed.

_create_empty_model()[source]

Returns the empty model for this compound model.

Returns:

EmptyParameterModel

filter_accepts_model(model)[source]

Returns a boolean indicating whether the given model passes the filter for compound model.

Parameters:

model (SingleModelBase or EmptyModelBase)

Returns:

bool

_class_filter_accepts_model(model)[source]
_auto_filter_accepts_model(model)[source]
accepted_single_models()[source]

Returns a list of accepted single models by calling filter_accepts_model on each of them, just for convenience.

Returns:

list

_invalidate_filter()[source]

Sets the filter invalid.

stop_invalidating_filter()[source]

Stops invalidating the filter.

set_filter_class_ids(class_ids)[source]
clear_auto_filter()[source]
set_auto_filter(field, values)[source]

Updates and applies the auto filter.

Parameters:
  • field (str) – the field name

  • values (dict) – mapping (db_map, entity_class_id) to set of valid values

_set_compound_auto_filter(field, values)[source]

Sets the auto filter for given column in the compound model.

Parameters:
  • field (str) – the field name

  • values (set) – set of valid (db_map, item_type, id) tuples

_set_single_auto_filter(model, field)[source]

Sets the auto filter for given column in the given single model.

Parameters:
  • model (SingleParameterModel) – the model

  • field (str) – the field name

Returns:

True if the auto-filtered values were updated, None otherwise

Return type:

bool

_row_map_iterator_for_model(model)[source]

Yields row map for the given model. Reimplemented to take filter status into account.

Parameters:

model (SingleParameterModel, EmptyParameterModel)

Yields:

tuple – (model, row number) for each accepted row

_models_with_db_map(db_map)[source]

Returns a collection of single models with given db_map.

Parameters:

db_map (DatabaseMapping)

Returns:

list

static _items_per_class(items)[source]

Returns a dict mapping entity_class ids to a set of items.

Parameters:

items (list)

Returns:

dict

handle_items_added(db_map_data)[source]

Runs when either parameter definitions or values are added to the dbs. Adds necessary sub-models and initializes them with data. Also notifies the empty model so it can remove rows that are already in.

Parameters:

db_map_data (dict) – list of added dict-items keyed by DatabaseMapping

_get_insert_position(model)[source]
_create_single_model(db_map, entity_class_id, committed)[source]
_add_items(db_map, entity_class_id, ids, committed)[source]

Creates new single model and resets it with the given parameter ids.

Parameters:
  • db_map (DatabaseMapping) – database map

  • entity_class_id (int) – parameter’s entity class id

  • ids (list of int) – parameter ids

  • committed (bool) – True if the ids have been committed, False otherwise

handle_items_updated(db_map_data)[source]

Runs when either parameter definitions or values are updated in the dbs. Emits dataChanged so the parameter_name column is refreshed.

Parameters:

db_map_data (dict) – list of updated dict-items keyed by DatabaseMapping

handle_items_removed(db_map_data)[source]

Runs when either parameter definitions or values are removed from the dbs. Removes the affected rows from the corresponding single models.

Parameters:

db_map_data (dict) – list of removed dict-items keyed by DatabaseMapping

db_item(index)[source]
db_map_id(index)[source]
get_entity_class_id(index, db_map)[source]
filter_by(rows_per_column)[source]
filter_excluding(rows_per_column)[source]
class spinetoolbox.spine_db_editor.mvcmodels.compound_models.FilterEntityAlternativeMixin(*args, **kwargs)[source]

Provides the interface to filter by entity and alternative.

init_model()[source]
set_filter_entity_ids(entity_ids)[source]
set_filter_alternative_ids(alternative_ids)[source]
_create_single_model(db_map, entity_class_id, committed)[source]
class spinetoolbox.spine_db_editor.mvcmodels.compound_models.EditParameterValueMixin[source]

Provides the interface to edit values via ParameterValueEditor.

index_name(index)[source]

Generates a name for data at given index.

Parameters:

index (QModelIndex) – index to model

Returns:

label identifying the data

Return type:

str

get_set_data_delayed(index)[source]

Returns a function that ParameterValueEditor can call to set data for the given index at any later time, even if the model changes.

Parameters:

index (QModelIndex)

Returns:

function

class spinetoolbox.spine_db_editor.mvcmodels.compound_models.CompoundParameterDefinitionModel(parent, db_mngr, *db_maps)[source]

Bases: EditParameterValueMixin, CompoundModelBase

A model that concatenates several single parameter_definition models and one empty parameter_definition model.

Parameters:
  • parent (SpineDBEditor) – the parent object

  • db_mngr (SpineDBManager) – the database manager

  • *db_maps (DatabaseMapping) – the database maps included in the model

property item_type[source]

Returns the DB item type, e.g., ‘parameter_value’.

Returns:

str

property field_map[source]
property _single_model_type[source]

Returns a constructor for the single models.

Returns:

SingleParameterModel

property _empty_model_type[source]

Returns a constructor for the empty model.

Returns:

EmptyParameterModel

_make_header()[source]
class spinetoolbox.spine_db_editor.mvcmodels.compound_models.CompoundParameterValueModel(*args, **kwargs)[source]

Bases: FilterEntityAlternativeMixin, EditParameterValueMixin, CompoundModelBase

A model that concatenates several single parameter_value models and one empty parameter_value model.

property item_type[source]

Returns the DB item type, e.g., ‘parameter_value’.

Returns:

str

property field_map[source]
property _single_model_type[source]

Returns a constructor for the single models.

Returns:

SingleParameterModel

property _empty_model_type[source]

Returns a constructor for the empty model.

Returns:

EmptyParameterModel

_make_header()[source]
class spinetoolbox.spine_db_editor.mvcmodels.compound_models.CompoundEntityAlternativeModel(*args, **kwargs)[source]

Bases: FilterEntityAlternativeMixin, CompoundModelBase

Provides the interface to filter by entity and alternative.

property item_type[source]

Returns the DB item type, e.g., ‘parameter_value’.

Returns:

str

property _single_model_type[source]

Returns a constructor for the single models.

Returns:

SingleParameterModel

property _empty_model_type[source]

Returns a constructor for the empty model.

Returns:

EmptyParameterModel

_make_header()[source]