MCPcopy Create free account
hub / github.com/davy7125/polyphone / copy

Method copy

sources/editor/widgets/tablewidget.cpp:273–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271}
272
273void TableWidget::copy()
274{
275 if (selectedItems().isEmpty())
276 {
277 // no items selected
278 QApplication::clipboard()->setText("");
279 }
280 else
281 {
282 // Selected items
283 // They may not be contiguous!
284 QModelIndexList indexes = selectionModel()->selectedIndexes();
285
286 // Row 0 is for selection
287 int indexNumber = indexes.size();
288 for (int i = indexNumber - 1; i >= 0; i--)
289 if (indexes.at(i).row() == 0)
290 indexes.removeAt(i);
291
292 QMap<int, QMap<int, QString> > mapText;
293 foreach (QModelIndex index, indexes)
294 {
295 QString text = model()->data(index).toString();
296
297 // Maybe data comes from the UserRole (loopmode?)
298 if (!model()->data(index, Qt::UserRole).isNull())
299 text = QString::number(model()->data(index, Qt::UserRole).toInt());
300
301 // "!" stands for "erase", empty cell in the selection
302 if (text.isEmpty())
303 text = "!";
304 mapText[index.row()][index.column()] = text;
305 }
306
307 int minRow = mapText.keys().first();
308 int maxRow = mapText.keys().last();
309
310 int minCol = -1;
311 int maxCol = -1;
312 QMap<int, QString> mapTmp;
313 foreach (mapTmp, mapText.values())
314 {
315 int minColTmp = mapTmp.keys().first();
316 int maxColTmp = mapTmp.keys().last();
317 if (minCol == -1)
318 minCol = minColTmp;
319 else
320 minCol = qMin(minCol, minColTmp);
321 if (maxCol == -1)
322 maxCol = maxColTmp;
323 else
324 maxCol = qMax(maxCol, maxColTmp);
325 }
326
327 QString selected_text;
328 for (int numRow = minRow; numRow <= maxRow; numRow++)
329 {
330 if (numRow != minRow)

Callers

nothing calls this directly

Calls 5

setTextMethod · 0.80
valuesMethod · 0.80
foreachFunction · 0.70
sizeMethod · 0.45
rowMethod · 0.45

Tested by

no test coverage detected