When used by QML, only populate after component is complete
ClosedPublic

Authored by hein on Nov 8 2017, 2:14 PM.

Details

Summary

This introduces the use of QQmlParserStatus to delay populating
the model until all properties have been set, to avoid delegate
churn.

TasksModel is also meant to be used by C++. There's no good way
to determine whether an object is being instanciated by QML
during construction time, therefore this patch also introduces a
delay in initial population of the model after construction via
a single-shot timer. At the time the slot is invoked we know if
we're used by QML (because QQmlParserStatus::classBegin has
either been called or not by then) so we can decide to populate
or wait more for QQmlParserStatus::componentComplete.

I'm not super happy with this behavior change for C++ users,
however as the model is usually used via QML currently, it's
pragmatic to optimize performance for the common case, and it
doesn't technically break QAbstractItemModel semantics, as model
population isn't required to be sync.

There's a decent change this fixes a recently-reported crash as a
by-product:
CCBUG:386630

Diff Detail

Repository
R120 Plasma Workspace
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
hein created this revision.Nov 8 2017, 2:14 PM
Restricted Application added a project: Plasma. · View Herald TranscriptNov 8 2017, 2:14 PM

I'm not super happy with this behavior change for C++ users,

I've seen other people export a subclass for QtQuick that sets the usedByQml flag.

I love QQmlParserStatus so +1

libtaskmanager/tasksmodel.cpp
632

.

921

may as well QTimer:;singleShot(0, this, [this](...

just in case you get deleted in the same space.

broulik added a subscriber: broulik.Nov 8 2017, 3:06 PM
broulik added inline comments.
libtaskmanager/tasksmodel.h
814

override

hein updated this revision to Diff 22083.Nov 8 2017, 3:29 PM

Fix review comments by David and Kai.

davidedmundson accepted this revision.Nov 8 2017, 3:43 PM
This revision is now accepted and ready to land.Nov 8 2017, 3:43 PM
This revision was automatically updated to reflect the committed changes.