| 2460 | } |
| 2461 | |
| 2462 | void SpreadsheetView::fillSelectedCellsWithConstValues() { |
| 2463 | const auto& columns = selectedColumns(false); |
| 2464 | if (columns.isEmpty()) |
| 2465 | return; |
| 2466 | |
| 2467 | int first = firstSelectedRow(); |
| 2468 | int last = lastSelectedRow(); |
| 2469 | if (first < 0) |
| 2470 | return; |
| 2471 | |
| 2472 | bool doubleOk = false; |
| 2473 | bool intOk = false; |
| 2474 | bool bigIntOk = false; |
| 2475 | bool stringOk = false; |
| 2476 | double doubleValue = 0; |
| 2477 | int intValue = 0; |
| 2478 | qint64 bigIntValue = 0; |
| 2479 | QString stringValue; |
| 2480 | |
| 2481 | m_spreadsheet->beginMacro(i18n("%1: fill cells with const values", m_spreadsheet->name())); |
| 2482 | for (auto* col_ptr : columns) { |
| 2483 | int col = m_spreadsheet->indexOfChild<Column>(col_ptr); |
| 2484 | col_ptr->setSuppressDataChangedSignal(true); |
| 2485 | col_ptr->clearFormula(); // clear the potentially available column formula |
| 2486 | |
| 2487 | switch (col_ptr->columnMode()) { |
| 2488 | case AbstractColumn::ColumnMode::Double: |
| 2489 | if (!doubleOk) |
| 2490 | doubleValue = QInputDialog::getDouble(this, |
| 2491 | i18n("Fill the selection with constant value"), |
| 2492 | i18n("Value"), |
| 2493 | 0, |
| 2494 | -std::numeric_limits<double>::max(), |
| 2495 | std::numeric_limits<double>::max(), |
| 2496 | 6, |
| 2497 | &doubleOk); |
| 2498 | if (doubleOk) { |
| 2499 | WAIT_CURSOR; |
| 2500 | QVector<double> results(last - first + 1); |
| 2501 | for (int row = first; row <= last; row++) { |
| 2502 | if (isCellSelected(row, col)) |
| 2503 | results[row - first] = doubleValue; |
| 2504 | else |
| 2505 | results[row - first] = col_ptr->valueAt(row); |
| 2506 | } |
| 2507 | col_ptr->replaceValues(first, results); |
| 2508 | RESET_CURSOR; |
| 2509 | } |
| 2510 | break; |
| 2511 | case AbstractColumn::ColumnMode::Integer: |
| 2512 | if (!intOk) |
| 2513 | intValue = QInputDialog::getInt(this, i18n("Fill the selection with constant value"), i18n("Value"), 0, -2147483647, 2147483647, 1, &intOk); |
| 2514 | if (intOk) { |
| 2515 | WAIT_CURSOR; |
| 2516 | QVector<int> results(last - first + 1); |
| 2517 | for (int row = first; row <= last; row++) { |
| 2518 | if (isCellSelected(row, col)) |
| 2519 | results[row - first] = intValue; |
nothing calls this directly
no test coverage detected