From 7f2785c5bb533a92e7d33bf4c58691373e3c2678 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Thu, 13 Jun 2024 14:11:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(full-screen):=20=E4=BF=AE=E5=A4=8D=E5=85=A8?= =?UTF-8?q?=E5=B1=8F=E5=BA=94=E7=94=A8=E5=88=97=E8=A1=A8=E5=9C=A8=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E6=88=96=E5=8D=B8=E8=BD=BD=E5=BA=94=E7=94=A8=E6=97=B6?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E9=94=99=E4=B9=B1=E9=97=AE=E9=A2=98,?= =?UTF-8?q?=E4=BC=98=E5=8C=96model=E5=88=A0=E9=99=A4=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qml/AppUI/FullScreenAppList.qml | 8 +++++++- src/libappdata/app-group-model.cpp | 14 +++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/qml/AppUI/FullScreenAppList.qml b/qml/AppUI/FullScreenAppList.qml index 266f43f..16efd9d 100644 --- a/qml/AppUI/FullScreenAppList.qml +++ b/qml/AppUI/FullScreenAppList.qml @@ -76,7 +76,13 @@ ListView { model: DelegateModel { model: appGroupModel - rootIndex: modelIndex(index) + + Component.onCompleted: { + // Warning: rootIndex只需要设置一次,多次设置会导致对应关系错误, + // delegateModel使用persistedIndex保存rootIndex,会自动进行修正 + rootIndex = modelIndex(index); + } + delegate: Item { width: GridView.view.cellWidth height: GridView.view.cellHeight diff --git a/src/libappdata/app-group-model.cpp b/src/libappdata/app-group-model.cpp index 4dbb0d4..07fb317 100644 --- a/src/libappdata/app-group-model.cpp +++ b/src/libappdata/app-group-model.cpp @@ -340,13 +340,13 @@ void AppGroupModel::onRowsAboutToBeRemoved(const QModelIndex &parent, int first, break; } - // 删除组里的元素 - beginRemoveRows(index(groupIndex, 0, QModelIndex()), itemIndex, itemIndex); - subItems->removeAt(itemIndex); - endRemoveRows(); - - // 删除组 - if (subItems->isEmpty()) { + if (subItems->size() > 1) { + // 删除组里的元素 + beginRemoveRows(index(groupIndex, 0, QModelIndex()), itemIndex, itemIndex); + subItems->removeAt(itemIndex); + endRemoveRows(); + } else { + // 删除组 beginRemoveRows(QModelIndex(), groupIndex, groupIndex); delete m_groups.takeAt(groupIndex); endRemoveRows();