MCPcopy Create free account
hub / github.com/KDE/labplot / prepareImport

Method prepareImport

src/backend/spreadsheet/Spreadsheet.cpp:1326–1434  ·  view source on GitHub ↗

############################################################################## ######################## Data Import ####################################### ##############################################################################

Source from the content-addressed store, hash-verified

1324// ######################## Data Import #######################################
1325// ##############################################################################
1326int Spreadsheet::prepareImport(std::vector<void*>& dataContainer,
1327 AbstractFileFilter::ImportMode importMode,
1328 int actualRows,
1329 int actualCols,
1330 const QStringList& colNameList,
1331 const QVector<AbstractColumn::ColumnMode>& columnMode,
1332 bool& ok,
1333 bool initializeContainer) {
1334 Q_D(Spreadsheet);
1335 PERFTRACE(QLatin1String(Q_FUNC_INFO));
1336 DEBUG(Q_FUNC_INFO << ", resize spreadsheet to rows = " << actualRows << " and cols = " << actualCols)
1337 QDEBUG(Q_FUNC_INFO << ", column name list = " << colNameList)
1338 assert(d->m_usedInPlots.size() == 0);
1339 int columnOffset = 0;
1340 setUndoAware(false);
1341 if (m_model != nullptr)
1342 m_model->suppressSignals(true);
1343
1344 // make the available columns undo unaware before we resize and rename them below,
1345 // the same will be done for new columns in this->resize().
1346 {
1347 const auto& columns = children<Column>();
1348 for (auto* column : std::as_const(columns))
1349 column->setUndoAware(false);
1350 }
1351
1352 columnOffset = this->resize(importMode, colNameList, actualCols);
1353 if (initializeContainer)
1354 dataContainer.resize(actualCols);
1355 const auto& columns = children<Column>(); // Get new children because of the resize it might be different
1356
1357 // resize the spreadsheet
1358 if (initializeContainer) {
1359 try {
1360 if (importMode == AbstractFileFilter::ImportMode::Replace) {
1361 clear();
1362 setRowCount(actualRows);
1363 } else {
1364 if (rowCount() < actualRows)
1365 setRowCount(actualRows);
1366 }
1367 } catch (std::bad_alloc&) {
1368 ok = false;
1369 return 0;
1370 }
1371 }
1372
1373 if (columnMode.size() < actualCols) {
1374 QDEBUG(Q_FUNC_INFO << ", columnMode[] size " << columnMode.size() << " is too small, should be " << actualCols << "! Giving up.");
1375 return -1;
1376 }
1377
1378 for (int n = 0; n < actualCols; n++) {
1379 // data() returns a void* which is a pointer to any data type (see ColumnPrivate.cpp)
1380 auto* column = columns.at(columnOffset + n);
1381 DEBUG(" column " << n << " columnMode = " << ENUM_TO_STRING(AbstractColumn, ColumnMode, columnMode[n]));
1382 column->setColumnModeFast(columnMode[n]);
1383

Callers

nothing calls this directly

Calls 9

resizeMethod · 0.95
rowCountFunction · 0.85
suppressSignalsMethod · 0.80
setUndoAwareMethod · 0.80
setColumnModeFastMethod · 0.80
sizeMethod · 0.45
setPlotDesignationMethod · 0.45
dataMethod · 0.45
setDataMethod · 0.45

Tested by

no test coverage detected