13#include "KDChartPlotterDiagramCompressor_p.h"
14#include <QtCore/QPointF>
16#include <KDABLibFakes>
34 if (
parent->rowCount() > m_dataset &&
parent->rowCount() > 0) {
50 , m_timeOfCreation(
QDateTime::currentDateTime())
57 if (
parent->datasetCount() > m_dataset &&
parent->rowCount() > 0 && m_buffer.isEmpty()) {
67 if (m_parent.data()->d->m_timeOfLastInvalidation < m_timeOfCreation)
68 m_parent.data()->d->m_bufferlist[m_dataset] = m_buffer;
74 if (m_parent ==
nullptr)
76 return m_dataset >= 0 && m_index >= 0 && m_parent.data()->rowCount() > m_index;
242void PlotterDiagramCompressor::Iterator::handleSlopeForward(
const DataPoint &
dp)
251 if (m_bufferIndex > 1) {
262 if (m_index >= m_parent.data()->rowCount()) {
265 m_index =
parent->rowCount();
270 newdp =
parent->data(CachePosition(m_index, m_dataset));
282 m_buffer.append(
newdp);
291 const int count =
parent->rowCount();
298 if (m_index >= count || (!m_rebuffer && m_bufferIndex == m_buffer.count())) {
299 if (m_bufferIndex == m_buffer.count()) {
301 m_index =
parent->rowCount();
309 if (m_bufferIndex == m_buffer.count() && m_index >= 0 && m_rebuffer) {
313 handleSlopeForward(
dp);
330 for (
int index = m_index; index + value != m_index; ++(*this)) { };
359 if (m_index == m_parent.data()->rowCount())
360 return m_parent.data()->data(
CachePosition(m_parent.data()->rowCount() - 1, m_dataset));
361 return m_buffer[m_bufferIndex];
366 return m_parent.data() ==
other.m_parent.data() && m_index ==
other.m_index && m_dataset ==
other.m_dataset;
371 return !(*
this ==
other);
391void PlotterDiagramCompressor::Private::setModelToZero()
531void PlotterDiagramCompressor::Private::rowsInserted(
const QModelIndex & ,
int start,
int end)
537 calculateDataBoundaries();
558 olddp = m_parent->data(CachePosition(start - 1,
dataset));
570 for (
int row = start; row <=
end; ++row) {
611 for (
int row = start; row <=
end; ++row) {
632 Q_EMIT m_parent->rowCountChanged();
638 if (d->m_mode != value) {
645void PlotterDiagramCompressor::Private::setBoundaries(
const Boundaries &
bound)
649 Q_EMIT m_parent->boundariesChanged();
653void PlotterDiagramCompressor::Private::calculateDataBoundaries()
656 qreal minX = std::numeric_limits<qreal>::quiet_NaN();
657 qreal minY = std::numeric_limits<qreal>::quiet_NaN();
658 qreal maxX = std::numeric_limits<qreal>::quiet_NaN();
659 qreal maxY = std::numeric_limits<qreal>::quiet_NaN();
661 for (
int row = 0; row < m_parent->rowCount(); ++row) {
685QModelIndexList PlotterDiagramCompressor::Private::mapToModel(
const CachePosition &pos)
687 QModelIndexList indexes;
689 index = m_model->index(pos.first, pos.second * 2,
QModelIndex());
692 index = m_model->index(pos.first, pos.second * 2 + 1,
QModelIndex());
706void PlotterDiagramCompressor::Private::clearBuffer()
733 d->m_forcedYBoundaries =
bounds;
735 d->m_forcedXBoundaries =
bounds;
751 d->m_model->disconnect(
this);
752 d->m_model->disconnect(d);
758 d->calculateDataBoundaries();
768 QModelIndexList indexes = d->mapToModel(pos);
780 point.
index = indexes.first();
786 if (d->m_mergeRadius != radius) {
787 d->m_mergeRadius = radius;
795 if (d->m_maxSlopeRadius != value) {
796 d->m_maxSlopeRadius = value;
803 return d->m_maxSlopeRadius;
817 return d->m_model ? d->m_model->rowCount() : 0;
827 if (d->m_model && d->m_model->columnCount() == 0)
829 return d->m_model ? (d->m_model->columnCount() + 1) / 2 : 0;
836 bounds.first.setY(d->m_forcedYBoundaries.first);
837 bounds.second.setY(d->m_forcedYBoundaries.second);
840 bounds.first.setX(d->m_forcedXBoundaries.first);
841 bounds.second.setX(d->m_forcedXBoundaries.second);
qreal calculateSlope(const PlotterDiagramCompressor::DataPoint &lhs, const PlotterDiagramCompressor::DataPoint &rhs)
bool inBoundary(const QPair< qreal, qreal > &bounds, qreal value)
bool operator!=(const Iterator &other) const
Iterator & operator-=(int value)
Iterator & operator+=(int value)
bool operator==(const Iterator &other) const
Iterator(int dataSet, PlotterDiagramCompressor *parent)
Iterator begin(int dataSet)
QPair< QPointF, QPointF > dataBoundaries() const
DataPoint data(const CachePosition &pos) const
void setCompressionModel(CompressionMode value)
void setForcedDataBoundaries(const QPair< qreal, qreal > &bounds, Qt::Orientation direction)
Iterator end(int dataSet)
QAbstractItemModel * model() const
void setModel(QAbstractItemModel *model)
void setMergeRadiusPercentage(qreal radius)
PlotterDiagramCompressor(QObject *parent=nullptr)
~PlotterDiagramCompressor() override
void setMaxSlopeChange(qreal value)
void setMergeRadius(qreal radius)
qreal maxSlopeChange() const
void rowsInserted(const QModelIndex &parent, int first, int last)
QDateTime currentDateTime()
bool isValid() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void destroyed(QObject *obj)
QObject * parent() const const
T qobject_cast(QObject *object)