Refactor: all standard, icon, delegate columns to use new column API

XMLWordPrintable

    • Type: Task
    • Resolution: Fixed
    • Priority: Normal
    • 3.0.0a1
    • Affects Version/s: None
    • Component/s: None
    • None

      see: https://github.com/metabrainz/picard/pull/2709#issuecomment-3239928988

      and see: https://github.com/metabrainz/picard/pull/2709#issuecomment-3240021428

      The existing `columns.py` contains several types of columns:

      1. *Simple Field Columns*: `Column(N_("Artist"), 'artist')`
      2. *Default Columns*: `DefaultColumn(N_("Title"), 'title', ...)`
      3. *Custom Sort Columns*: Using `sortkey` functions like `_sortkey_length`, `_sortkey_filesize`
      4. *Special Columns*: `MatchQualityColumn`, `IconColumn` (fingerprint status)

      Benefits of Refactoring

      1. *Code Unification: Eliminates duplicate sorting logic across multiple `sortkey` functions
      2. *Consistency*: All columns use the same provider-based architecture
      3. *Maintainability*: Centralized sorting logic in reusable adapters
      4. *Extensibility*: Easy to add new sorting behaviors without creating new functions
      5. *Type Safety*: Better type hints and validation through the provider system

      Implementation Plan

      Phase 1: Create Missing Providers
      1. *MatchQualityProvider*: Implement custom provider for match quality column
      2. *Enhanced NumericSortAdapter: Handle edge cases from current `sortkey` functions
      3. *StatusIconProvider*: For columns with status icons

      Phase 2: Refactor Standard Columns
      1. *Simple columns*: Replace `Column()` with `make_provider_column()`
      2. *Numeric columns*: Use `NumericSortAdapter` with `FieldReferenceProvider`
      3. *Natural sort columns*: Use `NaturalSortAdapter`
      4. *Special columns*: Create custom providers

      Phase 3: Cleanup
      1. *Remove redundant functions: Delete `sortkey` functions
      2. *Update imports*: Remove unused imports
      3. *Testing*: Ensure all sorting behaviors are preserved

      Migration Strategy

      *Backward Compatibility*: The refactoring can be done incrementally:
      1. Keep existing `Column` classes working
      2. Gradually replace with `make_provider_column()` calls
      3. Remove old code only after verification

      *Testing Approach*:
      1. Create comprehensive tests for each sorting adapter
      2. Verify sorting behavior matches current implementation
      3. Test edge cases (empty values, invalid data, etc.)

      Challenges & Solutions

      1. *MatchQualityColumn Complexity*: 
         - *Solution*: Create dedicated `MatchQualityProvider` that handles both display and sorting

      2. *Status Icon Integration*:
         - *Solution*: Extend `FieldReferenceProvider` or create `StatusIconProvider`

      3. *DefaultColumn vs Column*:
         - *Solution*: Use `always_visible=True` parameter in `make_provider_column()`

      4. *ImageColumn Special Cases*:
         - *Solution*: Keep `ImageColumn` for complex rendering, use providers for simple cases

            Assignee:
            knguyen
            Reporter:
            knguyen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Version Package
                3.0.0a1