| 1732 | } |
| 1733 | |
| 1734 | void 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 | /* |
| 1789 | bool determineLocale(const QString& value, QLocale& locale) { |
| 1790 | int pointIndex = value.indexOf(QLatin1Char('.')); |
nothing calls this directly
no test coverage detected