Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp
Show First 20 Lines • Show All 157 Lines • ▼ Show 20 Line(s) | 155 | { | |||
---|---|---|---|---|---|
158 | endInsertRows(); | 158 | endInsertRows(); | ||
159 | } | 159 | } | ||
160 | 160 | | |||
161 | void ButtonsModel::move(int sourceIndex, int targetIndex) | 161 | void ButtonsModel::move(int sourceIndex, int targetIndex) | ||
162 | { | 162 | { | ||
163 | if (sourceIndex == qMax(0, targetIndex)) { | 163 | if (sourceIndex == qMax(0, targetIndex)) { | ||
164 | return; | 164 | return; | ||
165 | } | 165 | } | ||
166 | | ||||
167 | /* When moving an item down, the destination index needs to be incremented | ||||
168 | by one, as explained in the documentation: | ||||
169 | http://doc.qt.nokia.com/qabstractitemmodel.html#beginMoveRows */ | ||||
170 | if (targetIndex > sourceIndex) { | ||||
171 | // Row will be moved down | ||||
166 | beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), targetIndex + 1); | 172 | beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), targetIndex + 1); | ||
167 | m_buttons.insert(qMax(0, targetIndex), m_buttons.takeAt(sourceIndex)); | 173 | } else { | ||
174 | beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), qMax(0, targetIndex)); | ||||
175 | } | ||||
176 | | ||||
177 | m_buttons.move(sourceIndex, qMax(0, targetIndex)); | ||||
168 | endMoveRows(); | 178 | endMoveRows(); | ||
169 | } | 179 | } | ||
170 | 180 | | |||
171 | } | 181 | } | ||
172 | } | 182 | } | ||
173 | 183 | |