Skip to content

Commit

Permalink
Improved itemselection copy
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkvdb committed Nov 8, 2018
1 parent 86028ef commit 86f658e
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions ui/tabletools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,18 @@ void itemSelectionToClipboard(const QItemSelectionModel* selectionModel)
return;
}

QStringList currentRow;
std::map<int, QStringList> rows;

QString selected_text;
// You need a pair of indexes to find the row changes
int previousRow = indexes.front().row();
for (auto& current : indexes) {
if (current.row() != previousRow) {
selected_text.append(currentRow.join('\t'));
selected_text.append('\n');
currentRow.clear();
}

currentRow.append(model->data(current).toString());
previousRow = current.row();
rows[current.row()].append(model->data(current).toString());
}

if (!currentRow.empty()) {
selected_text.append(currentRow.join('\t'));
QStringList rowStrings;
for (auto& row : rows) {
rowStrings.push_back(row.second.join('\t'));
}

QApplication::clipboard()->setText(selected_text);
QApplication::clipboard()->setText(rowStrings.join('\n'));
}
}

0 comments on commit 86f658e

Please sign in to comment.