KChart

KChartAbstractGrid.cpp
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#include "KChartAbstractGrid.h"
10#include "KChartPaintContext.h"
11
12#include "KChartMath_p.h"
13
14#include <qglobal.h>
15
16
17using namespace KChart;
18using namespace std;
19
20
21static qreal _trunc( qreal v )
22{
23 return (( v > 0.0 ) ? floor( v ) : ceil( v ));
24}
25
26
27AbstractGrid::AbstractGrid ()
28 : mPlane( nullptr )
29{
30 // this block left empty intentionally
31}
32
33AbstractGrid::~AbstractGrid()
34{
35 // this block left empty intentionally
36}
37
39{
40 mCachedRawDataDimensions.clear();
41}
42
44{
45 if ( plane ) {
46 const DataDimensionsList rawDataDimensions( plane->getDataDimensionsList() );
47 // ### this could be dangerous because calculateGrid() looks at some data we are not checking
48 // for changes here.
49 if ( mCachedRawDataDimensions.empty() || ( rawDataDimensions != mCachedRawDataDimensions ) ) {
50 mCachedRawDataDimensions = rawDataDimensions;
51 mPlane = plane;
52 mDataDimensions = calculateGrid( rawDataDimensions );
53 }
54 }
55 return mDataDimensions;
56}
57
59{
60 return isBoundariesValid( qMakePair( r.topLeft(), r.bottomRight() ) );
61}
62
63bool AbstractGrid::isBoundariesValid(const QPair<QPointF,QPointF>& b )
64{
65 return isValueValid( b.first.x() ) && isValueValid( b.first.y() ) &&
66 isValueValid( b.second.x() ) && isValueValid( b.second.y() );
67}
68
70{
71 for (int i = 0; i < l.size(); ++i)
72 if ( ! isValueValid( l.at(i).start ) || ! isValueValid( l.at(i).end ) )
73 return false;
74 return true;
75}
76
77bool AbstractGrid::isValueValid(const qreal& r )
78{
79 return !(ISNAN(r) || ISINF(r));
80}
81
83 qreal& start, qreal& end,
84 qreal stepWidth,
85 bool adjustLower, bool adjustUpper )
86{
87 const qreal startAdjust = ( start >= 0.0 ) ? 0.0 : -1.0;
88 const qreal endAdjust = ( end >= 0.0 ) ? 1.0 : 0.0;
89 if ( adjustLower && !qFuzzyIsNull( fmod( start, stepWidth ) ) )
90 start = stepWidth * (_trunc( start / stepWidth ) + startAdjust);
91 if ( adjustUpper && !qFuzzyIsNull( fmod( end, stepWidth ) ) )
92 end = stepWidth * (_trunc( end / stepWidth ) + endAdjust);
93}
94
96 const DataDimension& dim,
97 bool adjustLower, bool adjustUpper )
98{
99 DataDimension result( dim );
101 result.start, result.end,
102 result.stepWidth,
103 adjustLower, adjustUpper );
104 return result;
105}
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane,...
DataDimensionsList updateData(AbstractCoordinatePlane *plane)
Returns the cached result of data calculation.
static bool isValueValid(const qreal &r)
Checks if r is neither NaN nor infinity.
static void adjustLowerUpperRange(qreal &start, qreal &end, qreal stepWidth, bool adjustLower, bool adjustUpper)
Adjusts start and/or end so that they are a multiple of stepWidth.
void setNeedRecalculate()
Causes grid to be recalculated upon the next call of updateData().
static const DataDimension adjustedLowerUpperRange(const DataDimension &dim, bool adjustLower, bool adjustUpper)
Adjusts dim so that dim.start and/or dim.end are a multiple of dim.stepWidth.
static bool isBoundariesValid(const QRectF &r)
Checks whether both coordinates of r are valid according to isValueValid.
Helper class for one dimension of data, e.g.
Q_SCRIPTABLE Q_NOREPLY void start()
const_reference at(qsizetype i) const const
void clear()
bool empty() const const
qsizetype size() const const
QPointF bottomRight() const const
QPointF topLeft() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.