diff --git a/artiq/browser/datasets.py b/artiq/browser/datasets.py index 4f49c1ba5..4f3e9e181 100644 --- a/artiq/browser/datasets.py +++ b/artiq/browser/datasets.py @@ -4,7 +4,7 @@ import asyncio from PyQt5 import QtCore, QtWidgets from artiq.tools import short_format -from artiq.gui.tools import LayoutWidget +from artiq.gui.tools import LayoutWidget, QRecursiveFilterProxyModel from artiq.gui.models import DictSyncTreeSepModel from artiq.protocols.pc_rpc import AsyncioClient as RPCClient @@ -77,7 +77,7 @@ class DatasetsDock(QtWidgets.QDockWidget): def set_model(self, model): self.table_model = model - self.table_model_filter = QtCore.QSortFilterProxyModel() + self.table_model_filter = QRecursiveFilterProxyModel() 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 46252a043..cdb8d3ef6 100644 --- a/artiq/dashboard/datasets.py +++ b/artiq/dashboard/datasets.py @@ -5,7 +5,7 @@ import numpy as np from PyQt5 import QtCore, QtWidgets from artiq.tools import short_format -from artiq.gui.tools import LayoutWidget +from artiq.gui.tools import LayoutWidget, QRecursiveFilterProxyModel from artiq.gui.models import DictSyncTreeSepModel @@ -141,7 +141,7 @@ class DatasetsDock(QtWidgets.QDockWidget): def set_model(self, model): self.table_model = model - self.table_model_filter = QtCore.QSortFilterProxyModel() + self.table_model_filter = QRecursiveFilterProxyModel() 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 fc3daf91a..bc681bb77 100644 --- a/artiq/gui/tools.py +++ b/artiq/gui/tools.py @@ -61,3 +61,21 @@ async def get_open_file_name(parent, caption, dir, filter): dialog.rejected.connect(fut.cancel) 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.filterRegExp() + 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.indexIn(key) != -1 + return QtCore.QSortFilterProxyModel.filterAcceptsRow( + self, source_row, source_parent)