feat: search is filtered by category
This commit is contained in:
@@ -183,9 +183,32 @@ class PluginTableModel(QAbstractTableModel):
|
||||
self._apply_sort()
|
||||
self.endResetModel()
|
||||
|
||||
def filter_by_search_results(self, plugins: list[AudioComponent]) -> None:
|
||||
def filter_by_search_results(
|
||||
self,
|
||||
plugins: list[AudioComponent],
|
||||
category: str | None = None,
|
||||
manufacturer: str | None = None,
|
||||
) -> None:
|
||||
self.beginResetModel()
|
||||
self._plugins = plugins
|
||||
if manufacturer is not None:
|
||||
self._plugins = [
|
||||
p for p in plugins if p.manufacturer.lower() == manufacturer.lower()
|
||||
]
|
||||
elif category == "Show All" or category is ...:
|
||||
self._plugins = plugins
|
||||
elif category is None:
|
||||
self._plugins = [p for p in plugins if not p.categories]
|
||||
elif category == "Top Level":
|
||||
self._plugins = [
|
||||
p for p in plugins if any(c.name == "" for c in p.categories)
|
||||
]
|
||||
elif category is not None:
|
||||
self._plugins = [
|
||||
p for p in plugins if any(c.name == category for c in p.categories)
|
||||
]
|
||||
else:
|
||||
self._plugins = plugins
|
||||
self._apply_sort()
|
||||
self.endResetModel()
|
||||
|
||||
def get_plugin(self, row: int) -> AudioComponent | None:
|
||||
|
||||
@@ -40,6 +40,8 @@ class MainWindow(QMainWindow):
|
||||
self._logic: Logic | None = None
|
||||
self._glass_applied = False
|
||||
self._settings = Settings()
|
||||
self._current_category: str | None = "Show All"
|
||||
self._current_manufacturer: str | None = None
|
||||
|
||||
self._setup_ui()
|
||||
self._setup_service()
|
||||
@@ -139,16 +141,31 @@ class MainWindow(QMainWindow):
|
||||
self._plugin_table.focus_table()
|
||||
|
||||
def _on_category_selected(self, category: str | None) -> None:
|
||||
self._plugin_table.clear_search()
|
||||
self._plugin_table.filter_by_category(category)
|
||||
self._current_category = category
|
||||
self._current_manufacturer = None
|
||||
query = self._plugin_table.get_search_text()
|
||||
if query:
|
||||
self._service.search(query)
|
||||
else:
|
||||
self._plugin_table.filter_by_category(category)
|
||||
|
||||
def _on_manufacturer_selected(self, manufacturer: str) -> None:
|
||||
self._plugin_table.clear_search()
|
||||
self._plugin_table.filter_by_manufacturer(manufacturer)
|
||||
self._current_manufacturer = manufacturer
|
||||
self._current_category = None
|
||||
query = self._plugin_table.get_search_text()
|
||||
if query:
|
||||
self._service.search(query)
|
||||
else:
|
||||
self._plugin_table.filter_by_manufacturer(manufacturer)
|
||||
|
||||
def _on_search_changed(self, query: str) -> None:
|
||||
if not query:
|
||||
self._plugin_table.filter_by_category("Show All")
|
||||
if self._current_manufacturer:
|
||||
self._plugin_table.filter_by_manufacturer(self._current_manufacturer)
|
||||
else:
|
||||
self._plugin_table.filter_by_category(
|
||||
self._current_category if self._current_category else "Show All"
|
||||
)
|
||||
return
|
||||
self._service.search(query)
|
||||
|
||||
@@ -179,7 +196,11 @@ class MainWindow(QMainWindow):
|
||||
|
||||
def _on_search_results(self, results: list[SearchResult]) -> None:
|
||||
plugins = [r.plugin for r in results]
|
||||
self._plugin_table.filter_by_search_results(plugins)
|
||||
self._plugin_table.filter_by_search_results(
|
||||
plugins,
|
||||
category=self._current_category,
|
||||
manufacturer=self._current_manufacturer,
|
||||
)
|
||||
|
||||
def _on_error(self, message: str) -> None:
|
||||
self._loading_overlay.set_message(f"Error: {message}")
|
||||
|
||||
@@ -148,8 +148,13 @@ class PluginTableView(QWidget):
|
||||
def filter_by_manufacturer(self, manufacturer: str) -> None:
|
||||
self._model.filter_by_manufacturer(manufacturer)
|
||||
|
||||
def filter_by_search_results(self, plugins: list[AudioComponent]) -> None:
|
||||
self._model.filter_by_search_results(plugins)
|
||||
def filter_by_search_results(
|
||||
self,
|
||||
plugins: list[AudioComponent],
|
||||
category: str | None = None,
|
||||
manufacturer: str | None = None,
|
||||
) -> None:
|
||||
self._model.filter_by_search_results(plugins, category, manufacturer)
|
||||
|
||||
def update_plugin_display(self, plugin: AudioComponent, column: int) -> None:
|
||||
self._model.update_plugin_display(plugin, column)
|
||||
@@ -157,6 +162,9 @@ class PluginTableView(QWidget):
|
||||
def clear_search(self) -> None:
|
||||
self._search_bar.clear()
|
||||
|
||||
def get_search_text(self) -> str:
|
||||
return self._search_bar.text()
|
||||
|
||||
def focus_search(self) -> None:
|
||||
self._search_bar.setFocus()
|
||||
self._search_bar.selectAll()
|
||||
|
||||
Reference in New Issue
Block a user