From 66a271a150a9be8f8e67e9aa4b4d01a2c583866a Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 28 Jun 2018 10:14:57 +0200 Subject: [PATCH] Fix inserting tasks into issues pane When tasks are inserted into the source model, the source indices in the filtered model after the new items where not updated correctly. The indices must be increased by the number of items added to the source model, not the number of items added to the filtered model (which can be less). Task-number: QTCREATORBUG-20542 Task-number: QTCREATORBUG-18951 Change-Id: Idae9cf4241c31229dadf5c9fea383aef3fdfffb0 Reviewed-by: Orgad Shaneh --- src/plugins/projectexplorer/taskmodel.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/plugins/projectexplorer/taskmodel.cpp b/src/plugins/projectexplorer/taskmodel.cpp index d59162f5c55..981f85651d3 100644 --- a/src/plugins/projectexplorer/taskmodel.cpp +++ b/src/plugins/projectexplorer/taskmodel.cpp @@ -393,6 +393,8 @@ void TaskFilterModel::handleNewRows(const QModelIndex &index, int first, int las { QTC_ASSERT(!index.isValid(), return); + const int newItemCount = last - first + 1; + QList newMapping; for (int i = first; i <= last; ++i) { const Task &task = m_sourceModel->task(m_sourceModel->index(i, 0)); @@ -400,8 +402,8 @@ void TaskFilterModel::handleNewRows(const QModelIndex &index, int first, int las newMapping.append(i); } - const int newItems = newMapping.count(); - if (!newItems) + const int newMappingCount = newMapping.count(); + if (!newMappingCount) return; int filteredFirst = -1; @@ -410,18 +412,18 @@ void TaskFilterModel::handleNewRows(const QModelIndex &index, int first, int las else filteredFirst = std::lower_bound(m_mapping.constBegin(), m_mapping.constEnd(), first) - m_mapping.constBegin(); - const int filteredLast = filteredFirst + newItems - 1; + const int filteredLast = filteredFirst + newMappingCount - 1; beginInsertRows(QModelIndex(), filteredFirst, filteredLast); if (filteredFirst == m_mapping.count()) { m_mapping.append(newMapping); } else { - QList rest = m_mapping.mid(filteredFirst); + const QList rest = m_mapping.mid(filteredFirst); - m_mapping.reserve(m_mapping.count() + newItems); + m_mapping.reserve(m_mapping.count() + newMappingCount); m_mapping.erase(m_mapping.begin() + filteredFirst, m_mapping.end()); m_mapping.append(newMapping); - foreach (int pos, rest) - m_mapping.append(pos + newItems); + for (int pos : rest) + m_mapping.append(pos + newItemCount); } endInsertRows(); }