Skip to content

Commit

Permalink
Fix for QComponents Widget Sort & Filter
Browse files Browse the repository at this point in the history
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.

#45
  • Loading branch information
Shark-y committed May 7, 2023
1 parent a25450a commit 71e5657
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions qiskit_metal/_gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 71e5657

Please sign in to comment.