Skip to content

filter

filter

Attributes

Classes

FilterProxy(parent=None)

Bases: QSortFilterProxyModel

Filters the tree by key text and hides binary blobs.

Hidden values stay in the source model, so they are preserved on save.

Initialize the proxy.

Parameters:

Name Type Description Default
parent QObject | None

Parent object.

None
Source code in src/json_config_qt/tree/filter.py
13
14
15
16
17
18
19
20
21
22
def __init__(self, parent: QtCore.QObject | None = None):
    """Initialize the proxy.

    Args:
        parent (QtCore.QObject | None, optional): Parent object.
    """
    super().__init__(parent)
    self.setRecursiveFilteringEnabled(True)
    self.setFilterKeyColumn(KEY_COLUMN)
    self.setFilterCaseSensitivity(QtCore.Qt.CaseSensitivity.CaseInsensitive)
Methods:
filterAcceptsRow(source_row, source_parent)

Return whether a row is visible.

Binary rows are always hidden; other rows are shown if their key, a descendant's key or an ancestor's key matches the filter.

Parameters:

Name Type Description Default
source_row int

Row in the source model.

required
source_parent QModelIndex

Parent index in the source model.

required

Returns:

Name Type Description
bool bool

True if the row is shown.

Source code in src/json_config_qt/tree/filter.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def filterAcceptsRow(self, source_row, source_parent) -> bool:
    """Return whether a row is visible.

    Binary rows are always hidden; other rows are shown if their key, a
    descendant's key or an ancestor's key matches the filter.

    Args:
        source_row (int): Row in the source model.
        source_parent (QtCore.QModelIndex): Parent index in the source model.

    Returns:
        bool: True if the row is shown.
    """
    index = self.sourceModel().index(source_row, KEY_COLUMN, source_parent)
    if index.data(KIND_ROLE) == Kind.BINARY:
        return False
    if super().filterAcceptsRow(source_row, source_parent):
        return True
    return self._ancestor_matches(source_parent)
set_filter_text(text)

Show only keys containing text (case-insensitive) and their subtrees.

Source code in src/json_config_qt/tree/filter.py
24
25
26
def set_filter_text(self, text: str) -> None:
    """Show only keys containing *text* (case-insensitive) and their subtrees."""
    self.setFilterFixedString(text)