From 5c64d59d8a315e91a3452a138fa9644efc45387d Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 18 Nov 2019 12:41:48 +0100 Subject: [PATCH] Debugger: Fix copying stack content to clipboard Change-Id: I41240e15235a4906439a514fcf56fa1f7ddc8a80 Fixes: QTCREATORBUG-23199 Reviewed-by: Christian Stenger --- src/plugins/debugger/stackhandler.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/plugins/debugger/stackhandler.cpp b/src/plugins/debugger/stackhandler.cpp index 65c6f092643..ea26e929995 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 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);