Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp
Show First 20 Lines • Show All 147 Lines • ▼ Show 20 Line(s) | |||||
148 | { | 148 | { | ||
149 | beginInsertRows(QModelIndex(), m_buttons.count(), m_buttons.count()); | 149 | beginInsertRows(QModelIndex(), m_buttons.count(), m_buttons.count()); | ||
150 | m_buttons.append(type); | 150 | m_buttons.append(type); | ||
151 | endInsertRows(); | 151 | endInsertRows(); | ||
152 | } | 152 | } | ||
153 | 153 | | |||
154 | void ButtonsModel::add(int index, int type) | 154 | void ButtonsModel::add(int index, int type) | ||
155 | { | 155 | { | ||
156 | beginInsertRows(QModelIndex(), index + 1, index+1); | 156 | beginInsertRows(QModelIndex(), index, index); | ||
157 | m_buttons.insert(index+1, KDecoration2::DecorationButtonType(type)); | 157 | m_buttons.insert(index, KDecoration2::DecorationButtonType(type)); | ||
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 | 166 | | |||
167 | /* When moving an item down, the destination index needs to be incremented | 167 | /* When moving an item down, the destination index needs to be incremented | ||
168 | by one, as explained in the documentation: | 168 | by one, as explained in the documentation: | ||
169 | http://doc.qt.nokia.com/qabstractitemmodel.html#beginMoveRows */ | 169 | http://doc.qt.nokia.com/qabstractitemmodel.html#beginMoveRows */ | ||
davidedmundson: This still applies.
You're not seeing it because you now add +1 in your QML side, but that… | |||||
170 | if (targetIndex > sourceIndex) { | 170 | if (targetIndex > sourceIndex) { | ||
171 | // Row will be moved down | 171 | // Row will be moved down | ||
172 | beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), targetIndex + 1); | 172 | beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), targetIndex + 1); | ||
173 | } else { | 173 | } else { | ||
174 | beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), qMax(0, targetIndex)); | 174 | beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), qMax(0, targetIndex)); | ||
175 | } | 175 | } | ||
176 | 176 | | |||
177 | m_buttons.move(sourceIndex, qMax(0, targetIndex)); | 177 | m_buttons.move(sourceIndex, qMax(0, targetIndex)); | ||
178 | endMoveRows(); | 178 | endMoveRows(); | ||
179 | } | 179 | } | ||
180 | 180 | | |||
181 | void ButtonsModel::clear() | ||||
182 | { | ||||
183 | beginResetModel(); | ||||
184 | m_buttons.clear(); | ||||
185 | endResetModel(); | ||||
186 | } | ||||
187 | | ||||
181 | } | 188 | } | ||
182 | } | 189 | } | ||
183 | 190 | |
This still applies.
You're not seeing it because you now add +1 in your QML side, but that makes the guard at the top wrong and the else statement here wrong.
I would suggest adding https://doc.qt.io/qt-5.11/qabstractitemmodeltester.html whilst you're doing dev work and you'll see this crash.