Models

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: MockExt.QtCore.

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

int

columnCount()
parentSource()

Returns the parent of this node

Return type

Node

setParentSource(parentSource)
index()
child(index)
Parameters

index (int) – the column index

addChild(child)
insertChild(index, child)
insertChildren(index, children)
setData(index, value)

Sets the text value of this node at the specified column

Parameters

index (int) – The column index

Returns

the new text value for this nodes column index

Return type

str

data(index)

The text for this node or column. index parameter with a value of 0 is the first column.

Parameters

index (int) – The column index for the item

Returns

the column text

Return type

str

customRoles(index)
dataByRole(index, role)
toolTip(index)

The tooltip for the index.

Parameters

index (int) – The column index for the item

Return type

str

icon(index)

The icon for the index.

Parameters

index (int) – The column index for the item.

Return type

QtGui.QIcon

headerIcon()

Returns the column header icon.

Return type

QtGui.QIcon

headerText(index)

Returns the column header text

Returns

the header value

Return type

str

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.

Parameters

index (int) – The column index for the item.

Return type

str or None

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.

Parameters

index (int) – The column index for the item.

Returns

whether this node is editable, defaults to False

Return type

bool

isEnabled(index)

Determines if this node is enabled.

Parameters

index (int) – The column index for the item

Returns

whether this node is enabled, defaults to True

Return type

bool

supportsDrag(index)
Parameters

index (int) – the column index

supportsDrop(index)
Parameters

index (int) – the column index

mimeData(indices)
dropMimeData(items, action)
Parameters

items (list[value]) – the column index

isSelectable(index)
Parameters

index (int) – the column index

foregroundColor(index)
Parameters

index (int) – the column index

backgroundColor(index)
Parameters

index (int) – the column index

displayChangedColor(index)
Parameters

index (int) – the column index

textMargin(index)
alignment(index)
Parameters

index (int) – the column index

font(index)
Parameters

index (int) – the column index

isCheckable(index)
Parameters

index (int) – the column index

insertColumnDataSources(index, count)
Parameters

index (int) – the column index

removeColumnDataSources(index, count)
Parameters

index (int) – the column index

removeRowDataSource(index)
Parameters

index (int) – the column index

removeRowDataSources(index, count)
Parameters

index (int) – the column index

insertRowDataSources(index, count)
Parameters

index (int) – the column index

insertRowDataSource(index)
Parameters

index (int) – the column 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.

Parameters
  • index (int) – the column index to sort

  • order (int) – The Qt order

delegate(parent)
class ColumnDataSource(*args: Any, **kwargs: Any)

Bases: MockExt.QtCore.

sort(rowDataSource, index=0, order=MockExt.QtCore.Qt.DescendingOrder)

This sort function purpose is for sorting the data by column.

Parameters
  • index (int) – the column index to sort

  • order (int) – The Qt order

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

str

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

str

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

str

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

bool

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

bool

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

bool

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

bool

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

removeRowDataSources(rowDataSource, index, count)
Parameters

index (int) – the column index

class RowDoubleDataSource(*args: Any, **kwargs: Any)

Bases: MockExt.QtCore.

delegate(parent)
minimum(index)
maximum(index)
class RowIntNumericDataSource(*args: Any, **kwargs: Any)

Bases: MockExt.QtCore.

delegate(parent)
minimum(index)
maximum(index)
class RowEnumerationDataSource(*args: Any, **kwargs: Any)

Bases: MockExt.QtCore.

delegate(parent)
enums(index)
class IconRowDataSource(*args: Any, **kwargs: Any)

Bases: MockExt.QtCore.

delegate(parent)
isEditable(rowDataSource, index)

Determines if this node can be editable e.g set text. Defaults to False.

Parameters

index (int) – The column index for the item.

Returns

whether this node is editable, defaults to False

Return type

bool

class RowBooleanDataSource(*args: Any, **kwargs: Any)

Bases: MockExt.QtCore.

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: MockExt.QtCore.

delegate(parent)
minimum(rowDataSource, index)
maximum(rowDataSource, index)
class ColumnIntNumericDataSource(*args: Any, **kwargs: Any)

Bases: MockExt.QtCore.

delegate(parent)
minimum(rowDataSource, index)
maximum(rowDataSource, index)
class ColumnEnumerationDataSource(*args: Any, **kwargs: Any)

Bases: MockExt.QtCore.

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

str

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

str

enums(rowDataSource, index)
setEnums(rowDataSource, index, enums)
setCurrentIndex(rowDataSource, index, newIndex)
clearEnums()
removeRowDataSources(rowDataSource, index, count)
Parameters

index (int) – the column index

class ColumnEnumerationButtonDataSource(*args: Any, **kwargs: Any)

Bases: MockExt.QtCore.

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

str

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

str

enums(rowDataSource, index)
setEnums(rowDataSource, index, enums)
setCurrentIndex(rowDataSource, index, newIndex)
clearEnums()
removeRowDataSources(rowDataSource, index, count)
Parameters

index (int) – the column index

customRoles(rowDataSource, index)
dataByRole(rowDataSource, index, role)
class ColumnBooleanDataSource(*args: Any, **kwargs: Any)

Bases: MockExt.QtCore.

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: MockExt.QtCore.

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

bool

Delegates

drawRect(painter, option, color)
paintHtml(delegate, painter, option, index)
Parameters
  • delegate (QtWidgets.QStyledItemDelegate) –

  • painter (QtGui.QPainter) –

  • option (QStyleOptionViewItem) –

  • index (QtCore.QModelIndex) –

Return type

bool

class NumericDoubleDelegate(*args: Any, **kwargs: Any)

Bases: MockExt.QtWidgets.

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: MockExt.QtWidgets.

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: MockExt.QtWidgets.

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: MockExt.QtWidgets.

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 editor

  • option (QtWidgets.QStyleOptionViewItem) – The styling instance for the cell.

  • index (QtCore.QModelIndex) – The cell Model index

Returns

The created custom editor.

Return type

ButtonEnumerationWidget

setEditorData(editor, index)
setModelData(editor, model, index)
paint(painter, option, index)
class ButtonDelegate(*args: Any, **kwargs: Any)

Bases: MockExt.QtWidgets.

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: MockExt.QtWidgets.

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: MockExt.QtWidgets.

paint(painter, option, index)
class DateColumnDelegate(*args: Any, **kwargs: Any)

Bases: MockExt.QtWidgets.

createEditor(parent, option, index)
setEditorData(editor, index)
setModelData(editor, model, index)
paint(painter, option, index)
class HtmlDelegate(*args: Any, **kwargs: Any)

Bases: MockExt.QtWidgets.

paint(painter, option, index)
sizeHint(option, index)
class ButtonEnumerationWidget(*args: Any, **kwargs: Any)

Bases: MockExt.QtWidgets.

Combobox with a button to the left side.

This widget has overrides for the enter and leave events to handle visibility of the combo.

buttonClicked
enterEvent(event)
leaveEvent(event)

Listmodel

class ListModel(*args: Any, **kwargs: Any)

Bases: MockExt.QtCore.

sortRole
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: MockExt.QtCore.

filterAcceptsRow(row_num, source_parent)
setFilterFixedString(pattern)
class TableFilterProxyModel(*args: Any, **kwargs: Any)

Bases: MockExt.QtCore.

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: MockExt.QtCore.

property rowDataSource
columnDataSource(index)
dataSource(index)
Parameters

index (int) – The column index

Returns

Return type

zoo.libs.pyqt.models.datasources.BaseDataSource

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: MockExt.QtCore.

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

zoo.libs.pyqt.models.datasources.BaseDataSource

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)