! * the spreadsheet can have empty rows at the end full with NaNs. * for the export we only need to export valid (non-empty) rows. * this functions determines the maximal row to export, or -1 * if the spreadsheet doesn't have any data yet. */
| 3978 | * if the spreadsheet doesn't have any data yet. |
| 3979 | */ |
| 3980 | int SpreadsheetView::maxRowToExport() const { |
| 3981 | int maxRow = -1; |
| 3982 | for (int j = 0; j < m_spreadsheet->columnCount(); ++j) { |
| 3983 | Column* col = m_spreadsheet->column(j); |
| 3984 | auto mode = col->columnMode(); |
| 3985 | if (mode == AbstractColumn::ColumnMode::Double) { |
| 3986 | for (int i = 0; i < m_spreadsheet->rowCount(); ++i) { |
| 3987 | if (!std::isnan(col->valueAt(i)) && i > maxRow) |
| 3988 | maxRow = i; |
| 3989 | } |
| 3990 | } |
| 3991 | if (mode == AbstractColumn::ColumnMode::Integer || mode == AbstractColumn::ColumnMode::BigInt) { |
| 3992 | // TODO: |
| 3993 | // integer column found. Since empty integer cells are equal to 0 |
| 3994 | // at the moment, we need to export the whole column. |
| 3995 | // this logic needs to be adjusted once we're able to descriminate |
| 3996 | // between empty and 0 values for integer columns |
| 3997 | maxRow = m_spreadsheet->rowCount() - 1; |
| 3998 | break; |
| 3999 | } else if (mode == AbstractColumn::ColumnMode::DateTime) { |
| 4000 | for (int i = 0; i < m_spreadsheet->rowCount(); ++i) { |
| 4001 | if (col->dateTimeAt(i).isValid() && i > maxRow) |
| 4002 | maxRow = i; |
| 4003 | } |
| 4004 | } else if (mode == AbstractColumn::ColumnMode::Text) { |
| 4005 | for (int i = 0; i < m_spreadsheet->rowCount(); ++i) { |
| 4006 | if (!col->textAt(i).isEmpty() && i > maxRow) |
| 4007 | maxRow = i; |
| 4008 | } |
| 4009 | } |
| 4010 | } |
| 4011 | |
| 4012 | return maxRow; |
| 4013 | } |
| 4014 | |
| 4015 | void SpreadsheetView::exportToFile(const QString& path, const bool exportHeader, const QString& separator, QLocale::Language language) const { |
| 4016 | QFile file(path); |
nothing calls this directly
no test coverage detected