{
    "sourceFile": "Tickets/FEAT-008-gui-preview-refinement.md",
    "activeCommit": 0,
    "commits": [
        {
            "activePatchIndex": 1,
            "patches": [
                {
                    "date": 1745322980308,
                    "content": "Index: \n===================================================================\n--- \n+++ \n"
                },
                {
                    "date": 1745323701534,
                    "content": "Index: \n===================================================================\n--- \n+++ \n@@ -51,5 +51,89 @@\n *   [ ] Within each asset group, the table automatically sorts by the Status column according to the specified multi-level order.\r\n *   [ ] Clicking the Status header cycles through ascending/descending sort based on the custom multi-level order: Asset > Status (Error > (Mapped & Model) > Ignored > Extra) > Filename.\r\n *   [ ] The \"Predicted Output\" column is not present in the detailed preview table.\r\n *   [ ] Status text for relevant items displays concisely as: \"Extra\", \"[Extra=#####]\", \"Superseeded by 16bit ####\".\r\n-*   [ ] The \"Original Path\" column is visually the last column on the right side of the table.\n\\ No newline at end of file\n+*   [ ] The \"Original Path\" column is visually the last column on the right side of the table.\r\n+---\r\n+\r\n+## Implementation Plan (Generated 2025-04-22)\r\n+\r\n+This plan outlines the steps to implement the GUI preview refinements described in this ticket.\r\n+\r\n+**Goal:** Enhance the GUI's detailed file preview table for better usability and clarity by implementing grouping, refined sorting, simplified status text, and adjusted column layout.\r\n+\r\n+**Affected Files:**\r\n+\r\n+*   `gui/main_window.py`: Handles table view setup, data population trigger, and column management.\r\n+*   `gui/preview_table_model.py`: Contains the table model (`PreviewTableModel`) and the sorting proxy model (`PreviewSortFilterProxyModel`).\r\n+\r\n+**Plan Steps:**\r\n+\r\n+1.  **Correct Data Population in `main_window.py`:**\r\n+    *   **Action:** Modify the `on_prediction_results_ready` slot (around line 893).\r\n+    *   **Change:** Update the code to call `self.preview_model.set_data(results)` instead of populating the old `self.preview_table`.\r\n+    *   **Remove:** Delete code manually setting headers, rows, and items on `self.preview_table`.\r\n+    *   **Keep:** Retain the initial setup of `self.preview_table_view` (lines 400-424).\r\n+\r\n+2.  **Implement Status Text Simplification in `preview_table_model.py`:**\r\n+    *   **Action:** Modify the `data()` method within the `PreviewTableModel` class (around line 56).\r\n+    *   **Change:** Inside the `if role == Qt.ItemDataRole.DisplayRole:` block for `COL_STATUS`, add logic to transform the raw status string:\r\n+        *   \"Unmatched Extra\" -> \"Extra\"\r\n+        *   \"[Unmatched Extra (Regex match: PATTERN)]\" -> \"[Extra=PATTERN]\"\r\n+        *   \"Ignored (Superseed by 16bit variant for FILENAME)\" -> \"Superseeded by 16bit FILENAME\"\r\n+        *   Otherwise, return original status.\r\n+    *   **Note:** Ensure `ROLE_RAW_STATUS` still returns the original status for sorting.\r\n+\r\n+3.  **Refine Sorting Logic in `preview_table_model.py`:**\r\n+    *   **Action:** Modify the `lessThan` method within the `PreviewSortFilterProxyModel` class (around line 166).\r\n+    *   **Change:** Adjust the \"Level 2: Sort by Status\" logic to use a priority mapping where \"Mapped\" and \"Model\" have the same priority index, causing the sort to fall through to Level 3 (Path) for items within this group.\r\n+        ```python\r\n+        # Example Priority Mapping\r\n+        STATUS_PRIORITY = {\r\n+            \"Error\": 0,\r\n+            \"Mapped\": 1,\r\n+            \"Model\": 1,\r\n+            \"Ignored\": 2,\r\n+            \"Extra\": 3,\r\n+            \"Unrecognised\": 3,\r\n+            \"Unmatched Extra\": 3,\r\n+            \"[No Status]\": 99\r\n+        }\r\n+        # ... comparison logic using STATUS_PRIORITY ...\r\n+        ```\r\n+    *   **Remove/Update:** Replace the old `STATUS_ORDER` list with this priority dictionary logic.\r\n+\r\n+4.  **Adjust Column Order in `main_window.py`:**\r\n+    *   **Action:** Modify the `setup_main_panel_ui` method (around lines 404-414).\r\n+    *   **Change:** After setting up `self.preview_table_view`, explicitly move the \"Original Path\" column to the last visual position using `header.moveSection()`.\r\n+    *   **Verify:** Ensure the \"Predicted Output\" column remains hidden.\r\n+\r\n+**Visual Plan (Mermaid):**\r\n+\r\n+```mermaid\r\n+graph TD\r\n+    A[Start FEAT-008 Implementation] --> B(Refactor `main_window.py::on_prediction_results_ready`);\r\n+    B --> C{Use `self.preview_model.set_data()`?};\r\n+    C -- Yes --> D(Remove manual `QTableWidget` population);\r\n+    C -- No --> E[ERROR: Incorrect data flow];\r\n+    D --> F(Modify `preview_table_model.py::PreviewTableModel::data()`);\r\n+    F --> G{Implement Status Text Simplification?};\r\n+    G -- Yes --> H(Add formatting logic for DisplayRole);\r\n+    G -- No --> I[ERROR: Status text not simplified];\r\n+    H --> J(Modify `preview_table_model.py::PreviewSortFilterProxyModel::lessThan()`);\r\n+    J --> K{Implement Mapped/Model Grouping & Custom Sort Order?};\r\n+    K -- Yes --> L(Use priority mapping for status comparison);\r\n+    K -- No --> M[ERROR: Sorting incorrect];\r\n+    L --> N(Modify `main_window.py::setup_main_panel_ui()`);\r\n+    N --> O{Move 'Original Path' Column to End?};\r\n+    O -- Yes --> P(Use `header.moveSection()`);\r\n+    O -- No --> Q[ERROR: Column order incorrect];\r\n+    P --> R(Verify All Acceptance Criteria);\r\n+    R --> S[End FEAT-008 Implementation];\r\n+\r\n+    subgraph main_window.py Modifications\r\n+        B; D; N; P;\r\n+    end\r\n+\r\n+    subgraph preview_table_model.py Modifications\r\n+        F; H; J; L;\r\n+    end\n\\ No newline at end of file\n"
                }
            ],
            "date": 1745322980308,
            "name": "Commit-0",
            "content": "---\r\nID: FEAT-008\r\nType: Feature\r\nStatus: Backlog\r\nPriority: Medium\r\nLabels: [gui, enhancement]\r\nCreated: 2025-04-22\r\nUpdated: 2025-04-22\r\nRelated: gui/main_window.py, gui/prediction_handler.py\r\n---\r\n\r\n# [FEAT-008]: Refine GUI Preview Table Display and Sorting\r\n\r\n## Description\r\nEnhance the usability and clarity of the GUI's detailed file preview table. This involves improving the default sorting to group by asset and then status, removing redundant information, simplifying status text, and rearranging columns.\r\n\r\n## Current Behavior\r\n*   The preview table lists all files from all assets together without clear grouping.\r\n*   The table does not sort by status by default, or the sort order isn't optimized for clarity.\r\n*   The table includes a \"Predicted Output\" column which is considered redundant.\r\n*   Status text can be verbose (e.g., \"unmatched extra\", \"[Unmatched Extra (Regex match: #####)]\", \"Ignored (Superseed by 16bit variant for ####)\").\r\n*   The \"Original Path\" column is not necessarily the rightmost column.\r\n\r\n## Desired Behavior / Goals\r\n*   The preview table should group files by the asset they belong to (e.g., based on the input ZIP/folder name or derived asset name).\r\n*   Within each asset group, the table should sort rows by 'Status' by default.\r\n*   The default secondary sort order for 'Status' should prioritize actionable or problematic statuses, grouping models with their maps: Error > (Mapped & Model) > Ignored > Extra. (Note: Assumes 'Unrecognised' files are displayed as 'Extra').\r\n*   Within the 'Mapped & Model' group, files should be sorted alphabetically by original path or filename to keep related items together.\r\n*   The \"Predicted Output\" column should be removed from the table view.\r\n*   Status display text should be made more concise:\r\n    *   \"unmatched extra\" should be displayed as \"Extra\".\r\n    *   \"[Unmatched Extra (Regex match: #####)]\" should be displayed as \"[Extra=#####]\".\r\n    *   \"Ignored (Superseed by 16bit variant for ####)\" should be displayed as \"Superseeded by 16bit ####\".\r\n    *   Other statuses (\"Mapped\", \"Model\", \"Error\") should remain clear.\r\n*   The \"Original Path\" column should be positioned as the rightmost column in the table.\r\n\r\n## Implementation Notes (Optional)\r\n*   Modifications will likely be needed in `gui/main_window.py` (table view setup, column management, data population, sorting proxy model) and `gui/prediction_handler.py` (ensure prediction results include the source asset identifier).\r\n*   The table model (`QAbstractTableModel` or similar) needs to store the source asset identifier for each file row.\r\n*   Implement a custom multi-level sorting logic using `QSortFilterProxyModel`.\r\n    *   The primary sort key will be the asset identifier.\r\n    *   The secondary sort key will be the status, mapping 'Mapped' and 'Model' to the same priority level.\r\n    *   The tertiary sort key will be the original path/filename.\r\n*   Update the column hiding/showing logic to remove the \"Predicted Output\" column.\r\n*   Implement string formatting or replacement logic for the status display text.\r\n*   Adjust the column order.\r\n*   Consider the performance implications of grouping and multi-level sorting, especially with a large number of assets/files. Add necessary optimizations (e.g., efficient data structures, potentially deferring sorting until needed).\r\n\r\n## Acceptance Criteria (Optional)\r\n*   [ ] When assets are added to the queue and detailed preview is active, the table visually groups files by their source asset.\r\n*   [ ] Within each asset group, the table automatically sorts by the Status column according to the specified multi-level order.\r\n*   [ ] Clicking the Status header cycles through ascending/descending sort based on the custom multi-level order: Asset > Status (Error > (Mapped & Model) > Ignored > Extra) > Filename.\r\n*   [ ] The \"Predicted Output\" column is not present in the detailed preview table.\r\n*   [ ] Status text for relevant items displays concisely as: \"Extra\", \"[Extra=#####]\", \"Superseeded by 16bit ####\".\r\n*   [ ] The \"Original Path\" column is visually the last column on the right side of the table."
        }
    ]
}