6.1 KiB
6.1 KiB
GUI Preview Table Restructure Plan
Objective
Restructure the Graphical User Interface (GUI) preview table to group files by source asset and display "Ignored" and "Extra" files in a new "Additional Files" column, aligned with the mapped files of the same asset.
Analysis
Based on the review of gui/prediction_handler.py and gui/preview_table_model.py:
- The
PredictionHandlerprovides a flat list of file prediction dictionaries. - The
PreviewTableModelcurrently stores and displays this flat list directly. - The
PreviewSortFilterProxyModelsorts this flat list. - The data transformation to achieve the desired grouped layout must occur within the
PreviewTableModel.
Proposed Plan
-
Modify
gui/preview_table_model.py:- Add New Column:
- Define a new constant:
COL_ADDITIONAL_FILES = 5. - Add "Additional Files" to the
_headers_detailedlist.
- Define a new constant:
- Introduce New Internal Data Structure:
- Create a new internal list,
self._table_rows, to store dictionaries representing the final rows to be displayed in the table.
- Create a new internal list,
- Update
set_data(self, data: list):- Process the incoming flat
datalist (received fromPredictionHandler). - Group file dictionaries by their
source_asset. - Within each asset group, separate files into two lists:
main_files: Files with status "Mapped", "Model", or "Error".additional_files: Files with status "Ignored", "Extra", "Unrecognised", or "Unmatched Extra".
- Determine the maximum number of rows needed for this asset block:
max(len(main_files), len(additional_files)). - Build the row dictionaries for
self._table_rowsfor this asset block:- For
ifrom 0 tomax_rows - 1:- Get the
i-th file frommain_files(orNoneifiis out of bounds). - Get the
i-th file fromadditional_files(orNoneifiis out of bounds). - Create a row dictionary containing:
source_asset: The asset name.predicted_asset: From themain_file(if exists).details: From themain_file(if exists).original_path: From themain_file(if exists).additional_file_path: Path from theadditional_file(if exists).additional_file_details: The original dictionary of theadditional_file(if exists, for tooltips).is_main_row: Boolean flag (True if this row corresponds to a file inmain_files, False otherwise).
- Get the
- For
- Append these row dictionaries to
self._table_rows. - After processing all assets, call
self.beginResetModel()andself.endResetModel().
- Process the incoming flat
- Update
rowCount: Returnlen(self._table_rows)when in detailed mode. - Update
columnCount: Returnlen(self._headers_detailed). - Update
data(self, index, role):- Retrieve the row dictionary:
row_data = self._table_rows[index.row()]. - For
Qt.ItemDataRole.DisplayRole:- If
index.column()isCOL_ADDITIONAL_FILES, returnrow_data.get('additional_file_path', ''). - For other columns (
COL_STATUS,COL_PREDICTED_ASSET,COL_ORIGINAL_PATH,COL_DETAILS), return data from themain_filepart ofrow_dataifrow_data['is_main_row']is True, otherwise return an empty string or appropriate placeholder.
- If
- For
Qt.ItemDataRole.ToolTipRole:- If
index.column()isCOL_ADDITIONAL_FILESandrow_data.get('additional_file_details')exists, generate a tooltip using the status and details fromadditional_file_details. - For other columns, use the existing tooltip logic based on the
main_filedata.
- If
- For
Qt.ItemDataRole.ForegroundRole:- Apply existing color-coding based on the status of the
main_fileifrow_data['is_main_row']is True. - For the
COL_ADDITIONAL_FILEScell and for rows whererow_data['is_main_row']is False, use neutral styling (default text color).
- Apply existing color-coding based on the status of the
- Retrieve the row dictionary:
- Update
headerData: Return the correct header forCOL_ADDITIONAL_FILES.
- Add New Column:
-
Modify
gui/preview_table_model.py(PreviewSortFilterProxyModel):- Update
lessThan(self, left, right):- Retrieve the row dictionaries for
leftandrightindices from the source model (model._table_rows[left.row()], etc.). - Level 1: Source Asset: Compare
source_assetfrom the row dictionaries. - Level 2: Row Type: If assets are the same, compare
is_main_row(True sorts before False). - Level 3 (Main Rows): If both are main rows (
is_main_rowis True), compareoriginal_path. - Level 4 (Additional-Only Rows): If both are additional-only rows (
is_main_rowis False), compareadditional_file_path.
- Retrieve the row dictionaries for
- Update
Clarifications & Decisions
- Error Handling: "Error" files will remain in the main columns, similar to "Mapped" files, with their current "Error" status.
- Sorting within Asset: The proposed sorting logic within an asset block is acceptable (mapped rows by original path, additional-only rows by additional file path).
- Styling of Additional Column: Use neutral text and background styling for the "Additional Files" column, relying on tooltips for specific file details.
Mermaid Diagram (Updated Data Flow)
graph LR
A[PredictionHandler] -- prediction_results_ready(flat_list) --> B(PreviewTableModel);
subgraph PreviewTableModel
C[set_data] -- Processes flat_list --> D{Internal Grouping & Transformation};
D -- Creates --> E[_table_rows (Structured List)];
F[data()] -- Reads from --> E;
end
B -- Provides data via data() --> G(QTableView via Proxy);
style B fill:#f9f,stroke:#333,stroke-width:2px
style C fill:#ccf,stroke:#333,stroke-width:1px
style D fill:#lightgrey,stroke:#333,stroke-width:1px
style E fill:#ccf,stroke:#333,stroke-width:1px
style F fill:#ccf,stroke:#333,stroke-width:1px