fix(src/libappdata): 修改全屏模式下卸载安装应用时导致排序错位的问题

This commit is contained in:
youdiansaodongxi 2024-06-12 17:20:10 +08:00
parent 09bcddf500
commit f643dd14df
1 changed files with 15 additions and 6 deletions

View File

@ -241,25 +241,34 @@ int AppGroupModel::findGroupIndex(const QModelIndex &sourceIndex) const
void AppGroupModel::insertApp(int groupIndex, const QModelIndex &sourceIndex) void AppGroupModel::insertApp(int groupIndex, const QModelIndex &sourceIndex)
{ {
int newIndex = sourceIndex.row();
if (groupIndex < 0 || groupIndex >= m_groups.size()) { if (groupIndex < 0 || groupIndex >= m_groups.size()) {
beginInsertRows(QModelIndex(), m_groups.size(), m_groups.size()); if (newIndex > 0) {
m_groups.append(new QVector<int>(1, sourceIndex.row())); // 查找前一个item的index
newIndex = findGroupIndex(sourceModel()->index(--newIndex, 0));
if (newIndex < 0) {
newIndex = m_groups.size();
} else {
++newIndex;
}
}
beginInsertRows(QModelIndex(), newIndex, newIndex);
m_groups.insert(newIndex, new QVector<int>(1, sourceIndex.row()));
endInsertRows(); endInsertRows();
return; return;
} }
int index = 0; int index = 0;
int newItem = sourceIndex.row();
QVector<int> *subItems = m_groups[groupIndex]; QVector<int> *subItems = m_groups[groupIndex];
for (; index < subItems->size(); ++index) { for (; index < subItems->size(); ++index) {
if (newItem < subItems->at(index)) { if (newIndex < subItems->at(index)) {
break; break;
} }
} }
beginInsertRows(AppGroupModel::index(groupIndex, 0, QModelIndex()), index, index); beginInsertRows(AppGroupModel::index(groupIndex, 0, QModelIndex()), index, index);
subItems->insert(index, newItem); subItems->insert(index, newIndex);
endInsertRows(); endInsertRows();
} }