diff --git a/artiq/browser/datasets.py b/artiq/browser/datasets.py index d748ce153..28afd54c0 100644 --- a/artiq/browser/datasets.py +++ b/artiq/browser/datasets.py @@ -6,7 +6,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets from sipyco.pc_rpc import AsyncioClient as RPCClient from artiq.tools import short_format -from artiq.gui.tools import LayoutWidget, QRecursiveFilterProxyModel +from artiq.gui.tools import LayoutWidget from artiq.gui.models import DictSyncTreeSepModel # reduced read-only version of artiq.dashboard.datasets @@ -112,7 +112,8 @@ class DatasetsDock(QtWidgets.QDockWidget): def set_model(self, model): self.table_model = model - self.table_model_filter = QRecursiveFilterProxyModel() + self.table_model_filter = QtCore.QSortFilterProxyModel() + self.table_model_filter.setRecursiveFilteringEnabled(True) self.table_model_filter.setSourceModel(self.table_model) self.table.setModel(self.table_model_filter) diff --git a/artiq/dashboard/datasets.py b/artiq/dashboard/datasets.py index 5d9befad9..697792804 100644 --- a/artiq/dashboard/datasets.py +++ b/artiq/dashboard/datasets.py @@ -6,7 +6,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets from sipyco import pyon from artiq.tools import scale_from_metadata, short_format, exc_to_warning -from artiq.gui.tools import LayoutWidget, QRecursiveFilterProxyModel +from artiq.gui.tools import LayoutWidget from artiq.gui.models import DictSyncTreeSepModel @@ -227,7 +227,8 @@ class DatasetsDock(QtWidgets.QDockWidget): def set_model(self, model): self.table_model = model - self.table_model_filter = QRecursiveFilterProxyModel() + self.table_model_filter = QtCore.QSortFilterProxyModel() + self.table_model_filter.setRecursiveFilteringEnabled(True) self.table_model_filter.setSourceModel(self.table_model) self.table.setModel(self.table_model_filter) diff --git a/artiq/gui/tools.py b/artiq/gui/tools.py index 2b277c3e7..0fc9e4615 100644 --- a/artiq/gui/tools.py +++ b/artiq/gui/tools.py @@ -119,20 +119,3 @@ async def get_save_file_name(parent, caption, dir, filter, suffix=None): dialog.open() return await fut - -# Based on: -# http://stackoverflow.com/questions/250890/using-qsortfilterproxymodel-with-a-tree-model -class QRecursiveFilterProxyModel(QtCore.QSortFilterProxyModel): - def filterAcceptsRow(self, source_row, source_parent): - regexp = self.filterRegularExpression() - if not regexp.isEmpty(): - source_index = self.sourceModel().index( - source_row, self.filterKeyColumn(), source_parent) - if source_index.isValid(): - for i in range(self.sourceModel().rowCount(source_index)): - if self.filterAcceptsRow(i, source_index): - return True - key = self.sourceModel().data(source_index, self.filterRole()) - return regexp.match(key).hasMatch() - return QtCore.QSortFilterProxyModel.filterAcceptsRow( - self, source_row, source_parent)