KChart

KChartAbstractGrid.h
1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef KCHARTABSTRACTGRID_H
21 #define KCHARTABSTRACTGRID_H
22 
23 #include <QPair>
24 
25 #include "KChartAbstractCoordinatePlane.h"
26 #include "KChartGridAttributes.h"
27 #include "KChartAbstractDiagram.h"
28 #include "KChartCartesianAxis.h"
29 
30 namespace KChart {
31 
32  class PaintContext;
33 
34 
35  /**
36  * \internal
37  *
38  * \brief Abstract base class for grid classes: cartesian, polar, ...
39  *
40  * The AbstractGrid interface is the base class used by
41  * AbstractCoordinatePlane, for calculating and for drawing
42  * the grid lines of the plane.
43  */
45  {
46  public:
47  virtual ~AbstractGrid();
48  protected:
49  AbstractGrid ();
50 
51 
52  public:
53  /** \brief Returns the cached result of data calculation.
54  *
55  * For this, all derived classes need to implement the
56  * pure-virtual calculateGrid() method.
57  */
59 
60  /**
61  * Doing the actual drawing.
62  *
63  * Every derived class must implement this.
64  *
65  * \note When implementing drawGrid(): Before you start drawing,
66  * make sure to call updateData(), to get the data boundaries
67  * recalculated.
68  * For an example, see the implementation of CartesianGrid:drawGrid().
69  */
70  virtual void drawGrid( PaintContext* context ) = 0;
71 
72  /**
73  * Causes grid to be recalculated upon the next call
74  * of updateData().
75  *
76  * \see calculateGrid
77  */
78  void setNeedRecalculate();
79 
80  /**
81  * Checks whether both coordinates of r are valid according
82  * to isValueValid
83  *
84  * \see isValueValid
85  */
86  static bool isBoundariesValid(const QRectF& r );
87 
88  /**
89  * Checks whether both coordinates of both points are valid
90  * according to isValueValid
91  *
92  * \see isValueValid
93  */
94  static bool isBoundariesValid(const QPair<QPointF,QPointF>& b );
95 
96  /**
97  * Checks whether all start and end properties of every
98  * DataDimension in the list l are valid according to
99  * isValueValid().
100  *
101  * \see isValueValid
102  */
103  static bool isBoundariesValid(const DataDimensionsList& l );
104 
105  /**
106  * Checks if r is neither NaN nor infinity.
107  */
108  static bool isValueValid(const qreal& r );
109 
110  /**
111  * Adjusts \a start and/or \a end so that they are a multiple of
112  * \a stepWidth
113  */
114  static void adjustLowerUpperRange(
115  qreal& start, qreal& end,
116  qreal stepWidth,
117  bool adjustLower, bool adjustUpper );
118 
119  /**
120  * Adjusts \a dim so that \c dim.start and/or \c dim.end are a multiple
121  * of \c dim.stepWidth.
122  *
123  * \see adjustLowerUpperRange
124  */
126  const DataDimension& dim,
127  bool adjustLower, bool adjustUpper );
128 
129  GridAttributes gridAttributes;
130 
131  protected:
132  DataDimensionsList mDataDimensions;
133  AbstractCoordinatePlane* mPlane;
134 
135  private:
136  /**
137  * \brief Calculates the grid start/end/step width values.
138  *
139  * Gets the raw data dimensions - e.g. the data model's boundaries,
140  * together with their isCalculated flags.
141  *
142  * Returns the calculated start/end values for the grid, and their
143  * respective step widths.
144  * If at least one of the step widths is Zero, all dimensions of
145  * the returned list are considered invalid!
146  *
147  * \note This function needs to be implemented by all derived classes,
148  * like CartesianGrid, PolarGrid, ...
149  */
150  virtual DataDimensionsList calculateGrid( const DataDimensionsList& rawDataDimensions ) const = 0;
151  DataDimensionsList mCachedRawDataDimensions;
152  };
153 
154 }
155 
156 #endif
Helper class for one dimension of data, e.g.
void setNeedRecalculate()
Causes grid to be recalculated upon the next call of updateData().
static bool isBoundariesValid(const QRectF &r)
Checks whether both coordinates of r are valid according to isValueValid.
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.
Stores information about painting diagrams.
virtual void drawGrid(PaintContext *context)=0
Doing the actual drawing.
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane, TernaryCoordinatePlane.
DataDimensionsList updateData(AbstractCoordinatePlane *plane)
Returns the cached result of data calculation.
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.
A set of attributes controlling the appearance of grids.
static bool isValueValid(const qreal &r)
Checks if r is neither NaN nor infinity.
Global namespace.
Abstract base class for grid classes: cartesian, polar, ...
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 9 2021 22:36:27 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.