Models¶
Constants¶
Datasources¶
This Module contains generic classes for handle table model data items Broken into to main base classes:
BaseDataSource - Used to represent Table rows ColumnDataSource - Used to represent Table columns
Subclasses defined here contain linked delegates based on dataType i.e list == combobox
- class BaseDataSource(*args: Any, **kwargs: Any)¶
Bases:
QObject
- enabledColor = '#C4C4C4'¶
- disabledColor = '#5E5E5E'¶
- property children¶
- iterChildren(recursive=True)¶
- modelIndex()¶
- width()¶
- userObject(index)¶
- userObjects()¶
- setUserObjects(objects)¶
- hasChildren()¶
- canFetchMore()¶
- fetchMore()¶
- isRoot()¶
Determines if this item is the root of the tree
- Returns:
- Return type:
- rowCount()¶
Returns the total row count for the dataSource defaults to the len of the dataSource children
- Return type:
- columnCount()¶
- parentSource()¶
Returns the parent of this node
- Return type:
Node
- setParentSource(parentSource)¶
- index()¶
- addChild(child)¶
- insertChild(index, child)¶
- insertChildren(index, children)¶
- setData(index, value)¶
Sets the text value of this node at the specified column
- data(index)¶
The text for this node or column. index parameter with a value of 0 is the first column.
- customRoles(index)¶
- dataByRole(index, role)¶
- setDataByCustomRole(index, data, role)¶
- toolTip(index)¶
The tooltip for the index.
- setToolTip(index, value)¶
- icon(index)¶
The icon for the index.
- Parameters:
index (int) – The column index for the item.
- Return type:
QtGui.QIcon
- iconSize(index)¶
- headerIcon()¶
Returns the column header icon.
- Return type:
QtGui.QIcon
- headerVerticalText(index)¶
The Vertical header text, if the return type is None then no text is displayed, an empty string will produce a gap in the header.
- headerVerticalIcon(index)¶
The Vertical header icon.
- Parameters:
index (int) – The column index for the item
- Return type:
QtGui.QIcon()
- isEditable(index)¶
Determines if this node can be editable e.g set text. Defaults to False.
- isEnabled(index)¶
Determines if this node is enabled.
- mimeData(indices)¶
- dropMimeData(items, action)¶
- Parameters:
items (list[value]) – the column index
- textMargin(index)¶
- onVerticalHeaderSelection(index)¶
Triggered by the table view(if this source is attached to one) when the vertical header is clicked.
- Parameters:
index (int) – the row index
- contextMenu(selection, menu)¶
- sort(index=0, order=MockExt.QtCore.Qt.DescendingOrder)¶
This sort function purpose is for sorting the data by column.
- delegate(parent)¶
- class ColumnDataSource(*args: Any, **kwargs: Any)¶
Bases:
BaseDataSource
- sort(rowDataSource, index=0, order=MockExt.QtCore.Qt.DescendingOrder)¶
This sort function purpose is for sorting the data by column.
- setData(rowDataSource, index, value)¶
Sets the text value of this node at the specified column.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – The column index
- Returns:
the new text value for this nodes column index
- Return type:
- data(rowDataSource, index)¶
The text for this node or column. index parameter with a value of 0 is the first column.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – The column index for the text
- Returns:
the column text
- Return type:
- dataByRole(rowDataSource, index, role)¶
- customRoles(rowDataSource, index)¶
- textMargin(rowDataSource, index)¶
- toolTip(rowDataSource, index)¶
The tooltip for this node.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
- Return type:
- icon(rowDataSource, index)¶
The icon for this node.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
- Return type:
QtGui.QIcon
- isCheckable(rowDataSource, index)¶
The icon for this node.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
- Return type:
QtGui.QIcon
- isEditable(rowDataSource, index)¶
Determines if this node can be editable e.g set text. Defaults to False.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- Returns:
whether or not this node is editable, defaults to False
- Return type:
- isEnabled(rowDataSource, index)¶
Determines if this node is enabled.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- Returns:
whether or not this node is enabled, defaults to True
- Return type:
- supportsDrag(rowDataSource, index)¶
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- Returns:
whether or not this node supports drag
- Return type:
- supportsDrop(rowDataSource, index)¶
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- Returns:
whether or not this node supports drop
- Return type:
- mimeData(rowDataSource, index)¶
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- Returns:
The mime data for drag drop features
- Return type:
QtCore.QMimeData
- dropMimeData(rowDataSource, index)¶
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- mimeText(rowDataSource, index)¶
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- isSelectable(rowDataSource, index)¶
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- foregroundColor(rowDataSource, index)¶
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- backgroundColor(rowDataSource, index)¶
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- displayChangedColor(rowDataSource, index)¶
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- alignment(rowDataSource, index)¶
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- font(rowDataSource, index)¶
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- class RowDoubleDataSource(*args: Any, **kwargs: Any)¶
Bases:
BaseDataSource
- delegate(parent)¶
- minimum(index)¶
- maximum(index)¶
- class RowIntNumericDataSource(*args: Any, **kwargs: Any)¶
Bases:
BaseDataSource
- delegate(parent)¶
- minimum(index)¶
- maximum(index)¶
- class RowEnumerationDataSource(*args: Any, **kwargs: Any)¶
Bases:
BaseDataSource
- delegate(parent)¶
- enums(index)¶
- class IconRowDataSource(*args: Any, **kwargs: Any)¶
Bases:
BaseDataSource
- delegate(parent)¶
- class RowBooleanDataSource(*args: Any, **kwargs: Any)¶
Bases:
ColumnDataSource
- isCheckable(rowDataSource, index)¶
The icon for this node.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
- Return type:
QtGui.QIcon
- class ColumnDoubleDataSource(*args: Any, **kwargs: Any)¶
Bases:
ColumnDataSource
- delegate(parent)¶
- minimum(rowDataSource, index)¶
- maximum(rowDataSource, index)¶
- class ColumnIntNumericDataSource(*args: Any, **kwargs: Any)¶
Bases:
ColumnDataSource
- delegate(parent)¶
- minimum(rowDataSource, index)¶
- maximum(rowDataSource, index)¶
- class ColumnEnumerationDataSource(*args: Any, **kwargs: Any)¶
Bases:
ColumnDataSource
- delegate(parent)¶
- data(rowDataSource, index)¶
The text for this node or column. index parameter with a value of 0 is the first column.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – The column index for the text
- Returns:
the column text
- Return type:
- setData(rowDataSource, index, value)¶
Sets the text value of this node at the specified column.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – The column index
- Returns:
the new text value for this nodes column index
- Return type:
- enums(rowDataSource, index)¶
- setEnums(rowDataSource, index, enums)¶
- setCurrentIndex(rowDataSource, index, newIndex)¶
- clearEnums()¶
- class ColumnEnumerationButtonDataSource(*args: Any, **kwargs: Any)¶
Bases:
ColumnDataSource
- delegate(parent)¶
- data(rowDataSource, index)¶
The text for this node or column. index parameter with a value of 0 is the first column.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – The column index for the text
- Returns:
the column text
- Return type:
- setData(rowDataSource, index, value)¶
Sets the text value of this node at the specified column.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – The column index
- Returns:
the new text value for this nodes column index
- Return type:
- enums(rowDataSource, index)¶
- setEnums(rowDataSource, index, enums)¶
- setCurrentIndex(rowDataSource, index, newIndex)¶
- clearEnums()¶
- customRoles(rowDataSource, index)¶
- dataByRole(rowDataSource, index, role)¶
- class ColumnBooleanDataSource(*args: Any, **kwargs: Any)¶
Bases:
ColumnDataSource
- delegate(parent)¶
- isCheckable(rowDataSource, index)¶
The icon for this node.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
- Return type:
QtGui.QIcon
- class IconColumnDataSource(*args: Any, **kwargs: Any)¶
Bases:
ColumnDataSource
- delegate(parent)¶
- isEditable(rowDataSource, index)¶
Determines if this node can be editable e.g set text. Defaults to False.
- Parameters:
rowDataSource (BaseDataSource) – The rowDataSource model for the column index
index (int) – the column index
- Returns:
whether or not this node is editable, defaults to False
- Return type:
Delegates¶
- drawRect(painter, option, color)¶
- paintHtml(delegate, painter, option, index)¶
- Parameters:
delegate (
QtWidgets.QStyledItemDelegate
) –painter (
QtGui.QPainter
) –option (
QStyleOptionViewItem
) –index (
QtCore.QModelIndex
) –
- Return type:
- class NumericDoubleDelegate(*args: Any, **kwargs: Any)¶
Bases:
QStyledItemDelegate
- createEditor(parent, option, index)¶
- setEditorData(widget, index)¶
- setModelData(widget, model, index)¶
- updateEditorGeometry(editor, option, index)¶
- paint(painter, option, index)¶
- class NumericIntDelegate(*args: Any, **kwargs: Any)¶
Bases:
QStyledItemDelegate
- createEditor(parent, option, index)¶
- setEditorData(widget, index)¶
- setModelData(widget, model, index)¶
- updateEditorGeometry(editor, option, index)¶
- paint(painter, option, index)¶
- class EnumerationDelegate(*args: Any, **kwargs: Any)¶
Bases:
QStyledItemDelegate
- createEditor(parent, option, index)¶
- editorEvent(event, model, option, index)¶
- setEditorData(editor, index)¶
- setModelData(editor, model, index)¶
- paint(painter, option, index)¶
- class ButtonEnumerationDelegate(*args: Any, **kwargs: Any)¶
Bases:
QStyledItemDelegate
Delegate which displays a combobox and button. Designed to be persistent on the view.
The combobox will be visible when the users mouse enters the cell only.
- createEditor(parent, option, index)¶
Returns the editor to be used for editing the data item with the given index. Contains both a comboBox(leftSide) and a button(right side).
- Parameters:
parent (
QtWidgets.QWidget
) – The parent widget for the editoroption (
QtWidgets.QStyleOptionViewItem
) – The styling instance for the cell.index (
QtCore.QModelIndex
) – The cell Model index
- Returns:
The created custom editor.
- Return type:
- setEditorData(editor, index)¶
- setModelData(editor, model, index)¶
- paint(painter, option, index)¶
- class ButtonDelegate(*args: Any, **kwargs: Any)¶
Bases:
QStyledItemDelegate
- createEditor(parent, option, index)¶
- setEditorData(widget, index)¶
- setModelData(widget, model, index)¶
- updateEditorGeometry(editor, option, index)¶
- paint(painter, option, index)¶
- class CheckBoxDelegate(*args: Any, **kwargs: Any)¶
Bases:
QStyledItemDelegate
A delegate that places a fully functioning QCheckBox in every cell of the column to which it’s applied
- createEditor(parent, option, index)¶
Important, otherwise an editor is created if the user clicks in this cell. ** Need to hook up a signal to the model
- paint(painter, option, index)¶
Paint a checkbox without the label.
- editorEvent(event, model, option, index)¶
Change the data in the model and the state of the checkbox if the user presses the left mousebutton or presses Key_Space or Key_Select and this cell is editable. Otherwise do nothing.
- setModelData(editor, model, index)¶
The user wanted to change the old state in the opposite.
- getCheckBoxRect(option)¶
- class PixmapDelegate(*args: Any, **kwargs: Any)¶
Bases:
QStyledItemDelegate
- paint(painter, option, index)¶
- class DateColumnDelegate(*args: Any, **kwargs: Any)¶
Bases:
QStyledItemDelegate
- createEditor(parent, option, index)¶
- setEditorData(editor, index)¶
- setModelData(editor, model, index)¶
- paint(painter, option, index)¶
Listmodel¶
- class ListModel(*args: Any, **kwargs: Any)¶
Bases:
QAbstractTableModel
- reload()¶
Hard reloads the model, we do this by the modelReset slot, the reason why we do this instead of insertRows() is because we expect that the tree structure has already been rebuilt with its children so by calling insertRows we would in turn create duplicates.
- rowCount(parent)¶
- columnCount(parent)¶
- data(index, role)¶
- setData(index, value, role=MockExt.QtCore.Qt.EditRole)¶
- mimeTypes()¶
- mimeData(indices)¶
- supportedDropActions()¶
- flags(index)¶
- headerData(section, orientation, role)¶
- insertRow(position, parent=MockExt.QtCore.QModelIndex, **kwargs)¶
- insertRows(position, rows, parent=MockExt.QtCore.QModelIndex)¶
- itemFromIndex(index)¶
Returns the user Object from the rowDataSource
- Parameters:
index (QtCore.Qt.QModelIndex) –
- Returns:
- Return type:
Sortmodel¶
- class LeafTreeFilterProxyModel(*args: Any, **kwargs: Any)¶
Bases:
QSortFilterProxyModel
- filterAcceptsRow(row_num, source_parent)¶
- setFilterFixedString(pattern)¶
- class TableFilterProxyModel(*args: Any, **kwargs: Any)¶
Bases:
QSortFilterProxyModel
- Class to override the following behaviour:
If a parent item doesn’t match the filter, none of its children will be shown.
This Model matches items which are descendants or ascendants of matching items.
- filterAcceptsRow(row_num, source_parent)¶
- sort(column, order)¶
Sort table by given column number.
Tablemodel¶
- class TableModel(*args: Any, **kwargs: Any)¶
Bases:
QAbstractTableModel
- property rowDataSource¶
- columnDataSource(index)¶
- reload()¶
Hard reloads the model, we do this by the modelReset slot, the reason why we do this instead of insertRows() is because we expect that the tree structure has already been rebuilt with its children so by calling insertRows we would in turn create duplicates.
- rowCount(parent=MockExt.QtCore.QModelIndex)¶
- columnCount(parent=MockExt.QtCore.QModelIndex)¶
- data(index, role)¶
- setData(index, value, role=MockExt.QtCore.Qt.EditRole)¶
- flags(index)¶
- headerData(section, orientation, role)¶
- supportedDropActions()¶
- mimeTypes()¶
- mimeData(indices)¶
Encode serialized data from the item at the given index into a QMimeData object.
- dropMimeData(mimeData, action, row, column, parent)¶
- insertRow(position, parent=MockExt.QtCore.QModelIndex, **kwargs)¶
- insertRows(position, count, parent=MockExt.QtCore.QModelIndex, **kwargs)¶
- insertColumns(position, columns, parent=MockExt.QtCore.QModelIndex)¶
- removeRow(position, parent=MockExt.QtCore.QModelIndex)¶
- removeRows(position, count, parent=MockExt.QtCore.QModelIndex, **kwargs)¶
- removeColumn(row, parent)¶
- removeColumns(row, count, parent)¶
- moveRow(sourceParent, sourceRow, destinationParent, destinationChild)¶
- moveRows(sourceParent, sourceRow, count, destinationParent, destinationChild)¶
- itemFromIndex(index)¶
Returns the user Object from the rowDataSource :param index: :type index: :return: :rtype:
- sort(column, order)¶
Sort table by given column number.
Treemodel¶
This module is for a standard Qt tree model
- pprintTree(model, item, _prefix='', _last=True)¶
- class TreeModel(*args: Any, **kwargs: Any)¶
Bases:
QAbstractItemModel
- pprintItemTree(item)¶
- setRoot(root, refresh=False)¶
- reload()¶
Hard reloads the model, we do this by the modelReset slot, the reason why we do this instead of insertRows() is because we expect that the tree structure has already been rebuilt with its children so by calling insertRows we would in turn create duplicates.
- itemFromIndex(index)¶
Returns the datasource for the index.
- Parameters:
index (
QtCore.QModelIndex
) – The Qt Model index- Returns:
- Return type:
- rowCount(parent)¶
- columnCount(parent)¶
- data(index, role=MockExt.QtCore.Qt.DisplayRole)¶
- hasChildren(index)¶
- canFetchMore(index)¶
- fetchMore(index)¶
- setData(index, value, role=MockExt.QtCore.Qt.EditRole)¶
- flags(index)¶
- supportedDropActions()¶
- mimeTypes()¶
- mimeData(indices)¶
Encode serialized data from the item at the given index into a QMimeData object.
- dropMimeData(mimeData, action, row, column, parentIndex)¶
- headerData(section, orientation, role)¶
- index(row, column, parent=MockExt.QtCore.QModelIndex)¶
- parent(index)¶
- insertRow(position, parent=MockExt.QtCore.QModelIndex, **kwargs)¶
- insertRows(position, count, parent=MockExt.QtCore.QModelIndex, **kwargs)¶
- removeRows(position, count, parent=MockExt.QtCore.QModelIndex, **kwargs)¶
- removeRow(position, parent=MockExt.QtCore.QModelIndex)¶
- moveRow(sourceParent, sourceRow, destinationParent, destinationChild)¶
- moveRows(sourceParent, sourceRow, count, destinationParent, destinationChild)¶