36 #include "qwt/src/qwt.h"
37 #include "qwt/src/qwt_plot_histogram.h"
39 #define MAX_NUMBER_OF_INTERVALS 1000
52 , histogramBins(nullptr)
53 , histogramInterval(nullptr)
54 , intervalSeriesData(nullptr)
56 this->binWidth = binWidth;
57 this->numberOfBins = numberOfBins;
61 histogramBins =
new QVector<QwtIntervalSample>();
62 histogramInterval =
new QVector<QwtInterval>();
65 intervalSeriesData =
new QwtIntervalSeriesData(*histogramBins);
76 Q_UNUSED(scopeGadgetWidget);
77 Q_UNUSED(scopeConfig);
80 histogram->setData(intervalSeriesData);
81 intervalSeriesData->setSamples(*histogramBins);
102 double step = binWidth;
106 if (numberOfBins > MAX_NUMBER_OF_INTERVALS)
107 numberOfBins = MAX_NUMBER_OF_INTERVALS;
110 double currentValue =
114 if (!histogramInterval->empty()) {
115 while (currentValue < histogramInterval->front().minValue()
116 && histogramInterval->size() <= (int)numberOfBins) {
117 histogramInterval->prepend(
118 QwtInterval(histogramInterval->front().minValue() - step,
119 histogramInterval->front().minValue()));
120 histogramBins->prepend(QwtIntervalSample(0, histogramInterval->front()));
123 while (currentValue > histogramInterval->back().maxValue()
124 && histogramInterval->size() <= (int)numberOfBins) {
125 histogramInterval->append(
126 QwtInterval(histogramInterval->back().maxValue(),
127 histogramInterval->back().maxValue() + step));
128 histogramBins->append(QwtIntervalSample(0, histogramInterval->back()));
134 if (histogramInterval->size() > (int)numberOfBins) {
135 histogramBins->pop_back();
136 histogramInterval->pop_back();
144 for (
int i = 0;
i < histogramInterval->size();
i++) {
145 if (histogramInterval->at(
i).contains(currentValue)) {
146 histogramBins->replace(
i, QwtIntervalSample(histogramBins->at(
i).value + 1,
147 histogramInterval->at(
i)));
154 if (tmp < currentValue) {
155 while (tmp < currentValue) {
158 histogramInterval->append(QwtInterval(tmp - step, tmp));
163 histogramInterval->append(QwtInterval(tmp, tmp + step));
166 histogramBins->append(QwtIntervalSample(0, histogramInterval->front()));
184 delete histogramInterval;
185 delete histogramBins;
193 delete histogramData;
201 histogramBins->clear();
202 histogramInterval->clear();
QVector< double > * xData
The Plot2dData class Base class that keeps the data for each curve in the plot.
virtual void deletePlots(PlotData *)
HistogramScopeConfig::deletePlots Delete all plot data.
QVector< double > * yData
virtual void plotNewData(PlotData *, ScopeConfig *, ScopeGadgetWidget *)
HistogramScopeConfig::plotNewData Update plot with new data.
UAVObjectField * getField(const QString &name)
The ScopeConfig class The parent class for scope configuration classes data sources.
HistogramData(QString uavObject, QString uavField, double binWidth, uint numberOfBins)
HistogramData::HistogramData.
void clearPlots()
HistogramScopeConfig::clearPlots Clear all plot data.
bool append(UAVObject *obj)
HistogramData::append Appends data to histogram.
double valueAsDouble(UAVObject *obj, UAVObjectField *field, bool haveSubField, QString uavSubFieldName)
valueAsDouble Fetch the value from the UAVO and return it as a double