Fix crash on dragging titlebar buttons in System Settings
Summary: Currently, if user tries to move one of buttons to the left, ending up dragging one button onto another, crash occurs. In addition, this patch replaces verbose replacement(remove/insert) with more elegant QVector<T>::move(int, int) BUG: 374153 FIXED-IN: 5.8.7 Reviewers: graesslin, #kwin Reviewed By: graesslin, #kwin Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D5117icc-effect-5.14.5
parent
c3362fe866
commit
1bfe1164f4
|
@ -162,8 +162,18 @@ void ButtonsModel::move(int sourceIndex, int targetIndex)
|
||||||
if (sourceIndex == qMax(0, targetIndex)) {
|
if (sourceIndex == qMax(0, targetIndex)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), targetIndex + 1);
|
|
||||||
m_buttons.insert(qMax(0, targetIndex), m_buttons.takeAt(sourceIndex));
|
/* When moving an item down, the destination index needs to be incremented
|
||||||
|
by one, as explained in the documentation:
|
||||||
|
http://doc.qt.nokia.com/qabstractitemmodel.html#beginMoveRows */
|
||||||
|
if (targetIndex > sourceIndex) {
|
||||||
|
// Row will be moved down
|
||||||
|
beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), targetIndex + 1);
|
||||||
|
} else {
|
||||||
|
beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), qMax(0, targetIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_buttons.move(sourceIndex, qMax(0, targetIndex));
|
||||||
endMoveRows();
|
endMoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue