Skip to content

MarkdownModel

Qt Base Class: QAbstractItemModel

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

Base classes

Name Children Inherits
TreeModel
prettyqt.itemmodels.treemodel

⋔ Inheritance diagram

graph TD
  1473290749152["prettyqtmarkdown.MarkdownModel"]
  1473299686192["itemmodels.TreeModel"]
  1473299893104["core.AbstractItemModel"]
  1473299890176["core.AbstractItemModelMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473289050128["QtCore.QAbstractItemModel"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473299686192 --> 1473290749152
  1473299893104 --> 1473299686192
  1473299890176 --> 1473299893104
  1473299815024 --> 1473299890176
  140713234304496 --> 1473299815024
  1473289050128 --> 1473299893104
  1473288842240 --> 1473289050128
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: TreeModel

An ItemModel for displaying a mknodes tree.

Source code in prettyqt\prettyqtmarkdown\markdownmodel.py
class MarkdownModel(itemmodels.TreeModel):
    """An ItemModel for displaying a mknodes tree."""

    HEADER = ["Repr", "Type", "Files"]

    class Roles:
        MarkdownRole = constants.USER_ROLE + 5325

    def headerData(
        self,
        section: int,
        orientation: constants.Orientation,
        role: constants.ItemDataRole = constants.DISPLAY_ROLE,
    ):
        match orientation, role, section:
            case constants.HORIZONTAL, constants.DISPLAY_ROLE, _:
                return self.HEADER[section]
        return None

    def columnCount(self, index: core.ModelIndex | None = None) -> int:
        return len(self.HEADER)

    def data(
        self,
        index: core.ModelIndex,
        role: constants.ItemDataRole = constants.DISPLAY_ROLE,
    ):
        node = self.data_by_index(index).obj
        match role, index.column():
            case constants.DISPLAY_ROLE, 0:
                match node:
                    case mknodes.MkNav():
                        return f"{node.section}/"
                    case mknodes.MkPage():
                        return node.path
                    case _:
                        return repr(node)
            # case constants.DISPLAY_ROLE, 1:
            #     with contextlib.suppress(AttributeError):
            #         return node._to_markdown().count("\n")
            case constants.DISPLAY_ROLE, 1:
                return type(node).__name__
            case constants.DISPLAY_ROLE, 2:
                keys = node.resolved_virtual_files.keys()
                return ", ".join(keys)
            case self.Roles.MarkdownRole, _:
                return node.to_markdown()

    def _fetch_object_children(self, item) -> list[MarkdownModel.TreeItem]:
        return [self.TreeItem(i) for i in item.obj.children]

    def _has_children(self, item) -> bool:
        return len(item.obj.children) > 0

⌗ Property table

Qt Property Type Doc
objectName QString