Skip to content

Commit 3de0f01

Browse files
committed
fix: avoid calling endMoveRows() if beginMoveRows() is failed
避免在开始移动行失败的时候仍然调用结束移动行的API以至于崩溃. 包括两个改动: 1. 尽早返回 2. 原始模型重置时不再尝试将其视为数据变更,而是也视为模型重置, 避免此处导致的 reorder() 重入 注意 reorder() 目前仍然不可重入. Log:
1 parent 20f8627 commit 3de0f01

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

src/models/sortproxymodel.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
/*
2-
This file was part of KDToolBox, modified by deepin to fit their own needs.
2+
This file was part of KDToolBox (52611ec, sortproxymodel.{h,cpp}).
3+
Modified by deepin to fit their own needs.
4+
5+
Changes between the original and this version:
6+
7+
1. QML support.
8+
2. Handle `modelReset` as well (still for QML support).
39
410
SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
511
Author: André Somers <andre.somers@kdab.com>
6-
SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
12+
SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
713
Author: Wang Zichong <wangzichong@deepin.org>
814
915
SPDX-License-Identifier: MIT
@@ -339,6 +345,10 @@ void SortProxyModel::reorder()
339345
contents << index(row).data(m_sortRole).toString();
340346
}
341347
qWarning() << "moving failed. Current contents:" << contents.join(QLatin1String(", "));
348+
// if beginMoveRows fails, we cannot continue, skip this move
349+
// do not call endMoveRows() and do not modify internal data structure
350+
--orderedIt;
351+
continue;
342352
}
343353
auto rotateEnd = successor(unorderedIt);
344354
std::rotate(it, it + moveCount, rotateEnd);
@@ -561,16 +571,9 @@ void SortProxyModel::handleModelReset()
561571
if (!sourceModel())
562572
return;
563573

564-
const int sourceModelRowCount = sourceModel()->rowCount();
565-
if (sourceModelRowCount > 0)
566-
{
567-
if (sourceModelRowCount != rowCount())
568-
resetInternalData();
569-
570-
handleDataChanged(sourceModel()->index(0, 0),
571-
sourceModel()->index(sourceModel()->rowCount() - 1, 0),
572-
QList<int>());
573-
}
574+
beginResetModel();
575+
resetInternalData();
576+
endResetModel();
574577
}
575578

576579
/**

0 commit comments

Comments
 (0)