Skip to content

Commit

Permalink
Show all items if no search pattern set
Browse files Browse the repository at this point in the history
  • Loading branch information
zrgt committed Apr 24, 2024
1 parent 6ee305c commit 33ce4c5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions aas_editor/models/search_proxy_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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)

Expand All @@ -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)):
Expand Down

0 comments on commit 33ce4c5

Please sign in to comment.