summaryrefslogtreecommitdiff
path: root/tidal_dl_ng/helper/gui.py
diff options
context:
space:
mode:
authorRobert Honz <exislow+github@gmail.com>2024-05-15 08:33:39 +0200
committerRobert Honz <exislow+github@gmail.com>2024-05-15 08:33:39 +0200
commitb257f48d6a91b341580a940263c6c6f1609f893d (patch)
tree617db238dc391c846262d70cc2388abc85d62a42 /tidal_dl_ng/helper/gui.py
parent79e60a0ac723cc6b307b726de25a001e96f6cdfa (diff)
downloadtidal-dl-ng-b257f48d6a91b341580a940263c6c6f1609f893d.tar.gz
✨ Filtering keeps top level item shown.
Diffstat (limited to 'tidal_dl_ng/helper/gui.py')
-rw-r--r--tidal_dl_ng/helper/gui.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/tidal_dl_ng/helper/gui.py b/tidal_dl_ng/helper/gui.py
index 82b7f7b..82a44d8 100644
--- a/tidal_dl_ng/helper/gui.py
+++ b/tidal_dl_ng/helper/gui.py
@@ -105,8 +105,10 @@ class FilterHeader(QtWidgets.QHeaderView):
def sizeHint(self):
size = super().sizeHint()
+
if self._editors:
height = self._editors[0].sizeHint().height()
+
size.setHeight(size.height() + height + self._padding)
return size
@@ -114,6 +116,7 @@ class FilterHeader(QtWidgets.QHeaderView):
def updateGeometries(self):
if self._editors:
height = self._editors[0].sizeHint().height()
+
self.setViewportMargins(0, 0, 0, height + self._padding)
else:
self.setViewportMargins(0, 0, 0, 0)
@@ -167,18 +170,25 @@ class HumanProxyModel(QtCore.QSortFilterProxyModel):
@filters.setter
def filters(self, filters):
- print("filters() called.")
-
self._filters = filters
self.invalidateFilter()
- def filterAcceptsRow(self, sourceRow, sourceParent) -> bool:
+ def filterAcceptsRow(self, source_row: int, source_parent: QtCore.QModelIndex) -> bool:
+ model = self.sourceModel()
+ source_index = model.index(source_row, 0, source_parent)
+
+ # Show top level children
+ for child_row in range(model.rowCount(source_index)):
+ if self.filterAcceptsRow(child_row, source_index):
+ return True
+
+ # Filter for actual needle
for i, text in self.filters:
if 0 <= i < self.columnCount():
- ix = self.sourceModel().index(sourceRow, i, sourceParent)
+ ix = self.sourceModel().index(source_row, i, source_parent)
data = ix.data()
- if str(data) in text:
- return False
+
+ return bool(text.lower() in str(data).lower())
return True