@@ -57,6 +57,33 @@ void ExtendedTableWidget::copy()
57
57
return ;
58
58
}
59
59
60
+ m_buffer.clear ();
61
+
62
+ // If any of the cells contain binary data - we use inner buffer
63
+ bool containsBinary = false ;
64
+ SqliteTableModel* m = qobject_cast<SqliteTableModel*>(model ());
65
+ foreach (const QModelIndex& index, indices)
66
+ if (m->isBinary (index)) {
67
+ containsBinary = true ;
68
+ break ;
69
+ }
70
+
71
+ if (containsBinary) {
72
+ qApp->clipboard ()->clear ();
73
+ // Copy selected data into inner buffer
74
+ int columns = indices.last ().column () - indices.first ().column () + 1 ;
75
+ while (!indices.isEmpty ()) {
76
+ QByteArrayList lst;
77
+ for (int i = 0 ; i < columns; ++i) {
78
+ lst << indices.first ().data (Qt::EditRole).toByteArray ();
79
+ indices.pop_front ();
80
+ }
81
+ m_buffer.push_back (lst);
82
+ }
83
+
84
+ return ;
85
+ }
86
+
60
87
QModelIndex first = indices.first ();
61
88
QString result;
62
89
int currentRow = 0 ;
@@ -82,8 +109,6 @@ void ExtendedTableWidget::copy()
82
109
83
110
void ExtendedTableWidget::paste ()
84
111
{
85
- QString clipboard = qApp->clipboard ()->text ();
86
-
87
112
// Get list of selected items
88
113
QItemSelectionModel* selection = selectionModel ();
89
114
QModelIndexList indices = selection->selectedIndexes ();
@@ -92,6 +117,42 @@ void ExtendedTableWidget::paste()
92
117
if (indices.isEmpty ())
93
118
return ;
94
119
120
+ SqliteTableModel* m = qobject_cast<SqliteTableModel*>(model ());
121
+
122
+ if (qApp->clipboard ()->text ().isEmpty () && !m_buffer.isEmpty ()) {
123
+ // If buffer contains something - use it instead of clipboard
124
+ int rows = m_buffer.size ();
125
+ int columns = m_buffer.first ().size ();
126
+
127
+ int firstRow = indices.front ().row ();
128
+ int firstColumn = indices.front ().column ();
129
+
130
+ int lastRow = qMin (firstRow + rows - 1 , m->rowCount () - 1 );
131
+ int lastColumn = qMin (firstColumn + columns - 1 , m->columnCount () - 1 );
132
+
133
+ int row = firstRow;
134
+
135
+ foreach (const QByteArrayList& lst, m_buffer) {
136
+ int column = firstColumn;
137
+ foreach (const QByteArray& ba, lst) {
138
+ m->setData (m->index (row, column), ba);
139
+
140
+ column++;
141
+ if (column > lastColumn)
142
+ break ;
143
+ }
144
+
145
+ row++;
146
+ if (row > lastRow)
147
+ break ;
148
+ }
149
+
150
+ return ;
151
+ }
152
+
153
+
154
+ QString clipboard = qApp->clipboard ()->text ();
155
+
95
156
// Find out end of line character
96
157
QString endOfLine;
97
158
if (clipboard.endsWith (' \n ' ))
@@ -155,7 +216,6 @@ void ExtendedTableWidget::paste()
155
216
// Here we have positive answer even if cliboard is bigger than selection
156
217
157
218
158
- SqliteTableModel* m = qobject_cast<SqliteTableModel*>(model ());
159
219
// If last row and column are after table size clamp it
160
220
int lastRow = qMin (firstRow + clipboardRows - 1 , m->rowCount () - 1 );
161
221
int lastColumn = qMin (firstColumn + clipboardColumns - 1 , m->columnCount () - 1 );
0 commit comments