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/D5117
This commit is contained in:
parent
70ecf7bfef
commit
c947e0a601
1 changed files with 12 additions and 2 deletions
|
@ -163,8 +163,18 @@ void ButtonsModel::move(int sourceIndex, int targetIndex)
|
|||
if (sourceIndex == qMax(0, targetIndex)) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue