Skip to content

fix: limit watermark text input length - #788

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-378143
Sep 24, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-378143

Conversation

@wjyrich

@wjyrich wjyrich commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
  1. Add setMaxLength(16) to the watermark text input field in the print preview dialog
  2. Prevent users from entering excessively long custom watermark text that could cause rendering issues
  3. Ensure watermark text remains readable and fits properly on printed pages

Log: Limited watermark custom text input to 16 characters maximum

Influence:

  1. Verify watermark text input accepts up to 16 characters
  2. Confirm input is blocked when reaching the 16 character limit
  3. Test that existing watermark text longer than 16 characters displays correctly
  4. Verify watermark rendering on print preview with maximum length text
  5. Test copy-paste behavior with text exceeding the limit

fix: 限制水印文本输入长度

  1. 在打印预览对话框的水印文本输入框中添加 setMaxLength(16)
  2. 防止用户输入过长的自定义水印文本导致渲染问题
  3. 确保水印文本保持可读性并正确适配打印页面

Log: 限制水印自定义文本输入最多16个字符

Influence:

  1. 验证水印文本输入框最多接受16个字符
  2. 确认达到16个字符限制时输入被阻止
  3. 测试超过16个字符的现有水印文本是否正确显示
  4. 验证最大长度文本在打印预览中的水印渲染效果
  5. 测试超出限制的文本复制粘贴行为

PMS: BUG-378143

Summary by Sourcery

Bug Fixes:

  • Limit custom watermark text input to 16 characters in the print preview dialog to prevent overly long text from causing rendering and readability issues.

1. Add setMaxLength(16) to the watermark text input field in the print
preview dialog
2. Prevent users from entering excessively long custom watermark text
that could cause rendering issues
3. Ensure watermark text remains readable and fits properly on printed
pages

Log: Limited watermark custom text input to 16 characters maximum

Influence:
1. Verify watermark text input accepts up to 16 characters
2. Confirm input is blocked when reaching the 16 character limit
3. Test that existing watermark text longer than 16 characters displays
correctly
4. Verify watermark rendering on print preview with maximum length text
5. Test copy-paste behavior with text exceeding the limit

fix: 限制水印文本输入长度

1. 在打印预览对话框的水印文本输入框中添加 setMaxLength(16)
2. 防止用户输入过长的自定义水印文本导致渲染问题
3. 确保水印文本保持可读性并正确适配打印页面

Log: 限制水印自定义文本输入最多16个字符

Influence:
1. 验证水印文本输入框最多接受16个字符
2. 确认达到16个字符限制时输入被阻止
3. 测试超过16个字符的现有水印文本是否正确显示
4. 验证最大长度文本在打印预览中的水印渲染效果
5. 测试超出限制的文本复制粘贴行为

PMS: BUG-378143
@sourcery-ai

sourcery-ai Bot commented Sep 23, 2026

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

Reviewer's Guide

The print preview dialog now limits custom watermark text to 16 characters by configuring the underlying line edit, preventing overlong user input while leaving watermark rendering and existing UI behavior otherwise unchanged.

File-Level Changes

Change Details Files
Constrain custom watermark text input to 16 characters in the print preview dialog.
  • Apply the maximum-length constraint directly to the watermark field’s underlying line edit.
  • Preserve the existing watermark control setup, placeholder, layout, and enablement behavior.
src/widgets/dprintpreviewdialog.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

@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 1 issue

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

## Individual Comments

### Comment 1
<location path="src/widgets/dprintpreviewdialog.cpp" line_range="857" />
<code_context>
     waterTextEdit->setObjectName(_d_printSettingNameMap[DPrintPreviewSettingInterface::SC_Watermark_CustomText]);
     settingHelper->setSubControlEnabled(DPrintPreviewSettingInterface::SC_Watermark_CustomText, false);
     waterTextEdit->lineEdit()->setPlaceholderText(qApp->translate("DPrintPreviewDialogPrivate", "Input your text"));
+    waterTextEdit->lineEdit()->setMaxLength(16);
     hlayout2->addStretch(5);
     hlayout2->addWidget(waterTextEdit, 10);
</code_context>
<issue_to_address>
**issue (bug_risk):** Setting the QLineEdit maximum before watermark settings are restored causes any existing `customText` longer than 16 characters to be silently truncated by subsequent `setText()` calls, so the preview and returned print settings no longer preserve the caller's watermark text.

**Triggers:** When an application restores or supplies a watermark whose custom text exceeds 16 characters.

**Suggested fix:** Apply the 16-character restriction only to user-edited input, while preserving and rendering programmatically supplied existing text, or explicitly handle long restored values without silently truncating them.
</issue_to_address>

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

waterTextEdit->setObjectName(_d_printSettingNameMap[DPrintPreviewSettingInterface::SC_Watermark_CustomText]);
settingHelper->setSubControlEnabled(DPrintPreviewSettingInterface::SC_Watermark_CustomText, false);
waterTextEdit->lineEdit()->setPlaceholderText(qApp->translate("DPrintPreviewDialogPrivate", "Input your text"));
waterTextEdit->lineEdit()->setMaxLength(16);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Setting the QLineEdit maximum before watermark settings are restored causes any existing customText longer than 16 characters to be silently truncated by subsequent setText() calls, so the preview and returned print settings no longer preserve the caller's watermark text.

Triggers: When an application restores or supplies a watermark whose custom text exceeds 16 characters.

Suggested fix: Apply the 16-character restriction only to user-edited input, while preserving and rendering programmatically supplied existing text, or explicitly handle long restored values without silently truncating them.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交在打印预览对话框的水印文本输入框中添加 setMaxLength(16) 限制输入长度,修复 BUG-378143。代码变更简洁明确,语法正确,逻辑清晰,无安全漏洞,无性能问题。仅有一个轻微代码质量建议(魔法数字16建议定义为常量),不影响功能正确性。该变更符合 bug 修复的目的,有效防止用户输入过长水印文本导致渲染问题。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: []


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. src/widgets/dprintpreviewdialog.cpp:857 - 水印文本最大长度16为硬编码魔法数字,建议定义为命名常量以提高可维护性

建议: ['建议将魔法数字16定义为命名常量,例如:static const int kMaxWatermarkTextLength = 16; 然后使用 waterTextEdit->lineEdit()->setMaxLength(kMaxWatermarkTextLength);']


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: []


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 建议将魔法数字定义为命名常量
static const int kMaxWatermarkTextLength = 16;

// 在 initWaterMarkui() 函数中使用
waterTextEdit->lineEdit()->setMaxLength(kMaxWatermarkTextLength);

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

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@wjyrich

wjyrich commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit a1c52a8 into linuxdeepin:master Sep 24, 2026
22 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