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

Method updateCompleteCursorTreeModel

src/backend/worksheet/Worksheet.cpp:1467–1566  ·  view source on GitHub ↗

* @brief Worksheet::updateCompleteCursorTreeModel * If the plot or the curve are not available, the plot/curve is not in the treemodel! */

Source from the content-addressed store, hash-verified

1465 * If the plot or the curve are not available, the plot/curve is not in the treemodel!
1466 */
1467void Worksheet::updateCompleteCursorTreeModel() {
1468 Q_D(const Worksheet);
1469 if (isLoading())
1470 return;
1471
1472 TreeModel* treeModel = cursorModel();
1473
1474 if (treeModel->rowCount() > 0)
1475 treeModel->removeRows(0, treeModel->rowCount()); // remove all data
1476
1477 int pc = plotCount();
1478 if (pc < 1)
1479 return;
1480
1481 if (cartesianPlotCursorMode() == CartesianPlotActionMode::ApplyActionToAll) {
1482 // 1 because of the X data
1483 treeModel->insertRows(0, 1); //, treeModel->index(0,0)); // add empty rows. Then they become filled
1484
1485 // set X data
1486 QModelIndex xName = treeModel->index(0, static_cast<int>(WorksheetPrivate::TreeModelColumn::SIGNALNAME));
1487 treeModel->setData(xName, QVariant(QStringLiteral("X")));
1488 auto* plot0 = plot(0);
1489 if (plot0) {
1490 double valueCursor[2];
1491 for (int i = 0; i < 2; i++) {
1492 valueCursor[i] = plot0->cursorPos(i);
1493 QModelIndex cursor = treeModel->index(0, static_cast<int>(WorksheetPrivate::TreeModelColumn::CURSOR0) + i);
1494
1495 treeModel->setData(cursor, QVariant(valueCursor[i]));
1496 }
1497 QModelIndex diff = treeModel->index(0, static_cast<int>(WorksheetPrivate::TreeModelColumn::CURSORDIFF));
1498 treeModel->setData(diff, QVariant(valueCursor[1] - valueCursor[0]));
1499 }
1500 } else {
1501 // treeModel->insertRows(0, plotCount, treeModel->index(0,0)); // add empty rows. Then they become filled
1502 }
1503
1504 // set plot name, y value, background
1505 for (int i = 0; i < pc; i++) {
1506 auto* p = plot(i);
1507 QModelIndex plotName;
1508 int addOne = 0;
1509
1510 if (!p || !p->isVisible())
1511 continue;
1512
1513 // add new entry for the plot
1514 treeModel->insertRows(treeModel->rowCount(), 1); //, treeModel->index(0, 0));
1515
1516 // add plot name and X row if needed
1517 if (cartesianPlotCursorMode() == CartesianPlotActionMode::ApplyActionToAll) {
1518 plotName = treeModel->index(i + 1, static_cast<int>(WorksheetPrivate::TreeModelColumn::PLOTNAME)); // plus one because first row are the x values
1519 treeModel->setData(plotName, QVariant(p->name()));
1520 } else {
1521 addOne = 1;
1522 plotName = treeModel->index(i, static_cast<int>(WorksheetPrivate::TreeModelColumn::PLOTNAME));
1523 treeModel->setData(plotName, QVariant(p->name()));
1524 treeModel->insertRows(0, 1, plotName); // one, because the first row are the x values

Callers

nothing calls this directly

Calls 14

cursorPosMethod · 0.80
curveCountMethod · 0.80
getCurveMethod · 0.80
setTreeDataMethod · 0.80
rowCountMethod · 0.45
removeRowsMethod · 0.45
insertRowsMethod · 0.45
indexMethod · 0.45
setDataMethod · 0.45
isVisibleMethod · 0.45
nameMethod · 0.45
yMethod · 0.45

Tested by

no test coverage detected