summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladyslav Tronko <innermous@gmail.com>2017-03-24 15:57:43 (GMT)
committerDavid Edmundson <kde@davidedmundson.co.uk>2017-04-12 17:16:52 (GMT)
commit1bfe1164f41dc328d54f7dc6ed13b2fabfde09f6 (patch)
treea5085d091ca7b73b62c4a2281a396860f58cd1e2
parentc3362fe866dd6368855905b8fbc6e828197cb538 (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 b2ac124..8053c80 100644
--- a/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp
+++ b/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp
@@ -162,8 +162,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();
}