Skip to content

Conversation

@deepin-ci-robot
Copy link
Contributor

@deepin-ci-robot deepin-ci-robot commented Sep 4, 2025

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

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

Summary by Sourcery

Synchronize layout logic from linuxdeepin/dde-session-shell and adjust UserFrameList to dynamically set height limits based on row count

Enhancements:

  • Limit UserFrameList height when displaying a single row to avoid unnecessary scrollbars
  • Remove height limit when multiple rows are present to allow content to auto-fit and support scrolling

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

Source-pull-request: linuxdeepin/dde-session-shell#32
@deepin-ci-robot
Copy link
Contributor Author

deepin pr auto review

这段代码是关于用户界面布局更新的逻辑,我来分析一下并提供改进建议:

语法逻辑

  1. 代码逻辑基本清晰,根据用户数量(count)来决定是单行显示还是多行显示
  2. 使用了条件判断来设置不同的尺寸,逻辑合理

代码质量

  1. 代码注释不够详细,建议添加更多说明为什么使用特定的数值(如"+20"、"-10"等)
  2. 建议将魔法数字(如20、10等)定义为命名常量,提高可维护性
  3. 变量命名可以更具描述性,如countWidth可以改为totalContentWidth

代码性能

  1. 每次调用updateLayout都会重新计算尺寸,如果频繁调用可能影响性能
  2. 建议添加尺寸变化的判断,只有在尺寸确实需要改变时才更新,避免不必要的重绘

代码安全

  1. 没有看到对输入参数width的有效性检查,建议添加参数验证
  2. 建议添加边界条件检查,防止负数或过大值导致的问题

改进建议

// 建议在类开头定义常量
static const int SCROLL_AREA_PADDING = 20;
static const int CENTER_WIDGET_MARGIN = 10;
static const int MAX_VISIBLE_ROWS = 2;

void UserFrameList::updateLayout(int width)
{
    // 参数验证
    if (width <= 0) {
        qWarning() << "Invalid width provided:" << width;
        return;
    }

    const int countWidth = /* 计算总宽度的逻辑 */;
    const int userWidgetHeight = /* 计算用户控件高度的逻辑 */;
    const int count = m_flowLayout->count();
    
    // 只在尺寸确实需要改变时更新
    QSize currentSize = m_scrollArea->size();
    bool sizeChanged = false;
    
    if (countWidth > 0) {
        QSize newSize;
        if (count <= MAX_VISIBLE_ROWS) {
            newSize = QSize(countWidth, userWidgetHeight + SCROLL_AREA_PADDING);
            m_centerWidget->setMaximumHeight(newSize.height());
        } else {
            newSize = QSize(countWidth, (userWidgetHeight + UserFrameSpacing) * MAX_VISIBLE_ROWS);
            m_centerWidget->setMaximumHeight(QWIDGETSIZE_MAX);
        }
        
        // 检查尺寸是否真的需要改变
        if (newSize != currentSize) {
            m_scrollArea->setFixedSize(newSize);
            sizeChanged = true;
        }
        
        const int newCenterWidth = newSize.width() - CENTER_WIDGET_MARGIN;
        if (m_centerWidget->width() != newCenterWidth) {
            m_centerWidget->setFixedWidth(newCenterWidth);
            sizeChanged = true;
        }
        
        if (sizeChanged) {
            // 触发必要的重绘
            updateGeometry();
        }
    }
}

其他建议

  1. 考虑将布局逻辑封装到单独的函数中,提高代码的可读性和可维护性
  2. 可以考虑添加日志记录,便于调试和追踪布局变化
  3. 如果性能是关键考虑,可以考虑添加布局更新的节流(throttle)机制

这些改进建议旨在提高代码的健壮性、可维护性和性能。根据实际应用场景和需求,可以选择性地实施这些建议。

Copy link

@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 there - I've reviewed your changes and they look great!


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.

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 4, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR syncs upstream changes to userframelist.cpp by refining how the center widget’s height is managed: it’s constrained to avoid scrollbars for a single row and reset to unlimited for multi-row layouts, with inline comments added for clarity.

Sequence diagram for UserFrameList layout update logic

sequenceDiagram
participant UserFrameList
participant m_flowLayout
participant m_scrollArea
participant m_centerWidget
UserFrameList->>m_flowLayout: count()
alt Single row (count <= threshold)
    UserFrameList->>m_scrollArea: setFixedSize(countWidth, userWidgetHeight + 20)
    UserFrameList->>m_centerWidget: setMaximumHeight(m_scrollArea.height())
else Multi-row (count > threshold)
    UserFrameList->>m_scrollArea: setFixedSize(countWidth, (userWidgetHeight + UserFrameSpacing) * 2)
    UserFrameList->>m_centerWidget: setMaximumHeight(QWIDGETSIZE_MAX)
end
UserFrameList->>m_centerWidget: setFixedWidth(m_scrollArea.width() - 10)
Loading

Class diagram for updated UserFrameList layout logic

classDiagram
class UserFrameList {
  - m_flowLayout
  - m_scrollArea
  - m_centerWidget
  + updateLayout(width: int)
}
UserFrameList --> QWidget : uses m_centerWidget
UserFrameList --> QScrollArea : uses m_scrollArea
UserFrameList --> QLayout : uses m_flowLayout
Loading

File-Level Changes

Change Details Files
Refine center widget height handling for single vs multi-line user lists
  • Limit max height to scroll area height for single-row layouts
  • Reset max height to QWIDGETSIZE_MAX for multi-row layouts to enable scrolling
src/session-widgets/userframelist.cpp
Add inline comments explaining height adjustment logic
  • Comment on single-row height constraint to avoid scrollbars
  • Comment on multi-row height reset to support scrolling
src/session-widgets/userframelist.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
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@yixinshark yixinshark merged commit ce2921b into master Sep 4, 2025
26 of 27 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