#ifndef GRAPH_H #define GRAPH_H #include "qcustomplot.h" class GraphColoredSegment { public: GraphColoredSegment(QCPDataRange dataRange, QPen pen, QBrush brush) : mDataRange(dataRange), mPen(pen), mBrush(brush) { } QCPDataRange dataRange() const { return mDataRange; } QPen pen() const { return mPen; } QBrush brush() const { return mBrush; } private: QCPDataRange mDataRange; QPen mPen; QBrush mBrush; }; class PlotTimeGraph : public QCPGraph { Q_OBJECT public: enum FillStyle { fsZero, fsBottom }; PlotTimeGraph(QCPAxis *keyAxis, QCPAxis *valueAxis); void addColoredSegment(double lowerValue, double upperValue, QPen pen, QBrush brush); void clearColoredSegments(); FillStyle getFillStyle() const; void setFillStyle(const FillStyle &fillStyle); protected: virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; virtual void drawFill(QCPPainter *painter, QVector *lines) const Q_DECL_OVERRIDE; const QPolygonF getCustomFillPolygon(const QVector *lineData, QCPDataRange segment) const; QPointF getCustomFillBasePoint(QPointF matchingDataPoint) const; private: QList mLowerValues; QList mUpperValues; QList mPens; QList mBrushs; FillStyle mFillStyle; inline static bool lessThanSegment(const GraphColoredSegment &a, const GraphColoredSegment &b) { return a.dataRange().begin() < b.dataRange().begin(); } }; #endif // GRAPH_H