From da34d9524dc255bfb52afa585d9dbedb7ffdc54d Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Mon, 24 Aug 2015 20:04:41 +0100 Subject: [PATCH] Add Gapped Curve .. want to mod ride plot to not plot gaps in recording, but instead draw a break in the curve. --- .../qwtcurve/qwt_plot_gapped_curve.cpp | 63 +++++++++++++++++++ qtsolutions/qwtcurve/qwt_plot_gapped_curve.h | 39 ++++++++++++ src/src.pro | 6 +- 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 qtsolutions/qwtcurve/qwt_plot_gapped_curve.cpp create mode 100644 qtsolutions/qwtcurve/qwt_plot_gapped_curve.h diff --git a/qtsolutions/qwtcurve/qwt_plot_gapped_curve.cpp b/qtsolutions/qwtcurve/qwt_plot_gapped_curve.cpp new file mode 100644 index 000000000..3c198b379 --- /dev/null +++ b/qtsolutions/qwtcurve/qwt_plot_gapped_curve.cpp @@ -0,0 +1,63 @@ +#include "qwt_plot_gapped_curve.h" + +//////////////////////////////////////////////////////////////////////////////// +QwtPlotGappedCurve::QwtPlotGappedCurve(double gapValue) +: QwtPlotCurve(), + gapValue_(gapValue) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +QwtPlotGappedCurve::QwtPlotGappedCurve(const QwtText &title, double gapValue) +: QwtPlotCurve(title), + gapValue_(gapValue) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +QwtPlotGappedCurve::QwtPlotGappedCurve(const QString &title, double gapValue) +: QwtPlotCurve(title), + gapValue_(gapValue) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +void QwtPlotGappedCurve::drawSeries(QPainter *painter, const QwtScaleMap &xMap, + const QwtScaleMap &yMap, const QRectF &canvRect, int from, int to) const +{ + if ( !painter || dataSize() <= 0 ) + return; + + if (to < 0) + to = dataSize() - 1; + + int i = from; + while (i < to) + { + // If data begins with missed values, + // we need to find first non-missed point. + double y = sample(i).y(); + while ((i < to) && (y == gapValue_)) + { + ++i; + y = sample(i).y(); + } + // First non-missed point will be the start of curve section. + int start = i; + y = sample(i).y(); + // Find the last non-missed point, it will be the end of curve section. + while ((i < to) && (y != gapValue_)) + { + ++i; + y = sample(i).y(); + } + // Correct the end of the section if it is at missed point + int end = (y == gapValue_) ? i - 1 : i; + + // Draw the curve section + if (start <= end) + QwtPlotCurve::drawSeries(painter, xMap, yMap, canvRect, start, end); + } +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/qtsolutions/qwtcurve/qwt_plot_gapped_curve.h b/qtsolutions/qwtcurve/qwt_plot_gapped_curve.h new file mode 100644 index 000000000..9d6e6fa37 --- /dev/null +++ b/qtsolutions/qwtcurve/qwt_plot_gapped_curve.h @@ -0,0 +1,39 @@ +#ifndef QWT_PLOT_GAPPED_CURVE_H +#define QWT_PLOT_GAPPED_CURVE_H + +#include + +#include "qwt_plot_curve.h" +#include "qwt_text.h" +#include "qwt_plot_curve.h" +#include "qwt_scale_map.h" + +//////////////////////////////////////////////////////////////////////////////// +/// This class is a plot curve that can have gaps at points +/// with specific Y value. +/// This specific "gap" value can be passed to constructors, +/// it's zero by default. +class QwtPlotGappedCurve: public QwtPlotCurve +{ +public: + /// gapValue is an Y value which denotes missed data + QwtPlotGappedCurve(double gapValue = 0); + + /// gapValue is an Y value which denotes missed data + QwtPlotGappedCurve(const QwtText &title, double gapValue = 0); + + /// gapValue is an Y value which denotes missed data + QwtPlotGappedCurve(const QString &title, double gapValue = 0); + + /// Override draw method to create gaps for missed Y values + virtual void drawSeries(QPainter *painter, const QwtScaleMap &xMap, + const QwtScaleMap &yMap, const QRectF &canvRect, int from, int to) const; + +private: + /// Value that denotes missed Y data at point + double gapValue_; +}; + +//////////////////////////////////////////////////////////////////////////////// + +#endif diff --git a/src/src.pro b/src/src.pro index 7744edcae..6e179d046 100644 --- a/src/src.pro +++ b/src/src.pro @@ -12,7 +12,7 @@ DEPENDPATH += . QMAKE_INFO_PLIST = ./mac/Info.plist.app ## qwt and libz -INCLUDEPATH += ../qwt/src ../qxt/src $${LIBZ_INCLUDE} ../qtsolutions/json +INCLUDEPATH += ../qwt/src ../qxt/src $${LIBZ_INCLUDE} ../qtsolutions/json ../qtsolutions/qwtcurve LIBS += ../qwt/lib/libqwt.a LIBS += -lm $${LIBZ_LIBS} @@ -266,6 +266,10 @@ HEADERS += TPUpload.h TPUploadDialog.h TPDownload.h TPDownloadDialog.h SOURCES += TPUpload.cpp TPUploadDialog.cpp TPDownload.cpp TPDownloadDialog.cpp DEFINES += GC_HAVE_SOAP +# gapped curve +HEADERS += ../qtsolutions/qwtcurve/qwt_plot_gapped_curve.h +SOURCES += ../qtsolutions/qwtcurve/qwt_plot_gapped_curve.cpp + HEADERS += \ AboutDialog.h \ AddDeviceWizard.h \