diff options
author | hjk <hjk@qt.io> | 2019-11-18 12:41:48 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2019-11-20 14:55:32 +0000 |
commit | 5c64d59d8a315e91a3452a138fa9644efc45387d (patch) | |
tree | 8198760e8b0f02aadf005bb7826cffafb1b0849b | |
parent | da25ac632263d16b1ebb9cd3fee195f0dbb8d72d (diff) | |
download | qt-creator-5c64d59d8a315e91a3452a138fa9644efc45387d.tar.gz |
Debugger: Fix copying stack content to clipboard
Change-Id: I41240e15235a4906439a514fcf56fa1f7ddc8a80
Fixes: QTCREATORBUG-23199
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | src/plugins/debugger/stackhandler.cpp | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/plugins/debugger/stackhandler.cpp b/src/plugins/debugger/stackhandler.cpp index 65c6f09264..ea26e92999 100644 --- a/src/plugins/debugger/stackhandler.cpp +++ b/src/plugins/debugger/stackhandler.cpp @@ -457,33 +457,31 @@ bool StackHandler::contextMenuEvent(const ItemViewEvent &ev) void StackHandler::copyContentsToClipboard() { - QString str; - int n = rowCount(); - int m = columnCount(QModelIndex()); + const int m = columnCount(QModelIndex()); QVector<int> largestColumnWidths(m, 0); // First, find the widths of the largest columns, // so that we can print them out nicely aligned. - for (int i = 0; i != n; ++i) { + forItemsAtLevel<2>([m, &largestColumnWidths](StackFrameItem *item) { for (int j = 0; j < m; ++j) { - const QModelIndex idx = index(i, j); - const int columnWidth = data(idx, Qt::DisplayRole).toString().size(); + const int columnWidth = item->data(j, Qt::DisplayRole).toString().size(); if (columnWidth > largestColumnWidths.at(j)) largestColumnWidths[j] = columnWidth; } - } + }); - for (int i = 0; i != n; ++i) { + QString str; + forItemsAtLevel<2>([m, largestColumnWidths, &str](StackFrameItem *item) { for (int j = 0; j != m; ++j) { - QModelIndex idx = index(i, j); - const QString columnEntry = data(idx, Qt::DisplayRole).toString(); + const QString columnEntry = item->data(j, Qt::DisplayRole).toString(); str += columnEntry; const int difference = largestColumnWidths.at(j) - columnEntry.size(); // Add one extra space between columns. - str += QString().fill(' ', difference > 0 ? difference + 1 : 1); + str += QString(qMax(difference, 0) + 1, QChar(' ')); } str += '\n'; - } + }); + QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(str, QClipboard::Selection); clipboard->setText(str, QClipboard::Clipboard); |