12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #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<QPointF> *lines) const Q_DECL_OVERRIDE;
- const QPolygonF getCustomFillPolygon(const QVector<QPointF> *lineData, QCPDataRange segment) const;
- QPointF getCustomFillBasePoint(QPointF matchingDataPoint) const;
- private:
- QList<double> mLowerValues;
- QList<double> mUpperValues;
- QList<QPen> mPens;
- QList<QBrush> mBrushs;
- FillStyle mFillStyle;
- inline static bool lessThanSegment(const GraphColoredSegment &a, const GraphColoredSegment &b)
- {
- return a.dataRange().begin() < b.dataRange().begin();
- }
- };
- #endif // GRAPH_H
|