graph.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef GRAPH_H
  2. #define GRAPH_H
  3. #include "qcustomplot.h"
  4. class GraphColoredSegment
  5. {
  6. public:
  7. GraphColoredSegment(QCPDataRange dataRange, QPen pen, QBrush brush)
  8. : mDataRange(dataRange), mPen(pen), mBrush(brush)
  9. {
  10. }
  11. QCPDataRange dataRange() const { return mDataRange; }
  12. QPen pen() const { return mPen; }
  13. QBrush brush() const { return mBrush; }
  14. private:
  15. QCPDataRange mDataRange;
  16. QPen mPen;
  17. QBrush mBrush;
  18. };
  19. class PlotTimeGraph : public QCPGraph
  20. {
  21. Q_OBJECT
  22. public:
  23. enum FillStyle
  24. {
  25. fsZero,
  26. fsBottom
  27. };
  28. PlotTimeGraph(QCPAxis *keyAxis, QCPAxis *valueAxis);
  29. void addColoredSegment(double lowerValue, double upperValue, QPen pen, QBrush brush);
  30. void clearColoredSegments();
  31. FillStyle getFillStyle() const;
  32. void setFillStyle(const FillStyle &fillStyle);
  33. protected:
  34. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  35. virtual void drawFill(QCPPainter *painter, QVector<QPointF> *lines) const Q_DECL_OVERRIDE;
  36. const QPolygonF getCustomFillPolygon(const QVector<QPointF> *lineData, QCPDataRange segment) const;
  37. QPointF getCustomFillBasePoint(QPointF matchingDataPoint) const;
  38. private:
  39. QList<double> mLowerValues;
  40. QList<double> mUpperValues;
  41. QList<QPen> mPens;
  42. QList<QBrush> mBrushs;
  43. FillStyle mFillStyle;
  44. inline static bool lessThanSegment(const GraphColoredSegment &a, const GraphColoredSegment &b)
  45. {
  46. return a.dataRange().begin() < b.dataRange().begin();
  47. }
  48. };
  49. #endif // GRAPH_H