Skip to content

fix(palette): remove palette.windowText writes to break binding loop - #682

Open
52cyb wants to merge 1 commit into
linuxdeepin:masterfrom
52cyb:master
Open

fix(palette): remove palette.windowText writes to break binding loop#682
52cyb wants to merge 1 commit into
linuxdeepin:masterfrom
52cyb:master

Conversation

@52cyb

@52cyb 52cyb commented Sep 8, 2026

Copy link
Copy Markdown
Contributor
  1. Remove palette.windowText: D.ColorSelector.* bindings from Button, MenuItem
    and ItemDelegate, the three controls reporting "Binding loop detected for
    property windowText"
  2. Let contentItem text read the state foreground color directly from
    D.ColorSelector.textColor; ItemDelegate exposes a new readonly
    resolvedTextColor for its checked text
  3. Add makeIconPaletteWithForeground(QQuickPalette*, QColor) and switch the
    state-dependent icons (Button/MenuItem/ItemDelegate plus the inherited
    IconButton/WindowButton/ButtonIndicator) to it
  4. Keep other controls' palette.windowText bindings unchanged (scope limited to
    the three reported loops)

Influence:

  1. Open control center; no more "Binding loop detected for property windowText"
    from the three controls
  2. Verify checked/highlighted text and icon foreground still turn white
    (HighlightedText) in light theme
  3. Verify other controls (ToolButton/TitleBar/ActionButton...) unchanged
  4. Verify light/dark theme switching

fix(palette): 移除 palette.windowText 写入以断开绑定环

  1. 移除 Button、MenuItem、ItemDelegate 三处 palette.windowText: D.ColorSelector.*
    绑定,这三者报告 "Binding loop detected for property windowText"
  2. contentItem 文字改直接读 D.ColorSelector.textColor;ItemDelegate 新增只读
    resolvedTextColor 表达选中文字色
  3. 新增 makeIconPaletteWithForeground(QQuickPalette*, QColor),让三者及连带控件
    (IconButton / WindowButton / ButtonIndicator,继承或关联 Button)的图标显式
    传入前景色
  4. 其余控件(ToolButton/TitleBar/ActionButton 等)的 palette.windowText 绑定
    保持不变(范围限定到三处报告的环)

Influence:

  1. 打开控制中心,三个控件不再出现 "Binding loop detected for property windowText"
  2. 验证浅色主题下选中/高亮文字与图标前景仍为白色(HighlightedText)
  3. 验证其余控件(ToolButton/TitleBar/ActionButton 等)行为不变
  4. 验证亮/暗主题切换

PMS: Task-392413

Summary by Sourcery

Eliminate palette binding loops in core controls while preserving state-dependent text and icon foreground colors.

Bug Fixes:

  • Remove state-dependent palette.windowText bindings from Button, MenuItem, and ItemDelegate to eliminate reported QML binding loops while preserving checked and highlighted text colors.

Enhancements:

  • Resolve control text colors directly from state selectors and apply explicit foreground colors to state-dependent icons, including related IconButton, WindowButton, and ButtonIndicator controls.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 52cyb

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

@sourcery-ai

sourcery-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR breaks palette.windowText binding loops by restoring its native inherited-foreground behavior, routing state colors directly to text and icon consumers, and adding an explicit icon-palette foreground helper. Review should verify binding-loop elimination, checked/hovered/pressed color correctness, and theme/accent responsiveness.

Sequence diagram for explicit state foreground resolution

sequenceDiagram
    participant Control
    participant ColorSelector
    participant DQMLGlobalObject
    participant DciIcon
    participant Text

    Control->>ColorSelector: textColor
    Control->>DQMLGlobalObject: makeIconPaletteWithForeground(palette, textColor)
    DQMLGlobalObject->>DQMLGlobalObject: makeIconPalette(palette)
    DQMLGlobalObject->>DciIcon: setForeground(textColor)
    Control->>Text: color = textColor
    Control->>DciIcon: palette = iconPalette
Loading

Flow diagram for restoring native windowText semantics

flowchart LR
    State["Control state changes"] --> Selector["D.ColorSelector resolves state foreground"]
    Selector --> Text["Text or Label reads state color directly"]
    Selector --> Icons["makeIconPaletteWithForeground sets icon foreground"]
    Palette["palette.windowText"] --> Native["Qt-native inherited general foreground"]
    Native --> Default["Normal-state default foreground"]
Loading

File-Level Changes

Change Details Files
Remove DTK state-color bindings from Qt palette.windowText so it retains inherited Qt foreground semantics and avoids binding loops.
  • Delete state-dependent windowText assignments and undefined resets across controls and dialogs.
  • Move state-color reads to text, Label, and content-item color properties.
  • Expose ItemDelegate.resolvedTextColor for checked/drag-aware text resolution.
qt6/src/qml/ActionButton.qml
qt6/src/qml/Button.qml
qt6/src/qml/ItemDelegate.qml
qt6/src/qml/LicenseDialog.qml
qt6/src/qml/MenuItem.qml
qt6/src/qml/NavigationTitle.qml
qt6/src/qml/SliderTipItem.qml
qt6/src/qml/SpinBoxIndicator.qml
qt6/src/qml/TitleBar.qml
qt6/src/qml/ToolButton.qml
qt6/src/qml/private/ArrowListViewButton.qml
qt6/src/qml/settings/NavigationTitle.qml
Make state-dependent icon foreground colors explicit instead of deriving them from palette.windowText.
  • Add makeIconPaletteWithForeground to clone an icon palette and override its foreground.
  • Update control, menu, delegate, title-bar, spin-box, action, indicator, and window-button icons to pass the resolved state foreground.
  • Preserve icon mode/theme handling while supplying highlighted, pressed, or inactive colors explicitly.
src/private/dqmlglobalobject.cpp
src/private/dqmlglobalobject_p.h
qt6/src/qml/ActionButton.qml
qt6/src/qml/Button.qml
qt6/src/qml/ButtonIndicator.qml
qt6/src/qml/IconButton.qml
qt6/src/qml/ItemDelegate.qml
qt6/src/qml/MenuItem.qml
qt6/src/qml/SpinBoxIndicator.qml
qt6/src/qml/TitleBar.qml
qt6/src/qml/ToolButton.qml
qt6/src/qml/WindowButton.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 reviewed your changes and they look great!


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

@52cyb
52cyb force-pushed the master branch 4 times, most recently from bf948e3 to 4522a44 Compare September 10, 2026 07:10
1. Remove `palette.windowText: D.ColorSelector.*` bindings from Button,
   MenuItem and ItemDelegate, the three controls reporting "Binding loop
   detected for property windowText"
2. Let contentItem text read the state foreground color directly from
   `D.ColorSelector.textColor`; ItemDelegate exposes a new readonly
   `resolvedTextColor` for its checked text
3. Add `makeIconPaletteWithForeground(QQuickPalette*, QColor)` and switch the
   state-dependent icons (Button/MenuItem/ItemDelegate plus the inherited
   IconButton/WindowButton/ButtonIndicator) to it, passing their foreground
   explicitly
4. Keep other controls' `palette.windowText` bindings unchanged (scope limited
   to the three reported loops)

Influence:
1. Open control center; no more "Binding loop detected for property windowText"
   from the three controls
2. Verify checked/highlighted text and icon foreground still turn white
   (HighlightedText) in light theme
3. Verify other controls (ToolButton/TitleBar/ActionButton...) unchanged
4. Verify light/dark theme switching

fix(palette): 移除 palette.windowText 写入以断开绑定环

1. 移除 Button、MenuItem、ItemDelegate 三处 `palette.windowText: D.ColorSelector.*`
   绑定,这三者报告 "Binding loop detected for property windowText"
2. contentItem 文字改直接读 `D.ColorSelector.textColor`;ItemDelegate 新增只读
   `resolvedTextColor` 表达选中文字色
3. 新增 `makeIconPaletteWithForeground(QQuickPalette*, QColor)`,让三者及连带控件
   (IconButton / WindowButton / ButtonIndicator,继承或关联 Button)的图标显式
   传入前景色
4. 其余控件(ToolButton/TitleBar/ActionButton 等)的 `palette.windowText` 绑定
   保持不变(范围限定到三处报告的环)

Influence:
1. 打开控制中心,三个控件不再出现 "Binding loop detected for property windowText"
2. 验证浅色主题下选中/高亮文字与图标前景仍为白色(HighlightedText)
3. 验证其余控件(ToolButton/TitleBar/ActionButton 等)行为不变
4. 验证亮/暗主题切换

PMS: Task-392413
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 100 分,大于 70 分通过阈值,代码质量优秀。本次提交修复了 QML 绑定环问题,移除 palette.windowText 写入操作,通过新增 makeIconPaletteWithForeground 函数直接传入前景色,逻辑清晰,实现正确。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 代码语法正确,逻辑清晰。移除 palette.windowText 写入操作并通过 makeIconPaletteWithForeground 直接传入前景色的方案有效断开了绑定环。ItemDelegate.qml 中新增的 resolvedTextColor 只读属性正确复制了原有的文字颜色逻辑。C++ 端 makeIconPaletteWithForeground 函数通过 foreground.isValid() 检查确保传入颜色有效。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 代码结构清晰,注释完整。新增的 C++ 函数 makeIconPaletteWithForeground 附带清晰的中文注释说明用途。QML 变更在 6 个文件中保持一致的模式(Button/ButtonIndicator/IconButton/ItemDelegate/MenuItem/WindowButton),resolvedTextColor 属性命名清晰自解释。无重复代码,无残留调试代码。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,资源使用合理。移除绑定环实际上提升了性能,避免了 QML 引擎中无限绑定求值循环。makeIconPaletteWithForeground 在 makeIconPalette 基础上仅增加一次 QColor 赋值,开销可忽略。无不必要的计算或资源使用。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 本次变更纯涉及 UI 调色板逻辑,无用户输入处理、无网络操作、无文件系统访问、无硬编码凭证,不存在安全风险。


💡 改进建议代码示例

// 本次变更已正确实现,无需修复
// makeIconPaletteWithForeground 实现简洁正确:
// DDciIconPalette DQMLGlobalObject::makeIconPaletteWithForeground(
//     const QQuickPalette *palette, const QColor &foreground)
// {
//     DDciIconPalette iconPalette = makeIconPalette(palette);
//     if (foreground.isValid())
//         iconPalette.setForeground(foreground);
//     return iconPalette;
// }

本报告由 AI 代码审查工具自动生成

@deepin-bot

deepin-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.7.49
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #685

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.

2 participants