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

Method createTextLabelText

src/backend/worksheet/InfoElement.cpp:461–508  ·  view source on GitHub ↗

! * create Text which will be shown in the TextLabel * Called when: * - The position of the infoelement was changed * - a curve was removed * - a curve was added * @return Text */

Source from the content-addressed store, hash-verified

459 * @return Text
460 */
461TextLabel::TextWrapper InfoElement::createTextLabelText() {
462 // TODO: save positions of the variables in extra variables to replace faster, because replace takes long time
463 auto wrapper = m_title->text();
464 if (markerPointsCount() < 1) {
465 DEBUG(STDSTRING(wrapper.text))
466 DEBUG(STDSTRING(wrapper.textPlaceholder))
467 wrapper.text = wrapper.textPlaceholder;
468 return wrapper;
469 }
470
471 if (!(markerpoints.at(0).curve && markerpoints.at(0).curve->xColumn()))
472 return wrapper; // no data is set in the curve yet, nothing to do
473
474 Q_D(const InfoElement);
475
476 // replace the placeholder for the x-value
477 QString xValueStr;
478 const auto columnMode = markerpoints.at(0).curve->xColumn()->columnMode();
479 if (columnMode == AbstractColumn::ColumnMode::Double || columnMode == AbstractColumn::ColumnMode::Integer
480 || columnMode == AbstractColumn::ColumnMode::BigInt)
481 xValueStr = QString::number(d->positionLogical);
482 else if (columnMode == AbstractColumn::ColumnMode::Day || columnMode == AbstractColumn::ColumnMode::Month
483 || columnMode == AbstractColumn::ColumnMode::DateTime) {
484 const auto& dateTime = QDateTime::fromMSecsSinceEpoch(d->positionLogical, QTimeZone::UTC);
485 xValueStr = dateTime.toString(d->m_plot->rangeDateTimeFormat(Dimension::X));
486 }
487
488 QString text = wrapper.textPlaceholder;
489 if (wrapper.mode == TextLabel::Mode::Text)
490 text.replace(QStringLiteral("&amp;(x)"), xValueStr);
491 else
492 text.replace(QStringLiteral("&(x)"), xValueStr);
493
494 // replace the placeholders for curve's y-values
495 for (const auto& markerpoint : std::as_const(markerpoints)) {
496 QString replace;
497 if (wrapper.mode == TextLabel::Mode::Text)
498 replace = QStringLiteral("&amp;(");
499 else
500 replace = QStringLiteral("&(");
501
502 replace += markerpoint.curve->name() + QLatin1Char(')');
503 text.replace(replace, QString::number(markerpoint.customPoint->positionLogical().y()));
504 }
505
506 wrapper.text = text;
507 return wrapper;
508}
509
510TextLabel* InfoElement::title() {
511 return m_title;

Callers

nothing calls this directly

Calls 7

rangeDateTimeFormatMethod · 0.80
replaceMethod · 0.80
textMethod · 0.45
columnModeMethod · 0.45
toStringMethod · 0.45
nameMethod · 0.45
yMethod · 0.45

Tested by

no test coverage detected