KD Chart API Documentation  3.1
KDChartPlotterDiagramCompressor.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** This file is part of the KD Chart library.
4 **
5 ** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: MIT
8 **
9 ****************************************************************************/
10 
11 #ifndef PLOTTERDIAGRAMCOMPRESSOR_H
12 #define PLOTTERDIAGRAMCOMPRESSOR_H
13 
14 #include <QtCore/QAbstractItemModel>
15 #include <QtCore/QDateTime>
16 #include <QtCore/QObject>
17 #include <QtCore/QPointer>
18 #include <QtCore/QVector>
19 
20 #include <cmath>
21 #include <limits>
22 
23 namespace KDChart {
24 
25 class PlotterDiagramCompressor : public QObject
26 {
27  Q_OBJECT
28  Q_ENUMS(CompressionMode)
29 public:
31  {
32  SLOPE = 0,
34  BOTH
35  };
36  class DataPoint
37  {
38  public:
40  : key(std::numeric_limits<qreal>::quiet_NaN())
41  , value(std::numeric_limits<qreal>::quiet_NaN())
42  {
43  }
44  inline qreal distance(const DataPoint &other)
45  {
46  const qreal dx = key - other.key;
47  const qreal dy = value - other.value;
48  return std::sqrt(dx * dx + dy * dy);
49  }
50 
51  inline bool operator==(const DataPoint &other)
52  {
53  return key == other.key && value == other.value;
54  }
55 
56  inline bool operator!=(const DataPoint &other)
57  {
58  return !(*this == other);
59  }
60 
61  qreal key;
62  qreal value;
63  bool hidden = false;
64  QModelIndex index;
65  };
66 
67  class Iterator
68  {
70 
71  public:
72  Iterator(int dataSet, PlotterDiagramCompressor *parent);
73  ~Iterator();
74  bool isValid() const;
76  Iterator operator++(int);
77  Iterator &operator+=(int value);
79  Iterator operator--(int);
80  Iterator &operator-=(int value);
82  bool operator==(const Iterator &other) const;
83  bool operator!=(const Iterator &other) const;
84  void invalidate();
85 
86  protected:
87  Iterator(int dataSet, PlotterDiagramCompressor *parent, QVector<DataPoint> &buffer);
88 
89  private:
90  void handleSlopeForward(const DataPoint &dp);
91  QPointer<PlotterDiagramCompressor> m_parent;
92  QVector<DataPoint> m_buffer;
93  int m_index;
94  int m_dataset;
95  int m_bufferIndex;
96  int m_rebuffer;
97  QDateTime m_timeOfCreation;
98  };
99 
100  typedef QVector<DataPoint> DataPointVector;
102  {
103  public:
105  {
106  }
108  : first(first)
109  , second(second)
110  {
111  }
112  int first = -1;
113  int second = -1;
114 
115  bool operator==(const CachePosition &rhs) const
116  {
117  return first == rhs.first && second == rhs.second;
118  }
119  };
120  explicit PlotterDiagramCompressor(QObject *parent = nullptr);
121  ~PlotterDiagramCompressor() override;
122  Iterator begin(int dataSet);
123  Iterator end(int dataSet);
124  void setMergeRadius(qreal radius);
125  void setMergeRadiusPercentage(qreal radius);
126  void setModel(QAbstractItemModel *model);
127  QAbstractItemModel *model() const;
128  DataPoint data(const CachePosition &pos) const;
129  int rowCount() const;
130  int datasetCount() const;
132  void setMaxSlopeChange(qreal value);
133  qreal maxSlopeChange() const;
134  void cleanCache();
135  QPair<QPointF, QPointF> dataBoundaries() const;
136  void setForcedDataBoundaries(const QPair<qreal, qreal> &bounds, Qt::Orientation direction);
137 Q_SIGNALS:
140 
141 private:
142  class Private;
143  Private *d;
144 };
145 }
146 
147 #endif // PLOTTERDIAGRAMCOMPRESSOR_H
Iterator(int dataSet, PlotterDiagramCompressor *parent)
QPair< QPointF, QPointF > dataBoundaries() const
DataPoint data(const CachePosition &pos) const
void setForcedDataBoundaries(const QPair< qreal, qreal > &bounds, Qt::Orientation direction)

© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated by doxygen 1.9.1