summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladyslav Tronko <innermous@gmail.com>2017-03-24 15:57:43 (GMT)
committerMartin Gräßlin <mgraesslin@kde.org>2017-03-24 16:04:09 (GMT)
commitc947e0a6012c551f559e45892ac70af58c023b55 (patch)
tree497b82c366c887b04de9c9d03ee43ecb147168d3
parent70ecf7bfef46bf8f35a2c1d49215a37f0383617c (diff)
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
-rw-r--r--kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp b/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp
index 26d7790..b417525 100644
--- a/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp
+++ b/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp
@@ -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();
}