Skip to content

fix: restore resetBottomToolbarGeometry call in showEvent to fix toolbar missing - #182

Closed
Resurgamz wants to merge 1 commit into
linuxdeepin:masterfrom
Resurgamz:master
Closed

Resurgamz wants to merge 1 commit into
linuxdeepin:masterfrom
Resurgamz:master

Conversation

@Resurgamz

@Resurgamz Resurgamz commented Oct 13, 2026 •

Copy link
Copy Markdown

Root Cause Analysis

When opening images in the image viewer, the prev/next navigation buttons and thumbnail bar occasionally fail to appear. The root cause is that toolbar geometry is not recalculated at the correct timing — two independent trigger paths lead to the same symptom:

  • Trigger path 1 (window show): resetBottomToolbarGeometry was commented out in showEvent (viewpanel.cpp:2204), so toolbar width was never recomputed when the window became visible. Under startup timing races where slotDrogImg runs before show(), the window dimensions are invalid and the toolbar geometry is wrong — this causes the prev/next buttons to go missing.
  • Trigger path 2 (image ready): slotOneImgReady (viewpanel.cpp:1996) only updates menu content but never triggers a toolbar re-layout. After async image loading completes, the thumbnail content is not displayed — this causes thumbnails to not show.

Evidence: resetBottomToolbarGeometry depends on this->width(), which is 0 before show(); slotOneImgReady is signal-driven via Qt::QueuedConnection with no geometry re-layout call.

Fix Approach

Two fixes, complementary coverage of the same root cause ("toolbar geometry not recalculated at the correct timing"):

Fix Location Trigger path Covers
Candidate 1 showEvent — restore resetBottomToolbarGeometry Window becomes visible Prev/next buttons missing
Candidate 2 slotOneImgReady — add resetBottomToolbarGeometry Image async load completes Thumbnail content not showing

Both fixes call the same resetBottomToolbarGeometry with the same visible parameter pattern, ensuring toolbar geometry is recomputed on both the window-show and image-ready trigger paths.

Additionally, 8 temporary qInfo diagnostic logs tagged [BUG-376715] are added at key positions for FlemingX environment verification and to investigate whether candidates 3-6 (getToolbarWidth timing, estimatedDisplayCount stale width, button gating, QDir::entryInfoList filesystem behavior) are actually triggered.

Diagnostic Log Handling

The 8 [BUG-376715] diagnostic logs are temporary, for verification purposes only. They are retained in this PR because FlemingX environment verification has not yet been completed — the logs are a necessary means to verify fix effectiveness and diagnose candidates 3-6. After FlemingX verification passes, these diagnostic logs must be removed in a separate commit.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • slotOneImgReady is purely signal-driven (no direct callers), so the new resetBottomToolbarGeometry call does not break any existing call chain
  • resetBottomToolbarGeometry already has 5 call sites; the 6th in slotOneImgReady follows the same pattern, and the function body is unchanged

Business Impact Scope

  • Image viewer — open image: Prev/next buttons and thumbnails now appear consistently when opening images via double-click or drag-and-drop
  • Toolbar geometry calculation: resetBottomToolbarGeometry call sites increase from 5 to 6; the new slotOneImgReady trigger path uses the same visible parameter pattern
  • Diagnostic logs: 8 qInfo read-only outputs with zero side effects, removable after verification
  • Candidates 3-6 (follow-up tracking): getToolbarWidth timing, estimatedDisplayCount stale width, button gating, QDir::entryInfoList filesystem behavior — deferred pending FlemingX diagnostic log results

Verification Suggestion

  1. On FlemingX devices, open images via double-click and drag-and-drop 50+ times each, verify toolbar buttons and thumbnails appear consistently
  2. Under high system load, repeat open/close 50+ times, observe diagnostic log output for expected values
  3. Analyze diagnostic logs (paths.size, width/height, event trigger order) to confirm whether candidates 3-6 are actually triggered

根因分析

看图打开图片时工具栏[上一张/下一张]按钮与缩略图偶现缺失。根因为工具栏几何未在正确时机重算——两条独立触发路径导致同一症状:

  • 触发路径 1(窗口显示):showEvent(viewpanel.cpp:2204)中 resetBottomToolbarGeometry 被注释,窗口显示后未重算工具栏宽度。在 slotDrogImg 先于 show() 执行的启动时序竞态下,窗口尺寸无效导致工具栏几何错误——导致上一张/下一张按钮缺失。
  • 触发路径 2(图片就绪):slotOneImgReady(viewpanel.cpp:1996)仅更新菜单内容,图片就绪后不触发工具栏重布局,异步图片加载完成后缩略图内容不显示——导致缩略图不显示。

证据:resetBottomToolbarGeometry 依赖 this->width(),在 show() 前为 0;slotOneImgReady 经 Qt::QueuedConnection 信号驱动,无几何重排调用。

修复方案

两处修复,互补覆盖同一根因("工具栏几何未在正确时机重算"):

修复 位置 触发路径 覆盖症状
候选 1 showEvent — 恢复 resetBottomToolbarGeometry 窗口显示 上一张/下一张按钮缺失
候选 2 slotOneImgReady — 补充 resetBottomToolbarGeometry 图片异步加载完成 缩略图内容不显示

两处修复调用同一 resetBottomToolbarGeometry,visible 参数模式一致,确保窗口显示与图片就绪两条触发路径都会重算工具栏几何。

同时添加 8 处带 [BUG-376715] 标记的临时 qInfo 诊断日志,供 FlemingX 环境验证修复有效性并排查候选 3-6 是否实际触发。

诊断日志处理

8 处 [BUG-376715] 诊断日志为临时验证用途。因 FlemingX 环境验证尚未完成,日志是验证修复有效性的必要手段,故暂保留于本 PR。FlemingX 验证通过后,须在单独 commit 中移除这些诊断日志。

改动安全评估

代码安全

  • 风险等级: 低
  • slotOneImgReady 纯信号驱动(无直接调用者),新增 resetBottomToolbarGeometry 调用不破坏任何现有调用链
  • resetBottomToolbarGeometry 已有 5 处调用点,slotOneImgReady 中第 6 处遵循相同模式,函数内部逻辑未变

业务影响范围

  • 看图——打开图片:双击/拖拽打开图片时,工具栏[上一张/下一张]按钮与缩略图稳定显示
  • 工具栏几何计算:resetBottomToolbarGeometry 调用点从 5 处增至 6 处,新增 slotOneImgReady 触发路径,visible 参数模式一致
  • 诊断日志:8 处 qInfo 只读输出,零副作用,验证通过后可移除
  • 候选 3-6(后续跟踪):getToolbarWidth 时序、estimatedDisplayCount 过期宽度、按钮门控、QDir::entryInfoList 文件系统行为,待 FlemingX 诊断日志确认

验证建议

  1. 在 FlemingX 设备上双击和拖拽方式打开图片各 50+ 次,验证工具栏按钮与缩略图稳定显示
  2. 高负载下重复打开关闭 50 次以上,观察诊断日志输出是否符合预期
  3. 分析诊断日志中 paths.size、width/height、事件触发顺序,确认候选 3-6 是否实际触发

Bug: #376715

后续跟踪项(候选 3-6):待 FlemingX 诊断日志结果决定是否处理。

@sourcery-ai

sourcery-ai Bot commented Oct 13, 2026

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

Reviewer's Guide

Restores the show-time toolbar layout recalculation so images loaded before display receive the correct width and consistently show navigation buttons and thumbnails.

Sequence diagram for show-time toolbar geometry recalculation

sequenceDiagram
    participant ImageLoader
    participant LibViewPanel
    participant Toolbar

    ImageLoader->>LibViewPanel: load image before show()
    LibViewPanel->>LibViewPanel: showEvent(e)
    LibViewPanel->>LibViewPanel: noAnimationBottomMove()
    LibViewPanel->>LibViewPanel: resetBottomToolbarGeometry(currentWidget() == view)
    LibViewPanel->>Toolbar: apply recalculated width
    Toolbar-->>LibViewPanel: navigation buttons and thumbnails visible
Loading

File-Level Changes

Change Details Files
Restore bottom toolbar geometry recalculation when the view panel becomes visible.
  • Uncomment the existing geometry reset call in showEvent.
  • Recalculate using whether the current stacked widget is the main view, preserving the established toolbar state logic.
libimageviewer/viewpanel/viewpanel.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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Resurgamz

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 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: resetBottomToolbarGeometry was commented out in
   showEvent, so toolbar width was not recomputed when the window
   became visible; slotOneImgReady updated menu content but also
   never triggered a toolbar re-layout, leaving thumbnails and
   prev/next buttons missing after async image load
2. Fix: restore resetBottomToolbarGeometry in showEvent and add
   the same call in slotOneImgReady so geometry is recomputed both
   on window show and on image-ready, covering both trigger paths
3. Impact: prev/next buttons and thumbnails now appear consistently
   when opening images; add temporary qInfo diagnostics tagged
   [BUG-376715] for FlemingX verification, removable after confirm

Log: Fix missing prev/next buttons and thumbnails when opening images

Influence:
1. Open images via double-click and drag-and-drop, verify toolbar
   buttons and thumbnails appear consistently
2. Repeat open/close 50+ times under high system load
3. Verify diagnostic logs output expected values on FlemingX

fix: 显示与图片就绪时重算工具栏几何

1. 根因:showEvent 中 resetBottomToolbarGeometry 被注释,窗口显示时
   未重算工具栏宽度;slotOneImgReady 仅更新菜单内容未触发工具栏
   重布局,异步图片加载后缩略图与上一张/下一张按钮偶现缺失
2. 方案:恢复 showEvent 中的 resetBottomToolbarGeometry 调用,并在
   slotOneImgReady 中补充同一调用,覆盖窗口显示与图片就绪两条触发路径
3. 影响:打开图片时上一张/下一张按钮与缩略图稳定显示;新增带
   [BUG-376715] 标记的临时 qInfo 诊断日志供 FlemingX 验证,确认后可移除

Log: 修复打开图片时上一张/下一张按钮与缩略图偶现缺失

Influence:
1. 双击与拖拽方式打开图片,验证工具栏按钮与缩略图稳定显示
2. 高负载下重复打开关闭 50 次以上
3. 在 FlemingX 环境验证诊断日志输出符合预期

Bug: #376715
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 94 分,大于 70 分通过阈值。本次提交修复了打开图片时工具栏(上一张/下一张按钮与缩略图)偶现缺失的问题,恢复并补充了 resetBottomToolbarGeometry 调用,逻辑正确且与 commit 目的一致。未发现安全漏洞,存在少量临时诊断日志与一处冗余几何重算需后续清理优化。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: 语法正确,逻辑清晰。resetBottomToolbarGeometry(bool) 调用参数类型匹配(m_stack->currentWidget() == m_view 返回 bool),showEvent 与 slotOneImgReady 两条触发路径均覆盖,无明显语法或逻辑缺陷。


2. 代码质量 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. libimageviewer/viewpanel/viewpanel.cpp:2001 - [BUG-376715] 临时 qInfo 诊断日志保留在生产代码中,commit 声明确认后可移除
  2. libimageviewer/viewpanel/contents/bottomtoolbar.cpp:647 - [BUG-376715] 临时 qInfo 诊断日志,建议移除或降级为 qDebug
  3. commit-msg.txt:1 - commit-msg.txt 疑似误提交的提交信息模板文件,不应纳入仓库

建议: 1.FlemingX 验证完成后及时移除 [BUG-376715] 标记的临时 qInfo 诊断日志,或将 qInfo 降级为 qDebug 以避免污染生产日志 2.移除误提交的 commit-msg.txt 文件 3.代码结构清晰,注释完整,核心修复处已补充中文注释说明根因


3. 代码性能 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. libimageviewer/viewpanel/viewpanel.cpp:2007 - slotOneImgReady 无条件调用 resetBottomToolbarGeometry,批量加载时可能产生冗余几何重算

建议: 1.建议在 slotOneImgReady 中仅当 path 匹配 ItemInfo.path 时才调用 resetBottomToolbarGeometry,或增加防抖/脏标记避免冗余重布局 2.诊断日志移除后 UI 路径 I/O 开销即可消除 3.算法复杂度合理,无性能瓶颈


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 安全合规。无用户输入注入、无硬编码密钥、无路径遍历、无命令注入风险。qInfo 日志输出的路径、尺寸、计数等信息为本地图片查看器非敏感数据。


💡 改进建议代码示例

// slotOneImgReady: 仅在路径匹配时触发重布局,避免冗余计算
void LibViewPanel::slotOneImgReady(QString path, imageViewerSpace::ItemInfo itemInfo)
{
    imageViewerSpace::ItemInfo ItemInfo = m_bottomToolbar->getCurrentItemInfo();
    if (path.contains(ItemInfo.path)) {
        updateMenuContent();
        // 图片就绪后重算底部工具栏几何,覆盖缩略图内容不显示的独立根因
        resetBottomToolbarGeometry(m_stack->currentWidget() == m_view);
    }
    Q_UNUSED(itemInfo);
}

// 验证完成后移除所有 [BUG-376715] 标记的临时 qInfo 诊断日志
// 并删除误提交的 commit-msg.txt 文件

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

@Resurgamz Resurgamz closed this Oct 20, 2026
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