From 1eb2650cd585192b9e9d0b4264896840e399d398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Fri, 11 May 2012 16:01:58 +0200 Subject: [PATCH] Do not reset the model when new matches are added REVIEW: 104914 --- .../krunnermodel/runnermodel.cpp | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/declarativeimports/krunnermodel/runnermodel.cpp b/declarativeimports/krunnermodel/runnermodel.cpp index 7c5485b47..73595beef 100644 --- a/declarativeimports/krunnermodel/runnermodel.cpp +++ b/declarativeimports/krunnermodel/runnermodel.cpp @@ -190,10 +190,36 @@ void RunnerModel::createManager() void RunnerModel::matchesChanged(const QList &matches) { //kDebug() << "got matches:" << matches.count(); - beginResetModel(); - m_matches = matches; - endResetModel(); - emit countChanged(); + bool fullReset = false; + int oldCount = m_matches.count(); + int newCount = matches.count(); + if (newCount > oldCount) { + // We received more matches than we had. If all common matches are the + // same, we can just append new matches instead of resetting the whole + // model + for (int row = 0; row < oldCount; ++row) { + if (m_matches.at(row) != matches.at(row)) { + fullReset = true; + break; + } + } + if (!fullReset) { + // Not a full reset, inserting rows + beginInsertRows(QModelIndex(), oldCount, newCount); + m_matches = matches; + endInsertRows(); + emit countChanged(); + } + } else { + fullReset = true; + } + + if (fullReset) { + beginResetModel(); + m_matches = matches; + endResetModel(); + emit countChanged(); + } m_runningChangedTimeout->start(3000); }