MCPcopy Create free account
hub / github.com/Zalafina/QKeyMapper / mappingSequenceTableDragDropMove

Method mappingSequenceTableDragDropMove

QKeyMapper/qmappingsequenceedit.cpp:1201–1262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1199}
1200
1201void QMappingSequenceEdit::mappingSequenceTableDragDropMove(int top_row, int bottom_row, int dragged_to)
1202{
1203 MappingSequenceEditTableWidget *table = ui->mappingSequenceEditTable;
1204
1205 const int rowCount = m_MappingSequenceList.size();
1206 if (rowCount <= 0) {
1207 return;
1208 }
1209
1210 top_row = qBound(0, top_row, rowCount - 1);
1211 bottom_row = qBound(0, bottom_row, rowCount - 1);
1212 if (top_row > bottom_row) {
1213 qSwap(top_row, bottom_row);
1214 }
1215
1216 dragged_to = qBound(0, dragged_to, rowCount - 1);
1217
1218 const int draggedCount = bottom_row - top_row + 1;
1219 if (draggedCount <= 0) {
1220 return;
1221 }
1222
1223 // If dropping inside the dragged range, no-op.
1224 if (dragged_to >= top_row && dragged_to <= bottom_row) {
1225 return;
1226 }
1227
1228 ensureBaseSnapshotBeforeListChange();
1229
1230 const bool isDraggedToBottom = (dragged_to > bottom_row);
1231
1232 QStringList moved;
1233 moved.reserve(draggedCount);
1234 for (int i = top_row; i <= bottom_row; ++i) {
1235 moved.append(m_MappingSequenceList.at(i));
1236 }
1237
1238 // Remove original block
1239 for (int i = 0; i < draggedCount; ++i) {
1240 m_MappingSequenceList.removeAt(top_row);
1241 }
1242
1243 int insertPos = dragged_to;
1244 if (isDraggedToBottom) {
1245 // List shrinks above the drop target.
1246 insertPos = dragged_to - draggedCount + 1;
1247 }
1248 insertPos = qBound(0, insertPos, m_MappingSequenceList.size());
1249
1250 for (int i = 0; i < moved.size(); ++i) {
1251 m_MappingSequenceList.insert(insertPos + i, moved.at(i));
1252 }
1253
1254 refreshMappingSequenceEditTableWidget(table, m_MappingSequenceList);
1255
1256 const int newTop = insertPos;
1257 const int newBottom = insertPos + draggedCount - 1;
1258 reselectionRangeAndScroll(newTop, newBottom);

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.80
insertMethod · 0.80

Tested by

no test coverage detected