MCPcopy Create free account
hub / github.com/LUX-Core/lux / updatePosition

Method updatePosition

src/qt/qcustomplot.cpp:29810–29858  ·  view source on GitHub ↗

! If the tracer is connected with a graph (\ref setGraph), this function updates the tracer's \a position to reside on the graph data, depending on the configured key (\ref setGraphKey). It is called automatically on every redraw and normally doesn't need to be called manually. One exception is when you want to read the tracer coordinates via \a position and are not sure that the grap

Source from the content-addressed store, hash-verified

29808 If there is no graph set on this tracer, this function does nothing.
29809*/
29810void QCPItemTracer::updatePosition()
29811{
29812 if (mGraph)
29813 {
29814 if (mParentPlot->hasPlottable(mGraph))
29815 {
29816 if (mGraph->data()->size() > 1)
29817 {
29818 QCPGraphDataContainer::const_iterator first = mGraph->data()->constBegin();
29819 QCPGraphDataContainer::const_iterator last = mGraph->data()->constEnd()-1;
29820 if (mGraphKey <= first->key)
29821 position->setCoords(first->key, first->value);
29822 else if (mGraphKey >= last->key)
29823 position->setCoords(last->key, last->value);
29824 else
29825 {
29826 QCPGraphDataContainer::const_iterator it = mGraph->data()->findBegin(mGraphKey);
29827 if (it != mGraph->data()->constEnd()) // mGraphKey is not exactly on last iterator, but somewhere between iterators
29828 {
29829 QCPGraphDataContainer::const_iterator prevIt = it;
29830 ++it; // won't advance to constEnd because we handled that case (mGraphKey >= last->key) before
29831 if (mInterpolating)
29832 {
29833 // interpolate between iterators around mGraphKey:
29834 double slope = 0;
29835 if (!qFuzzyCompare((double)it->key, (double)prevIt->key))
29836 slope = (it->value-prevIt->value)/(it->key-prevIt->key);
29837 position->setCoords(mGraphKey, (mGraphKey-prevIt->key)*slope+prevIt->value);
29838 } else
29839 {
29840 // find iterator with key closest to mGraphKey:
29841 if (mGraphKey < (prevIt->key+it->key)*0.5)
29842 position->setCoords(prevIt->key, prevIt->value);
29843 else
29844 position->setCoords(it->key, it->value);
29845 }
29846 } else // mGraphKey is exactly on last iterator (should actually be caught when comparing first/last keys, but this is a failsafe for fp uncertainty)
29847 position->setCoords(it->key, it->value);
29848 }
29849 } else if (mGraph->data()->size() == 1)
29850 {
29851 QCPGraphDataContainer::const_iterator it = mGraph->data()->constBegin();
29852 position->setCoords(it->key, it->value);
29853 } else
29854 qDebug() << Q_FUNC_INFO << "graph has no data";
29855 } else
29856 qDebug() << Q_FUNC_INFO << "graph not contained in QCustomPlot instance (anymore)";
29857 }
29858}
29859
29860/*! \internal
29861

Callers

nothing calls this directly

Calls 7

hasPlottableMethod · 0.80
constBeginMethod · 0.80
constEndMethod · 0.80
setCoordsMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45
findBeginMethod · 0.45

Tested by

no test coverage detected