spinetoolbox.mvcmodels.compound_parameter_models
¶
Compound models for object parameter definitions and values. These models concatenate several ‘single’ models and one ‘empty’ model.
authors: |
|
---|---|
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
-
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
-
_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
Makes auto filter menus.
Returns auto filter menu for given logical index from header view.
Parameters: logical_index (int) – Returns: ParameterViewFilterMenu
Adds data of given sub-model to filter menus.
Parameters: sub_model (SingleParameterModel) –
Modifies data in filter menus.
Parameters: - action (str) – either ‘add’, ‘remove’, or ‘update’
- db_map (DiffDatabaseMapping) –
- db_items (list(dict)) –
-
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
-
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_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) –
-
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: - 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_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
-
class
spinetoolbox.mvcmodels.compound_parameter_models.
CompoundObjectParameterMixin
[source]¶ Implements the interface for populating and filtering a compound object parameter model.
-
class
spinetoolbox.mvcmodels.compound_parameter_models.
CompoundRelationshipParameterMixin
[source]¶ Implements the interface for populating and filtering a compound relationship parameter model.
-
class
spinetoolbox.mvcmodels.compound_parameter_models.
CompoundParameterDefinitionMixin
[source]¶ Handles signals from db mngr for parameter definition models.
-
class
spinetoolbox.mvcmodels.compound_parameter_models.
CompoundParameterValueMixin
[source]¶ Handles signals from db mngr for parameter value models.
-
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.
-
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.
-
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.
-
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.