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

Method copy

src/backend/core/column/ColumnPrivate.cpp:1411–1467  ·  view source on GitHub ↗

* \brief Copy another column of the same type * * This function will return false if the data type * of 'other' is not the same as the type of 'this'. * Use a filter to convert a column to another type. */

Source from the content-addressed store, hash-verified

1409 * Use a filter to convert a column to another type.
1410 */
1411bool ColumnPrivate::copy(const AbstractColumn* other) {
1412 DEBUG(Q_FUNC_INFO)
1413 if (other->columnMode() != columnMode())
1414 return false;
1415 // DEBUG(Q_FUNC_INFO << ", mode = " << ENUM_TO_STRING(AbstractColumn, ColumnMode, columnMode()));
1416 int num_rows = other->rowCount();
1417 // DEBUG(Q_FUNC_INFO << ", rows " << num_rows);
1418
1419 Q_EMIT q->dataAboutToChange(q);
1420 resizeTo(num_rows);
1421
1422 if (!m_data) {
1423 if (!initDataContainer())
1424 return false; // failed to allocate memory
1425 }
1426
1427 // copy the data
1428 switch (m_columnMode) {
1429 case AbstractColumn::ColumnMode::Double: {
1430 double* ptr = static_cast<QVector<double>*>(m_data)->data();
1431 for (int i = 0; i < num_rows; ++i)
1432 ptr[i] = other->valueAt(i);
1433 break;
1434 }
1435 case AbstractColumn::ColumnMode::Integer: {
1436 int* ptr = static_cast<QVector<int>*>(m_data)->data();
1437 for (int i = 0; i < num_rows; ++i)
1438 ptr[i] = other->integerAt(i);
1439 break;
1440 }
1441 case AbstractColumn::ColumnMode::BigInt: {
1442 qint64* ptr = static_cast<QVector<qint64>*>(m_data)->data();
1443 for (int i = 0; i < num_rows; ++i)
1444 ptr[i] = other->bigIntAt(i);
1445 break;
1446 }
1447 case AbstractColumn::ColumnMode::Text: {
1448 auto* vec = static_cast<QVector<QString>*>(m_data);
1449 for (int i = 0; i < num_rows; ++i)
1450 vec->replace(i, other->textAt(i));
1451 break;
1452 }
1453 case AbstractColumn::ColumnMode::DateTime:
1454 case AbstractColumn::ColumnMode::Month:
1455 case AbstractColumn::ColumnMode::Day: {
1456 auto* vec = static_cast<QVector<QDateTime>*>(m_data);
1457 for (int i = 0; i < num_rows; ++i)
1458 vec->replace(i, other->dateTimeAt(i));
1459 break;
1460 }
1461 }
1462
1463 q->setChanged();
1464
1465 DEBUG(Q_FUNC_INFO << ", done")
1466 return true;
1467}
1468

Callers

nothing calls this directly

Calls 11

rowCountFunction · 0.85
replaceMethod · 0.80
columnModeMethod · 0.45
rowCountMethod · 0.45
dataMethod · 0.45
valueAtMethod · 0.45
integerAtMethod · 0.45
bigIntAtMethod · 0.45
textAtMethod · 0.45
dateTimeAtMethod · 0.45
setChangedMethod · 0.45

Tested by

no test coverage detected