KChart

KChartPlotterDiagramCompressor.h
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KD Chart library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#ifndef PLOTTERDIAGRAMCOMPRESSOR_H
10#define PLOTTERDIAGRAMCOMPRESSOR_H
11
12#include <QObject>
13#include <QAbstractItemModel>
14#include <QPointer>
15#include <QVector>
16#include <QDateTime>
17
18#include <cmath>
19#include <limits>
20
21namespace KChart
22{
23
24
25class PlotterDiagramCompressor : public QObject
26{
28public:
29
30 enum CompressionMode{ SLOPE = 0, DISTANCE, BOTH };
31 Q_ENUM( CompressionMode )
32
33 class DataPoint {
34 public:
35 DataPoint()
36 : key( std::numeric_limits< qreal >::quiet_NaN() ),
37 value( std::numeric_limits< qreal >::quiet_NaN() ),
38 hidden( false )
39 {}
40 inline qreal distance( const DataPoint &other )
41 {
42 const qreal dx = key - other.key;
43 const qreal dy = value - other.value;
44 return std::sqrt( dx * dx + dy * dy );
45 }
46
47 inline bool operator==( const DataPoint &other )
48 {
49 return key == other.key && value == other.value;
50 }
51
52 inline bool operator!=( const DataPoint &other )
53 {
54 return !( *this == other );
55 }
56
57 qreal key;
58 qreal value;
59 bool hidden;
60 QModelIndex index;
61 };
62
63 class Iterator
64 {
65 friend class PlotterDiagramCompressor;
66 public:
67 Iterator( int dataSet, PlotterDiagramCompressor *parent );
68 ~Iterator();
69 bool isValid() const;
70 Iterator& operator++();
71 Iterator operator++( int );
72 Iterator& operator += ( int value );
73 Iterator& operator--();
74 Iterator operator--( int );
75 Iterator& operator-=( int value );
76 DataPoint operator*();
77 bool operator==( const Iterator &other ) const;
78 bool operator!=( const Iterator &other ) const;
79 void invalidate();
80 protected:
81 Iterator( int dataSet, PlotterDiagramCompressor *parent, QVector< DataPoint > buffer );
82 private:
83 void handleSlopeForward( const DataPoint &dp );
85 QVector< DataPoint > m_buffer;
86 int m_index;
87 int m_dataset;
88 int m_bufferIndex;
89 int m_rebuffer;
90 QDateTime m_timeOfCreation;
91 };
92
93 typedef QVector<DataPoint> DataPointVector;
94 class CachePosition {
95 public:
96 CachePosition()
97 : first( -1 ),
98 second( -1 )
99 {}
100 CachePosition( int first, int second )
101 : first( first ),
102 second( second )
103 {}
104 int first;
105 int second;
106
107 bool operator==( const CachePosition& rhs ) const
108 {
109 return first == rhs.first &&
110 second == rhs.second;
111 }
112 };
113 explicit PlotterDiagramCompressor(QObject *parent = nullptr);
114 ~PlotterDiagramCompressor() override;
115 Iterator begin( int dataSet );
116 Iterator end( int dataSet );
117 void setMergeRadius( qreal radius );
118 void setMergeRadiusPercentage( qreal radius );
119 void setModel( QAbstractItemModel *model );
120 QAbstractItemModel* model() const;
121 DataPoint data( const CachePosition& pos ) const;
122 int rowCount() const;
123 int datasetCount() const;
124 void setCompressionModel( CompressionMode value );
125 void setMaxSlopeChange( qreal value );
126 qreal maxSlopeChange() const;
127 void cleanCache();
128 QPair< QPointF, QPointF > dataBoundaries() const;
129 void setForcedDataBoundaries( const QPair< qreal, qreal > &bounds, Qt::Orientation direction );
131 void boundariesChanged();
132 void rowCountChanged();
133
134private:
135 class Private;
136 Private *d;
137};
138
139}
140
141#endif // PLOTTERDIAGRAMCOMPRESSOR_H
Q_ENUM(...)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
T qobject_cast(QObject *object)
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.