forked from M-Labs/artiq
1
0
Fork 0

gui: improve search of hierarchical datasets. Closes #258

This commit is contained in:
Sebastien Bourdeauducq 2016-08-14 18:33:24 +08:00
parent 17582047cb
commit b7151a253f
3 changed files with 22 additions and 4 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)