Skip to content

Commit

Permalink
gui: improve search of hierarchical datasets. Closes #258
Browse files Browse the repository at this point in the history
sbourdeauducq committed Aug 14, 2016
1 parent 1758204 commit b7151a2
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions artiq/browser/datasets.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
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 @@ def metadata_changed(self, new):

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)

4 changes: 2 additions & 2 deletions artiq/dashboard/datasets.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
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 @@ def _search_datasets(self):

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)

18 changes: 18 additions & 0 deletions artiq/gui/tools.py
Original file line number Diff line number Diff line change
@@ -61,3 +61,21 @@ def on_accept():
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)

0 comments on commit b7151a2

Please sign in to comment.