Skip to content

Commit

Permalink
307 q library filtering fix (#940)
Browse files Browse the repository at this point in the history
* Fix for layout of the GDS/Q3D export window in the gui

Issue #549
#549

The scaling for the GDS/Q3D/HFSS dialogs should be fixed now.

* 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.

#45

* Revert "Fix for layout of the GDS/Q3D export window in the gui"

This reverts commit a25450a.

* Update for lint test failures

Run yapf on all files plus a few method updates in the filter/sort logic.

* Fix for QLibrary Filtering #307

Issue #307

* Update for issuecomment-1540641146

Update for comment
#940 (comment)

This bug is really though :(

---------

Co-authored-by: Priti Ashvin Shah <74020801+priti-ashvin-shah-ibm@users.noreply.github.com>
  • Loading branch information
Shark-y and priti-ashvin-shah-ibm authored May 10, 2023
1 parent c813968 commit 99811f1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
26 changes: 26 additions & 0 deletions qiskit_metal/_gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ def _setup_library_widget(self):
#QSortFilterProxyModel: sorting items, filtering out items, or both. maps the original model indexes to new indexes, allows a given source model to be restructured as far as views are concerned without requiring any transformations on the underlying data, and without duplicating the data in memory.
dock.proxy_library_model = LibraryFileProxyModel()
dock.proxy_library_model.setSourceModel(dock.library_model)
dock.proxy_library_model.setFilterCaseSensitivity(Qt.CaseInsensitive)
dock.proxy_library_model.setRecursiveFilteringEnabled(True)

# --------------------------------------------------
# View
Expand Down Expand Up @@ -686,6 +688,30 @@ def _setup_library_widget(self):
dock.proxy_library_model.mapFromSource(
dock.library_model.index(stringLibraryRootPath)))

# Add a text changed event to the filter text box
self.ui.dockLibrary_filter.textChanged.connect(
self.dockLibrary_filter_onChanged)

def dockLibrary_filter_onChanged(self, text):
""" Text changed event for filter_text_design
Args:
text: Text typed in the filter box.
"""
view = self.ui.dockLibrary_tree_view
dock = self.ui.dockLibrary
dock.proxy_library_model.filter_text = text

dock.proxy_library_model.setFilterWildcard(text)

view.setRootIndex(
dock.proxy_library_model.mapFromSource(
dock.library_model.index(dock.library_model.rootPath())))

if len(text) >= 1 and dock.proxy_library_model.rowCount() > 0:
view.expandAll()
else:
view.collapseAll()

################################################
# UI
def toggle_docks(self, do_hide: bool = None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import typing

from PySide2.QtCore import QModelIndex, QSortFilterProxyModel, Qt, QSize
from PySide2.QtWidgets import QWidget
from PySide2.QtWidgets import QWidget, QFileSystemModel


class LibraryFileProxyModel(QSortFilterProxyModel):
Expand All @@ -39,6 +39,7 @@ def __init__(self, parent: QWidget = None):
# (QComponent files) OR (Directories)
self.accepted_files__regex = r"(^((?!\.))(?!base)(?!__init__)(?!_template)(?!_parsed)(?!__pycache__).*\.py)|(?!__pycache__)(^([^.]+)$)" # pylint: disable=line-too-long
self.setFilterRegExp(self.accepted_files__regex)
self.filter_text = ""

def filterAcceptsColumn(
self, source_column: int, source_parent: QModelIndex) -> bool: #pylint: disable=unused-argument
Expand All @@ -57,6 +58,35 @@ def filterAcceptsColumn(
return False
return True

def filterAcceptsRow(
self, source_row: int, source_parent: QModelIndex) -> bool: #pylint: disable=unused-argument
"""
Filters out unwanted file information in display
Args:
source_column(int): Display column in question
source_parent(QModelIndex): Parent index
Returns:
bool: Whether to display column
"""
source_model = self.sourceModel()
nameCache = source_model.nameCache

index = source_model.index(source_row, 0, source_parent)
relativeFilename = index.data(QFileSystemModel.FileNameRole)
displayName = nameCache[
relativeFilename] if relativeFilename in nameCache else None
#fi = source_model.fileInfo(index)

if displayName != None:
found = (self.filter_text in relativeFilename) or (self.filter_text
in displayName)
else:
found = (self.filter_text in relativeFilename)

accept = (not relativeFilename.startswith("_")) and found
return accept

def data(self,
index: QModelIndex,
role: int = Qt.DisplayRole) -> typing.Any:
Expand Down

0 comments on commit 99811f1

Please sign in to comment.