fix: optimize fullscreen launcher item sorting initialization#709
Conversation
Reviewer's GuideEnables declarative initial sorting in the fullscreen launcher by introducing a sortColumn Q_PROPERTY on SortProxyModel, wiring it from QML, and ensuring resorting occurs when sortColumn changes, while conditionally enabling item move animations to avoid conflicts with model move signals. Sequence diagram for declarative initial sorting of fullscreen launcher itemssequenceDiagram
actor User
participant QML_Engine
participant FullscreenFrame_QML
participant ItemArrangementProxyModel_QML
participant SortProxyModel
participant SourceModel
participant GridView
User->>QML_Engine: Open fullscreen launcher
QML_Engine->>FullscreenFrame_QML: Instantiate FullscreenFrame
FullscreenFrame_QML->>ItemArrangementProxyModel_QML: Create ItemArrangementProxyModel
ItemArrangementProxyModel_QML->>SortProxyModel: Create SortProxyModel instance
QML_Engine->>SortProxyModel: setSortRole(IndexInPageRole)
QML_Engine->>SortProxyModel: setSortColumn(0)
SortProxyModel->>SortProxyModel: store m_sortColumn = 0
QML_Engine->>SortProxyModel: setSourceModel(SourceModel)
SortProxyModel->>SourceModel: setSourceModel
SourceModel-->>SortProxyModel: beginResetModel
SortProxyModel->>SortProxyModel: rebuildRowMap using m_sortColumn
SourceModel-->>SortProxyModel: endResetModel
SortProxyModel-->>GridView: expose already sorted data
GridView-->>User: Display items sorted with no move animations
Note over SortProxyModel,GridView: No beginMoveRows or endMoveRows emitted during initial sort
Sequence diagram for runtime change of sortColumn triggering reordersequenceDiagram
participant QML_Code
participant SortProxyModel
participant SourceModel
participant GridView
QML_Code->>SortProxyModel: setSortColumn(newColumn)
SortProxyModel->>SortProxyModel: compare m_sortColumn with newColumn
alt sortColumn changed and proxy map populated
SortProxyModel->>SortProxyModel: update m_sortColumn
SortProxyModel-->>QML_Code: sortColumnChanged signal
SortProxyModel->>SortProxyModel: reorder()
SortProxyModel->>GridView: beginMoveRows signals
SortProxyModel->>GridView: endMoveRows signals
GridView->>GridView: run itemMoveTransition
else no change or no data
SortProxyModel-->>QML_Code: no reordering
end
Sequence diagram for conditional enabling of itemMoveTransition in FullscreenFramesequenceDiagram
participant FullscreenFrame_QML
participant GridView
participant LauncherController
FullscreenFrame_QML->>GridView: Component.onCompleted
GridView->>LauncherController: read currentFrame
LauncherController-->>GridView: currentFrame value
alt currentFrame is FullscreenFrame
GridView->>GridView: itemMoveTransition.enabled = true
else currentFrame is not FullscreenFrame
GridView->>GridView: itemMoveTransition remains disabled
end
GridView->>GridView: gridViewContainer.checkPageSwitchState()
Class diagram for updated SortProxyModel with sortColumn Q_PROPERTYclassDiagram
class QAbstractProxyModel
class SortProxyModel {
<<QML_ELEMENT>>
- int m_sortRole
- int m_sortColumn
- Qt_CaseSensitivity m_sortCaseSensitivity
+ int sortRole()
+ void setSortRole(int role)
+ int sortColumn()
+ void setSortColumn(int column)
+ Qt_CaseSensitivity sortCaseSensitivity()
+ void setSortCaseSensitivity(Qt_CaseSensitivity sensitivity)
+ void setSourceModel(QAbstractItemModel model)
+ void reorder()
+ void sortRoleChanged()
+ void sortColumnChanged()
}
SortProxyModel --|> QAbstractProxyModel
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
SortProxyModel::setSortColumn, theoldColumnvariable is never used except forQ_UNUSED(oldColumn); you can drop the temporary and theQ_UNUSEDcall entirely to simplify the setter. - The
Component.onCompletedhandler that conditionally enablesitemMoveTransitionbased onLauncherController.currentFrameonly runs once; ifcurrentFramecan change later, consider bindingitemMoveTransition.enabledto an expression or reacting tocurrentFramechanges so the transition state stays in sync.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `SortProxyModel::setSortColumn`, the `oldColumn` variable is never used except for `Q_UNUSED(oldColumn)`; you can drop the temporary and the `Q_UNUSED` call entirely to simplify the setter.
- The `Component.onCompleted` handler that conditionally enables `itemMoveTransition` based on `LauncherController.currentFrame` only runs once; if `currentFrame` can change later, consider binding `itemMoveTransition.enabled` to an expression or reacting to `currentFrame` changes so the transition state stays in sync.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
d7e568f to
03b2cff
Compare
1. Replaced Component.onCompleted with sortColumn property in FullscreenFrame.qml for ItemArrangementProxyModel 2. Added setSortColumn method to SortProxyModel to enable declarative sorting in QML 3. Modified SortProxyModel to reorder items when sortColumn changes if source model is already populated 4. Added conditional enabling of itemMoveTransition in FullscreenFrame grid view Component.onCompleted Log: Improved fullscreen launcher item sorting performance and stability fix: 优化全屏启动器项目排序初始化 1. 在 FullscreenFrame.qml 中将 ItemArrangementProxyModel 的 Component.onCompleted 替换为 sortColumn 属性 2. 为 SortProxyModel 添加 setSortColumn 方法以支持在 QML 中声明式排序 3. 修改 SortProxyModel 在 sortColumn 变化时重新排序项目(如果源模型已 填充) 4. 在 FullscreenFrame 网格视图的 Component.onCompleted 中添加条件启用 sort(0)时,reorder() 会发出 beginMoveRows/endMoveRows 信号,与 GridView 的 displaced/move 动画冲突 根本解决方案:让排序在 setSourceModel() 的 beginResetModel/endResetModel 阶段就完成,这样视图第一次看到数据时就已经是排好序的,不会产生任何 move 信号。 做法:给 SortProxyModel 增加 sortColumn 的 Q_PROPERTY,在 QML 中声明式地设置 sortColumn: 0。QML 引擎会先设置简单值属性(sortColumn、sortRole),再设置复杂对象属性(sourceModel)。这样 rebuildRowMap() 执行m_sortColumn 已经是 0,数据在 reset 阶段就排好了。 Log: 改进全屏启动器项目排序性能和稳定性
03b2cff to
8c0eafd
Compare
deepin pr auto review这段代码 diff 展示了对 以下是对这段代码的详细审查和改进意见: 1. 语法与逻辑审查
2. 代码质量
3. 代码性能
4. 代码安全
改进建议
总结这段代码修改整体质量较高,成功地将命令式调用转换为声明式属性,提升了代码的可维护性和 QML 风格的一致性。逻辑上安全,考虑了边界条件。主要的改进点在于清理未使用的变量以及考虑 QML 端是否可以使用属性绑定来替代 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BLumia, wjyrich 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 |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
Log: Improved fullscreen launcher item sorting performance and stability
fix: 优化全屏启动器项目排序初始化
sort(0)时,reorder() 会发出 beginMoveRows/endMoveRows 信号,与 GridView 的 displaced/move 动画冲突
根本解决方案:让排序在 setSourceModel() 的 beginResetModel/endResetModel 阶段就完成,这样视图第一次看到数据时就已经是排好序的,不会产生任何 move 信号。
做法:给 SortProxyModel 增加 sortColumn 的 Q_PROPERTY,在 QML 中声明式地设置 sortColumn: 0。QML 引擎会先设置简单值属性(sortColumn、sortRole),再设置复杂对象属性(sourceModel)。这样 rebuildRowMap() 执行m_sortColumn 已经是 0,数据在 reset 阶段就排好了。
Log: 改进全屏启动器项目排序性能和稳定性
Summary by Sourcery
Enable declarative initial sorting for fullscreen launcher items and avoid animation conflicts during model initialization.
New Features:
Bug Fixes:
Enhancements: