KSelectionProxyModel listens to two delegate objects for changes: the
source model of the proxy, and the selectionModel. When a QModelIndex
which is selected gets removed, slots connected to signals for both
clients are executed. Whichever slot is executed first updates the
KSelectionProxyModel, and when the other slot is executed it ignores the
already-handled event.
Until Qt 5.5. QItemSelectionModel required the model to be passed in its
constructor. Prior to commit v5.9.0~21 (KSPM: Make the
setSelectionModel method public., 2015-03-08) the KSelectionProxyModel
required the selectionModel to be passed in its constructor.
Because the order of slot execution follows the order of signal slot
connection, the KSelectionProxyModel slot for handling deselection was
always executed first to process the removal.
Since Qt 5.5 and KItemModels 5.9.0, it is possible to set the model on
the QItemSelectionModel and the selectionModel on the
KSelectionProxyModel in a different order, meaning that the
(before/after) slots for handling removal of a row from the source model
is executed first. When the before slot is executed the selectionModel
still has a selection, but by the time the after slot is executed the
selection has already been removed (because QItemSelectionModel updates
its selection on rowsAboutToBeRemoved).
Remove the check for the selection being empty in the after slot to
handle this case.
The model can be changed after the constructor is run as of Qt 5.5.
At this point, the KLinkItemSelectionModel would still break if that is
attempted, so a unit test comes later.
When the model of the selectionModel is changed, it is necessary to
reset the proxy and clear any selection state.
This amends commit v5.9.0~5 (KSPM: Connect properly to the source model if it
is changed., 2015-03-12)
The proxy would initially say columnCount==0 and would then omit to notify
about the insertion of columns. Simpler to just always have columns, even
when we have 0 rows.
CCBUG: 352369
CCMAIL: steveire@gmail.com
We need to disconnect from a previous source model if present, not the new
one, and we need to be prepared for the new source model to be 0.
REVIEW: 126117
Note: QStringLiteral and multi-line string literals are not possible
with MSVC 2013 and below (known compiler bug/limitation).
Patch by Paul Wulff <paul.wulff@gmail.com>
CCMAIL: montel@kde.org