diff --git a/containments/desktop/plugins/folder/positioner.h b/containments/desktop/plugins/folder/positioner.h --- a/containments/desktop/plugins/folder/positioner.h +++ b/containments/desktop/plugins/folder/positioner.h @@ -126,8 +126,6 @@ int m_perStripe; - int m_lastRow; - QModelIndexList m_pendingChanges; bool m_ignoreNextTransaction; diff --git a/containments/desktop/plugins/folder/positioner.cpp b/containments/desktop/plugins/folder/positioner.cpp --- a/containments/desktop/plugins/folder/positioner.cpp +++ b/containments/desktop/plugins/folder/positioner.cpp @@ -29,7 +29,6 @@ , m_enabled(false) , m_folderModel(nullptr) , m_perStripe(0) -, m_lastRow(-1) , m_ignoreNextTransaction(false) , m_pendingPositions(false) , m_updatePositionsTimer(new QTimer(this)) @@ -379,6 +378,7 @@ } const int oldCount = rowCount(); + int newLast = 0; for (int i = 0; i < fromIndices.count(); ++i) { @@ -407,37 +407,54 @@ toIndices[i] = to; - if (!toIndices.contains(from)) { - m_proxyToSource.remove(from); + if (to > newLast) { + newLast = to; } + } - updateMaps(to, sourceRow); + const int newCount = newLast + 1; + QModelIndexList changed; - const QModelIndex &fromIdx = index(from, 0); - emit dataChanged(fromIdx, fromIdx); + auto doUpdateMaps = [&]() { + for (int i = 0; i < fromIndices.count(); ++i) + { + const int from = fromIndices[i]; + const int to = toIndices[i]; + const int sourceRow = sourceRows[i]; - if (to < oldCount) { - const QModelIndex &toIdx = index(to, 0); - emit dataChanged(toIdx, toIdx); - } - } + if (!toIndices.contains(from)) { + m_proxyToSource.remove(from); + } - const int newCount = rowCount(); + updateMaps(to, sourceRow); + changed.append(index(from, 0)); + + if (to < oldCount) { + changed.append(index(to, 0)); + } + } + }; if (newCount > oldCount) { if (m_beginInsertRowsCalled) { endInsertRows(); m_beginInsertRowsCalled = false; } beginInsertRows(QModelIndex(), oldCount, newCount - 1); + doUpdateMaps(); endInsertRows(); } if (newCount < oldCount) { beginRemoveRows(QModelIndex(), newCount, oldCount - 1); + doUpdateMaps(); endRemoveRows(); } + for (auto idx : changed) { + emit dataChanged(idx, idx); + } + m_updatePositionsTimer->start(); } @@ -608,7 +625,6 @@ m_proxyToSource = newProxyToSource; m_sourceToProxy = newSourceToProxy; - m_lastRow = -1; int newLast = lastRow(); if (oldLast > newLast) { @@ -717,7 +733,6 @@ { m_proxyToSource.insert(proxyIndex, sourceIndex); m_sourceToProxy.insert(sourceIndex, proxyIndex); - m_lastRow = -1; } int Positioner::firstRow() const @@ -735,13 +750,9 @@ int Positioner::lastRow() const { if (!m_proxyToSource.isEmpty()) { - if (m_lastRow != -1) { - return m_lastRow; - } else { - QList keys(m_proxyToSource.keys()); - qSort(keys); - return keys.last(); - } + QList keys(m_proxyToSource.keys()); + qSort(keys); + return keys.last(); } return 0;