From b00f7e17239784faa4243af1c83f22cf2f2f127a Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 2 Feb 2016 16:28:43 +0100 Subject: Align copied stacktrace contents with spaces instead of tabs So that they are properly aligned in columns. Change-Id: I71279133492fee477541e255da809662b6f1ba5a Reviewed-by: hjk --- src/plugins/debugger/stackwindow.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/plugins/debugger/stackwindow.cpp') diff --git a/src/plugins/debugger/stackwindow.cpp b/src/plugins/debugger/stackwindow.cpp index f02b7ca056..248e8c19a5 100644 --- a/src/plugins/debugger/stackwindow.cpp +++ b/src/plugins/debugger/stackwindow.cpp @@ -244,11 +244,27 @@ void StackTreeView::copyContentsToClipboard() QString str; int n = model()->rowCount(); int m = model()->columnCount(); + 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) { + for (int j = 0; j < m; ++j) { + const QModelIndex index = model()->index(i, j); + const int columnWidth = model()->data(index).toString().size(); + if (columnWidth > largestColumnWidths.at(j)) + largestColumnWidths[j] = columnWidth; + } + } + for (int i = 0; i != n; ++i) { for (int j = 0; j != m; ++j) { QModelIndex index = model()->index(i, j); - str += model()->data(index).toString(); - str += QLatin1Char('\t'); + const QString columnEntry = model()->data(index).toString(); + str += columnEntry; + const int difference = largestColumnWidths.at(j) - columnEntry.size(); + // Add one extra space between columns. + str += QString().fill(QLatin1Char(' '), difference > 0 ? difference + 1 : 1); } str += QLatin1Char('\n'); } -- cgit v1.2.1