spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models
Provides pivot table models for the Tabular View.
Module Contents
Classes
Base class for all 'top left pivot headers'. |
|
A top left header for an entity class. |
|
A top left header for parameter_definition. |
|
A top left header for parameter index. |
|
A top left header for alternative. |
|
A top left header for scenario. |
|
A top left header for database. |
|
|
|
A model for the pivot table in parameter_value input type. |
|
A model for the pivot table in parameter index expansion input type. |
|
A model for the pivot table in element input type. |
|
A model for the pivot table in scenario alternative input type. |
|
Initialize class. |
Functions
|
Returns a function to compute the db_map-id tuple of an item. |
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftHeaderItem(model)[source]
Base class for all ‘top left pivot headers’. Represents a header located in the top left area of the pivot table.
- Parameters
model (PivotTableModelBase) –
- static accepts(header_id)[source]
Tests if header id is valid.
- Parameters
header_id (Any) – header id
- Returns
True if id is valid, False otherwise
- Return type
bool
- abstract header_data(header_id, role=Qt.ItemDataRole.DisplayRole)[source]
Returns header data for given id.
- Parameters
header_id (Any) – header id
role (Qt.ItemDataRole) – data role
- Returns
data corresponding to role
- Return type
Any
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftEntityHeaderItem(model, rank, class_name, class_id)[source]
Bases:
TopLeftHeaderItem
A top left header for an entity class.
- Parameters
model (PivotTableModelBase) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftParameterHeaderItem(model)[source]
Bases:
TopLeftHeaderItem
A top left header for parameter_definition.
- Parameters
model (PivotTableModelBase) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftParameterIndexHeaderItem(model)[source]
Bases:
TopLeftHeaderItem
A top left header for parameter index.
- Parameters
model (PivotTableModelBase) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftAlternativeHeaderItem(model)[source]
Bases:
TopLeftHeaderItem
A top left header for alternative.
- Parameters
model (PivotTableModelBase) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftScenarioHeaderItem(model)[source]
Bases:
TopLeftHeaderItem
A top left header for scenario.
- Parameters
model (PivotTableModelBase) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftDatabaseHeaderItem(model)[source]
Bases:
TopLeftHeaderItem
A top left header for database.
- Parameters
model (PivotTableModelBase) –
- set_data(codename)[source]
Sets database mapping’s codename.
- Parameters
codename (str) – database codename
- Returns
True if codename was acceptable, False otherwise
- Return type
bool
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.PivotTableModelBase(db_editor)[source]
Bases:
PySide6.QtCore.QAbstractTableModel
- Parameters
db_editor (SpineDBEditor) –
- property plot_x_column[source]
Returns the index of the column designated as Y values for plotting or None.
- abstract call_reset_model(pivot=None)[source]
- Parameters
pivot (tuple, optional) – list of rows, list of columns, list of frozen indexes, frozen value
- update_model(data)[source]
Update model with new data, but doesn’t grow the model.
- Parameters
data (dict) –
- set_frozen(frozen)[source]
Sets the order of frozen headers without changing model data.
- Parameters
frozen (list of str) – new frozen
- set_frozen_value(frozen_value)[source]
Sets frozen value resetting the model.
- Parameters
frozen_value (tuple) – frozen value
- Returns
True if value was set, False otherwise
- Return type
bool
- x_value(index)[source]
Returns x value for given model index.
- Parameters
index (QModelIndex) – model index
- Returns
x value
- Return type
Any
- x_parameter_name()[source]
Returns x column’s parameter name.
- Returns
parameter name
- Return type
str
- rowCount(parent=QModelIndex())[source]
Number of rows in table, number of header rows + datarows + 1 empty row
- columnCount(parent=QModelIndex())[source]
Number of columns in table, number of header columns + datacolumns + 1 empty columns
- top_left_indexes()[source]
Returns indexes in the top left area.
- Returns
list(QModelIndex): top indexes (horizontal headers, associated to rows) list(QModelIndex): left indexes (vertical headers, associated to columns)
- index_in_top_left(index)[source]
Returns whether the given index is in top left corner, where pivot names are displayed.
- index_in_column_headers(index)[source]
Returns whether the given index is in column headers (horizontal) area.
- index_in_row_headers(index)[source]
Returns whether the given index is in row headers (vertical) area.
- index_in_empty_column_headers(index)[source]
Returns whether the given index is in empty column headers (vertical) area.
- index_in_empty_row_headers(index)[source]
Returns whether the given index is in empty row headers (vertical) area.
- column_is_index_column(column)[source]
Returns True if column is the column containing expanded parameter_value indexes.
- map_to_pivot(index)[source]
Returns a tuple of row and column in the pivot model that corresponds to the given model index.
- Parameters
index (QModelIndex) –
- Returns
row int: column
- Return type
int
- top_left_id(index)[source]
Returns the id of the top left header corresponding to the given header index.
- Parameters
index (QModelIndex) –
- Returns
int, NoneType
- _header_id(index)[source]
Returns the id of the given row or column header index.
- Parameters
index (QModelIndex) –
- Returns
tuple or DatabaseMapping or NoneType
- _header_ids(row, column)[source]
Returns the ids for the headers at given row and column.
- Parameters
row (int) –
column (int) –
- Returns
tuple(int)
- header_name(index)[source]
Returns the name corresponding to the given header index. Used by PivotTableView.
- Parameters
index (QModelIndex) –
- Returns
str
- get_db_map_entities()[source]
Returns a dict mapping db maps to a list of dict entity items in the current class.
- Returns
dict
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.ParameterValuePivotTableModel(parent)[source]
Bases:
PivotTableModelBase
A model for the pivot table in parameter_value input type.
- Parameters
parent (SpineDBEditor) –
- _load_empty_parameter_value_data(db_map_entities=None, db_map_parameter_ids=None, db_map_alternative_ids=None)[source]
Returns a dict containing all possible combinations of entities and parameters for the current class in all db_maps.
- Parameters
db_map_entities (dict, optional) – if given, only load data for these db maps and entities
db_map_parameter_ids (dict, optional) – if given, only load data for these db maps and parameter definitions
db_map_alternative_ids (dict, optional) – if given, only load data for these db maps and alternatives
- Returns
Key is a tuple object_id, …, parameter_id, value is None.
- Return type
dict
- _all_combination_for_empty_parameter_value(db_map_entities, db_map_parameter_ids, db_map_alternative_ids)[source]
- _load_full_parameter_value_data(db_map_parameter_values=None, action='add')[source]
Returns a dict of parameter values for the current class.
- Parameters
db_map_parameter_values (list, optional) –
action (str) –
- Returns
Key is a tuple object_id, …, parameter_id, value is the parameter_value.
- Return type
dict
- db_map_entity_ids(indexes)[source]
Returns db_map and entity ids for given indexes. Used by PivotTableView.
- Parameters
indexes (list of QModelIndex) – indexes corresponding to entity items
- Returns
mapping DatabaseMapping to set of entity ids
- Return type
dict
- all_header_names(index)[source]
Returns the entity, parameter, alternative, and db names corresponding to the given data index.
- Parameters
index (QModelIndex) –
- Returns
object names str: parameter name str: alternative name str: db name
- Return type
list(str)
- index_name(index)[source]
Returns a string that concatenates the object and parameter names corresponding to the given data index. Used by plotting and ParameterValueEditor.
- Parameters
index (QModelIndex) –
- Returns
str
- column_name(column)[source]
Returns a string that concatenates the object and parameter names corresponding to the given column. Used by plotting.
- Parameters
column (int) –
- Returns
str
- _batch_set_parameter_value_data(row_map, column_map, data, values)[source]
Sets parameter values in batch.
- 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
- _get_db_map_parameter_value_or_def_ids(item_type)[source]
Returns a dict mapping db maps to a list of integer parameter (value or def) ids from the current class.
- Parameters
item_type (str) – either “parameter_value” or “parameter_definition”
- Returns
dict
- _get_db_map_parameter_values_or_defs(item_type)[source]
Returns a dict mapping db maps to list of dict parameter (value or def) items from the current class.
- Parameters
item_type (str) – either “parameter_value” or “parameter_definition”
- Returns
dict
- load_full_parameter_value_data(db_map_parameter_values=None, action='add')[source]
Returns a dict of parameter values for the current class.
- Parameters
db_map_parameter_values (list, optional) –
action (str) –
- Returns
Key is a tuple object_id, …, parameter_id, value is the parameter_value.
- Return type
dict
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.IndexExpansionPivotTableModel(parent)[source]
Bases:
ParameterValuePivotTableModel
A model for the pivot table in parameter index expansion input type.
- Parameters
parent (SpineDBEditor) –
- column_is_index_column(column)[source]
Returns True if column is the column containing expanded parameter_value indexes.
- _load_empty_parameter_value_data(db_map_entities=None, db_map_parameter_ids=None, db_map_alternative_ids=None)[source]
Does not load the data since adding values in index expansion mode is disabled.
- Parameters
db_map_entities (dict, optional) – mapping from database map to iterable of entity items
db_map_parameter_ids (dict, optional) – mapping from database map to iterable of parameter definition id tuples
db_map_alternative_ids (dict, optional) – mapping from database map to iterable of alternative id tuples
- Returns
empty data
- Return type
dict
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.ElementPivotTableModel(parent)[source]
Bases:
PivotTableModelBase
A model for the pivot table in element input type.
- Parameters
parent (SpineDBEditor) –
- _load_full_element_data(db_map_entities=None, action='add')[source]
Returns a dict of entity elements in the current class.
- Parameters
db_map_entities (dict, optional) – a mapping from database map to entities in the current entity class
action (str) – ‘add’ or ‘remove’
- Returns
Key is db_map-object id tuple, value is relationship id.
- Return type
dict
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.ScenarioAlternativePivotTableModel(parent)[source]
Bases:
PivotTableModelBase
A model for the pivot table in scenario alternative input type.
- Parameters
parent (SpineDBEditor) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.PivotTableSortFilterProxy(parent=None)[source]
Bases:
PySide6.QtCore.QSortFilterProxyModel
Initialize class.
- set_filter(identifier, filter_value)[source]
Sets filter for a given index (object_class) name.
- Parameters
identifier (int) – index identifier
filter_value (set, None) – A set of accepted values, or None if no filter (all pass)
- filterAcceptsRow(source_row, source_parent)[source]
Returns true if the item in the row indicated by the given source_row and source_parent should be included in the model; otherwise returns false.