populse_mia 3.0.0-dev+e05f3e3c documentation

populse_mia.user_interface.data_browser.advanced_search

Contents

populse_mia.user_interface.data_browser.advanced_search¶

Module to define the advanced search.

Classes

AdvancedSearch(project, data_browser[, ...])

Class that manages the widget of the advanced search.

class populse_mia.user_interface.data_browser.advanced_search.AdvancedSearch(project, data_browser, scans_list=None, tags_list=None, from_pipeline=False)[source]¶

Bases: QWidget

Class that manages the widget of the advanced search.

The advanced search creates a complex query to the database and is a combination of several “query lines” which are linked with AND or OR and all composed of:

  • A negation or not.

  • A tag name or all visible tags.

  • A condition (==, !=, >, <, >=, <=, CONTAINS, IN, BETWEEN).

  • A value.

Contains:

Methods:

  • add_search_bar: Create and define the advanced research bar.

  • apply_filter: Apply an opened filter to update the table.

  • displayConditionRules: Set the list of condition choices, depending on the tag type.

  • displayValueRules: Update the placeholder text when the condition choice is changed.

  • get_filters: Get the filters in list form.

  • launch_search: Start the search and update the table.

  • prepare_filters: Prepare the str representation of the filter.

  • refresh_search: Refresh the widget.

  • remove_row: Remove a row.

  • rows_borders_added: Add the links and the added row to the good rows.

  • rows_borders_removed: Link and adds row removed from every row.

  • show_search: Reset the rows when the Advanced Search button is clicked.

__init__(project, data_browser, scans_list=None, tags_list=None, from_pipeline=False)[source]¶

Initialize the AdvancedSearch widget.

Parameters:
  • project – The current project instance.

  • data_browser – The parent DataBrowser widget that contains this search.

  • scans_list – List of document scans to search within. Defaults to empty list.

  • tags_list – List of tags to display in the search interface. Defaults to empty list.

  • from_pipeline – (bool) Whether the widget is instantiated from the pipeline manager. Defaults to False.

add_search_bar()[source]¶

Add an advanced search bar row to the search interface.

Creates a complete search row containing:
  • NOT operator toggle.

  • Field selector (populated with available tags).

  • Condition operator selector (==, !=, >, <, etc.).

  • Value input field.

  • Remove button to delete this row.

The row components are connected with signals to update dynamically based on field type and selected condition.

Contains:

Inner functions:

  • _create_combo_box: Create and return a QComboBox populated with the given items.

  • _get_shown_tags_from_db: Retrieve the tags currently marked as visible from the project database.

apply_filter(filter)[source]¶

Apply a filter to update the displayed scans in the data browser.

Retrieves documents from the database based on the provided filter criteria and updates the table visualization accordingly. If the filter is invalid or an error occurs, displays a warning and reverts to showing all scans.

Parameters:

filter –

Filter object containing the query criteria with attributes:

  • nots (list): Negation flags for each condition.

  • values (list): Values to match against.

  • conditions (list): Comparison operators (e.g., ‘==’, ‘>’, ‘<’).

  • links (list): Logical operators connecting conditions (‘AND’, ‘OR’).

  • fields (list): Database fields to query.

Side effects:
  • Updates self.rows with filter parameters.

  • Modifies self.data_browser.table_data.scans_to_visualize.

  • May display a warning dialog on error.

  • Calls self.data_browser.table_data.update_visualized_rows().

displayConditionRules(field, condition)[source]¶

Update available condition operators based on the selected field’s type.

Dynamically adjusts the condition dropdown to show only operators that are valid for the selected field’s data type. Numeric fields allow comparison operators (<, >, <=, >=, BETWEEN), while non-numeric fields exclude them. List fields exclude the IN operator, while non-list fields include it.

Parameters:
  • field – QComboBox widget containing the selected tag name.

  • condition – QComboBox widget whose items will be updated based on the field’s type.

Behavior:
  • Numeric types: Include <, >, <=, >=, BETWEEN operators.

  • String/Boolean/List types: Exclude comparison operators.

  • List types: Exclude IN operator.

  • Non-list types: Include IN operator.

  • Special case “All visualized tags”: Treated as non-numeric.

Contains:

Inner functions:

  • _update_operators: Add or remove operators from the condition widget.

displayValueRules(choice, value)[source]¶

Configure the value input widget based on the selected condition operator.

Adjusts the enabled state and placeholder text of the value input to match the requirements of the selected condition operator.

Parameters:
  • choice – QComboBox containing the selected condition operator.

  • value – QLineEdit widget that will be configured.

Behavior:
  • BETWEEN: Enabled with placeholder “value1; value2”.

  • IN: Enabled with placeholder for semicolon-separated list.

  • HAS VALUE/HAS NO VALUE: Disabled and cleared.

  • Other operators: Enabled with no placeholder.

get_filters(replace_all_by_fields)[source]¶

Extract filter criteria from UI widgets.

Parses the filter rows to extract search criteria including fields, conditions, values, logical operators, and negation flags. Handles special cases like “All visualized tags” expansion and operator compatibility validation.

Parameters:

replace_all_by_fields – If True, replaces “All visualized tags” with the actual list of visible fields. If False, keeps the literal “All visualized tags” text.

Returns:

(tuple) A 5-tuple containing:

  • fields (list): Field names to filter on

  • conditions (list): Comparison operators (e.g., ‘=’, ‘BETWEEN’)

  • values (list): Filter values (strings or lists for BETWEEN/IN)

  • links (list): Logical operators connecting filters (AND/OR)

  • nots (list): Negation flags for each filter

Note

  • BETWEEN and IN conditions have their values split into lists.

  • Fields incompatible with operators are automatically removed.

launch_search()[source]¶

Execute search query and update the data browser table.

Retrieves filter parameters, constructs and executes a database query, then updates the data browser’s visualized scans with the results. If the search fails, displays an error dialog and reverts to showing all available scans.

Side Effects:
  • Updates self.data_browser.table_data.scans_to_visualize.

  • Updates self.data_browser.table_data.scans_to_search.

  • Updates self.project.currentFilter (if not from_pipeline).

  • Displays error dialog on search failure.

static prepare_filters(links, fields, conditions, values, nots, scans)[source]¶

Construct a filter query string from filter components.

Builds a query by combining multiple filter rows with logical operators (AND/OR), where each row can filter across multiple fields with optional negation.

Parameters:
  • links – Logical operators joining filter rows (e.g. [‘AND’, ‘OR’]). Length should be len(fields) - 1.

  • fields – Nested list where each sublist contains field names to filter on. Fields within a row are OR-combined.

  • conditions – Filter operators for each row. Supported values: ‘==’, ‘!=’, ‘<’, ‘>’, ‘<=’, ‘>=’, ‘IN’, ‘BETWEEN’, ‘CONTAINS’, ‘HAS VALUE’, ‘HAS NO VALUE’.

  • values – Filter values corresponding to each condition. For ‘BETWEEN’, provide a two-element sequence [min, max].

  • nots – Negation flags for each row (‘NOT’ to negate, empty string otherwise).

  • scans – List of scan identifiers to restrict the search scope.

Returns:

Complete filter query string with all conditions and scan restrictions.

Contains:

Inner functions:

  • _format_value: Convert a Python value into a string safe for use in queries.

refresh_search()[source]¶

Refresh the search widget by rebuilding its layout with the current filters.

This method performs the following steps:
  1. Retrieves the current filter values without replacing “All visualized tags”.

  2. Clears the old layout and cleans up its widgets.

  3. Removes and restores row borders according to the links.

  4. Rebuilds the main grid layout with all row widgets.

  5. Adds the search button in a horizontal layout at the bottom.

  6. Sets the new combined layout as the widget’s layout.

remove_row(row_layout)[source]¶

Remove a specified row from the layout while ensuring at least one row remains.

This method deletes all widgets in the specified row, removes the row from the internal rows list, and refreshes the view.

Parameters:

row_layout – The row (list of widgets) to remove.

rows_borders_added(links)[source]¶

Add UI controls (links and add button) to search query rows.

Adds a green plus button to the last row for adding new search bars, and adds AND/OR combo boxes to all rows except the first one for linking query conditions.

Parameters:

links – List of previously selected link operators (‘AND’/’OR’) to restore when rebuilding the UI.

rows_borders_removed()[source]¶

Remove the link widget and the “add row” widget from every row.

This ensures that these widgets are properly removed from the layout and scheduled for deletion, preventing memory leaks.

Contains:

Inner functions:

  • _remove_widget: Safely removes a QWidget from its parent and schedules it for deletion.

show_search()[source]¶

Reset the search rows and display the search bar.

This method clears the current rows if there are none or fewer than one, and initializes the search bar for the advanced search functionality.

Contents

© Copyright 2022, populse. Created using Sphinx 8.1.3.