KFilePlacesView: Fix crash when dragging over topmost section header
b5de820a fixed incorrect highlighting of the section header label
during drag operations over the first place of a section in clients
m_dropOnPlace, e.g. Dolphin. This was effective for all except
the topmost section header, where it would cause a crash (independent of
the state of
KFilePlacesViewDelegate::previousVisibleIndex access to
fails, because the
index determined via
KFilePlacesView::paintEvent is invalid when dragging towards the
topmost section header label. This is because
extend above the entry's
visualRect, i.e. it covers the places items
below as well as above the separator, of which the latter does not exist
for the first entry.
By remembering the index belonging to
instead of reconstructing it, we can guarantee it to be valid.
No more crash when dragging places or folders over topmost section
header label in places view in
kdialog --getsaveurl as well as
dolphin. Other functionality related to dragging places around
(including existing bugs) is unaffected and the behavior of the original
KFilePlacesView: Fix potential crash in
The previous commit fixed a crash in
KFilePlacesViewDelegate::previousVisibleIndex, where access to
failed due to an invalid index.
In addition to the previous commit already fixing the crash, unrelated
potential crashes in the future can be avoided by checking for an
previousVisibleIndex. The existing logic of
indexIsSectionHeader is kept intact, since now an invalid
lead to comparing two empty strings, i.e. it will not be considered a
section header as required by the rest of the code.
This fix alone would already solve the crash without any side effects,
m_dropIndex seemed less brittle.
Functionality related to dragging places around (including existing bugs) is unaffected.