|
1 | 1 | /* |
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). |
3 | 9 |
|
4 | 10 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com> |
5 | 11 | 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. |
7 | 13 | Author: Wang Zichong <wangzichong@deepin.org> |
8 | 14 |
|
9 | 15 | SPDX-License-Identifier: MIT |
@@ -339,6 +345,10 @@ void SortProxyModel::reorder() |
339 | 345 | contents << index(row).data(m_sortRole).toString(); |
340 | 346 | } |
341 | 347 | 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; |
342 | 352 | } |
343 | 353 | auto rotateEnd = successor(unorderedIt); |
344 | 354 | std::rotate(it, it + moveCount, rotateEnd); |
@@ -561,16 +571,9 @@ void SortProxyModel::handleModelReset() |
561 | 571 | if (!sourceModel()) |
562 | 572 | return; |
563 | 573 |
|
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(); |
574 | 577 | } |
575 | 578 |
|
576 | 579 | /** |
|
0 commit comments