spinetoolbox.spine_io.io_models

Classes for handling models in PySide2’s model/view framework.

author:
  1. Vennström (VTT)
date:

1.6.2019

Module Contents

spinetoolbox.spine_io.io_models.Margin[source]
spinetoolbox.spine_io.io_models._MAPPING_COLORS[source]
spinetoolbox.spine_io.io_models._ERROR_COLOR[source]
spinetoolbox.spine_io.io_models._COLUMN_TYPE_ROLE[source]
spinetoolbox.spine_io.io_models._COLUMN_NUMBER_ROLE[source]
spinetoolbox.spine_io.io_models._ALLOWED_TYPES[source]
spinetoolbox.spine_io.io_models._TYPE_TO_FONT_AWESOME_ICON[source]
spinetoolbox.spine_io.io_models._MAPTYPE_DISPLAY_NAME[source]
spinetoolbox.spine_io.io_models._DISPLAY_TYPE_TO_TYPE[source]
spinetoolbox.spine_io.io_models._TYPE_TO_DISPLAY_TYPE[source]
class spinetoolbox.spine_io.io_models.MappingPreviewModel(parent=None)[source]

Bases: spinetoolbox.mvcmodels.minimal_table_model.MinimalTableModel

A model for highlighting columns, rows, and so on, depending on Mapping specification. Used by ImportPreviewWidget.

columnTypesUpdated[source]
rowTypesUpdated[source]
mappingChanged[source]
mapping(self)[source]
clear(self)[source]
reset_model(self, main_data=None)[source]
set_mapping(self, mapping)[source]

Set mapping to display colors from

Parameters:{MappingSpecModel} -- mapping model (mapping) –
validate(self, section, orientation=Qt.Horizontal)[source]
get_type(self, section, orientation=Qt.Horizontal)[source]
get_types(self, orientation=Qt.Horizontal)[source]
set_type(self, section, section_type, orientation=Qt.Horizontal)[source]
_mapping_data_changed(self)[source]
update_colors(self)[source]
data_error(self, index, role=Qt.DisplayRole, orientation=Qt.Horizontal)[source]
data(self, index, role=Qt.DisplayRole)[source]
data_color(self, index)[source]

returns background color for index depending on mapping

Parameters:{PySide2.QtCore.QModelIndex} -- index (index) –
Returns:[QColor] – QColor of index
index_in_mapping(self, mapping, index)[source]

Checks if index is in mapping

Parameters:
  • {Mapping} -- mapping (mapping) –
  • {QModelIndex} -- index (index) –
Returns:

[bool] – returns True if mapping is in index

mapping_column_ref_int_list(self)[source]

Returns a list of column indexes that are not pivoted

Returns:[List[int]] – list of ints
class spinetoolbox.spine_io.io_models.MappingSpecModel(model, parent=None)[source]

Bases: PySide2.QtCore.QAbstractTableModel

A model to hold a Mapping specification.

skip_columns[source]
map_type[source]
last_pivot_row[source]
dimension[source]
import_objects[source]
parameter_type[source]
is_pivoted[source]
read_start_row[source]
set_read_start_row(self, row)[source]
set_import_objects(self, flag)[source]
set_mapping(self, mapping)[source]
set_dimension(self, dim)[source]
change_model_class(self, new_class)[source]

Change model between Relationship and Object class

change_parameter_type(self, new_type)[source]

Change parameter type

update_display_table(self)[source]
get_map_type_display(self, mapping, name)[source]
get_map_value_display(self, mapping, name)[source]
get_map_append_display(self, mapping, name)[source]
get_map_prepend_display(self, mapping, name)[source]
data(self, index, role)[source]
data_color(self, display_name)[source]
rowCount(self, index=None)[source]
columnCount(self, index=None)[source]
headerData(self, section, orientation, role)[source]
flags(self, index)[source]
setData(self, index, value, role)[source]
set_type(self, name, value)[source]
set_value(self, name, value)[source]
set_append_str(self, name, value)[source]
set_prepend_str(self, name, value)[source]
get_mapping_from_name(self, name)[source]
set_mapping_from_name(self, name, mapping)[source]
set_skip_columns(self, columns=None)[source]
set_time_series_repeat(self, repeat)[source]

Toggles the repeat flag in the parameter’s options.

model_parameters(self)[source]

Returns the mapping’s parameters.

class spinetoolbox.spine_io.io_models.MappingListModel(mapping_list, parent=None)[source]

Bases: PySide2.QtCore.QAbstractListModel

A model to hold a list of Mappings.

set_model(self, model)[source]
get_mappings(self)[source]
rowCount(self, index=None)[source]
data_mapping(self, index)[source]
data(self, index, role=Qt.DisplayRole)[source]
add_mapping(self)[source]
remove_mapping(self, row)[source]
spinetoolbox.spine_io.io_models._create_allowed_types_menu(parent, trigger_slot)[source]

Returns a menu which contains actions for each allowed data type.

Parameters:
  • parent (QWidget) – a parent widget
  • trigger_slot (Slot) – a slot which is connected to QMenu’s ‘triggered’ signal
Returns:

a menu

Return type:

QMenu

class spinetoolbox.spine_io.io_models.HeaderWithButton(orientation, parent=None)[source]

Bases: PySide2.QtWidgets.QHeaderView

Class that reimplements the QHeaderView section paint event to draw a button that is used to display and change the type of that column or row.

display_all[source]
sections_with_buttons[source]
_menu_pressed(self, action)[source]

Sets the data type of a row or column according to menu action.

set_data_types(self, sections, type_str, update_viewport=True)[source]

Sets the data types of given sections (rows, columns).

Parameters:
  • sections (Iterable or int or NoneType) – row/column index
  • type_str (str) – data type name
  • update_viewport (bool) – True if the buttons need repaint
widget_width(self)[source]

Width of widget

Returns:[int] – Width of widget
widget_height(self)[source]

Height of widget

Returns:[int] – Height of widget
mouseMoveEvent(self, mouse_event)[source]

Moves the button to the correct section so that interacting with the button works.

mousePressEvent(self, mouse_event)[source]

Move the button to the pressed location and show or hide it if button should not be shown.

leaveEvent(self, event)[source]

Hide button

_set_button_geometry(self, button, index)[source]

Sets a buttons geometry depending on the index.

Parameters:
  • {QWidget} -- QWidget that geometry should be set (button) –
  • {int} -- logical_index to set position and geometry to. (index) –
_section_resize(self, i)[source]

When a section is resized.

Parameters:{int} -- logical index to section being resized (i) –
paintSection(self, painter, rect, logical_index)[source]

Paints a section of the QHeader view.

Works by drawing a pixmap of the button to the left of the original paint rectangle. Then shifts the original rect to the right so these two doesn’t paint over each other.

sectionSizeFromContents(self, logical_index)[source]

Add the button width to the section so it displays right.

Parameters:{int} -- logical index of section (logical_index) –
Returns:[QSize] – Size of section
_section_move(self, logical, old_visual_index, new_visual_index)[source]

Section beeing moved.

Parameters:
  • {int} -- logical index of section beeing moved. (logical) –
  • {int} -- old visual index of section (old_visual_index) –
  • {int} -- new visual index of section (new_visual_index) –
fix_widget_positions(self)[source]

Update position of interaction button

set_margins(self, margins)[source]

Sets the header margins.

class spinetoolbox.spine_io.io_models.TableViewWithButtonHeader(parent=None)[source]

Bases: PySide2.QtWidgets.QTableView

Customized table with data type buttons on horizontal and vertical headers

Parameters:parent (QWidget) – a parent widget
scrollContentsBy(self, dx, dy)[source]

Scrolls the table’s contents by given delta.

_create_horizontal_header_menu(self)[source]

Returns a new menu for the horizontal header

_create_vertical_header_menu(self)[source]

Returns a new menu for the vertical header.

_show_horizontal_header_menu(self, pos)[source]

Opens the context menu of the horizontal header.

_show_vertical_header_menu(self, pos)[source]

Opens the context menu of the vertical header.

_set_all_column_data_types(self, action)[source]

Sets all columns data types to the type given by action’s text.

_set_all_row_data_types(self, action)[source]

Sets all rows data types to the type given by action’s text.