Skip to content

generalmodel

Classes:

T module-attribute

T = TypeVar('T')

GeneralModel

GeneralModel(init_seq: Sequence[T], to_title: bool = True)

Bases: QAbstractListModel, Generic[T]

Methods:

Attributes:

Source code
35
36
37
38
def __init__(self, init_seq: Sequence[T], to_title: bool = True) -> None:
    super().__init__()
    self.items = list(init_seq)
    self.to_title = to_title

content_type instance-attribute

content_type: type[T]

items instance-attribute

items = list(init_seq)

to_title instance-attribute

to_title: bool = to_title

data

data(index: QModelIndex, role: int = UserRole) -> Any
Source code
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def data(self, index: QModelIndex, role: int = Qt.ItemDataRole.UserRole) -> Any:
    if (not index.isValid() or index.row() >= len(self.items)):
        return None

    if role == Qt.ItemDataRole.DisplayRole:
        value = self.items[index.row()]

        str_value = self._displayValue(value)

        if self.content_type is str and self.to_title:
            return str_value.title()

        return str_value

    if role == Qt.ItemDataRole.UserRole:
        return self.items[index.row()]

    return None

index_of

index_of(item: T) -> int
Source code
49
50
def index_of(self, item: T) -> int:
    return self.items.index(item)

rowCount

rowCount(parent: QModelIndex = QModelIndex()) -> int
Source code
71
72
def rowCount(self, parent: QModelIndex = QModelIndex()) -> int:
    return len(self.items)