Skip to content

fix: Incorrect positioning of error messages#3087

Open
JWWTSL wants to merge 2 commits intolinuxdeepin:masterfrom
JWWTSL:bug--352961
Open

fix: Incorrect positioning of error messages#3087
JWWTSL wants to merge 2 commits intolinuxdeepin:masterfrom
JWWTSL:bug--352961

Conversation

@JWWTSL
Copy link
Copy Markdown
Contributor

@JWWTSL JWWTSL commented Mar 16, 2026

log: D.AlertToolTip is of type Control (standard Item), not Popup, and is rendered within the visual tree of its parent container. The height of the page Item for customNTPServer is fixed at 40px; when AlertToolTip is displayed below the input field, it extends beyond this area and is obscured by the ‘System Time Zone’ component below (overridden by the z-order of the sibling DccObject).

pms: bug-352961

Summary by Sourcery

Bug Fixes:

  • Ensure the custom NTP server error tooltip is fully visible by increasing the container item height when the error is shown and repositioning the input field and edit button anchors.

log: D.AlertToolTip is of type Control (standard Item), not Popup, and is rendered within the visual tree of its parent container. The height of the page Item for customNTPServer is fixed at 40px; when AlertToolTip is displayed below the input field, it extends beyond this area and is obscured by the ‘System Time Zone’ component below (overridden by the z-order of the sibling DccObject).

pms: bug-352961
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JWWTSL

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
Copy link
Copy Markdown

sourcery-ai bot commented Mar 16, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the custom NTP server row layout so that the D.AlertToolTip for the address field is positioned correctly and not clipped, and switches from the built‑in line edit alert text to an explicit tooltip control that is shown/hidden in sync with validation logic.

Sequence diagram for custom NTP server validation and tooltip visibility

sequenceDiagram
    actor User
    participant AddrLineEdit as AddrLineEdit
    participant AddrErrorToolTip as AddrErrorToolTip
    participant EditButton as EditButton

    User->>EditButton: click
    EditButton->>AddrLineEdit: check text.length
    alt text.length === 0
        EditButton->>AddrLineEdit: addr.showAlert = true
        EditButton->>AddrErrorToolTip: visible = true
    else text.length > 0
        EditButton->>AddrLineEdit: addr.showAlert = false
        EditButton->>AddrErrorToolTip: visible = false
        EditButton->>EditButton: proceed with ntpServerAddress update
    end

    User->>AddrLineEdit: type characters
    AddrLineEdit->>AddrLineEdit: onTextChanged
    alt text.length > 0
        AddrLineEdit->>AddrLineEdit: addr.showAlert = false
        AddrLineEdit->>AddrErrorToolTip: visible = false
    end
Loading

Flow diagram for layout and tooltip-driven height of custom NTP server row

flowchart TD
    A[item.implicitHeight evaluation] --> B{addrErrorTip.visible?}
    B -- false --> C[implicitHeight = 40]
    B -- true --> D[implicitHeight = 40 + addrErrorTip.height + 4]

    subgraph AddressFieldLayout
        E[AddrLineEdit anchors.top = parent.top]
        F["AddrLineEdit topMargin = (40 - addr.height) / 2"]
        G[EditButton anchors.verticalCenter = addr.verticalCenter]
        E --> F --> G
    end
Loading

File-Level Changes

Change Details Files
Make the custom NTP server row height dynamic so the tooltip can render fully without being clipped.
  • Replace fixed implicitHeight of 40 with a conditional height that adds addrErrorTip.height + spacing when the tooltip is visible
  • Keep implicitWidth unchanged at 300 for the row item
src/plugin-datetime/qml/TimeAndDate.qml
Switch from LineEdit’s built-in alert UI to an explicit D.AlertToolTip instance tied to the address field.
  • Remove alertText and alertDuration properties from the D.LineEdit and instead control visibility via a new D.AlertToolTip child
  • Initialize AlertToolTip with target bound to the addr field, fixed error text, visible false, and a timeout of 3000 ms
  • Update click handler to set addrErrorTip.visible true when validation fails and false when it passes
  • Update text-change handler to hide both showAlert and addrErrorTip when the user types a non-empty value
src/plugin-datetime/qml/TimeAndDate.qml
Adjust layout and anchoring so the line edit stays vertically positioned while allowing space for the tooltip.
  • Change addr anchors from verticalCenter to top with a computed topMargin to keep it visually centered within the 40 px base height
  • Align the edit button vertically with the addr field instead of the parent for consistent vertical alignment
src/plugin-datetime/qml/TimeAndDate.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
Copy Markdown

@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, and left some high level feedback:

  • The hard-coded constants 40 and 4 in both implicitHeight and topMargin couple layout to specific pixel values; consider deriving these from the addr/parent heights or a shared constant to avoid layout breakage if the field size changes.
  • You now drive the tooltip via addrErrorTip.visible while still toggling addr.showAlert; if showAlert is no longer functionally used by D.LineEdit, consider either wiring the tooltip visibility to showAlert or removing the redundant state to keep the error handling logic in one place.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The hard-coded constants `40` and `4` in both `implicitHeight` and `topMargin` couple layout to specific pixel values; consider deriving these from the `addr`/parent heights or a shared constant to avoid layout breakage if the field size changes.
- You now drive the tooltip via `addrErrorTip.visible` while still toggling `addr.showAlert`; if `showAlert` is no longer functionally used by `D.LineEdit`, consider either wiring the tooltip visibility to `showAlert` or removing the redundant state to keep the error handling logic in one place.

## Individual Comments

### Comment 1
<location path="src/plugin-datetime/qml/TimeAndDate.qml" line_range="228" />
<code_context>
             page: Item {
                 id: item
-                implicitHeight: 40
+                implicitHeight: addrErrorTip.visible ? 40 + addrErrorTip.height + 4 : 40
                 implicitWidth: 300
+                
</code_context>
<issue_to_address>
**suggestion:** Avoid repeating the `40` constant in layout calculations to reduce maintenance issues.

This height is now hardcoded in multiple places (e.g. `implicitHeight` and `topMargin: (40 - addr.height) / 2`), so changing the base row height requires updating each occurrence. Define a local property (e.g. `property int rowHeight: 40`) on the `Item` and use it in all related calculations instead.

Suggested implementation:

```
            pageType: DccObject.Editor
            page: Item {
                id: item
                property int rowHeight: 40
                implicitHeight: addrErrorTip.visible ? rowHeight + addrErrorTip.height + 4 : rowHeight
                implicitWidth: 300


```

Search within the same `Item` (and related layout code for this row) for other hardcoded `40` usages, such as `topMargin: (40 - addr.height) / 2`, and replace them with expressions that use `rowHeight` instead, e.g. `topMargin: (rowHeight - addr.height) / 2`. This ensures all layout calculations stay consistent when `rowHeight` is changed.
</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.

page: Item {
id: item
implicitHeight: 40
implicitHeight: addrErrorTip.visible ? 40 + addrErrorTip.height + 4 : 40
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Avoid repeating the 40 constant in layout calculations to reduce maintenance issues.

This height is now hardcoded in multiple places (e.g. implicitHeight and topMargin: (40 - addr.height) / 2), so changing the base row height requires updating each occurrence. Define a local property (e.g. property int rowHeight: 40) on the Item and use it in all related calculations instead.

Suggested implementation:

            pageType: DccObject.Editor
            page: Item {
                id: item
                property int rowHeight: 40
                implicitHeight: addrErrorTip.visible ? rowHeight + addrErrorTip.height + 4 : rowHeight
                implicitWidth: 300


Search within the same Item (and related layout code for this row) for other hardcoded 40 usages, such as topMargin: (40 - addr.height) / 2, and replace them with expressions that use rowHeight instead, e.g. topMargin: (rowHeight - addr.height) / 2. This ensures all layout calculations stay consistent when rowHeight is changed.

@deepin-bot
Copy link
Copy Markdown

deepin-bot bot commented Mar 18, 2026

TAG Bot

New tag: 6.1.77
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3100

log: In TimeAndDate.qml, instead of using the built-in showAlert method of D.LineEdit (whose AlertToolTip pops up from the bottom and gets obscured), a separate D.AlertToolTip is placed inside the addr element, with the y value set to a negative value so that it pops up from the top; this prevents it from being obscured by the system time zone displayed below.

pms: bug-352961
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码的 diff 展示了对 TimeAndDate.qml 文件中日期时间插件 UI 的一些修改,主要涉及输入框验证逻辑的调整。以下是对这段代码的详细审查意见:

1. 语法逻辑审查

  • 修改内容:在 onClicked 事件处理中,当 addr.text.length === 0 时,增加了 addr.showAlert = false 的赋值。
  • 逻辑分析
    • 这段代码的意图很明确:当输入框为空时,触发警告显示。
    • 新增的 addr.showAlert = false 紧接着 addr.showAlert = true,这在 QML 属性绑定机制中通常是为了强制触发属性变更信号。
    • 如果 showAlert 属性原本已经是 true(例如用户连续两次点击按钮且输入框都为空),直接设置 addr.showAlert = true 可能不会产生任何效果,因为属性值没有变化,依赖该属性的 UI(如红色边框或提示文字)可能不会刷新动画或状态。
    • 通过先设为 false 再设为 true,确保了属性经历了 false -> true 的跳变,从而保证 UI 能够正确响应并显示警告状态。
  • 结论:逻辑上是合理的,这是一种常见的“强制刷新”UI 状态的技巧,用于处理属性值未改变但需要重置动画或状态的情况。

2. 代码质量审查

  • 可读性:代码逻辑简单直接,但 addr.showAlert = false 这一行对于不熟悉 QML 属性绑定机制的维护者来说可能略显突兀。
  • 建议:建议添加注释解释为什么需要先设为 false,以提高代码的可维护性。

改进后的代码示例:

onClicked: {
    if (addr.text.length === 0) {
        // 先重置为 false 以确保 showAlert 属性能触发变化信号,
        // 从而正确刷新 UI 状态(特别是处理连续点击时的动画重置)
        addr.showAlert = false
        addr.showAlert = true
        return
    }
    // ... 其他逻辑
}

3. 代码性能审查

  • 影响:这两行代码仅涉及简单的布尔值赋值,对性能的影响微乎其微,可以忽略不计。
  • 结论:在性能方面没有问题。

4. 代码安全审查

  • 安全性:此处仅涉及前端 UI 状态的切换,不涉及数据输入验证(如防止 SQL 注入或 XSS)或权限控制,因此没有明显的安全隐患。
  • 注意:虽然 addr.text 被检查了长度,但这只是 UI 层面的非空验证。请确保在后端逻辑或实际提交数据的地方也有相应的数据校验,不要仅依赖前端 UI 的状态。

总结

这段代码修改是为了解决 UI 状态刷新的问题,逻辑正确且性能无碍。主要的改进建议是增加注释以说明代码意图,方便后续维护。

@deepin-bot
Copy link
Copy Markdown

deepin-bot bot commented Mar 25, 2026

TAG Bot

New tag: 6.1.78
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3130

@deepin-bot
Copy link
Copy Markdown

deepin-bot bot commented Mar 30, 2026

TAG Bot

New tag: 6.1.79
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3135

@deepin-bot
Copy link
Copy Markdown

deepin-bot bot commented Apr 3, 2026

TAG Bot

New tag: 6.1.80
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3153

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