From 4ba41b661610ecba0a0c743d3f27aeed7efc1cbe Mon Sep 17 00:00:00 2001 From: wjyrich Date: Mon, 16 Mar 2026 15:39:59 +0800 Subject: [PATCH] refactor: remove redundant positionViewAtBeginning functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed multiple positionViewAtBeginning() functions from various QML view components (GridViewContainer, AnalysisView, FreeSortListView, FrequentlyUsedView, RecentlyInstalledView, SearchResultView) as they were redundant wrapper functions that simply called the underlying QML view's positionViewAtBeginning() method. Added a new itemBroughtToFront() signal to ItemArrangementProxyModel that triggers automatic view repositioning in FreeSortListView when items are brought to front, eliminating the need for manual view positioning calls. Log: N/A Influence: 1. Test that bringing items to front in free sort mode automatically scrolls the view to beginning 2. Verify all grid and list views still function correctly without explicit positionViewAtBeginning calls 3. Test search results display and navigation 4. Verify frequently used and recently installed views maintain proper scrolling behavior 5. Test drag and drop operations in free sort mode 6. Verify view focus behavior remains intact refactor: 移除冗余的positionViewAtBeginning函数 从多个QML视图组件(GridViewContainer、AnalysisView、FreeSortListView、 FrequentlyUsedView、RecentlyInstalledView、SearchResultView)中移除了 positionViewAtBeginning()函数,这些函数是冗余的包装函数,仅调用底层QML视 图的positionViewAtBeginning()方法。在ItemArrangementProxyModel中添加了新 的itemBroughtToFront()信号,当项目被置顶时自动触发FreeSortListView中的视 图重新定位,消除了手动调用视图定位的需求。 Log: 无 Influence: 1. 测试在自由排序模式下将项目置顶时是否自动滚动视图到起始位置 2. 验证所有网格和列表视图在没有显式positionViewAtBeginning调用的情况下仍 能正常工作 3. 测试搜索结果展示和导航功能 4. 验证常用应用和最近安装视图保持正确的滚动行为 5. 测试自由排序模式下的拖放操作 6. 验证视图焦点行为保持完整 PMS: BUG-335535 --- qml/GridViewContainer.qml | 6 +----- qml/windowed/AnalysisView.qml | 7 +------ qml/windowed/FreeSortListView.qml | 7 +++++-- qml/windowed/FrequentlyUsedView.qml | 6 +----- qml/windowed/GridViewContainer.qml | 6 +----- qml/windowed/RecentlyInstalledView.qml | 6 +----- qml/windowed/SearchResultView.qml | 6 +----- src/models/itemarrangementproxymodel.cpp | 4 +++- src/models/itemarrangementproxymodel.h | 3 ++- 9 files changed, 16 insertions(+), 35 deletions(-) diff --git a/qml/GridViewContainer.qml b/qml/GridViewContainer.qml index 00aceccf..6bd4972d 100644 --- a/qml/GridViewContainer.qml +++ b/qml/GridViewContainer.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -44,10 +44,6 @@ FocusScope { gridView.currentIndex = 0 } - function positionViewAtBeginning() { - gridView.positionViewAtBeginning() - } - function itemAt(x, y) { let point = mapToItem(gridView, x, y) return gridView.itemAt(point.x, point.y) diff --git a/qml/windowed/AnalysisView.qml b/qml/windowed/AnalysisView.qml index 3ad400ff..6be0f1c7 100644 --- a/qml/windowed/AnalysisView.qml +++ b/qml/windowed/AnalysisView.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -21,11 +21,6 @@ Control { frequentlyUsedView.focus = true } - function positionViewAtBeginning() { - frequentlyUsedView.positionViewAtBeginning() - recentlyInstalledView.positionViewAtBeginning() - } - contentItem: ColumnLayout { spacing: 0 diff --git a/qml/windowed/FreeSortListView.qml b/qml/windowed/FreeSortListView.qml index 1e647d74..e6ce7992 100644 --- a/qml/windowed/FreeSortListView.qml +++ b/qml/windowed/FreeSortListView.qml @@ -35,8 +35,11 @@ Item { listView.focus = true } - function positionViewAtBeginning() { - listView.positionViewAtBeginning() + Connections { + target: ItemArrangementProxyModel + function onItemBroughtToFront() { + listView.positionViewAtBeginning() + } } function resetViewState() { diff --git a/qml/windowed/FrequentlyUsedView.qml b/qml/windowed/FrequentlyUsedView.qml index 62f7a08a..ce16a9b2 100644 --- a/qml/windowed/FrequentlyUsedView.qml +++ b/qml/windowed/FrequentlyUsedView.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -25,10 +25,6 @@ Control { property int count: frequentlyUsedViewContainer.count property int maxCount: 16 - function positionViewAtBeginning() { - frequentlyUsedViewContainer.positionViewAtBeginning() - } - contentItem: ColumnLayout { spacing: 0 diff --git a/qml/windowed/GridViewContainer.qml b/qml/windowed/GridViewContainer.qml index 2b45fa90..ed274eb1 100644 --- a/qml/windowed/GridViewContainer.qml +++ b/qml/windowed/GridViewContainer.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -39,10 +39,6 @@ FocusScope { property ScrollBar vScrollBar property alias currentIndex: gridView.currentIndex - function positionViewAtBeginning() { - gridView.positionViewAtBeginning() - } - function itemAt(x, y) { let point = mapToItem(gridView, x, y) return gridView.itemAt(point.x, point.y) diff --git a/qml/windowed/RecentlyInstalledView.qml b/qml/windowed/RecentlyInstalledView.qml index aaf36833..5433252a 100644 --- a/qml/windowed/RecentlyInstalledView.qml +++ b/qml/windowed/RecentlyInstalledView.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -24,10 +24,6 @@ Control { recentlyInstalledViewContainer.focus = true } - function positionViewAtBeginning() { - recentlyInstalledViewContainer.positionViewAtBeginning() - } - contentItem: ColumnLayout { spacing: 0 Label { diff --git a/qml/windowed/SearchResultView.qml b/qml/windowed/SearchResultView.qml index 0672d91f..68ebf6b7 100644 --- a/qml/windowed/SearchResultView.qml +++ b/qml/windowed/SearchResultView.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -25,10 +25,6 @@ Control { searchResultViewContainer.currentItem?.itemClicked() } - function positionViewAtBeginning() { - searchResultViewContainer.positionViewAtBeginning() - } - contentItem: ColumnLayout { spacing: 0 visible: searchResultViewContainer.count > 0 diff --git a/src/models/itemarrangementproxymodel.cpp b/src/models/itemarrangementproxymodel.cpp index 297dd1ba..56ab91c4 100644 --- a/src/models/itemarrangementproxymodel.cpp +++ b/src/models/itemarrangementproxymodel.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023-2026 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -66,6 +66,8 @@ void ItemArrangementProxyModel::bringToFront(const QString & id) emit dataChanged(index(0, 0), index(rowCount() - 1, 0), { PageRole, IndexInPageRole, FolderIdNumberRole, IconsNameRole }); + + emit itemBroughtToFront(); } void ItemArrangementProxyModel::commitDndOperation(const QString &dragId, const QString &dropId, const DndOperation op, int pageHint) diff --git a/src/models/itemarrangementproxymodel.h b/src/models/itemarrangementproxymodel.h index 78dc97b7..5b70564e 100644 --- a/src/models/itemarrangementproxymodel.h +++ b/src/models/itemarrangementproxymodel.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -71,6 +71,7 @@ class ItemArrangementProxyModel : public QConcatenateTablesProxyModel signals: void topLevelPageCountChanged(); void folderPageCountChanged(int folderId); + void itemBroughtToFront(); private: explicit ItemArrangementProxyModel(QObject *parent = nullptr);