Skip to content

fix: reduce print preview delay by processEvents and dead code - #684

Merged
pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/bug/6099e56d31f2
Oct 23, 2026
Merged

pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/bug/6099e56d31f2

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

fix: reduce print preview delay by processEvents and dead code

  1. Root cause: updateHighlighterAll() rehighlighted every text block
    synchronously without yielding, blocking the UI thread for ~6s during
    print preview of syntax-highlighted documents
  2. Fix: call qApp->processEvents() every 100 blocks to keep the UI
    responsive, matching the existing pattern in cloneLargeDocument()
  3. Fix: remove dead DPrinter printer(QPrinter::HighResolution) local
    variable in popupPrintDialog(), introduced by commit 9fcf3e4; its
    constructor synchronously loads the cups plugin and enumerates
    printers but the variable was never used
  4. Impact: print preview opens faster, no behavior change for valid
    print paths, no -Wunused-variable warnings after removal

Log: Reduce print preview loading delay by adding processEvents and removing dead printer code

Influence:

  1. Test print preview with a syntax-highlighted large file
  2. Test print preview with a plain text file
  3. Verify no unused-variable warnings in build output
  4. Test print preview twice to confirm m_bHighlighterAll guard works

fix: 减少打印预览延迟并删除死代码

  1. 根因:updateHighlighterAll() 同步逐块重新高亮整个文档,未让出
    事件循环,导致语法高亮文档打印预览时 UI 线程阻塞约 6 秒
  2. 方案:每 100 块调用 qApp->processEvents() 保持 UI 响应,与
    cloneLargeDocument() 中已有模式一致
  3. 方案:删除 popupPrintDialog() 中 DPrinter printer(QPrinter::
    HighResolution) 死代码局部变量,该变量由 commit 9fcf3e4 引入,
    构造时同步加载 cups 插件并枚举打印机但从未使用
  4. 影响:打印预览打开更快,对有效打印路径无行为变化,删除后无
    -Wunused-variable 告警残留

Log: 减少打印预览加载延迟,添加 processEvents 并删除无用打印机构造

Influence:

  1. 测试语法高亮大文件的打印预览
  2. 测试纯文本文件的打印预览
  3. 验证编译输出无 unused-variable 告警
  4. 测试连续两次打印预览确认 m_bHighlighterAll 守卫生效

PMS: BUG-375053

Summary by Sourcery

Improve print preview responsiveness and remove unnecessary printer initialization.

Bug Fixes:

  • Reduce print preview delays for syntax-highlighted documents by allowing the UI event loop to process updates during full-document highlighting.

Enhancements:

  • Remove an unused printer initialization that unnecessarily loaded the printing backend and enumerated printers.

@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026

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

Reviewer's Guide

The PR improves print-preview responsiveness for syntax-highlighted documents by periodically processing Qt events during full-document rehighlighting, and removes an unused printer object that unnecessarily loaded and enumerated printers.

Sequence diagram for responsive print preview highlighting

sequenceDiagram
    participant Window
    participant Preview as DPrintPreviewDialog
    participant Editor as EditWrapper
    participant Highlighter as QSyntaxHighlighter
    participant Qt as QtEventLoop

    Window->>Preview: new DPrintPreviewDialog(this)
    Preview->>Editor: updateHighlighterAll()
    loop Each text block
        Editor->>Highlighter: rehighlightBlock(block)
        opt Every 100 blocks
            Editor->>Qt: processEvents()
        end
    end
    Editor->>Highlighter: rehighlightBlock(endBlock)
    Preview-->>Window: preview remains responsive
Loading

File-Level Changes

Change Details Files
Yield to the Qt event loop during full-document syntax rehighlighting to reduce print-preview UI blocking.
  • Count processed text blocks during updateHighlighterAll().
  • Call qApp->processEvents() after every 100 blocks while preserving the existing rehighlighting sequence.
src/editor/editwrapper.cpp
Remove an unused printer construction that caused unnecessary synchronous printer-plugin initialization.
  • Delete the unused high-resolution DPrinter local from popupPrintDialog().
  • Leave print-preview setup and valid print flows unchanged.
src/widgets/window.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 reviewed your changes and they look great!


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

1. Root cause: popupPrintDialog() constructs a DPrinter local
   variable (QPrinter::HighResolution) that is never used; its
   constructor synchronously loads the cups plugin and enumerates
   printers, adding avoidable latency to print preview
2. Fix: remove the unused DPrinter printer(QPrinter::HighResolution)
   line introduced by commit 9fcf3e4; the actual print dialog uses
   DPrintPreviewDialog with no arguments and builds its own printer
3. Impact: print preview opens faster by eliminating one redundant
   synchronous printer enumeration; no behavior change for valid
   print paths; no -Wunused-variable warning after removal

Log: Remove dead DPrinter construction to speed up print preview

Influence:
1. Test print preview with a syntax-highlighted file
2. Test print preview with a plain text file
3. Verify no unused-variable warnings in build output

fix: 删除 popupPrintDialog 中无用的 DPrinter 构造

1. 根因:popupPrintDialog() 构造了一个从未使用的 DPrinter 局部
   变量(QPrinter::HighResolution),其构造函数同步加载 cups
   插件并枚举打印机,为打印预览增加不必要的延迟
2. 方案:删除由 commit 9fcf3e4 引入的无用 DPrinter printer(
   QPrinter::HighResolution) 行;实际打印对话框使用无参
   DPrintPreviewDialog 并在内部自建 printer
3. 影响:消除一次冗余的同步打印机枚举,打印预览打开更快;
   对有效打印路径无行为变化;删除后无 -Wunused-variable 告警

Log: 删除无用 DPrinter 构造以加速打印预览

Influence:
1. 测试语法高亮文件的打印预览
2. 测试纯文本文件的打印预览
3. 验证编译输出无 unused-variable 告警

PMS: BUG-375053
@pengfeixx
pengfeixx force-pushed the agent/bug/6099e56d31f2 branch from 64f1130 to ece08fc Compare October 23, 2026 08:40
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交从 popupPrintDialog() 函数中移除了未使用的 DPrinter 局部变量,属于死代码清理,语法正确、逻辑无误、无安全风险,且减少了不必要的对象构造开销,有助于降低打印预览延迟。四维度均通过,OCR 审查与启发式扫描均未发现问题。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

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

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

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

建议: []


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

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

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例


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

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pengfeixx

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

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/merge

@pengfeixx
pengfeixx merged commit bc8f222 into linuxdeepin:master Oct 23, 2026
26 of 34 checks passed
@deepin-bot

deepin-bot Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: unknown)

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