Skip to content

RegexMatchesModel

Qt Base Class: QAbstractTableModel

Signature: QAbstractTableModel(self, parent: Optional[PySide6.QtCore.QObject] = None) -> None

Base classes

Name Children Inherits
AbstractTableModel
prettyqt.core.abstracttablemodel

⋔ Inheritance diagram

graph TD
  1473245680240["itemmodels.RegexMatchesModel"]
  1473299901888["core.AbstractTableModel"]
  1473299900912["core.AbstractTableModelMixin"]
  1473299890176["core.AbstractItemModelMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473289054032["QtCore.QAbstractTableModel"]
  1473289050128["QtCore.QAbstractItemModel"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473299901888 --> 1473245680240
  1473299900912 --> 1473299901888
  1473299890176 --> 1473299900912
  1473299815024 --> 1473299890176
  140713234304496 --> 1473299815024
  1473289054032 --> 1473299901888
  1473289050128 --> 1473289054032
  1473288842240 --> 1473289050128
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: AbstractTableModel

Model to display a list of re.Matches.

Source code in prettyqt\itemmodels\regexmatchesmodel.py
class RegexMatchesModel(core.AbstractTableModel):
    """Model to display a list of re.Matches."""

    HEADER = ["Start", "End", "Value", "Groups"]
    SUPPORTS = list[re.Match]

    def __init__(self, matches: list | None = None, **kwargs):
        super().__init__(**kwargs)
        self.matches = matches or []

    @classmethod
    def supports(cls, instance) -> bool:
        match instance:
            case (re.Match(), *_):
                return True
            case _:
                return False

    def columnCount(self, parent=None):
        return len(self.HEADER)

    def headerData(  # type: ignore
        self,
        section: int,
        orientation: constants.Orientation,
        role: constants.ItemDataRole = constants.DISPLAY_ROLE,
    ) -> str | None:
        match orientation, role:
            case constants.HORIZONTAL, constants.DISPLAY_ROLE:
                return self.HEADER[section]

    def data(
        self,
        index: core.ModelIndex,
        role: constants.ItemDataRole = constants.DISPLAY_ROLE,
    ):
        if not index.isValid():
            return None
        item = self.matches[index.row()]
        match role, index.column():
            case constants.DISPLAY_ROLE, 0:
                return str(item.span()[0])
            case constants.DISPLAY_ROLE, 1:
                return str(item.span()[1])
            case constants.DISPLAY_ROLE, 2:
                return repr(item.group())
            case constants.DISPLAY_ROLE, 3:
                return str(len(item.groups()))
            case constants.USER_ROLE, _:
                return item.span()

    def rowCount(self, parent: core.ModelIndex | None = None) -> int:
        """Override for AbstractitemModel base method."""
        parent = parent or core.ModelIndex()
        if parent.column() > 0:
            return 0
        return 0 if parent.isValid() else len(self.matches)

rowCount(parent: core.ModelIndex | None = None) -> int

Override for AbstractitemModel base method.

Source code in prettyqt\itemmodels\regexmatchesmodel.py
def rowCount(self, parent: core.ModelIndex | None = None) -> int:
    """Override for AbstractitemModel base method."""
    parent = parent or core.ModelIndex()
    if parent.column() > 0:
        return 0
    return 0 if parent.isValid() else len(self.matches)

Info

Supported data type: list[re.Match]

⌗ Property table

Qt Property Type Doc
objectName QString