spinetoolbox.mvcmodels.map_model

A model for maps, used by the parameter_value editors.

authors
  1. Soininen (VTT)

date

11.2.2020

Module Contents

Classes

MapModel

A model for Map type parameter values.

Functions

_rows_to_dict(rows)

Turns table into nested dictionaries.

_reconstruct_map(tree)

Constructs a Map from a nested dictionary.

_data_length(row)

Counts the number of non-None elements at the beginning of row.

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 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

append_column(self)[source]

Appends a new column to the right.

clear(self, indexes)[source]

Clears table cells.

Parameters

indexes (list of QModelIndex) – indexes to clear

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

Returns the number of columns in this model.

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

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

Return type

bool

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

reset(self, map_value)[source]

Resets the model to given map_value.

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

Returns the number of rows.

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

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

Sets data in the map.

Parameters
  • index (QModelIndex) – an index to the model

  • value (object) – JSON representation of the value

  • role (int) – a role

Returns

True if the operation was successful

Return type

bool

trim_columns(self)[source]

Removes empty columns from the right.

value(self)[source]

Returns the Map.

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-None elements at the beginning of row.

Parameters

row (list) – a row of data

Returns

data length

Return type

int