Skip to content

SliceToMarkdownProxyModel

Base classes

Name Children Inherits
SliceIdentityProxyModel
prettyqt.itemmodels.proxies.sliceidentityproxymodel
Base model for slice proxy models.

⋔ Inheritance diagram

graph TD
  1806517152["itemmodels.SliceToMarkdownProxyModel"]
  4214724289["itemmodels.SliceIdentityProxyModel"]
  527136029["core.IdentityProxyModel"]
  2431222121["core.AbstractProxyModelMixin"]
  3882849576["core.AbstractItemModelMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  3668892142["QtCore.QIdentityProxyModel"]
  3989152870["QtCore.QAbstractProxyModel"]
  1898060022["QtCore.QAbstractItemModel"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  4214724289 --> 1806517152
  527136029 --> 4214724289
  2431222121 --> 527136029
  3882849576 --> 2431222121
  3227531497 --> 3882849576
  2751680898 --> 3227531497
  2751680898 --> 3882849576
  2751680898 --> 2431222121
  3668892142 --> 527136029
  3989152870 --> 3668892142
  1898060022 --> 3989152870
  3984060476 --> 1898060022
  37984305 --> 3984060476
  2751680898 --> 37984305

🛈 DocStrings

Bases: SliceIdentityProxyModel

Proxy model which transforms cell contents to markdown.

Mainly used for documentation files. Text is formatted based on FontRole, Checkstate role, etc.

Source code in prettyqt/itemmodels/proxies/slicetomarkdownproxymodel.py
class SliceToMarkdownProxyModel(itemmodels.SliceIdentityProxyModel):
    """Proxy model which transforms cell contents to markdown.

    Mainly used for documentation files.
    Text is formatted based on FontRole, Checkstate role, etc.
    """

    ID = "to_markdown"
    ICON = "mdi.palette-outline"

    def data(
        self,
        index: core.ModelIndex,
        role: constants.ItemDataRole = constants.DISPLAY_ROLE,
    ):
        if not self.indexer_contains(index):
            return super().data(index, role)
        if role != constants.DISPLAY_ROLE:
            return None
        # self.strip_styling = True
        # if role != constants.DISPLAY_ROLE and self.strip_styling:
        #     return None
        label = super().data(index, constants.DISPLAY_ROLE)
        checkstate = super().data(index, constants.CHECKSTATE_ROLE)
        # if not label and checkstate is None:
        #     return ""
        label = escaped(str(label) if label is not None else "")
        if label:
            # background = super().data(index, constants.BACKGROUND_ROLE)
            foreground = super().data(index, constants.FOREGROUND_ROLE)
            if isinstance(foreground, gui.QColor):
                label = f'<span style="color:{foreground.name()}">{label}</span>'
            font = super().data(index, constants.FONT_ROLE)
            if font and font.bold():
                label = f"**{label}**"
            if font and font.italic():
                label = f"*{label}*"
        match checkstate:
            case True | constants.CheckState.Checked | 2:
                # :black_square_button:
                label = f"☑ {label}"
            case False | constants.CheckState.Unchecked | 0:
                # :heavy_check_mark:
                label = f"☐ {label}"
        return label

:fa-brands-github: Show source on GitHub