Skip to content

ItemModelResolver

Base classes

Name Children Inherits
BaseResolver
prettyqt.utils.baseresolver

⋔ Inheritance diagram

graph TD
  1473290762816["itemmodels.ItemModelResolver"]
  1473299906768["utils.BaseResolver"]
  140713234304496["builtins.object"]
  1473299906768 --> 1473290762816
  140713234304496 --> 1473299906768

🛈 DocStrings

Bases: BaseResolver

Allows globbing ItemModels.

Source code in prettyqt\itemmodels\itemmodelresolver.py
class ItemModelResolver(baseresolver.BaseResolver):
    """Allows globbing ItemModels."""

    def __init__(
        self,
        model: core.QAbstractItemModel,
        path_role: constants.ItemDataRole = constants.DISPLAY_ROLE,
        ignore_case: bool = False,
    ):
        """Resolve any `ModelIndex` paths using role `path_role`.

        Arguments:
            model: Model to search
            path_role: ItemDataRole to be used for resolving
            ignore_case: Enable case insensisitve handling.
        """
        super().__init__(ignore_case=ignore_case)
        self.model = model
        self.path_role = path_role
        self.fetch_more = True

    def get_parent(self, node):
        return node.parent()

    def get_children(self, node):
        if self.fetch_more:
            while self.model.canFetchMore(node):
                self.model.fetchMore(node)
        return [self.model.index(i, 0, node) for i in range(self.model.rowCount(node))]

    def get_root(self, node):
        return core.ModelIndex()

    def get_attribute(self, node):
        return str(node.data(self.path_role))

    def get(self, path: str, root_node=None):
        path = f"/None{path}"
        return super().get(path, root_node or core.ModelIndex())

    def glob(self, path: str, root_node=None):
        path = f"/None{path}"
        return super().glob(path, root_node or core.ModelIndex())

__init__(model: core.QAbstractItemModel, path_role: constants.ItemDataRole = constants.DISPLAY_ROLE, ignore_case: bool = False)

Resolve any ModelIndex paths using role path_role.

Parameters:

Name Type Description Default
model QAbstractItemModel

Model to search

required
path_role ItemDataRole

ItemDataRole to be used for resolving

DISPLAY_ROLE
ignore_case bool

Enable case insensisitve handling.

False
Source code in prettyqt\itemmodels\itemmodelresolver.py
def __init__(
    self,
    model: core.QAbstractItemModel,
    path_role: constants.ItemDataRole = constants.DISPLAY_ROLE,
    ignore_case: bool = False,
):
    """Resolve any `ModelIndex` paths using role `path_role`.

    Arguments:
        model: Model to search
        path_role: ItemDataRole to be used for resolving
        ignore_case: Enable case insensisitve handling.
    """
    super().__init__(ignore_case=ignore_case)
    self.model = model
    self.path_role = path_role
    self.fetch_more = True