widgets.custom_qtableview

Custom QTableView classes that support copy-paste and the like.

author:
  1. Marin (KTH)
date:

18.5.2018

Module Contents

class widgets.custom_qtableview.CopyPasteTableView[source]

Bases: PySide2.QtWidgets.QTableView

Custom QTableView class with copy and paste methods.

keyPressEvent(self, event)[source]

Copy and paste to and from clipboard in Excel-like format.

copy(self)[source]

Copy current selection to clipboard in excel format.

canPaste(self)[source]
paste(self)[source]

Paste data from clipboard.

static _read_pasted_text(text)[source]

Parses a tab separated CSV text table.

Parameters:text (str) – a CSV formatted table
Returns:a list of rows
paste_on_selection(self)[source]

Paste clipboard data on selection, but not beyond. If data is smaller than selection, repeat data to fit selection.

paste_normal(self)[source]

Paste clipboard data, overwriting cells if needed

class widgets.custom_qtableview.AutoFilterMenu(parent)[source]

Bases: PySide2.QtWidgets.QMenu

A widget to show the auto filter ‘menu’.

parent

the parent widget.

Type:QTableView
asc_sort_triggered[source]
desc_sort_triggered[source]
filter_triggered[source]
_model_flags(self, index)[source]

Return no item flags.

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

Read checked state from first column.

_proxy_model_filter_accepts_row(self, source_row, source_parent)[source]

Overridden method to always accept first row.

_handle_view_entered(self, index)[source]

Highlight current row.

_view_key_press_event(self, event)[source]
_handle_view_clicked(self, index)[source]
toggle_checked_state(self, checked_index)[source]

Toggle checked state.

_view_leave_event(self, event)[source]

Clear selection.

set_data_for_all_index(self)[source]

Set data for ‘all’ index based on data from all other indexes.

_handle_ok_action_triggered(self, checked=False)[source]

Called when user presses Ok.

set_values(self, values)[source]

Set values to show in the ‘menu’.

popup(self, pos, width=0, at_action=None)[source]
class widgets.custom_qtableview.AutoFilterCopyPasteTableView(parent)[source]

Bases: widgets.custom_qtableview.CopyPasteTableView

Custom QTableView class with autofilter functionality.

parent

The parent of this view

Type:QWidget
filter_changed[source]
keyPressEvent(self, event)[source]
setModel(self, model)[source]

Disconnect sectionPressed signal, only connect it to show_filter_menu slot. Otherwise the column is selected when pressing on the header.

toggle_auto_filter(self, logical_index)[source]

Called when user clicks on a horizontal section header. Show/hide the auto filter widget.

update_auto_filter(self)[source]

Called when the user selects Ok in the auto filter menu. Set ‘filtered out values’ in auto filter model.

sort_model_ascending(self)[source]

Called when the user selects sort ascending in the auto filter widget.

sort_model_descending(self)[source]

Called when the user selects sort descending in the auto filter widget.

class widgets.custom_qtableview.FrozenTableView(parent=None)[source]

Bases: PySide2.QtWidgets.QTableView

clear(self)[source]
get_selected_row(self)[source]
set_data(self, headers, values)[source]
class widgets.custom_qtableview.SimpleCopyPasteTableView(parent=None)[source]

Bases: PySide2.QtWidgets.QTableView

Custom QTableView class that copies and paste data in response to key press events.

parent

The parent of this view

Type:QWidget
clipboard_data_changed(self)[source]
keyPressEvent(self, event)[source]

Copy and paste to and from clipboard in Excel-like format.

class widgets.custom_qtableview.IndexedParameterValueTableViewBase[source]

Bases: widgets.custom_qtableview.CopyPasteTableView

Custom QTableView base class with copy and paste methods for indexed parameter values.

copy(self)[source]

Copy current selection to clipboard in CSV format.

static _read_pasted_text(text)[source]

Reads CSV formatted table.

paste(self)[source]

Pastes data from clipboard to selection.

static _range(indexes)[source]

Returns the top left and bottom right corners of selected model indexes.

Parameters:indexes (list) – a list of selected QModelIndex objects
Returns:a tuple (top row, bottom row, left column, right column)
_select_pasted(self, indexes)[source]

Selects the given model indexes.

class widgets.custom_qtableview.TimeSeriesFixedResolutionTableView[source]

Bases: widgets.custom_qtableview.IndexedParameterValueTableViewBase

A QTableView for fixed resolution time series table.

paste(self)[source]

Pastes data from clipboard.

static _read_pasted_text(text)[source]

Parses the given CSV table.

Parsing is locale aware.

Parameters:text (str) – a CSV table containing numbers
Returns:A list of floats
_paste_to_values_column(self, values, first_row, paste_length)[source]

Pastes data to the Values column.

Parameters:
  • values (list) – a list of float values to paste
  • first_row (int) – index of the first row where to paste
  • paste_length (int) – length of the paste selection (can be different from len(values))
Returns:

A tuple (list(pasted indexes), list(pasted values))

class widgets.custom_qtableview.IndexedValueTableView[source]

Bases: widgets.custom_qtableview.IndexedParameterValueTableViewBase

A QTableView class with for variable resolution time series and time patterns.

paste(self)[source]

Pastes data from clipboard.

_paste_two_columns(self, data_indexes, data_values, first_row, paste_length)[source]

Pastes data indexes and values.

Parameters:
  • data_indexes (list) – a list of data indexes (time stamps/durations)
  • data_values (list) – a list of data values
  • first_row (int) – first row index
  • paste_length (int) – selection length for pasting
Returns:

a tuple (modified model indexes, modified model values)

_paste_single_column(self, values, first_row, first_column, paste_length)[source]

Pastes a single column of data

Parameters:
  • values (list) – a list of data to paste (data indexes or values)
  • first_row (int) – first row index
  • paste_length (int) – selection length for pasting
Returns:

a tuple (modified model indexes, modified model values)

static _read_pasted_text(text)[source]

Parses a given CSV table

Parameters:text (str) – a CSV table
Returns:a tuple (data indexes, data values)