KD Chart 2  [rev.2.6]
KDChartPlotterDiagramCompressor.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2019 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #ifndef PLOTTERDIAGRAMCOMPRESSOR_H
24 #define PLOTTERDIAGRAMCOMPRESSOR_H
25 
26 #include <QtCore/QObject>
27 #include <QtCore/QAbstractItemModel>
28 #if QT_VERSION < 0x050000
29 #include <QtCore/QWeakPointer>
30 #else
31 #include <QtCore/QPointer>
32 #endif
33 #include <QtCore/QVector>
34 #include <QtCore/QDateTime>
35 
36 #include <cmath>
37 #include <limits>
38 
39 namespace KDChart
40 {
41 
42 
44 {
45  Q_OBJECT
46  Q_ENUMS( CompressionMode )
47 public:
48 
50  class DataPoint {
51  public:
53  : key( std::numeric_limits< qreal >::quiet_NaN() ),
54  value( std::numeric_limits< qreal >::quiet_NaN() ),
55  hidden( false )
56  {}
57  inline qreal distance( const DataPoint &other )
58  {
59  const qreal dx = key - other.key;
60  const qreal dy = value - other.value;
61  return std::sqrt( dx * dx + dy * dy );
62  }
63 
64  inline bool operator==( const DataPoint &other )
65  {
66  return key == other.key && value == other.value;
67  }
68 
69  inline bool operator!=( const DataPoint &other )
70  {
71  return !( *this == other );
72  }
73 
74  qreal key;
75  qreal value;
76  bool hidden;
77  QModelIndex index;
78  };
79 
80  class Iterator
81  {
83  public:
84  Iterator( int dataSet, PlotterDiagramCompressor *parent );
85  ~Iterator();
86  bool isValid() const;
87  Iterator& operator++();
88  Iterator operator++( int );
89  Iterator& operator += ( int value );
90  Iterator& operator--();
91  Iterator operator--( int );
92  Iterator& operator-=( int value );
93  DataPoint operator*();
94  bool operator==( const Iterator &other ) const;
95  bool operator!=( const Iterator &other ) const;
96  void invalidate();
97  protected:
98  Iterator( int dataSet, PlotterDiagramCompressor *parent, QVector< DataPoint > buffer );
99  private:
100  void handleSlopeForward( const DataPoint &dp );
101 #if QT_VERSION < 0x050000
102  QWeakPointer< PlotterDiagramCompressor > m_parent;
103 #else
104  QPointer< PlotterDiagramCompressor > m_parent;
105 #endif
106  QVector< DataPoint > m_buffer;
107  int m_index;
108  int m_dataset;
109  int m_bufferIndex;
110  int m_rebuffer;
111  QDateTime m_timeOfCreation;
112  };
113 
116  public:
118  : first( -1 ),
119  second( -1 )
120  {}
121  CachePosition( int first, int second )
122  : first( first ),
123  second( second )
124  {}
125  int first;
126  int second;
127 
128  bool operator==( const CachePosition& rhs ) const
129  {
130  return first == rhs.first &&
131  second == rhs.second;
132  }
133  };
134  explicit PlotterDiagramCompressor(QObject *parent = 0);
136  Iterator begin( int dataSet );
137  Iterator end( int dataSet );
138  void setMergeRadius( qreal radius );
139  void setMergeRadiusPercentage( qreal radius );
140  void setModel( QAbstractItemModel *model );
141  QAbstractItemModel* model() const;
142  DataPoint data( const CachePosition& pos ) const;
143  int rowCount() const;
144  int datasetCount() const;
146  void setMaxSlopeChange( qreal value );
147  qreal maxSlopeChange() const;
148  void cleanCache();
150  void setForcedDataBoundaries( const QPair< qreal, qreal > &bounds, Qt::Orientation direction );
151 Q_SIGNALS:
152  void boundariesChanged();
153  void rowCountChanged();
154 
155 private:
156  class Private;
157  Private *d;
158 };
159 
160 }
161 
162 #endif // PLOTTERDIAGRAMCOMPRESSOR_H
DataPoint data(const CachePosition &pos) const
QPair< QPointF, QPointF > dataBoundaries() const
Class only listed here to document inheritance of some KDChart classes.
void setForcedDataBoundaries(const QPair< qreal, qreal > &bounds, Qt::Orientation direction)

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
https://www.kdab.com/
https://www.kdab.com/products/kd-chart/