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

Method cursorPosChanged

src/backend/worksheet/Worksheet.cpp:1169–1291  ·  view source on GitHub ↗

! * \brief Worksheet::cursorPosChanged * Updates the cursor treemodel with the new data * \param xPos: new position of the cursor * It is assumed, that the plots/curves are in the same order than receiving from * the children() function. It's not checked if the names are the same */

Source from the content-addressed store, hash-verified

1167 * the children() function. It's not checked if the names are the same
1168 */
1169void Worksheet::cursorPosChanged(int cursorNumber, double xPos) {
1170 Q_D(const Worksheet);
1171 if (d->suppressCursorPosChanged)
1172 return;
1173
1174 auto* sender = dynamic_cast<CartesianPlot*>(QObject::sender());
1175 if (!sender)
1176 return;
1177
1178 TreeModel* treeModel = cursorModel();
1179
1180 // if ApplyActionToSelection, each plot has it's own x value
1181 bool isDatetime = sender->xRangeFormatDefault() == RangeT::Format::DateTime;
1182 if (cartesianPlotCursorMode() == CartesianPlotActionMode::ApplyActionToAll) {
1183 // x values
1184 int rowPlot = 1;
1185 QModelIndex xName = treeModel->index(0, static_cast<int>(WorksheetPrivate::TreeModelColumn::SIGNALNAME));
1186 treeModel->setData(xName, QVariant(QStringLiteral("X")));
1187 double valueCursor[2];
1188 QDateTime datetime[2];
1189 for (int i = 0; i < 2; i++) { // need both cursors to calculate diff
1190 QVariant data;
1191 valueCursor[i] = sender->cursorPos(i);
1192 if (isDatetime) {
1193 datetime[i] = QDateTime::fromMSecsSinceEpoch(valueCursor[i], QTimeZone::UTC);
1194 data = datetime[i].toString(sender->rangeDateTimeFormat(Dimension::X));
1195 } else
1196 data = QVariant(valueCursor[i]);
1197 treeModel->setTreeData(data, 0, static_cast<int>(WorksheetPrivate::TreeModelColumn::CURSOR0) + i);
1198 }
1199 if (isDatetime)
1200 treeModel->setTreeData(dateTimeDiffToString(datetime[0], datetime[1]), 0, static_cast<int>(WorksheetPrivate::TreeModelColumn::CURSORDIFF));
1201 else
1202 treeModel->setTreeData(QVariant(valueCursor[1] - valueCursor[0]), 0, static_cast<int>(WorksheetPrivate::TreeModelColumn::CURSORDIFF));
1203
1204 // y values
1205 for (int i = 0; i < plotCount(); i++) { // i=0 is the x Axis
1206
1207 auto* p = plot(i);
1208 if (!p || !p->isVisible())
1209 continue;
1210
1211 QModelIndex plotIndex = treeModel->index(rowPlot, static_cast<int>(WorksheetPrivate::TreeModelColumn::PLOTNAME));
1212
1213 // curves
1214 int rowCurve = 0;
1215 for (int j = 0; j < p->curveCount(); j++) {
1216 // assumption: index of signals in model is the same than the index of the signal in the plot
1217 bool valueFound;
1218
1219 const XYCurve* curve = p->getCurve(j);
1220 if (!curve->isVisible())
1221 continue;
1222
1223 double value = curve->y(xPos, valueFound);
1224 if (cursorNumber == 0) {
1225 treeModel->setTreeData(QVariant(value), rowCurve, static_cast<int>(WorksheetPrivate::TreeModelColumn::CURSOR0), plotIndex);
1226 double valueCursor1 = treeModel->treeData(rowCurve, static_cast<int>(WorksheetPrivate::TreeModelColumn::CURSOR1), plotIndex).toDouble();

Callers

nothing calls this directly

Calls 15

dateTimeDiffToStringFunction · 0.85
xRangeFormatDefaultMethod · 0.80
cursorPosMethod · 0.80
rangeDateTimeFormatMethod · 0.80
setTreeDataMethod · 0.80
curveCountMethod · 0.80
getCurveMethod · 0.80
treeDataMethod · 0.80
indexMethod · 0.45
setDataMethod · 0.45
toStringMethod · 0.45
isVisibleMethod · 0.45

Tested by

no test coverage detected