sync: from linuxdeepin/dde-session-shell#453
Merged
Merged
Conversation
Synchronize source files from linuxdeepin/dde-session-shell. Source-pull-request: linuxdeepin/dde-session-shell#32
Contributor
Author
deepin pr auto review这段代码是关于用户界面布局更新的逻辑,我来分析一下并提供改进建议: 语法逻辑
代码质量
代码性能
代码安全
改进建议// 建议在类开头定义常量
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();
}
}
}其他建议
这些改进建议旨在提高代码的健壮性、可维护性和性能。根据实际应用场景和需求,可以选择性地实施这些建议。 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis 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 logicsequenceDiagram
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)
Class diagram for updated UserFrameList layout logicclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
yixinshark
approved these changes
Sep 4, 2025
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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: