Skip to content

sync: from linuxdeepin/dde-session-shell - #525

Open
deepin-ci-robot wants to merge 1 commit into
masterfrom
sync-pr-76-nosync
Open

sync: from linuxdeepin/dde-session-shell#525
deepin-ci-robot wants to merge 1 commit into
masterfrom
sync-pr-76-nosync

Conversation

@deepin-ci-robot

@deepin-ci-robot deepin-ci-robot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#76

Summary by Sourcery

Bug Fixes:

  • Ensure placeholder text is elided and drawn within the QLineEdit text margins to prevent overlapping with left/right action icons.

Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#76

@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.

Sorry @deepin-ci-robot, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-ci-robot

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 Aug 7, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts DLineEditEx placeholder text rendering so elision and drawing respect the embedded QLineEdit’s text margins and widget offset, preventing long placeholders from overlapping icons.

File-Level Changes

Change Details Files
Constrain placeholder elision and drawing to the effective text area of the embedded QLineEdit to avoid overlap with side icons.
  • Compute the embedded QLineEdit’s rectangle in DLineEditEx’s coordinate system using mapTo and its size.
  • Derive a textRect by applying QLineEdit::textMargins() to the mapped rectangle to get the actual text area.
  • Use textRect.width() when eliding the placeholder text so truncation matches the available text area.
  • Draw the placeholder text within textRect instead of the full widget rect to align with the QLineEdit’s content area.
src/widgets/dlineeditex.cpp

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

@deepin-ci-robot

Copy link
Copy Markdown
Contributor Author

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码精准修复了长 placeholder 文本与功能图标重叠的视觉缺陷,逻辑严密且无副作用
四个维度均无扣分项,代码质量优秀

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

修复前直接使用 DLineEditEx 的 rect() 进行文本省略和绘制,忽略了父控件与内嵌 QLineEdit 之间的坐标偏移以及文本边距。修复后通过 le->mapTo(this, QPoint(0, 0)) 正确处理了坐标系映射,并通过 textMargins 扣除了左右图标预留空间,逻辑完全正确。
建议:保持现有逻辑即可。

  • 2.代码质量(优秀)✓

代码新增了三行高质量的注释,清晰解释了为什么要使用 textMargins 和 mapTo,极大提升了可维护性。局部变量命名(le、tm、lineEditRect、textRect)语义明确,计算步骤拆分合理,符合clean code规范。
建议:保持现有注释风格。

  • 3.代码性能(高效)✓

新增的代码仅包含一次坐标映射计算和一次矩形调整计算,这些都是极其轻量的 CPU 指令,在 paintEvent 这种被频繁调用的场景下也不会产生可感知的性能损耗。
建议:无需优化。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
该段代码仅涉及 UI 文本绘制与矩形几何计算,不涉及内存动态分配、外部字符串解析、文件操作或系统命令调用,不存在任何安全攻击面。

  • 建议:无需额外安全加固。

■ 【改进建议代码示例】

// 当前代码已为最佳实践,无需额外修改,此处展示完整上下文以供参考
void DLineEditEx::paintEvent(QPaintEvent *event)
{
    // ... 前置条件判断(当 lineEdit 无文本且未获得焦点时) ...
        QPainter pa(this);
        pa.setFont(lineEdit()->font());
        pa.setPen(pa.pen().color());

        QFontMetrics fm(pa.font());
        const QString &placeholderText = lineEdit()->placeholderText();
        
        // 将 placeholder 的省略与绘制约束到扣除内嵌 QLineEdit 的 textMargins()
        // 后的文本可用矩形内,避免长 placeholder 与左右功能图标重叠。
        // DLineEditEx(QFrame) 与内嵌 QLineEdit 存在父子控件偏移,需用 mapTo
        // 将 QLineEdit 坐标系映射到 DLineEditEx 绘制坐标系。
        QLineEdit *le = lineEdit();
        const QMargins tm = le->textMargins();
        const QRect lineEditRect(le->mapTo(this, QPoint(0, 0)), le->size());
        const QRect textRect = lineEditRect.adjusted(tm.left(), tm.top(), -tm.right(), -tm.bottom());
        
        QString elidedText = fm.elidedText(placeholderText, Qt::ElideRight, textRect.width());
        pa.drawText(textRect, Qt::AlignCenter | Qt::TextSingleLine, elidedText);

        // 当文本被省略时,设置 tooltip 显示完整文本
        if (elidedText != placeholderText) {
            this->setToolTip(placeholderText);
        } else {
            this->setToolTip("");
        }
    // ...
}

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.

1 participant