Skip to content

Commit b178a28

Browse files
wjyrichdeepin-bot[bot]
authored andcommitted
fix: optimize fullscreen launcher item sorting initialization
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: 改进全屏启动器项目排序性能和稳定性
1 parent a3bd6dd commit b178a28

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

qml/FullscreenFrame.qml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,7 @@ InputEventItem {
419419
folderId: 0
420420
}
421421
sortRole: ItemArrangementProxyModel.IndexInPageRole
422-
Component.onCompleted: {
423-
proxyModel.sort(0)
424-
}
422+
sortColumn: 0
425423
}
426424

427425
MouseArea {
@@ -666,6 +664,9 @@ InputEventItem {
666664
}
667665
}
668666
Component.onCompleted: {
667+
if (LauncherController.currentFrame === "FullscreenFrame") {
668+
itemMoveTransition.enabled = true
669+
}
669670
gridViewContainer.checkPageSwitchState()
670671
}
671672
Component.onDestruction: {

src/models/sortproxymodel.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,24 @@ void SortProxyModel::setSortRole(int role)
196196
}
197197
}
198198

199+
void SortProxyModel::setSortColumn(int column)
200+
{
201+
if (m_sortColumn != column)
202+
{
203+
int oldColumn = m_sortColumn;
204+
m_sortColumn = column;
205+
Q_EMIT sortColumnChanged();
206+
207+
// If source model is already set, reorder to apply the new sort column
208+
if (sourceModel() && !m_proxyToSourceMap.empty())
209+
{
210+
reorder();
211+
}
212+
213+
Q_UNUSED(oldColumn)
214+
}
215+
}
216+
199217
int SortProxyModel::sortRole() const
200218
{
201219
return m_sortRole;

src/models/sortproxymodel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ class SortProxyModelTest;
3030
* of the API, so if you used QSortFilterProxyModel only for sorting it
3131
* should be a drop-in replacement.
3232
*
33-
* @note BLumia: Currently, sort() needs to be called manually
33+
* @note sortColumn can be set declaratively in QML to enable
34+
* initial sorting during model reset (no move signals emitted).
3435
*/
3536
class SortProxyModel : public QAbstractProxyModel
3637
{
3738
Q_OBJECT
3839
Q_PROPERTY(int sortRole READ sortRole WRITE setSortRole NOTIFY sortRoleChanged)
40+
Q_PROPERTY(int sortColumn READ sortColumn WRITE setSortColumn NOTIFY sortColumnChanged)
3941
QML_ELEMENT
4042

4143
public:
@@ -60,6 +62,7 @@ class SortProxyModel : public QAbstractProxyModel
6062
public:
6163
void setSortRole(int role);
6264
int sortRole() const;
65+
void setSortColumn(int column);
6366
void setSortCaseSensitivity(Qt::CaseSensitivity sensitivity);
6467
Qt::CaseSensitivity sortCaseSensitivity() const;
6568
int sortColumn() const;

0 commit comments

Comments
 (0)