| 742 | } |
| 743 | |
| 744 | void AddSubtractValueDialog::generateForColumn(Column* col, int colIndex) { |
| 745 | // in case the result was already calculated for the first column for the preview, |
| 746 | // no need to calculate it again, re-use the already available result |
| 747 | if (colIndex == 0 && !m_previewDirty) { |
| 748 | // for the baseline subraction the mode has to be Double, set it if not the case yet |
| 749 | if (m_operation == SubtractBaseline && col->columnMode() != AbstractColumn::ColumnMode::Double) |
| 750 | col->setColumnMode(AbstractColumn::ColumnMode::Double); |
| 751 | col->copy(m_yColumnResult); |
| 752 | return; |
| 753 | } |
| 754 | |
| 755 | const auto mode = col->columnMode(); |
| 756 | const int rows = m_spreadsheet->rowCount(); |
| 757 | |
| 758 | if (mode == AbstractColumn::ColumnMode::Integer) { |
| 759 | int value; |
| 760 | setIntValue(value, colIndex); |
| 761 | auto* data = static_cast<QVector<int>*>(col->data()); |
| 762 | QVector<int> new_data(rows); |
| 763 | |
| 764 | switch (m_operation) { |
| 765 | case SubtractBaseline: { |
| 766 | // copy the int data to doubles |
| 767 | QVector<double> new_data(rows); |
| 768 | for (int i = 0; i < rows; ++i) |
| 769 | new_data[i] = data->at(i); |
| 770 | |
| 771 | subtractBaseline(new_data); |
| 772 | |
| 773 | // convert the column mode from int to double and subtract the baseline |
| 774 | col->setColumnMode(AbstractColumn::ColumnMode::Double); |
| 775 | col->setValues(new_data); |
| 776 | break; |
| 777 | } |
| 778 | case Subtract: |
| 779 | value *= -1.; |
| 780 | [[fallthrough]]; |
| 781 | case Add: { |
| 782 | for (int i = 0; i < rows; ++i) |
| 783 | new_data[i] = data->at(i) + value; |
| 784 | |
| 785 | col->setIntegers(new_data); |
| 786 | break; |
| 787 | } |
| 788 | case Multiply: |
| 789 | for (int i = 0; i < rows; ++i) |
| 790 | new_data[i] = data->at(i) * value; |
| 791 | |
| 792 | col->setIntegers(new_data); |
| 793 | break; |
| 794 | case Divide: |
| 795 | for (int i = 0; i < rows; ++i) |
| 796 | new_data[i] = data->at(i) / value; |
| 797 | |
| 798 | col->setIntegers(new_data); |
| 799 | break; |
| 800 | } |
| 801 | } else if (mode == AbstractColumn::ColumnMode::BigInt) { |
nothing calls this directly
no test coverage detected