| 237 | } |
| 238 | |
| 239 | void OdsFilterPrivate::readCurrentSheet(const QString& fileName, AbstractDataSource* dataSource, AbstractFileFilter::ImportMode importMode) { |
| 240 | DEBUG(Q_FUNC_INFO << ", current sheet name = " << currentSheetName.toStdString() << ", first row as column names = " << firstRowAsColumnNames) |
| 241 | |
| 242 | if (!dataSource) |
| 243 | return; |
| 244 | |
| 245 | #ifdef HAVE_ORCUS |
| 246 | DEBUG(Q_FUNC_INFO << ", sheet count = " << m_document.get_sheet_count()) |
| 247 | if (m_document.get_sheet_count() == 0) { // not loaded yet |
| 248 | DEBUG(Q_FUNC_INFO << ", loading file " << fileName.toStdString()) |
| 249 | m_document.clear(); |
| 250 | spreadsheet::import_factory factory{m_document}; |
| 251 | orcus_ods loader(&factory); |
| 252 | |
| 253 | loader.read_file(fileName.toStdString()); |
| 254 | } |
| 255 | |
| 256 | // get sheet index from name and read data into dataSource |
| 257 | auto* sheet = m_document.get_sheet(currentSheetName.toStdString()); |
| 258 | if (!sheet) { |
| 259 | DEBUG(Q_FUNC_INFO << ", sheet not found: " << currentSheetName.toStdString()) |
| 260 | q->setLastError(i18n("Selected sheet not found.")); |
| 261 | return; |
| 262 | } |
| 263 | |
| 264 | const auto sheetIndex = sheet->get_index(); |
| 265 | if (sheetIndex == ixion::invalid_sheet) { |
| 266 | DEBUG(Q_FUNC_INFO << ", invalid sheet") |
| 267 | q->setLastError(i18n("Invalid sheet.")); |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | auto ranges = sheet->get_data_range(); |
| 272 | DEBUG(Q_FUNC_INFO << ", data range: col " << ranges.first.column << ".." << ranges.last.column << ", row " << ranges.first.row << ".." << ranges.last.row) |
| 273 | if (firstRowAsColumnNames) // skip first row |
| 274 | ranges.first.row++; |
| 275 | size_t actualRows = ranges.last.row - ranges.first.row + 1; |
| 276 | size_t actualEndRow = (endRow == -1 ? ranges.last.row + 1 : endRow); |
| 277 | if ((size_t)startRow > actualRows) |
| 278 | startRow = 1; // start from the begining |
| 279 | DEBUG(Q_FUNC_INFO << ", start/end row = " << startRow << " " << endRow) |
| 280 | DEBUG(Q_FUNC_INFO << ", start/end col = " << startColumn << " " << endColumn) |
| 281 | actualRows = std::min(actualRows - startRow, (size_t)(actualEndRow - startRow)) + 1; |
| 282 | |
| 283 | size_t actualCols = ranges.last.column - ranges.first.column + 1; |
| 284 | size_t actualEndColumn = (endColumn == -1 ? ranges.last.column + 1 : endColumn); |
| 285 | if ((size_t)startColumn > actualCols) |
| 286 | startColumn = 1; // start from the begining |
| 287 | actualCols = std::min(actualCols - startColumn, (size_t)(actualEndColumn - startColumn)) + 1; |
| 288 | |
| 289 | DEBUG(Q_FUNC_INFO << ", actual rows/cols = " << actualRows << " " << actualCols) |
| 290 | if (actualRows < 1 || actualCols < 1) { |
| 291 | DEBUG(Q_FUNC_INFO << ", no actual rows of columns") |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | // column modes |
| 296 | QVector<AbstractColumn::ColumnMode> columnModes; |
nothing calls this directly
no test coverage detected