7#include <QtGraphs/QLineSeries>
8#include <QtGraphs/QAbstractSeries>
25 qCDebug(MAVLinkMessageFieldLog) <<
"Field:" << name << type;
39 _chartController = chartController;
45 _bucketWidthMs = chartController->
rangeXMs() / _bucketCount;
46 _currentBucketStart = -1;
57 _rangeMin = std::numeric_limits<qreal>::max();
58 _rangeMax = std::numeric_limits<qreal>::lowest();
59 QLineSeries *
const lineSeries =
static_cast<QLineSeries*
>(_pSeries);
60 lineSeries->replace(_values);
62 _chartController =
nullptr;
65 _currentBucketStart = -1;
73 _bucketCount = std::max(1, bucketCount);
74 _bucketWidthMs = bucketWidthMs;
75 _currentBucketStart = -1;
76 _currentBucketMin = 0;
77 _currentBucketMax = 0;
80 _rangeMin = std::numeric_limits<qreal>::max();
81 _rangeMax = std::numeric_limits<qreal>::lowest();
86 return (_msg->
name() +
": " + _name);
91 if (_selectable != sel) {
99 if (_chartController) {
108 if (_value != newValue) {
113 if (!_pSeries || !_chartController || _bucketCount <= 0) {
117 const qreal now =
qgcApp()->msecsSinceBoot();
119 if (_currentBucketStart < 0) {
121 _currentBucketStart = now;
122 _currentBucketMin = v;
123 _currentBucketMax = v;
125 bool changed =
false;
126 if (std::abs(_rangeMin - v) >
kMinDelta) {
130 if (std::abs(_rangeMax - v) >
kMinDelta) {
141 if (now < _currentBucketStart + _bucketWidthMs) {
143 _currentBucketMin = std::min(_currentBucketMin, v);
144 _currentBucketMax = std::max(_currentBucketMax, v);
146 bool changed =
false;
166 _currentBucketStart = now;
167 _currentBucketMin = v;
168 _currentBucketMax = v;
175 qreal vmin = _currentBucketMin;
176 qreal vmax = _currentBucketMax;
177 for (
const QPointF &point : _values) {
178 vmin = std::min(vmin, point.y());
179 vmax = std::max(vmax, point.y());
182 bool changed =
false;
183 if (std::abs(_rangeMin - vmin) >
kMinDelta) {
188 if (std::abs(_rangeMax - vmax) >
kMinDelta) {
198void QGCMAVLinkMessageField::_commitBucket()
200 const qreal bucketMidTime = _currentBucketStart + _bucketWidthMs * 0.5;
201 const int maxPoints = _bucketCount * 2;
204 const int count = _values.count();
205 if (count < maxPoints) {
206 _values.append(QPointF(bucketMidTime, _currentBucketMin));
207 _values.append(QPointF(bucketMidTime, _currentBucketMax));
210 if (_dataIndex >= maxPoints) {
213 _values[_dataIndex] = QPointF(bucketMidTime, _currentBucketMin);
215 if (_dataIndex >= maxPoints) {
218 _values[_dataIndex] = QPointF(bucketMidTime, _currentBucketMax);
225 const int count = _values.count();
228 s.reserve(count + 2);
229 int idx = _dataIndex;
230 for (
int i = 0; i < count; i++, idx++) {
235 const QPointF p(_values[idx]);
240 if (_currentBucketStart >= 0) {
241 const qreal now =
qgcApp()->msecsSinceBoot();
242 s.append(QPointF(now, _currentBucketMin));
243 if (std::abs(_currentBucketMax - _currentBucketMin) >
kMinDelta) {
244 s.append(QPointF(now, _currentBucketMax));
248 QLineSeries *
const lineSeries =
static_cast<QLineSeries*
>(_pSeries);
254 lineSeries->replace(s);
static constexpr qreal kMinDelta
static constexpr qreal kMinDelta
#define QGC_LOGGING_CATEGORY(name, categoryStr)
quint32 rangeYIndex() const
int plotPixelWidth() const
~QGCMAVLinkMessageField()
void updateValue(const QString &newValue, qreal v)
void addSeries(MAVLinkChartController *chartController, QAbstractSeries *series)
void setSelectable(bool sel)
const QAbstractSeries * series() const
void resetBucketing(int bucketCount, qreal bucketWidthMs)
void updateFieldSelection()