Skip to content

SliceToMarkdownProxyModel

Qt Base Class: QIdentityProxyModel

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

Base classes

Name Children Inherits
SliceIdentityProxyModel
prettyqt.itemmodels.proxies.sliceidentityproxymodel

⋔ Inheritance diagram

graph TD
  1473290737440["itemmodels.SliceToMarkdownProxyModel"]
  1473290716944["itemmodels.SliceIdentityProxyModel"]
  1473299892128["core.IdentityProxyModel"]
  1473299903840["core.AbstractProxyModelMixin"]
  1473299890176["core.AbstractItemModelMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473289064768["QtCore.QIdentityProxyModel"]
  1473289061840["QtCore.QAbstractProxyModel"]
  1473289050128["QtCore.QAbstractItemModel"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473290716944 --> 1473290737440
  1473299892128 --> 1473290716944
  1473299903840 --> 1473299892128
  1473299890176 --> 1473299903840
  1473299815024 --> 1473299890176
  140713234304496 --> 1473299815024
  1473289064768 --> 1473299892128
  1473289061840 --> 1473289064768
  1473289050128 --> 1473289061840
  1473288842240 --> 1473289050128
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 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

Info

This is a slice proxy and can be selectively applied to a model. Read more about slices.

⌗ Property table

Qt Property Type Doc
objectName QString
sourceModel QAbstractItemModel
column_slice QVariantList Column slice to include for the proxy
row_slice QVariantList Row slice to include for the proxy