| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/components/sensors/graphitem.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "graphitem.h"cxx . . $ `<file>/src/core/components/sensors/graphitem.h`/ |
| 5 | |
| 6 | #include <QTimer> |
| 7 | #include <QtCharts/QValueAxis> |
| 8 | #include <algorithm> |
| 9 | #include <limits> |
| 10 | |
| 11 | unsigned short const GraphItemcxx . . $ GraphItem#::PointsCountcxx . . $ GraphItem#PointsCount. = 120; |
| 12 | |
| 13 | GraphItemcxx . . $ GraphItem#::GraphItemcxx . . $ GraphItem#GraphItem(9ebb09e227cac344).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view# name, stdcxx . . $ std/::string_viewcxx . . $ std/string_view# unit) |
| 14 | : QQuickItemcxx . . $ QQuickItem#QQuickItem(28aa4acb8f529eea).() |
| 15 | , name_cxx . . $ GraphItem#name_.(name.datacxx . . $ std/basic_string_view#data(8e614c7de0b1573e).()) |
| 16 | , unit_cxx . . $ GraphItem#unit_.(unit.datacxx . . $ std/basic_string_view#data(8e614c7de0b1573e).()) |
| 17 | , yMin_cxx . . $ GraphItem#yMin_.(stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<qreal>::maxcxx . . $ std/numeric_limits#max(e4aa362e81f92a46).()) |
| 18 | , yMax_cxx . . $ GraphItem#yMax_.(stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<qreal>::mincxx . . $ std/numeric_limits#min(e4aa362e81f92a46).()) |
| 19 | { |
| 20 | setObjectNamecxx . . $ QObject#setObjectName(3520e46b33348bf6).(name_cxx . . $ GraphItem#name_.); |
| 21 | points_cxx . . $ GraphItem#points_..reservecxx . . $ QList#reserve(35cb52607f6af42f).(GraphItemcxx . . $ GraphItem#::PointsCountcxx . . $ GraphItem#PointsCount.); |
| 22 | |
| 23 | connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(this, &GraphItemcxx . . $ GraphItem#::visibleChangedcxx . . $ QQuickItem#visibleChanged(49f6e7a06ebc5aa8)., this, &GraphItemcxx . . $ GraphItem#::refreshSeriePointscxx . . $ GraphItem#refreshSeriePoints(49f6e7a06ebc5aa8).); |
| 24 | } |
| 25 | |
| 26 | QStringcxx . . $ QString# const &GraphItemcxx . . $ GraphItem#::namecxx . . $ GraphItem#name(a2fb7a6ce195d51).() const |
| 27 | { |
| 28 | return name_cxx . . $ GraphItem#name_.; |
| 29 | } |
| 30 | |
| 31 | QStringcxx . . $ QString# const &GraphItemcxx . . $ GraphItem#::unitcxx . . $ GraphItem#unit(a2fb7a6ce195d51).() const |
| 32 | { |
| 33 | return unit_cxx . . $ GraphItem#unit_.; |
| 34 | } |
| 35 | |
| 36 | QStringcxx . . $ QString# GraphItemcxx . . $ GraphItem#::colorcxx . . $ GraphItem#color(6ef7b6c27b00b43d).() const |
| 37 | { |
| 38 | return QStringcxx . . $ QString#::fromStdStringcxx . . $ QString#fromStdString(24a2e9bdf24626eb).(color_cxx . . $ GraphItem#color_.); |
| 39 | } |
| 40 | |
| 41 | qrealcxx . . $ qreal# GraphItemcxx . . $ GraphItem#::valuecxx . . $ GraphItem#value(21b6c25e127938e2).() const |
| 42 | { |
| 43 | return value_cxx . . $ GraphItem#value_.; |
| 44 | } |
| 45 | |
| 46 | void GraphItemcxx . . $ GraphItem#::initialRangecxx . . $ GraphItem#initialRange(bc12c9ec15586e6a).(qrealcxx . . $ qreal# min, qrealcxx . . $ qreal# max) |
| 47 | { |
| 48 | if (max > min) { |
| 49 | yMin_cxx . . $ GraphItem#yMin_. = min; |
| 50 | yMax_cxx . . $ GraphItem#yMax_. = max; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | void GraphItemcxx . . $ GraphItem#::updateGraphcxx . . $ GraphItem#updateGraph(ba8836b59fb42830).(qrealcxx . . $ qreal# value) |
| 55 | { |
| 56 | if (series_cxx . . $ GraphItem#series_. != nullptr && !ignoredcxx . . $ GraphItem#ignored(50ce9a9e25b4a850).()) { |
| 57 | |
| 58 | if (points_cxx . . $ GraphItem#points_..sizecxx . . $ QList#size(6b0412d51016192f).() == PointsCountcxx . . $ GraphItem#PointsCount.) |
| 59 | points_cxx . . $ GraphItem#points_..removeFirstcxx . . $ QList#removeFirst(ced63f7c635d850d).(); |
| 60 | |
| 61 | qrealcxx . . $ qreal# newX; |
| 62 | auto lastX = points_cxx . . $ GraphItem#points_..emptycxx . . $ QList#empty(3482b152b9333168).() ? PointsCountcxx . . $ GraphItem#PointsCount. : points_cxx . . $ GraphItem#points_..lastcxx . . $ QList#last(19b2b6f17af048b).().xcxx . . $ QPointF#x(d8440c0a87ad7443).(); |
| 63 | if (static_cast<unsigned short>(lastX) == |
| 64 | stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<unsigned short>::maxcxx . . $ std/numeric_limits#max(ab96d7673181286b).()) { |
| 65 | // 65535 * 0.5 / 60 / 60 ~> 9h 10min @ 0.5s refresh rate between restarts |
| 66 | |
| 67 | restartXPointscxx . . $ GraphItem#restartXPoints(49f6e7a06ebc5aa8).(); |
| 68 | newX = PointsCountcxx . . $ GraphItem#PointsCount.; |
| 69 | } |
| 70 | else { |
| 71 | newX = lastX + 1; |
| 72 | } |
| 73 | |
| 74 | points_cxx . . $ GraphItem#points_..appendcxx . . $ QList#append(1262c8661f7a27a7).(QPointFcxx . . $ QPointF#QPointF(acbf2dbd75fdf3c4).(newX, value)); |
| 75 | QTimercxx . . $ QTimer#::singleShotcxx . . $ QTimer#singleShot(aa6a4c6cfc6f625a).(0, this, &GraphItemcxx . . $ GraphItem#::refreshSeriePointscxx . . $ GraphItem#refreshSeriePoints(49f6e7a06ebc5aa8).); |
| 76 | |
| 77 | // update axes |
| 78 | xAxis_cxx . . $ GraphItem#xAxis_.->setRangecxx . . $ QAbstractAxis#setRange(a345ffe45cc67a61).(newXcxx . . $ QVariant#QVariant(4cbbf9c7388e6885). - PointsCountcxx . . $ GraphItem#PointsCount. + 1, newXcxx . . $ QVariant#QVariant(4cbbf9c7388e6885).); |
| 79 | updateYAxiscxx . . $ GraphItem#updateYAxis(ba8836b59fb42830).(value); |
| 80 | |
| 81 | value_cxx . . $ GraphItem#value_. = value; |
| 82 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! valueChangedcxx . . $ GraphItem#valueChanged(ba8836b59fb42830).(value); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Importablecxx . . $ Importable#::Importercxx . . $ Importable#Importer#>> |
| 87 | GraphItemcxx . . $ GraphItem#::provideImportercxx . . $ GraphItem#provideImporter(c13a3bcac0db4745).(Itemcxx . . $ Item# const &) |
| 88 | { |
| 89 | return {cxx . . $ std/optional#optional(ced63f7c635d850d).}; |
| 90 | } |
| 91 | |
| 92 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 93 | GraphItemcxx . . $ GraphItem#::provideExportercxx . . $ GraphItem#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &) |
| 94 | { |
| 95 | return {cxx . . $ std/optional#optional(ced63f7c635d850d).}; |
| 96 | } |
| 97 | |
| 98 | bool GraphItemcxx . . $ GraphItem#::provideActivecxx . . $ GraphItem#provideActive(50ce9a9e25b4a850).() const |
| 99 | { |
| 100 | return active_cxx . . $ GraphItem#active_.; |
| 101 | } |
| 102 | |
| 103 | stdcxx . . $ std/::stringcxx . . $ std/string# const &GraphItemcxx . . $ GraphItem#::provideColorcxx . . $ GraphItem#provideColor(f4fff0029955a25f).() const |
| 104 | { |
| 105 | return color_cxx . . $ GraphItem#color_.; |
| 106 | } |
| 107 | |
| 108 | void GraphItemcxx . . $ GraphItem#::takeActivecxx . . $ GraphItem#takeActive(b45ddcbc8423892c).(bool active) |
| 109 | { |
| 110 | if (active_cxx . . $ GraphItem#active_. != active) { |
| 111 | active_cxx . . $ GraphItem#active_. = active; |
| 112 | |
| 113 | if (series_cxx . . $ GraphItem#series_. != nullptr) |
| 114 | series_cxx . . $ GraphItem#series_.->setVisiblecxx . . $ QAbstractSeries#setVisible(b45ddcbc8423892c).(active); |
| 115 | |
| 116 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! activeChangedcxx . . $ GraphItem#activeChanged(b45ddcbc8423892c).(active); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | void GraphItemcxx . . $ GraphItem#::takeColorcxx . . $ GraphItem#takeColor(9c546c94e5fcce4e).(stdcxx . . $ std/::stringcxx . . $ std/string# const &color) |
| 121 | { |
| 122 | if (!color.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).() && color_cxx . . $ GraphItem#color_. != color) { |
| 123 | color_cxx . . $ GraphItem#color_. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). color; |
| 124 | |
| 125 | if (series_cxx . . $ GraphItem#series_. != nullptr) |
| 126 | series_cxx . . $ GraphItem#series_.->setColorcxx . . $ QXYSeries#setColor(129a55e114526ad3).(color_cxx . . $ QColor#QColor(85c52e162fed56f9)..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 127 | |
| 128 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! colorChangedcxx . . $ GraphItem#colorChanged(3520e46b33348bf6).(QStringcxx . . $ QString#::fromStdStringcxx . . $ QString#fromStdString(24a2e9bdf24626eb).(color_cxx . . $ GraphItem#color_.)); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | void GraphItemcxx . . $ GraphItem#::configurecxx . . $ GraphItem#configure(76486491299da10).(QAbstractSeriescxx . . $ QAbstractSeries# *series, QAbstractAxiscxx . . $ QAbstractAxis# *xAxis, |
| 133 | QAbstractAxiscxx . . $ QAbstractAxis# *yAxis) |
| 134 | { |
| 135 | series_cxx . . $ GraphItem#series_. = dynamic_cast<QLineSeriescxx . . $ QLineSeries# *>(series); |
| 136 | series_cxx . . $ GraphItem#series_.->setColorcxx . . $ QXYSeries#setColor(129a55e114526ad3).(color_cxx . . $ QColor#QColor(85c52e162fed56f9)..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 137 | series_cxx . . $ GraphItem#series_.->setVisiblecxx . . $ QAbstractSeries#setVisible(b45ddcbc8423892c).(active_cxx . . $ GraphItem#active_.); |
| 138 | |
| 139 | xAxis_cxx . . $ GraphItem#xAxis_. = xAxis; |
| 140 | yAxis_cxx . . $ GraphItem#yAxis_. = yAxis; |
| 141 | |
| 142 | xAxis_cxx . . $ GraphItem#xAxis_.->setRangecxx . . $ QAbstractAxis#setRange(a345ffe45cc67a61).(1cxx . . $ QVariant#QVariant(f349c77f591a7878)., PointsCountcxx . . $ QVariant#QVariant(f349c77f591a7878).); |
| 143 | yAxis_cxx . . $ GraphItem#yAxis_.->setRangecxx . . $ QAbstractAxis#setRange(a345ffe45cc67a61).(yMin_cxx . . $ QVariant#QVariant(4cbbf9c7388e6885)., yMax_cxx . . $ QVariant#QVariant(4cbbf9c7388e6885).); |
| 144 | } |
| 145 | |
| 146 | void GraphItemcxx . . $ GraphItem#::updateYAxisRangecxx . . $ GraphItem#updateYAxisRange(bc12c9ec15586e6a).(qrealcxx . . $ qreal# min, qrealcxx . . $ qreal# max) |
| 147 | { |
| 148 | yMin_cxx . . $ GraphItem#yMin_. = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(yMin_cxx . . $ GraphItem#yMin_., min); |
| 149 | yMax_cxx . . $ GraphItem#yMax_. = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(yMax_cxx . . $ GraphItem#yMax_., (max > yMin_cxx . . $ GraphItem#yMin_.) ? max : yMin_cxx . . $ GraphItem#yMin_. + 1); |
| 150 | |
| 151 | yAxis_cxx . . $ GraphItem#yAxis_.->setRangecxx . . $ QAbstractAxis#setRange(a345ffe45cc67a61).(yMin_cxx . . $ QVariant#QVariant(4cbbf9c7388e6885)., yMax_cxx . . $ QVariant#QVariant(4cbbf9c7388e6885).); |
| 152 | } |
| 153 | |
| 154 | void GraphItemcxx . . $ GraphItem#::refreshSeriePointscxx . . $ GraphItem#refreshSeriePoints(49f6e7a06ebc5aa8).() |
| 155 | { |
| 156 | if (isVisiblecxx . . $ QQuickItem#isVisible(50ce9a9e25b4a850).() && series_cxx . . $ GraphItem#series_. != nullptr) |
| 157 | series_cxx . . $ GraphItem#series_.->replacecxx . . $ QXYSeries#replace(af83b2e93935b218).(points_cxx . . $ GraphItem#points_.); |
| 158 | } |
| 159 | |
| 160 | bool GraphItemcxx . . $ GraphItem#::activecxx . . $ GraphItem#active(50ce9a9e25b4a850).() const |
| 161 | { |
| 162 | return provideActivecxx . . $ GraphItem#provideActive(50ce9a9e25b4a850).(); |
| 163 | } |
| 164 | |
| 165 | void GraphItemcxx . . $ GraphItem#::activecxx . . $ GraphItem#active(b45ddcbc8423892c).(bool active) |
| 166 | { |
| 167 | if (active_cxx . . $ GraphItem#active_. != active) { |
| 168 | active_cxx . . $ GraphItem#active_. = active; |
| 169 | |
| 170 | if (series_cxx . . $ GraphItem#series_. != nullptr) |
| 171 | series_cxx . . $ GraphItem#series_.->setVisiblecxx . . $ QAbstractSeries#setVisible(b45ddcbc8423892c).(active); |
| 172 | |
| 173 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! settingsChangedcxx . . $ GraphItem#settingsChanged(49f6e7a06ebc5aa8).(); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | bool GraphItemcxx . . $ GraphItem#::ignoredcxx . . $ GraphItem#ignored(50ce9a9e25b4a850).() const |
| 178 | { |
| 179 | return ignored_cxx . . $ GraphItem#ignored_.; |
| 180 | } |
| 181 | |
| 182 | void GraphItemcxx . . $ GraphItem#::ignoredcxx . . $ GraphItem#ignored(b45ddcbc8423892c).(bool ignored) |
| 183 | { |
| 184 | if (ignored_cxx . . $ GraphItem#ignored_. != ignored) { |
| 185 | ignored_cxx . . $ GraphItem#ignored_. = ignored; |
| 186 | |
| 187 | if (series_cxx . . $ GraphItem#series_. != nullptr) |
| 188 | series_cxx . . $ GraphItem#series_.->setVisiblecxx . . $ QAbstractSeries#setVisible(b45ddcbc8423892c).(active_cxx . . $ GraphItem#active_. && !ignored_cxx . . $ GraphItem#ignored_.); |
| 189 | |
| 190 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! ignoredChangedcxx . . $ GraphItem#ignoredChanged(b45ddcbc8423892c).(ignored); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | void GraphItemcxx . . $ GraphItem#::updateYAxiscxx . . $ GraphItem#updateYAxis(ba8836b59fb42830).(qrealcxx . . $ qreal# value) |
| 195 | { |
| 196 | if (value < yMin_cxx . . $ GraphItem#yMin_. || value > yMax_cxx . . $ GraphItem#yMax_.) { |
| 197 | updateYAxisRangecxx . . $ GraphItem#updateYAxisRange(bc12c9ec15586e6a).(value, value); |
| 198 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! yAxisRangeChangedcxx . . $ GraphItem#yAxisRangeChanged(bc12c9ec15586e6a).(yMin_cxx . . $ GraphItem#yMin_., yMax_cxx . . $ GraphItem#yMax_.); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | void GraphItemcxx . . $ GraphItem#::restartXPointscxx . . $ GraphItem#restartXPoints(49f6e7a06ebc5aa8).() |
| 203 | { |
| 204 | int pointX = 1; |
| 205 | for (auto &point : points_cxx . . $ GraphItem#points_.) |
| 206 | point.rxcxx . . $ QPointF#rx(683ba587bcaad6a5).() = pointX++; |
| 207 | } |