Skip to content

fix: prevent dpr override for FileUrl icons - #762

Merged
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:fix
Dec 3, 2026
Merged

18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:fix

Conversation

@18202781743

@18202781743 18202781743 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor
  1. Add refreshDtkDevicePixelRatio() wrapper in DQuickIconImagePrivate
    that returns false early when iconType is FileUrl
  2. Update updateDevicePixelRatio() override to delegate to
    QQuickImagePrivate::updateDevicePixelRatio() for FileUrl icons instead
    of forcing DTK pixel ratio logic
  3. Replace direct calls to updateDevicePixelRatio(1.0) with
    refreshDtkDevicePixelRatio() in DQuickIconImage::init(),
    componentComplete(), itemChange(), pixmapChange(), and
    DQuickDciIconImageItemPrivate::updatePlayer()
  4. Update unit test includes to reference the private header and add a
    new test verifying FileUrl icons preserve the decoded DPR and delegate
    to Qt Quick's native @nx lookup

The DTK pixel ratio logic was incorrectly overriding Qt Quick's native
device pixel ratio handling for raster file icons, which broke the
ability of Qt Quick to perform @nx file lookup. FileUrl icons now bypass
the DTK override and use the base QQuickImagePrivate implementation,
while theme/svg icon paths retain the previous behavior.

Influence:

  1. Verify raster image icons (FileUrl) load correct @nx variants on
    high-DPI displays
  2. Confirm theme name and SVG icons still honor the DTK device pixel
    ratio calculation
  3. Test window change and device pixel ratio change events update icon
    rendering correctly for both FileUrl and theme icons
  4. Run the new ut_DQuickIconImage.fileUrlIgnoresWindowDprRefresh unit
    test
  5. Validate DciIcon images under treeland still refresh their device
    pixel ratio on player update

fix: 修复 FileUrl 图标设备像素比被错误覆盖的问题

  1. 在 DQuickIconImagePrivate 中新增 refreshDtkDevicePixelRatio() 包装函
    数,当 iconType 为 FileUrl 时提前返回 false
  2. 修改 updateDevicePixelRatio() 重写实现,对 FileUrl 图标改为调用基类
    QQuickImagePrivate::updateDevicePixelRatio(),不再强制执行 DTK 像素比
    逻辑
  3. 在 DQuickIconImage::init()、componentComplete()、itemChange()、
    pixmapChange() 以及 DQuickDciIconImageItemPrivate::updatePlayer() 中,将
    直接调用 updateDevicePixelRatio(1.0) 替换为 refreshDtkDevicePixelRatio()
  4. 更新单元测试的私有头文件引用,新增测试用例验证 FileUrl 图标保持解码后
    的 DPR 并能委托给 Qt Quick 原生 @nx 查找

此前 DTK 的像素比逻辑会错误地覆盖 Qt Quick 对栅格文件图标的原生设备像素
比处理,导致 Qt Quick 无法执行 @nx 文件查找。现在 FileUrl 图标会绕过 DTK
覆盖逻辑并使用基类 QQuickImagePrivate 实现,而主题/SVG 图标路径保持原有
行为。

Influence:

  1. 验证栅格图像图标(FileUrl)在高 DPI 屏幕上能正确加载 @nx 变体
  2. 确认主题名称和 SVG 图标仍遵循 DTK 设备像素比计算
  3. 测试窗口变化和设备像素比变化事件对 FileUrl 及主题图标的渲染更新是否
    正确
  4. 运行新增的 ut_DQuickIconImage.fileUrlIgnoresWindowDprRefresh 单元测试
  5. 验证 treeland 下 DciIcon 图像在播放器更新时仍会刷新其设备像素比

Log: Fixed device pixel ratio being incorrectly overridden for FileUrl
icons
PMS: BUG-381363

Summary by Sourcery

Keep raster FileUrl icons on Qt Quick’s native device-pixel-ratio path without changing DTK scaling for theme and SVG icons.

Bug Fixes:

  • Preserve Qt Quick’s native device-pixel-ratio handling and @nx lookup for raster FileUrl icons, while keeping DTK scaling for theme and SVG icons.

Tests:

  • Add a unit test covering FileUrl DPR preservation and continued DTK DPR handling for SVG icons.

@18202781743
18202781743 requested review from BLumia and mhduiy December 2, 2026 05:54
@sourcery-ai

sourcery-ai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Add a FileUrl guard to DTK DPR refreshes and delegate FileUrl DPR updates to Qt Quick, preserving DTK scaling for other icon types.

  • src/private/dquickiconimage.cpp L17-29
  • src/private/dquickiconimage_p_p.h L1, L31

Use the guarded DPR refresh at icon initialization, lifecycle, pixmap, and Dci player update points.

  • src/private/dquickdciiconimage.cpp L184
  • src/private/dquickiconimage.cpp L81-398 (4 small edits)

Tests

Exercise FileUrl DPR preservation and verify SVG icons still use DTK DPR updates.

  • tests/ut_dquickiconimage.cpp L1, L8, L62-81

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 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/private/dquickiconimage.cpp" line_range="27-28" />
<code_context>

+bool DQuickIconImagePrivate::refreshDtkDevicePixelRatio()
+{
+    if (iconType == FileUrl)
+        return false;
+
+    return updateDevicePixelRatio(1.0);
+}
+
 bool DQuickIconImagePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio)
 {
+    if (iconType == FileUrl)
+        return QQuickImagePrivate::updateDevicePixelRatio(targetDevicePixelRatio);
+
 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
</code_context>
<issue_to_address>
**Raster fallbacks still lose native lookup**

When a theme icon fails to load and its `fallbackSource` is a raster file with `@Nx` variants, a theme icon that fails and falls back to a raster `fallbackSource` keeps `iconType` as `ThemeIconName`; the new guard therefore continues DTK DPR handling for that active file source, overriding Qt Quick’s native `@Nx` handling.

Apply the native DPR path based on the active fallback source, or mark local file fallbacks as `FileUrl` while they are active.
</issue_to_address>

### Comment 2
<location path="src/private/dquickiconimage.cpp" line_range="27-28" />
<code_context>

+bool DQuickIconImagePrivate::refreshDtkDevicePixelRatio()
+{
+    if (iconType == FileUrl)
+        return false;
+
+    return updateDevicePixelRatio(1.0);
+}
+
 bool DQuickIconImagePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio)
 {
+    if (iconType == FileUrl)
+        return QQuickImagePrivate::updateDevicePixelRatio(targetDevicePixelRatio);
+
 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
</code_context>
<issue_to_address>
**Local SVGs lose DTK scaling**

When an icon is a local SVG file URL, `refreshDtkDevicePixelRatio()` returns before calculating the DTK ratio, and `updateDevicePixelRatio()` delegates to Qt Quick; local SVG icons therefore stop using the DTK DPR calculation and can render at the wrong size.

Distinguish local SVGs from raster file sources in both DPR paths so SVGs retain DTK scaling while raster files use Qt Quick’s native handling.

Also at `src/private/dquickiconimage.cpp:20`.
</issue_to_address>

### Comment 3
<location path="tests/ut_dquickiconimage.cpp" line_range="74-76" />
<code_context>
+    EXPECT_FALSE(icon.d_func()->refreshDtkDevicePixelRatio());
+    EXPECT_DOUBLE_EQ(icon.d_func()->devicePixelRatio, decodedDpr);
+
+    // A raster file lets Qt Quick continue to its @Nx lookup.
+    EXPECT_FALSE(icon.d_func()->updateDevicePixelRatio(1.25));
+    EXPECT_DOUBLE_EQ(icon.d_func()->devicePixelRatio, decodedDpr);
+
+    icon.setName(QStringLiteral("qrc:/icon/red.svg"));
</code_context>
<issue_to_address>
**Native @Nx lookup goes untested**

When the test is used to validate native `@Nx` lookup, the test seeds `devicePixelRatio` and calls the private update method without loading an image or checking the selected or rendered variant, so it passes even if the override never delegates to Qt Quick and native `@Nx` lookup is broken.

Load a raster image with `@Nx` variants and assert which variant Qt Quick actually selects or renders.
</issue_to_address>

### Comment 4
<location path="tests/ut_dquickiconimage.cpp" line_range="78" />
<code_context>
+    EXPECT_FALSE(icon.d_func()->updateDevicePixelRatio(1.25));
+    EXPECT_DOUBLE_EQ(icon.d_func()->devicePixelRatio, decodedDpr);
+
+    icon.setName(QStringLiteral("qrc:/icon/red.svg"));
+    EXPECT_TRUE(icon.d_func()->updateDevicePixelRatio(1.0));
+    EXPECT_DOUBLE_EQ(icon.d_func()->devicePixelRatio, 1.0);
</code_context>
<issue_to_address>
**Theme DPR branch stays untested**

When the test uses a `qrc:` SVG URL as its purported theme-icon case, `fileUrlIgnoresWindowDprRefresh` sets another `qrc:` URL at line 78, so `setName()` classifies it as `FileUrl`; the assertion at line 79 then exercises the Qt Quick delegation branch, not DTK's theme-icon DPR calculation.

Use a theme icon name that is not a local URL to exercise the DTK DPR branch.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/private/dquickiconimage.cpp Resolved
Comment thread src/private/dquickiconimage.cpp Resolved
Comment thread tests/ut_dquickiconimage.cpp Resolved
Comment thread tests/ut_dquickiconimage.cpp Resolved
1. Add refreshDtkDevicePixelRatio() wrapper in DQuickIconImagePrivate
that returns false early when iconType is FileUrl
2. Update updateDevicePixelRatio() override to delegate to
QQuickImagePrivate::updateDevicePixelRatio() for FileUrl icons instead
of forcing DTK pixel ratio logic
3. Replace direct calls to updateDevicePixelRatio(1.0) with
refreshDtkDevicePixelRatio() in DQuickIconImage::init(),
componentComplete(), itemChange(), pixmapChange(), and
DQuickDciIconImageItemPrivate::updatePlayer()
4. Update unit test includes to reference the private header and add a
new test verifying FileUrl icons preserve the decoded DPR and delegate
to Qt Quick's native @nx lookup

The DTK pixel ratio logic was incorrectly overriding Qt Quick's native
device pixel ratio handling for raster file icons, which broke the
ability of Qt Quick to perform @nx file lookup. FileUrl icons now bypass
the DTK override and use the base QQuickImagePrivate implementation,
while theme/svg icon paths retain the previous behavior.

Influence:
1. Verify raster image icons (FileUrl) load correct @nx variants on
high-DPI displays
2. Confirm theme name and SVG icons still honor the DTK device pixel
ratio calculation
3. Test window change and device pixel ratio change events update icon
rendering correctly for both FileUrl and theme icons
4. Run the new ut_DQuickIconImage.fileUrlIgnoresWindowDprRefresh unit
test
5. Validate DciIcon images under treeland still refresh their device
pixel ratio on player update

fix: 修复 FileUrl 图标设备像素比被错误覆盖的问题

1. 在 DQuickIconImagePrivate 中新增 refreshDtkDevicePixelRatio() 包装函
数,当 iconType 为 FileUrl 时提前返回 false
2. 修改 updateDevicePixelRatio() 重写实现,对 FileUrl 图标改为调用基类
QQuickImagePrivate::updateDevicePixelRatio(),不再强制执行 DTK 像素比
逻辑
3. 在 DQuickIconImage::init()、componentComplete()、itemChange()、
pixmapChange() 以及 DQuickDciIconImageItemPrivate::updatePlayer() 中,将
直接调用 updateDevicePixelRatio(1.0) 替换为 refreshDtkDevicePixelRatio()
4. 更新单元测试的私有头文件引用,新增测试用例验证 FileUrl 图标保持解码后
的 DPR 并能委托给 Qt Quick 原生 @nx 查找

此前 DTK 的像素比逻辑会错误地覆盖 Qt Quick 对栅格文件图标的原生设备像素
比处理,导致 Qt Quick 无法执行 @nx 文件查找。现在 FileUrl 图标会绕过 DTK
覆盖逻辑并使用基类 QQuickImagePrivate 实现,而主题/SVG 图标路径保持原有
行为。

Influence:
1. 验证栅格图像图标(FileUrl)在高 DPI 屏幕上能正确加载 @nx 变体
2. 确认主题名称和 SVG 图标仍遵循 DTK 设备像素比计算
3. 测试窗口变化和设备像素比变化事件对 FileUrl 及主题图标的渲染更新是否
正确
4. 运行新增的 ut_DQuickIconImage.fileUrlIgnoresWindowDprRefresh 单元测试
5. 验证 treeland 下 DciIcon 图像在播放器更新时仍会刷新其设备像素比

Log: Fixed device pixel ratio being incorrectly overridden for FileUrl
 icons
PMS: BUG-381363
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy

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

@18202781743
18202781743 merged commit 3743a37 into linuxdeepin:master Dec 3, 2026
20 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants