From f05a049bdb2b5dda2583a2b9ae447a0055c282f7 Mon Sep 17 00:00:00 2001 From: Vladislav Tronko Date: Thu, 13 Oct 2016 23:10:46 +0300 Subject: [PATCH] Fix cells copying With this commit, we start to handle empty and NULL single cell selections in a special way. Well, there's nothing special about it. We just push them to inner buffer and clear outer clipboard. That's it. NB: possible side effect might appear if you copy empty value, then select some text and paste your empty value here. Nothing will happen with text though, because, well, we wiped clipboard. Plus, it fixes single-cell multiline text copy-pasting (#541) --- src/ExtendedTableWidget.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ExtendedTableWidget.cpp b/src/ExtendedTableWidget.cpp index fd0cfe581f..a50067ff38 100644 --- a/src/ExtendedTableWidget.cpp +++ b/src/ExtendedTableWidget.cpp @@ -88,6 +88,8 @@ void ExtendedTableWidget::copy() SqliteTableModel* m = qobject_cast(model()); + m_buffer.clear(); + // If a single cell is selected, copy it to clipboard if (indices.size() == 1) { QImage img; @@ -97,13 +99,23 @@ void ExtendedTableWidget::copy() qApp->clipboard()->setImage(img); return; } else { - qApp->clipboard()->setText(data.toString()); + QString text = data.toString(); + if (text.isEmpty()) { + // NULL and empty single-cells are handled via inner buffer + qApp->clipboard()->clear(); + QByteArrayList lst; + lst << data.toByteArray(); + m_buffer.push_back(lst); + return; + } + + if (text.contains('\n')) + text = QString("\"%1\"").arg(text); + qApp->clipboard()->setText(text); return; } } - m_buffer.clear(); - // If any of the cells contain binary data - we use inner buffer bool containsBinary = false; foreach (const QModelIndex& index, indices)