refactor(gui): ✨ Improve filter handling in MainWindow
* Refactored the filter extraction logic to directly use `header.filter_text(i)` for better clarity. * Updated the filters list to store tuples of index and text, enhancing the data structure used. * Ensured that the `proxy_model.filters` is set directly, simplifying the code.
This commit is contained in:
+7
-5
@@ -328,11 +328,13 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
header = self.tr_results.header()
|
header = self.tr_results.header()
|
||||||
filters: list[str] = []
|
filters: list[str] = []
|
||||||
for i in range(header.count()):
|
for i in range(header.count()):
|
||||||
# Use getattr to avoid attribute error
|
text: str = header.filter_text(i)
|
||||||
filters.append(getattr(header, "filter_text", lambda x: "")(i))
|
|
||||||
proxy_model = self.tr_results.model()
|
if text:
|
||||||
if hasattr(proxy_model, "filters"):
|
filters.append((i, text))
|
||||||
proxy_model.filters = filters
|
|
||||||
|
proxy_model: HumanProxyModel = self.tr_results.model()
|
||||||
|
proxy_model.filters = filters
|
||||||
|
|
||||||
def _init_tree_results(self, tree: QtWidgets.QTreeView, model: QtGui.QStandardItemModel) -> None:
|
def _init_tree_results(self, tree: QtWidgets.QTreeView, model: QtGui.QStandardItemModel) -> None:
|
||||||
"""Initialize the results tree view and its model.
|
"""Initialize the results tree view and its model.
|
||||||
|
|||||||
Reference in New Issue
Block a user