spinetoolbox.mvcmodels.map_model
A model for maps, used by the parameter_value editors.
Module Contents
Functions
|
Turns table into nested dictionaries. |
|
Constructs a |
|
Counts the number of non-empty elements at the beginning of row. |
|
Collects index names from Map. |
|
Applies index names to Map. |
Converts instances of |
Attributes
Sentinel for empty cells. |
- class spinetoolbox.mvcmodels.map_model.MapModel(map_value, parent)[source]
Bases:
PySide6.QtCore.QAbstractTableModel
A model for Map type parameter values.
This model represents the Map as a 2D table. Each row consists of one or more index columns and a value column. The last columns of a row are padded with Nones.
Example
Map { "A": 1.0 "B": Map {"a": -1.0} "C": 3.0 }
The table corresponding to the above map:
“A”
1.0
None
“B”
“a”
-1.0
“C”
3.0
None
- Parameters
map_value (Map) – a map
parent (QObject) – parent object
- clear(indexes)[source]
Clears table cells.
- Parameters
indexes (list of QModelIndex) – indexes to clear
- data(index, role=Qt.ItemDataRole.DisplayRole)[source]
Returns the data associated with the given role.
- headerData(section, orientation, role=Qt.ItemDataRole.DisplayRole)[source]
Returns row numbers for vertical headers and column titles for horizontal ones.
- insertColumns(column, count, parent=QModelIndex())[source]
Inserts new columns into the map.
- Parameters
column (int) – column index where to insert
count (int) – number of new columns
parent (QModelIndex) – ignored
- Returns
True if insertion was successful, False otherwise
- Return type
bool
- insertRows(row, count, parent=QModelIndex())[source]
Inserts new rows into the map.
- Parameters
row (int) – an index where to insert the new data
count (int) – number of rows to insert
parent (QModelIndex) – an index to a parent model
- Returns
True if the operation was successful
- Return type
bool
- is_leaf_value(index)[source]
Checks if given model index contains a leaf value.
- Parameters
index (QModelIndex) – index to check
- Returns
True if index points to leaf value, False otherwise
- Return type
bool
- _is_in_expanse(row, column)[source]
Returns True, if given row and column is in the right or bottom ‘expanding’ zone.
- Parameters
row (int) – row index
column (int) – column index
- Returns
True if the cell is in the expanse, False otherwise
- Return type
bool
- is_expanse_column(column)[source]
Returns True if given column is the expanse column.
- Parameters
column (int) – column
- Returns
True if column is expanse column, False otherwise
- Return type
bool
- is_expanse_row(row)[source]
Returns True if given row is the expanse row.
- Parameters
row (int) – row
- Returns
True if row is the expanse row, False otherwise
- Return type
bool
- removeColumns(column, count, parent=QModelIndex())[source]
Removes columns from the map.
- Parameters
column (int) – first column to remove
count (int) – number of columns to remove
parent (QModelIndex) – an index to a parent model
- Returns
True if the operation was successful
- removeRows(row, count, parent=QModelIndex())[source]
Removes rows from the map.
- Parameters
row (int) – first row to remove
count (int) – number of rows to remove
parent (QModelIndex) – an index to a parent model
- Returns
True if the operation was successful
- set_box(top_left, bottom_right, data)[source]
Sets data for several indexes at once.
- Parameters
top_left (QModelIndex) – a sequence of model indexes
bottom_right (QModelIndex) – a sequence of values corresponding to the indexes
data (list of list) – box of data
- spinetoolbox.mvcmodels.map_model._rows_to_dict(rows)[source]
Turns table into nested dictionaries.
- Parameters
rows (list) – a list of row data
- Returns
a nested dictionary
- Return type
dict
- spinetoolbox.mvcmodels.map_model._reconstruct_map(tree)[source]
Constructs a
Map
from a nested dictionary.- Parameters
tree (dict) – a nested dictionary
- Returns
reconstructed Map
- Return type
Map
- spinetoolbox.mvcmodels.map_model._data_length(row)[source]
Counts the number of non-empty elements at the beginning of row.
- Parameters
row (list) – a row of data
- Returns
data length
- Return type
int
- spinetoolbox.mvcmodels.map_model._gather_index_names(map_value)[source]
Collects index names from Map.
Returns only the ‘first’ index name for nested maps at the same depth.
- Parameters
map_value (Map) – map to investigate
- Returns
index names
- Return type
list of str