From 33ce4c5072085436702746cbf44ba5b6284c068d Mon Sep 17 00:00:00 2001 From: zrgt Date: Thu, 25 Apr 2024 01:06:40 +0200 Subject: [PATCH] Show all items if no search pattern set --- aas_editor/models/search_proxy_model.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/aas_editor/models/search_proxy_model.py b/aas_editor/models/search_proxy_model.py index 8400cdc..a607c8c 100644 --- a/aas_editor/models/search_proxy_model.py +++ b/aas_editor/models/search_proxy_model.py @@ -19,7 +19,7 @@ from typing import List, Any, Optional from PyQt6.QtCore import QSortFilterProxyModel, QModelIndex, Qt, \ - QPersistentModelIndex, QObject, QAbstractItemModel + QPersistentModelIndex, QObject, QAbstractItemModel, QRegularExpression class SearchProxyModel(QSortFilterProxyModel): @@ -39,6 +39,7 @@ def search(self, pattern: str, matchCase: bool = False) -> List[QPersistentModelIndex]: foundItems = [] if not pattern: + self.show_all_items() return foundItems if matchCase: @@ -47,7 +48,7 @@ def search(self, pattern: str, self.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive) if regExp: - self.setFilterRegExp(pattern) + self.setFilterRegularExpression(QRegularExpression(pattern)) else: self.setFilterFixedString(pattern) @@ -60,12 +61,14 @@ def search(self, pattern: str, foundItems.append(QPersistentModelIndex(srcIndex)) if not filter: - # show all items - self.setFilterRegExp("") + self.show_all_items() foundItems = [QPersistentModelIndex(self.mapFromSource(QModelIndex(i))) for i in foundItems] return foundItems + def show_all_items(self): + self.setFilterRegularExpression(QRegularExpression("")) + def iterItems(self, parent: QModelIndex = QModelIndex()) -> QModelIndex: def recurse(parent: QModelIndex): for row in range(self.rowCount(parent)):