Commit 5af228b8 authored by Jordan P. Lefebvre's avatar Jordan P. Lefebvre
Browse files

Adding paste functionality to TableView.

parent b104d235
Pipeline #13849 failed with stages
in 6 minutes and 15 seconds
......@@ -122,7 +122,37 @@ void TableView::copy()
QApplication::clipboard()->setText(data);
}
void TableView::paste() { radix_tagged_line("paste()"); }
void TableView::paste()
{
radix_tagged_line("paste()");
QModelIndex selectedCell = currentIndex();
if (selectedCell.isValid() == false) selectedCell = model()->index(0, 0);
// store in clipboard
QString text = QApplication::clipboard()->text();
// split into lines
QStringList rows = text.split("\n", QString::SkipEmptyParts);
for (int r = 0; r < rows.size(); ++r)
{
if (model()->rowCount() == r)
{
model()->insertRow(r);
}
QStringList columns = rows.at(r).split(p->separator);
for (int c = 0; c < columns.size(); ++c)
{
if (model()->columnCount() == c)
{
model()->insertColumn(c);
}
model()->setData(
model()->index(selectedCell.row() + r, selectedCell.column() + c),
columns.at(c));
}
}
}
void TableView::keyPressEvent(QKeyEvent *event)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment