Commit 892b1b9e authored by David Edmundson's avatar David Edmundson
Browse files

Fix model updates in RunnerMatchesModel

RunnerMatchesModel is backed by a list. When this list changes
RunnerManagerModel add/removes the new number of rows then called
dataChanged on everything that remained.

It's a common pattern, but not a great one. Especially with QtQuick
where moving a delegate is faster than updating all the properties of an
existing one - unfortunately I can't find a nice solution to do this
properly in linear time.

The problem with the current code is we update the entire list in the
insert/remove rows. This is a violation of the model rules as we're
updating rows outside the rows listed inside begin/remove rows.

It works, but Qt's model test fails.

We also have a lot of duplicates of a crash in QtQuick after runner
model changes, bug 369430. I think it could be related, but can't
prove anything.

This patch updates the rows that exist in both the before and after
models before adding/removing the remaining rows.

BUG: 402439

Test Plan:
Added Qt model tester in
It now passes.

Reviewers: #plasma, hein

Reviewed By: #plasma, hein

Subscribers: hein, apol, plasma-devel

Tags: #plasma

Differential Revision:
parent 1a23c2d9
......@@ -222,9 +222,12 @@ void RunnerMatchesModel::setMatches(const QList< Plasma::QueryMatch > &matches)
for (int row = 0; row < ceiling; ++row) {
if (!( == {
emitDataChange = true;
m_matches[row] =;
if (emitDataChange) {
emit dataChanged(index(0, 0), index(ceiling - 1, 0));
if (newCount > oldCount) {
......@@ -241,12 +244,6 @@ void RunnerMatchesModel::setMatches(const QList< Plasma::QueryMatch > &matches)
if (emitDataChange) {
m_matches = matches;
emit dataChanged(index(0, 0), index(ceiling - 1, 0));
if (emitCountChange) {
emit countChanged();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment