Skip to content

fix: improve QML compatibility and code quality - #740

Open
kt286 wants to merge 1 commit into
linuxdeepin:masterfrom
kt286:fix/qml-compatibility
Open

fix: improve QML compatibility and code quality#740
kt286 wants to merge 1 commit into
linuxdeepin:masterfrom
kt286:fix/qml-compatibility

Conversation

@kt286

@kt286 kt286 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor
  • Migrate signal/slot syntax to QML 5.15+ function form
  • Add null safety checks to prevent runtime crashes
  • Update copyright year to 2026
  • Fix animation properties from xScale/yScale to scale
  • Remove unused code and comments

改进 QML 兼容性和代码质量

  • 迁移信号/槽语法到 QML 5.15+ 函数形式
  • 添加空值检查防止运行时崩溃
  • 更新版权年份至 2026
  • 修复动画属性从 xScale/yScale 到 scale
  • 移除未使用的代码和注释

解决了艺人歌曲列表中按钮错位

Summary by Sourcery

Improve QML music player stability and compatibility while cleaning up legacy code and styling.

Bug Fixes:

  • Add null and existence checks for models, loaders, and data bindings to prevent runtime crashes and invalid access.
  • Guard QML update calls and shader view updates on component/window availability to avoid crashes.
  • Fix incorrect artist/album menu callbacks and search result handlers to use the proper data arguments.
  • Correct animation properties from deprecated xScale/yScale to scale to ensure transitions render properly.
  • Adjust drag image generation and wheel handlers to work safely with QML 5.15+ APIs.

Enhancements:

  • Migrate signal/slot handlers and Connections in QML to the QML 5.15+ function-based syntax across views and dialogs.
  • Replace SystemPalette usage with DTK palette-based colors and explicit palettes for better theming support.
  • Refine side bar, sublist, album, and list delegates layout and dimensions for more robust sizing and alignment.
  • Simplify lyric window and playlist visibility handling and improve toolbar logic for play mode changes when media data is absent.
  • Improve shortcut JSON serialization by using const references in range-for loops.

Documentation:

  • Update SPDX copyright headers across music player QML and C++ files to cover years 2023–2026.

Chores:

  • Remove unused and commented-out QML code, tooltips, debug logs, and obsolete connections in multiple components.

Summary by Sourcery

Improve QML compatibility and music player stability while correcting view interactions and cleaning up legacy code.

Bug Fixes:

  • Prevent crashes and invalid access when QML models, media data, loaders, menus, or rendering components are unavailable.
  • Correct artist and album detail callbacks and improve list delegate sizing to resolve misalignment and navigation issues.
  • Fix view transition animations and drag-image handling for reliable rendering and interaction.

Enhancements:

  • Modernize QML signal, slot, and event handlers to use the QML 5.15+ function syntax.
  • Improve layout sizing, theming, playlist behavior, and settings synchronization across music player views.

Documentation:

  • Update SPDX copyright headers to cover 2023–2026 and localize missing artist and album labels.

Chores:

  • Remove obsolete commented code, debug logging, unused connections, and legacy declarations.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kt286

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot

Copy link
Copy Markdown

Hi @kt286. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai

sourcery-ai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR modernizes QML signal/slot usage, hardens null-safety around models and loaders, aligns animations and drag images with current QML APIs, replaces SystemPalette with DTK Palette-based colors, and cleans up unused or legacy code while updating copyrights to 2026.

Flow diagram for null-safe album/artist hash list updates

flowchart TD
    A[onAlbumDataChanged] --> B{moreMenu.albumData<br/>and moreMenu.albumData.musicinfos ?}
    B -- no --> C[return]
    B -- yes --> D[Build tmplist from albumData.musicinfos]
    D --> E[ImportMenu.setHashList]

    A2[onArtistDataChanged] --> B2{moreMenu.artistData<br/>and moreMenu.artistData.musicinfos ?}
    B2 -- no --> C2[return]
    B2 -- yes --> D2[Build tmplist from artistData.musicinfos]
    D2 --> E2[ImportMenu.setHashList]
Loading

File-Level Changes

Change Details Files
Modernize QML signal/slot syntax to function-style handlers for Qt/QML 5.15+ compatibility.
  • Converted inline signal handlers like onFoo: blocks to named handler functions, e.g., function onFoo(args) { ... } across views and dialogs.
  • Updated Connections objects to define handler functions (e.g., function onValueChanged(value) { ... }) instead of relying on legacy implicit parameter usage.
  • Adjusted handler signatures to accept explicit parameters (e.g., onSearchItemTriggered(text, type), onMetaCodecChanged(name)) to match the underlying signals.
src/music-player/albumlist/AlbumView.qml
src/music-player/singerlist/ArtistView.qml
src/music-player/mainwindow/LyricWindow.qml
src/music-player/dialogs/SettingsDialog.qml
src/music-player/mainwindow/MainWindow.qml
src/music-player/musicbaseandsonglist/SideBarItemDelegate.qml
src/music-player/musicsublist/ArtistSublistView.qml
src/music-player/mainwindow/MusicContentWindow.qml
src/music-player/musicbaseandsonglist/MusicBaselistview.qml
src/music-player/albumlist/AlbumGridView.qml
src/music-player/albumlist/AlbumListView.qml
src/music-player/mainwindow/SearchResultWindow.qml
src/music-player/musicList/AllMusicListView.qml
src/music-player/playlist/CurrentPlayList.qml
src/music-player/lyric/LyricRect.qml
Add null-safety and bounds checks around model access, loader items, and currentData usage to prevent runtime crashes.
  • Guarded initial album/artist name properties with model count checks before get(0) access, defaulting to empty strings when models are empty.
  • Wrapped uses of playlistLoader.item, mediaListModels.get(index), and similar constructs with existence checks before dereferencing or reading properties.
  • Protected title/cover bindings by checking currentData before accessing fields such as coverUrl, name, artist, and musicCount, providing safe fallbacks.
  • Ensured anchors relying on parent exist, using ternaries like parent ? parent.horizontalCenter : undefined.
  • Added early returns in menu data-change handlers if backing data or nested properties (e.g., musicinfos) are missing.
src/music-player/albumlist/AlbumView.qml
src/music-player/singerlist/ArtistView.qml
src/music-player/mainwindow/MainWindow.qml
src/music-player/musicsublist/ArtistSublistView.qml
src/music-player/musicsublist/AlbumSublistView.qml
src/music-player/allItems/SublistTitleButton.qml
src/music-player/musicsublist/MusicSublistTitle.qml
src/music-player/musicList/AllMusicList.qml
src/music-player/musicmousemenu/AlbumMoreMenu.qml
src/music-player/musicmousemenu/ArtistMoreMenu.qml
src/music-player/mainwindow/Toolbar.qml
Update animations, drag image generation, and shader updates to use supported, consistent properties and safer behavior.
  • Replaced deprecated xScale/yScale animations with a single scale property animation and adjusted from/to values for enter/exit transitions in album and artist views.
  • Standardized opacity animations to use Easing.OutExpo without the nested Easing.Easing path, avoiding runtime issues.
  • Provided explicit sizes when calling grabToImage for drag delegates, using Qt.size(width, height) to control drag image resolution.
  • Adjusted drag image creation handlers to simpler signatures while preserving drag behavior.
  • Ensured ShaderDataView::setShaderData only calls update() when a window exists and the component is complete, preventing crashes during initialization or teardown.
src/music-player/albumlist/AlbumView.qml
src/music-player/singerlist/ArtistView.qml
src/music-player/musicbaseandsonglist/SideBarItemDelegate.qml
src/music-player/musicsublist/ArtistSublistView.qml
src/music-player/musicsublist/AlbumSublistView.qml
src/music-player/musicList/AllMusicListDelegate.qml
src/music-player/musicsublist/AlbumSublistDelegate.qml
src/music-player/playlist/CurrentPlayListDelegate.qml
src/music-player/effect/shaderdataview.cpp
Align palette usage and text coloring with DTK Palette and theme-aware colors instead of SystemPalette.
  • Replaced SystemPalette usage in sidebar items with DTK Palette objects representing normal and highlighted text palettes.
  • Bound foreground/text colors to ColorSelector palette properties instead of systemPalette to align with DTK styling.
  • Updated sidebar title label color to use theme-aware rgba constants based on DTK.themeType to improve dark/light theme compatibility.
src/music-player/musicbaseandsonglist/SideBarItemDelegate.qml
src/music-player/musicbaseandsonglist/SideBarItem.qml
Tidy up behavior and remove unused or legacy code and handlers to improve maintainability.
  • Removed unused Connections block from LyricWindow.qml that toggled lyrics via rootWindow.onClickForLyricUp in favor of toolbar/titlebar-driven control.
  • Deleted commented-out UI elements (e.g., hints/labels and old play-all button code) and logging statements that no longer serve a purpose.
  • Simplified album/artist/playlist menu QML by removing commented placeholders and ensuring only supported menu items remain.
  • Refined layout bindings (e.g., using anchors.fill instead of manual width/height) for delegates to reduce duplication and improve clarity.
  • Normalized copyright headers to "2023 - 2026" across QML and C++ files and removed duplicate legacy copyright comments.
src/music-player/mainwindow/LyricWindow.qml
src/music-player/allItems/ToolButtonItem.qml
src/music-player/musicList/AllMusicDefaultPage.qml
src/music-player/musicmousemenu/AlbumMoreMenu.qml
src/music-player/musicmousemenu/ArtistMoreMenu.qml
src/music-player/albumlist/AlbumListDelegate.qml
src/music-player/musicbaseandsonglist/SideBarItem.qml
src/music-player/util/shortcut.cpp
src/music-player/albumlist/AlbumGridDelegate.qml
src/music-player/music-list/AllMusicListDelegate.qml
Adjust lyric and metadata strings to be consistently localizable and user-friendly.
  • Replaced hard-coded Chinese placeholders like "未知" with qsTr("Unknown") for artist and album fallback strings in lyrics.
  • Ensured concatenated strings use translated segments (e.g., qsTr("Artist"), qsTr("Album")) combined with formatted values for better i18n consistency.
src/music-player/lyric/LyricPage.qml
Minor behavioral tweaks to artist sublists and playlists to improve UX.
  • Adjusted artist sublist header layout to make room for a new leading column (e.g., for a play button) by widening the left spacer and shrinking the title label width and padding.
  • Hooked ArtistMoreMenu and AlbumMoreMenu "view details" actions to re-use existing itemDoubleClicked handlers, passing the selected data object explicitly.
  • Ensured playlist hide animation completion toggles the playlist visibility flag using a modern function handler.
src/music-player/musicsublist/ArtistSublistView.qml
src/music-player/singerlist/ArtistView.qml
src/music-player/albumlist/AlbumGridView.qml
src/music-player/albumlist/AlbumListView.qml
src/music-player/mainwindow/SearchResultWindow.qml
src/music-player/playlist/CurrentPlayList.qml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In SideBarItemDelegate.qml, foregroundColor is defined as a color but is assigned ColorSelector.highlightedTextPalette / normalTextPalette (which are palettes), so you likely want to use a specific role from your palettes (e.g. highlightedTextPalette.normal vs normalTextPalette.normal) to ensure palette.buttonText gets an actual color.
  • In SearchResultWindow.qml, the onViewAlbumDatails handler takes a parameter named artistData but passes it to itemDoubleClicked, which is semantically confusing for album results; consider renaming this parameter to albumData to match the signal and avoid future misuses.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In SideBarItemDelegate.qml, `foregroundColor` is defined as a color but is assigned `ColorSelector.highlightedTextPalette` / `normalTextPalette` (which are palettes), so you likely want to use a specific role from your palettes (e.g. `highlightedTextPalette.normal` vs `normalTextPalette.normal`) to ensure `palette.buttonText` gets an actual color.
- In SearchResultWindow.qml, the `onViewAlbumDatails` handler takes a parameter named `artistData` but passes it to `itemDoubleClicked`, which is semantically confusing for album results; consider renaming this parameter to `albumData` to match the signal and avoid future misuses.

## Individual Comments

### Comment 1
<location path="src/music-player/musicbaseandsonglist/SideBarItemDelegate.qml" line_range="23-24" />
<code_context>
+        normal: Qt.rgba(255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 1)
+        normalDark: Qt.rgba(0, 0, 0, 1)
+    }
+    readonly property color foregroundColor: checked ? ColorSelector.highlightedTextPalette
+                                                     : ColorSelector.normalTextPalette
     id: item
     checked: globalVariant !== undefined && globalVariant.curListPage === model.uuid
</code_context>
<issue_to_address>
**issue (bug_risk):** foregroundColor is bound to a palette object instead of an actual color

`foregroundColor` is declared as a `color` and used to derive `palette.buttonText`, but it’s now assigned `ColorSelector.highlightedTextPalette` / `normalTextPalette`, which are `Palette` objects, not colors. This is likely to fail or misrender. Bind to a concrete color (e.g. `highlightedTextPalette.normal` / `normalTextPalette.normal`) or the corresponding `ColorSelector` color property instead.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/music-player/musicbaseandsonglist/SideBarItemDelegate.qml Outdated
@kt286
kt286 force-pushed the fix/qml-compatibility branch 5 times, most recently from 14265ec to c45dc7b Compare August 11, 2026 00:58
@deepin-bot

deepin-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 7.0.63
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #762

@deepin-bot

deepin-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 7.0.64
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #765

@kt286
kt286 force-pushed the fix/qml-compatibility branch from c45dc7b to 805ce8a Compare August 18, 2026 05:26
@deepin-bot

deepin-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 7.0.65
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #768

@deepin-bot

deepin-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 7.0.66
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #779

@kt286
kt286 force-pushed the fix/qml-compatibility branch from 805ce8a to 3ca699f Compare August 21, 2026 01:46
- Update QML signal handlers to function syntax (Qt 6.x compat)
- Add null checks for currentData/parent to prevent crashes
- Update SPDX copyright year to 2026
- Replace hardcoded Chinese strings with qsTr for i18n
- Remove commented-out dead code
- Guard update() call in shaderdataview.cpp before component is ready

fix: 修复 QML 兼容性问题并增强空值保护

- 更新 QML 信号处理语法为函数式写法 (Qt 6.x 兼容)
- 添加多处 currentData/parent 空值检查,防止崩溃
- 更新 SPDX 许可证年份至 2026
- 修复硬编码中文字符串,使用 qsTr 国际化
- 移除冗余注释代码
- 修复 shaderdataview.cpp 组件未就绪时的 update 调用
@kt286
kt286 force-pushed the fix/qml-compatibility branch from 3ca699f to 74aad82 Compare August 21, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants