MCPcopy Create free account
hub / github.com/KDE/labplot / copySelection

Method copySelection

src/frontend/spreadsheet/SpreadsheetView.cpp:1734–1787  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1732}
1733
1734void SpreadsheetView::copySelection() {
1735 PERFTRACE(QStringLiteral("copy selected cells"));
1736 const int first_col = firstSelectedColumn();
1737 if (first_col == -1)
1738 return;
1739 const int last_col = lastSelectedColumn();
1740 if (last_col == -2)
1741 return;
1742 const int first_row = firstSelectedRow();
1743 if (first_row == -1)
1744 return;
1745 const int last_row = lastSelectedRow();
1746 if (last_row == -2)
1747 return;
1748 const int cols = last_col - first_col + 1;
1749 const int rows = last_row - first_row + 1;
1750
1751 WAIT_CURSOR;
1752 QString output_str;
1753
1754 QVector<Column*> columns;
1755 QVector<char> formats;
1756 for (int c = 0; c < cols; c++) {
1757 Column* col = m_spreadsheet->column(first_col + c);
1758 columns << col;
1759 const auto* outFilter = static_cast<Double2StringFilter*>(col->outputFilter());
1760 formats << outFilter->numericFormat();
1761 }
1762
1763 const auto numberLocale = QLocale();
1764 for (int r = 0; r < rows; r++) {
1765 for (int c = 0; c < cols; c++) {
1766 const Column* col_ptr = columns.at(c);
1767 if (isCellSelected(first_row + r, first_col + c)) {
1768 // if (formulaModeActive())
1769 // output_str += col_ptr->formula(first_row + r);
1770 // else
1771 if (col_ptr->columnMode() == AbstractColumn::ColumnMode::Double)
1772 output_str += numberLocale.toString(col_ptr->valueAt(first_row + r), formats.at(c), 16); // copy with max. precision
1773 else if (col_ptr->columnMode() == AbstractColumn::ColumnMode::Integer || col_ptr->columnMode() == AbstractColumn::ColumnMode::BigInt)
1774 output_str += numberLocale.toString(col_ptr->valueAt(first_row + r));
1775 else
1776 output_str += col_ptr->asStringColumn()->textAt(first_row + r);
1777 }
1778 if (c < cols - 1)
1779 output_str += QLatin1Char('\t');
1780 }
1781 if (r < rows - 1)
1782 output_str += QLatin1Char('\n');
1783 }
1784
1785 QApplication::clipboard()->setText(output_str);
1786 RESET_CURSOR;
1787}
1788/*
1789bool determineLocale(const QString& value, QLocale& locale) {
1790 int pointIndex = value.indexOf(QLatin1Char('.'));

Callers

nothing calls this directly

Calls 9

numericFormatMethod · 0.80
asStringColumnMethod · 0.80
columnMethod · 0.45
outputFilterMethod · 0.45
columnModeMethod · 0.45
toStringMethod · 0.45
valueAtMethod · 0.45
textAtMethod · 0.45
setTextMethod · 0.45

Tested by

no test coverage detected