spinetoolbox.mvcmodels.compound_parameter_models

Compound models for object parameter definitions and values. These models concatenate several ‘single’ models and one ‘empty’ model.

authors:
  1. Marin (KTH)
date:

28.6.2019

Module Contents

class spinetoolbox.mvcmodels.compound_parameter_models.CompoundParameterModel(parent, db_mngr, *db_maps)[source]

Bases: spinetoolbox.mvcmodels.compound_table_model.CompoundWithEmptyTableModel

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

Initializes model.

Parameters:
  • parent (DataStoreForm) – the parent object
  • db_mngr (SpineDBManager) – the database manager
  • *db_maps (DiffDatabaseMapping) – the database maps included in the model
remove_selection_requested[source]
entity_class_type[source]

Returns the entity class type, either ‘object class’ or ‘relationship class’.

Returns:str
item_type[source]

Returns the parameter item type, either ‘parameter definition’ or ‘parameter value’.

Returns:str
_single_model_type[source]

Returns a constructor for the single models.

Returns:SingleParameterModel
_empty_model_type[source]

Returns a constructor for the empty model.

Returns:EmptyParameterModel
_entity_class_id_key[source]

Returns the key of the entity class id in the model items (either “object_class_id” or “relationship_class_id”)

Returns:str
_make_header(self)[source]
init_model(self)[source]

Initializes the model.

_make_auto_filter_menus(self)[source]

Makes auto filter menus.

get_auto_filter_menu(self, logical_index)[source]

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

Parameters:logical_index (int) –
Returns:ParameterViewFilterMenu
fetchMore(self, parent=QModelIndex())[source]

Populates filter menus as submodels are fetched.

_add_data_to_filter_menus(self, sub_model)[source]

Adds data of given sub-model to filter menus.

Parameters:sub_model (SingleParameterModel) –
_modify_data_in_filter_menus(self, action, db_map, db_items)[source]

Modifies data in filter menus.

Parameters:
  • action (str) – either ‘add’, ‘remove’, or ‘update’
  • db_map (DiffDatabaseMapping) –
  • db_items (list(dict)) –
_do_add_data_to_filter_menus(self, db_map, db_items)[source]
_do_update_data_in_filter_menus(self, db_map, db_items)[source]
_do_remove_data_from_filter_menus(self, db_map, db_items)[source]
headerData(self, section, orientation=Qt.Horizontal, role=Qt.DisplayRole)[source]

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

_get_entity_classes(self, db_map)[source]

Returns a list of entity classes from the given db_map.

Parameters:db_map (DiffDatabaseMapping) –
Returns:list
_create_single_models(self)[source]

Returns a list of single models for this compound model, one for each entity class in each database.

Returns:list
_create_empty_model(self)[source]

Returns the empty model for this compound model.

Returns:EmptyParameterModel
filter_accepts_model(self, model)[source]

Returns a boolean indicating whether or not the given model should be included in this compound model.

Parameters:model (SingleParameterModel, EmptyParameterModel) –
Returns:bool
_main_filter_accepts_model(self, model)[source]
_auto_filter_accepts_model(self, model)[source]
accepted_single_models(self)[source]

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

Returns:list
static _settattr_if_different(obj, attr, val)[source]

Sets the given attribute of the given object to the given value if it’s different from the one currently stored. Used for updating filters.

Returns:True if the attributed was set, False otherwise
Return type:bool
update_main_filter(self)[source]

Updates and applies the main filter.

update_compound_main_filter(self)[source]

Updates the main filter in the compound model by setting the _accepted_entity_class_ids attribute.

Returns:True if the filter was updated, None otherwise
Return type:bool
update_single_main_filter(self, model)[source]

Updates the filter in the given single model by setting its _selected_param_def_ids attribute.

Parameters:model (SingleParameterModel) –
Returns:True if the filter was updated, None otherwise
Return type:bool
update_auto_filter(self, field, valid_values, has_filter)[source]

Updates and applies the auto filter.

Parameters:
  • field (str) – the field name
  • valid_values (list(str)) – accepted values for the field
  • has_filter (bool) –
static _build_auto_filter(field_menu_data, valid_values, has_filter)[source]
update_compound_auto_filter(self, field, auto_filter)[source]

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

Parameters:
  • field (str) – the field name
  • auto_filter (dict) – maps tuple (database map, entity class id) to list of accepted ids for the field
update_single_auto_filter(self, model, field)[source]

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

Parameters:
Returns:

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

Return type:

bool

_row_map_for_model(self, model)[source]

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

Parameters:model (SingleParameterModel, EmptyParameterModel) –
Returns:tuples (model, row number) for each accepted row
Return type:list
_models_with_db_map(self, db_map)[source]

Returns a collection of single models with given db_map.

Parameters:db_map (DiffDatabaseMapping) –
Returns:list
receive_entity_classes_removed(self, db_map_data)[source]

Runs when entity classes are removed from the dbs. Removes sub-models for the given entity classes and dbs.

Parameters:db_map_data (dict) – list of removed dict-items keyed by DiffDatabaseMapping
_item_ids_per_class_id(self, items)[source]

Returns a dict mapping entity class ids to a set of item ids.

Parameters:items (list) –
Returns:dict
receive_parameter_data_added(self, 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 removed dict-items keyed by DiffDatabaseMapping
receive_parameter_data_updated(self, 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 DiffDatabaseMapping
receive_parameter_data_removed(self, 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 DiffDatabaseMapping
_emit_data_changed_for_column(self, field)[source]

Lazily emits data changed for an entire column.

Parameters:field (str) – the column header
db_item(self, index)[source]
value_name(self, index)[source]
class spinetoolbox.mvcmodels.compound_parameter_models.CompoundObjectParameterMixin[source]

Implements the interface for populating and filtering a compound object parameter model.

entity_class_type[source]
_get_entity_classes(self, db_map)[source]
class spinetoolbox.mvcmodels.compound_parameter_models.CompoundRelationshipParameterMixin[source]

Implements the interface for populating and filtering a compound relationship parameter model.

entity_class_type[source]
_get_entity_classes(self, db_map)[source]
class spinetoolbox.mvcmodels.compound_parameter_models.CompoundParameterDefinitionMixin[source]

Handles signals from db mngr for parameter definition models.

item_type[source]
receive_parameter_definition_tags_set(self, db_map_data)[source]
class spinetoolbox.mvcmodels.compound_parameter_models.CompoundParameterValueMixin[source]

Handles signals from db mngr for parameter value models.

item_type[source]
entity_type[source]

Returns the entity type, either ‘object’ or ‘relationship’ Used by update_single_main_filter.

Returns:str
update_single_main_filter(self, model)[source]

Update the filter for the given model.

class spinetoolbox.mvcmodels.compound_parameter_models.CompoundObjectParameterDefinitionModel[source]

Bases: spinetoolbox.mvcmodels.compound_parameter_models.CompoundObjectParameterMixin, spinetoolbox.mvcmodels.compound_parameter_models.CompoundParameterDefinitionMixin, spinetoolbox.mvcmodels.compound_parameter_models.CompoundParameterModel

A model that concatenates several single object parameter definition models and one empty object parameter definition model.

_make_header(self)[source]
class spinetoolbox.mvcmodels.compound_parameter_models.CompoundRelationshipParameterDefinitionModel[source]

Bases: spinetoolbox.mvcmodels.compound_parameter_models.CompoundRelationshipParameterMixin, spinetoolbox.mvcmodels.compound_parameter_models.CompoundParameterDefinitionMixin, spinetoolbox.mvcmodels.compound_parameter_models.CompoundParameterModel

A model that concatenates several single relationship parameter definition models and one empty relationship parameter definition model.

_make_header(self)[source]
class spinetoolbox.mvcmodels.compound_parameter_models.CompoundObjectParameterValueModel[source]

Bases: spinetoolbox.mvcmodels.compound_parameter_models.CompoundObjectParameterMixin, spinetoolbox.mvcmodels.compound_parameter_models.CompoundParameterValueMixin, spinetoolbox.mvcmodels.compound_parameter_models.CompoundParameterModel

A model that concatenates several single object parameter value models and one empty object parameter value model.

entity_type[source]
_make_header(self)[source]
class spinetoolbox.mvcmodels.compound_parameter_models.CompoundRelationshipParameterValueModel[source]

Bases: spinetoolbox.mvcmodels.compound_parameter_models.CompoundRelationshipParameterMixin, spinetoolbox.mvcmodels.compound_parameter_models.CompoundParameterValueMixin, spinetoolbox.mvcmodels.compound_parameter_models.CompoundParameterModel

A model that concatenates several single relationship parameter value models and one empty relationship parameter value model.

entity_type[source]
_make_header(self)[source]