When copy-pasting from a treeview, trim each line individually

* This helps with views that have icon-only columns at the start or end, which
  would generate unnecessary whitespace when copying multiple lines.
This commit is contained in:
baldurk
2021-07-22 11:08:28 +01:00
parent 92efebd5f0
commit f06171f733
2 changed files with 5 additions and 4 deletions
+5 -3
View File
@@ -604,6 +604,8 @@ void RDTreeView::copySelection()
int depth = GetDepth(model(), idx);
QString line;
for(int i = 0; i < colCount; i++)
{
QString format = i == 0 ? QFormatStr("%1") : QFormatStr(" %1");
@@ -614,14 +616,14 @@ void RDTreeView::copySelection()
if(i == 0)
text.prepend(QString((depth - minDepth) * 2, QLatin1Char(' ')));
clipData += format.arg(text, -widths[i]);
line += format.arg(text, -widths[i]);
}
clipData += lit("\n");
clipData += line.trimmed() + lit("\n");
}
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(clipData.trimmed());
clipboard->setText(clipData);
}
void RDTreeView::updateExpansionFromRow(RDTreeViewExpansionState &state, QModelIndex idx, uint seed,
@@ -24,7 +24,6 @@
#include "RDTreeWidget.h"
#include <QApplication>
#include <QClipboard>
#include <QColor>
#include <QDebug>
#include <QHeaderView>