File indexing completed on 2024-05-12 04:20:30
0001 /* 0002 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KCHARTABSTRACTGRID_H 0010 #define KCHARTABSTRACTGRID_H 0011 0012 #include <QPair> 0013 0014 #include "KChartAbstractCoordinatePlane.h" 0015 #include "KChartGridAttributes.h" 0016 #include "KChartAbstractDiagram.h" 0017 #include "KChartCartesianAxis.h" 0018 0019 namespace KChart { 0020 0021 class PaintContext; 0022 0023 0024 /** 0025 * \internal 0026 * 0027 * \brief Abstract base class for grid classes: cartesian, polar, ... 0028 * 0029 * The AbstractGrid interface is the base class used by 0030 * AbstractCoordinatePlane, for calculating and for drawing 0031 * the grid lines of the plane. 0032 */ 0033 class AbstractGrid 0034 { 0035 public: 0036 virtual ~AbstractGrid(); 0037 protected: 0038 AbstractGrid (); 0039 0040 0041 public: 0042 /** \brief Returns the cached result of data calculation. 0043 * 0044 * For this, all derived classes need to implement the 0045 * pure-virtual calculateGrid() method. 0046 */ 0047 DataDimensionsList updateData( AbstractCoordinatePlane* plane ); 0048 0049 /** 0050 * Doing the actual drawing. 0051 * 0052 * Every derived class must implement this. 0053 * 0054 * \note When implementing drawGrid(): Before you start drawing, 0055 * make sure to call updateData(), to get the data boundaries 0056 * recalculated. 0057 * For an example, see the implementation of CartesianGrid:drawGrid(). 0058 */ 0059 virtual void drawGrid( PaintContext* context ) = 0; 0060 0061 /** 0062 * Causes grid to be recalculated upon the next call 0063 * of updateData(). 0064 * 0065 * \see calculateGrid 0066 */ 0067 void setNeedRecalculate(); 0068 0069 /** 0070 * Checks whether both coordinates of r are valid according 0071 * to isValueValid 0072 * 0073 * \see isValueValid 0074 */ 0075 static bool isBoundariesValid(const QRectF& r ); 0076 0077 /** 0078 * Checks whether both coordinates of both points are valid 0079 * according to isValueValid 0080 * 0081 * \see isValueValid 0082 */ 0083 static bool isBoundariesValid(const QPair<QPointF,QPointF>& b ); 0084 0085 /** 0086 * Checks whether all start and end properties of every 0087 * DataDimension in the list l are valid according to 0088 * isValueValid(). 0089 * 0090 * \see isValueValid 0091 */ 0092 static bool isBoundariesValid(const DataDimensionsList& l ); 0093 0094 /** 0095 * Checks if r is neither NaN nor infinity. 0096 */ 0097 static bool isValueValid(const qreal& r ); 0098 0099 /** 0100 * Adjusts \a start and/or \a end so that they are a multiple of 0101 * \a stepWidth 0102 */ 0103 static void adjustLowerUpperRange( 0104 qreal& start, qreal& end, 0105 qreal stepWidth, 0106 bool adjustLower, bool adjustUpper ); 0107 0108 /** 0109 * Adjusts \a dim so that \c dim.start and/or \c dim.end are a multiple 0110 * of \c dim.stepWidth. 0111 * 0112 * \see adjustLowerUpperRange 0113 */ 0114 static const DataDimension adjustedLowerUpperRange( 0115 const DataDimension& dim, 0116 bool adjustLower, bool adjustUpper ); 0117 0118 GridAttributes gridAttributes; 0119 0120 protected: 0121 DataDimensionsList mDataDimensions; 0122 AbstractCoordinatePlane* mPlane; 0123 0124 private: 0125 /** 0126 * \brief Calculates the grid start/end/step width values. 0127 * 0128 * Gets the raw data dimensions - e.g. the data model's boundaries, 0129 * together with their isCalculated flags. 0130 * 0131 * Returns the calculated start/end values for the grid, and their 0132 * respective step widths. 0133 * If at least one of the step widths is Zero, all dimensions of 0134 * the returned list are considered invalid! 0135 * 0136 * \note This function needs to be implemented by all derived classes, 0137 * like CartesianGrid, PolarGrid, ... 0138 */ 0139 virtual DataDimensionsList calculateGrid( const DataDimensionsList& rawDataDimensions ) const = 0; 0140 DataDimensionsList mCachedRawDataDimensions; 0141 }; 0142 0143 } 0144 0145 #endif