Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Jan 21, 2026

Text.RichText doesn't support the elide property, for our case, using Text.StyledText could be enough.

Summary by Sourcery

Bug Fixes:

  • Adjust app label text formatting for newly installed apps to avoid layout issues caused by using rich text rendering.

Text.RichText doesn't support the elide property, for our case,
using Text.StyledText could be enough.

PMS: BUG-325737
Log:
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 21, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Switches the app name label for newly installed apps from using rich text formatting to styled text to support text eliding and avoid overlap, while keeping plain text for other cases unchanged.

Flow diagram for selecting textFormat based on newly installed status

flowchart TD
  A[IconItemDelegate evaluates model] --> B{Is app newly installed?}
  B -->|Yes, lastLaunchedTime == 0 and installedTime != 0| C[Set isNewlyInstalled to true]
  B -->|No| D[Set isNewlyInstalled to false]
  C --> E[Set text to badge_dot_plus_root_text]
  D --> F[Set text to root_text]
  C --> G[Set textFormat to Text.StyledText]
  D --> H[Set textFormat to Text.PlainText]
  G --> I[Label supports eliding and avoids overlap]
  H --> I
Loading

File-Level Changes

Change Details Files
Adjust text formatting mode for newly installed app labels so they can elide instead of overlapping.
  • Change the conditional textFormat for the icon label from using rich text to styled text when indicating newly installed apps
  • Preserve plain text formatting for non-newly-installed app labels while keeping the existing HTML-based bullet prefix logic intact
qml/IconItemDelegate.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

Copy link

@sourcery-ai sourcery-ai bot left a comment

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

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

## Individual Comments

### Comment 1
<location> `qml/IconItemDelegate.qml:195` </location>
<code_context>
                 id: iconItemLabel
                 text: isNewlyInstalled ? ("<font color='#669DFF' size='1' style='text-shadow: 0 0 1px rgba(255,255,255,0.1)'>●</font>&nbsp;&nbsp;" + root.text) : root.text
-                textFormat: isNewlyInstalled ? Text.RichText : Text.PlainText
+                textFormat: isNewlyInstalled ? Text.StyledText : Text.PlainText
                 width: parent.width
                 leftPadding: 2
</code_context>

<issue_to_address>
**suggestion:** Review whether the inline CSS in `text` is still meaningful with `Text.StyledText`.

`Text.StyledText` only supports a subset of HTML/CSS, so the `style='text-shadow: ...'` on the colored dot will likely be ignored. If the shadow isn’t needed, consider removing that unsupported style (or moving the visual effect to a separate QML item) to avoid implying that a text shadow is applied when it isn’t.

```suggestion
                text: isNewlyInstalled ? ("<font color='#669DFF' size='1'>●</font>&nbsp;&nbsp;" + root.text) : root.text
```
</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.

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码修改将 QML 文本组件的 textFormat 属性从 Text.RichText 改为 Text.StyledText。以下是对此修改的详细审查意见,涵盖语法逻辑、代码质量、性能和安全性四个方面:

1. 语法逻辑

  • 修改分析:代码逻辑上,当 isNewlyInstalled 为真时,text 属性中包含了 HTML 标签(如 <font>)。为了正确渲染这些标签,必须设置 textFormat 为支持 HTML 的格式。
  • 结论Text.StyledText 支持基本的 HTML 标签样式(如字体颜色、大小等),足以满足当前代码中 <font color='...' size='...'> 的渲染需求。逻辑上是正确的。

2. 代码质量

  • 改进点:这是一个推荐的修改。
    • 安全性提升Text.RichText 会解析完整的 HTML 标签集,如果 root.text 的来源不可信(例如包含用户输入),可能会引入 XSS(跨站脚本)安全风险(尽管在 QML 本地应用中风险较低,但仍是不良实践)。
    • 轻量化Text.StyledText 是 HTML 标签的一个子集,专门用于样式设置,不支持完整的 HTML 文档结构(如表格、CSS 样式块等)。对于仅用于改变颜色和字体的场景,它更符合“最小权限原则”,意图更明确。

3. 代码性能

  • 改进点:这是一个性能优化
    • Text.RichText 底层通常依赖重量级的 Web 渲染引擎(如 WebKit)进行解析,开销较大。
    • Text.StyledText 是 QML 内置的轻量级解析器,解析速度更快,内存占用更低。
    • 在列表视图(如 ListView 或 GridView)的代理中使用时,这种差异在滚动或大量数据渲染时会更加明显,有助于提升 UI 流畅度。

4. 代码安全

  • 改进点:这是一个安全加固
    • 如前所述,Text.StyledText 过滤掉了大部分危险的 HTML 标签和脚本执行能力。如果 root.text 包含恶意构造的 HTML 字符串(例如 <img src='x' onerror='malicious_code'>),使用 Text.RichText 可能会导致意外行为或潜在的安全漏洞。使用 Text.StyledText 可以有效规避此类风险。

总结与建议

总体评价:这是一个非常合理且优秀的修改。

建议

  1. 确认标签兼容性:虽然当前代码只使用了 <font>,但请确保未来如果需要增加样式,不要使用 Text.StyledText 不支持的标签(如 <a>, <b>, <i>, <u>, <br>, <font>, <img> 等是支持的,但复杂的 CSS 或布局标签不支持)。
  2. 样式替代方案(可选):从现代 QML 开发的最佳实践来看,直接使用 QML 的样式属性(如 color, font.pixelSize)配合 style 属性(如 Text.RichTextText.StyledText 之外的纯文本绘制)通常比嵌入 HTML 字符串更易于维护和调试。
    • 例如:可以考虑使用 Row 布局,左侧放一个 Text 元素绘制圆点,右侧放 root.text。这样完全避免了 HTML 解析,代码更清晰,性能也最好。
    • 代码示例
      Row {
          spacing: 4
          Text {
              text: ""
              color: "#669DFF"
              font.pixelSize: 1 // 注意:size=1 在 HTML 中可能很小,需确认 QML 中的实际效果
              visible: isNewlyInstalled
              // style: Text.Raised; styleColor: "rgba(255,255,255,0.1)" // 对应 text-shadow
          }
          Text {
              text: root.text
              color: "black" // 或默认颜色
          }
      }
    • 如果为了保持代码改动最小化,当前的 diff 修改是最佳选择。

最终结论:接受该修改。它在保持功能不变的前提下,提升了性能和安全性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@BLumia BLumia merged commit 65e42db into linuxdeepin:master Jan 22, 2026
10 checks passed
@BLumia BLumia deleted the pms-325737 branch January 26, 2026 14:12
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