From 71e56570089b7fdfae9a210c473912c7bced65a0 Mon Sep 17 00:00:00 2001 From: Shark-y <38670127+Shark-y@users.noreply.github.com> Date: Sun, 7 May 2023 17:25:21 -0400 Subject: [PATCH] Fix for QComponents Widget Sort & Filter Wrapped the The components table in a QSortFilterProxyModel for sorting, filtering, plus Added a textChanged event to the filter box to display only specific items. https://github.com/Qiskit/qiskit-metal/issues/45 --- qiskit_metal/_gui/main_window.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/qiskit_metal/_gui/main_window.py b/qiskit_metal/_gui/main_window.py index f68c9a225..59f1a06a2 100644 --- a/qiskit_metal/_gui/main_window.py +++ b/qiskit_metal/_gui/main_window.py @@ -593,8 +593,25 @@ def _setup_design_components_widget(self): model = QTableModel_AllComponents(self, logger=self.logger, tableView=self.ui.tableComponents) - self.ui.tableComponents.setModel(model) - + # Add Sort/Filter logic to the components table + self.ui.proxyModel = QSortFilterProxyModel() + self.ui.proxyModel.setSourceModel(model) + + # search all columns + self.ui.proxyModel.setFilterKeyColumn(-1) + self.ui.tableComponents.setSortingEnabled(True) + self.ui.tableComponents.setModel(self.ui.proxyModel) + + # Add a text changed event to the filter text box + self.ui.filter_text_design.textChanged.connect(self.filter_text_design_onChanged) + + def filter_text_design_onChanged (self, text): + """ Text changed event for filter_text_design + Args: + text: Text typed in the filter box. + """ + self.ui.proxyModel.setFilterWildcard(text) + def _create_new_component_object_from_qlibrary(self, full_path: str): """ Must be defined outside of _setup_library_widget to ensure self == MetalGUI and will retain opened ScrollArea @@ -743,7 +760,7 @@ def refresh(self): self.refresh_design() # Table models - self.ui.tableComponents.model().refresh() + self.ui.tableComponents.model().sourceModel().refresh() # Redraw plots self.refresh_plot()