forked from M-Labs/artiq
gui: QRecursiveFilterProxyModel is obsolete
The recursiveFilteringEnabled property, which was added in Qt 5.10, can now be used to obtain the same behaviour. Also fixes a PyQt6 incompatibility in the implementation.
This commit is contained in:
parent
5dd2f7c4e8
commit
4bd328afe7
|
@ -6,7 +6,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets
|
||||||
from sipyco.pc_rpc import AsyncioClient as RPCClient
|
from sipyco.pc_rpc import AsyncioClient as RPCClient
|
||||||
|
|
||||||
from artiq.tools import short_format
|
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
|
from artiq.gui.models import DictSyncTreeSepModel
|
||||||
|
|
||||||
# reduced read-only version of artiq.dashboard.datasets
|
# reduced read-only version of artiq.dashboard.datasets
|
||||||
|
@ -112,7 +112,8 @@ class DatasetsDock(QtWidgets.QDockWidget):
|
||||||
|
|
||||||
def set_model(self, model):
|
def set_model(self, model):
|
||||||
self.table_model = 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_model_filter.setSourceModel(self.table_model)
|
||||||
self.table.setModel(self.table_model_filter)
|
self.table.setModel(self.table_model_filter)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets
|
||||||
from sipyco import pyon
|
from sipyco import pyon
|
||||||
|
|
||||||
from artiq.tools import scale_from_metadata, short_format, exc_to_warning
|
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
|
from artiq.gui.models import DictSyncTreeSepModel
|
||||||
|
|
||||||
|
|
||||||
|
@ -227,7 +227,8 @@ class DatasetsDock(QtWidgets.QDockWidget):
|
||||||
|
|
||||||
def set_model(self, model):
|
def set_model(self, model):
|
||||||
self.table_model = 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_model_filter.setSourceModel(self.table_model)
|
||||||
self.table.setModel(self.table_model_filter)
|
self.table.setModel(self.table_model_filter)
|
||||||
|
|
||||||
|
|
|
@ -119,20 +119,3 @@ async def get_save_file_name(parent, caption, dir, filter, suffix=None):
|
||||||
dialog.open()
|
dialog.open()
|
||||||
return await fut
|
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)
|
|
||||||
|
|
Loading…
Reference in New Issue