MkNodesModel
Base classes
| Name |
Children |
Inherits |
TreeModel prettyqt.itemmodels.treemodel TreeModel which is used as a base for most TreeModels implemented. |
|
|
⋔ Inheritance diagram
graph TD
3404257279["prettyqtmarkdown.MkNodesModel"]
2846913429["itemmodels.TreeModel"]
874904086["core.AbstractItemModel"]
3882849576["core.AbstractItemModelMixin"]
3227531497["core.ObjectMixin"]
2751680898["builtins.object"]
1898060022["QtCore.QAbstractItemModel"]
3984060476["QtCore.QObject"]
37984305["Shiboken.Object"]
2846913429 --> 3404257279
874904086 --> 2846913429
3882849576 --> 874904086
3227531497 --> 3882849576
2751680898 --> 3227531497
2751680898 --> 3882849576
1898060022 --> 874904086
3984060476 --> 1898060022
37984305 --> 3984060476
2751680898 --> 37984305
🛈 DocStrings
Bases: TreeModel
An ItemModel for displaying a mknodes tree.
Source code in prettyqt/prettyqtmarkdown/markdownmodel.py
| class MkNodesModel(itemmodels.TreeModel):
"""An ItemModel for displaying a mknodes tree."""
HEADER: ClassVar = ["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.title}/"
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.get_resources().keys()
return ", ".join(keys)
case self.Roles.MarkdownRole, _:
return node.to_markdown()
def _fetch_object_children(self, item) -> list[MkNodesModel.TreeItem]:
return [self.TreeItem(i) for i in item.obj.children]
def _has_children(self, item) -> bool:
return len(item.obj.children) > 0
|
:fa-brands-github: Show source on GitHub