spinetoolbox.mvcmodels.map_model

A model for maps, used by the parameter value editors.

authors:
  1. Soininen (VTT)
date:

11.2.2020

Module Contents

class spinetoolbox.mvcmodels.map_model.MapModel(map_value)[source]

Bases: PySide2.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 None.

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
append_column(self)[source]

Appends a new column to the right.

columnCount(self, index=QModelIndex())[source]

Returns the number of columns in this model.

data(self, index, role=Qt.DisplayRole)[source]

Returns the data associated with the given role.

flags(self, index)[source]

Returns flags at index.

headerData(self, section, orientation, role=Qt.DisplayRole)[source]

Returns row numbers for vertical headers and column titles for horizontal ones.

insertRows(self, 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

reset(self, map_value)[source]

Resets the model to given map_value.

rowCount(self, parent=QModelIndex())[source]

Returns the number of rows.

removeRows(self, row, count, parent=QModelIndex())[source]

Removes rows from the map.

Parameters:
  • row (int) – an index where to remove the data
  • count (int) – number of rows pairs to remove
  • parent (QModelIndex) – an index to a parent model
Returns:

True if the operation was successful

setData(self, index, value, role=Qt.EditRole)[source]

Sets data in the map.

Parameters:
  • index (QModelIndex) – an index to the model
  • value (str) – JSON representation of the value
  • role (int) – a role
Returns:

True if the operation was successful

trim_columns(self)[source]

Removes empty columns from the right.

value(self)[source]

Returns the Map.

spinetoolbox.mvcmodels.map_model._as_rows(map_value, row_this_far=None)[source]

Converts given Map into list of rows recursively.

spinetoolbox.mvcmodels.map_model._make_square(rows)[source]

Makes a list of rows a 2D table by appending None to the row ends.

spinetoolbox.mvcmodels.map_model._reconstruct_map(rows, first_row, last_row, column_index)[source]