File indexing completed on 2024-06-09 04:18:32
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 KCHARTPOLARCOORDINATEPLANE_P_H 0010 #define KCHARTPOLARCOORDINATEPLANE_P_H 0011 0012 // 0013 // W A R N I N G 0014 // ------------- 0015 // 0016 // This file is not part of the KD Chart API. It exists purely as an 0017 // implementation detail. This header file may change from version to 0018 // version without notice, or even be removed. 0019 // 0020 // We mean it. 0021 // 0022 0023 #include "KChartAbstractCoordinatePlane_p.h" 0024 #include "KChartZoomParameters.h" 0025 #include "KChartPolarGrid.h" 0026 #include "KChartMath_p.h" 0027 0028 0029 namespace KChart { 0030 0031 /** 0032 * \internal 0033 */ 0034 struct PolarCoordinatePlane::CoordinateTransformation 0035 { 0036 // represents the distance of the diagram coordinate origin to the 0037 // origin of the coordinate plane space: 0038 QPointF originTranslation; 0039 qreal radiusUnit; 0040 qreal angleUnit; 0041 qreal minValue; 0042 0043 qreal startPosition; 0044 ZoomParameters zoom; 0045 0046 static QPointF polarToCartesian( qreal R, qreal theta ) 0047 { 0048 // de-inline me 0049 return QPointF( R * cos( DEGTORAD( theta ) ), R * sin( DEGTORAD( theta ) ) ); 0050 } 0051 0052 inline const QPointF translate( const QPointF& diagramPoint ) const 0053 { 0054 // ### de-inline me 0055 // calculate the polar coordinates 0056 const qreal x = (diagramPoint.x() * radiusUnit) - (minValue * radiusUnit); 0057 //qDebug() << x << "=" << diagramPoint.x() << "*" << radiusUnit << " startPosition: " << startPosition; 0058 const qreal y = ( diagramPoint.y() * -angleUnit) - 90.0 - startPosition; 0059 // convert to cartesian coordinates 0060 QPointF cartesianPoint = polarToCartesian( x, y ); 0061 cartesianPoint.setX( cartesianPoint.x() * zoom.xFactor ); 0062 cartesianPoint.setY( cartesianPoint.y() * zoom.yFactor ); 0063 0064 QPointF newOrigin = originTranslation; 0065 qreal minOrigin = qMin( newOrigin.x(), newOrigin.y() ); 0066 newOrigin.setX( newOrigin.x() + minOrigin * ( 1 - zoom.xCenter * 2 ) * zoom.xFactor ); 0067 newOrigin.setY( newOrigin.y() + minOrigin * ( 1 - zoom.yCenter * 2 ) * zoom.yFactor ); 0068 0069 return newOrigin + cartesianPoint; 0070 } 0071 0072 inline const QPointF translatePolar( const QPointF& diagramPoint ) const 0073 { 0074 // ### de-inline me 0075 return QPointF( diagramPoint.x() * angleUnit, diagramPoint.y() * radiusUnit ); 0076 } 0077 }; 0078 0079 class Q_DECL_HIDDEN PolarCoordinatePlane::Private : public AbstractCoordinatePlane::Private 0080 { 0081 friend class PolarCoordinatePlane; 0082 public: 0083 explicit Private() 0084 : currentTransformation(nullptr) 0085 , initialResizeEventReceived(false ) 0086 , hasOwnGridAttributesCircular ( false ) 0087 , hasOwnGridAttributesSagittal ( false ) 0088 {} 0089 0090 ~Private() override { } 0091 0092 void initialize() override 0093 { 0094 grid = new PolarGrid(); 0095 } 0096 0097 static QRectF contentsRect( const PolarCoordinatePlane* plane ); 0098 0099 // the coordinate plane will calculate coordinate transformations for all 0100 // diagrams and store them here: 0101 CoordinateTransformationList coordinateTransformations; 0102 // when painting, this pointer selects the coordinate transformation for 0103 // the current diagram: 0104 CoordinateTransformation* currentTransformation; 0105 // the reactangle occupied by the diagrams, in plane coordinates 0106 QRectF contentRect; 0107 // true after the first resize event came in 0108 bool initialResizeEventReceived; 0109 0110 // true after setGridAttributes( Qt::Orientation ) was used, 0111 // false if resetGridAttributes( Qt::Orientation ) was called 0112 bool hasOwnGridAttributesCircular; 0113 bool hasOwnGridAttributesSagittal; 0114 0115 GridAttributes gridAttributesCircular; 0116 GridAttributes gridAttributesSagittal; 0117 0118 qreal newZoomX, newZoomY; 0119 }; 0120 0121 0122 0123 KCHART_IMPL_DERIVED_PLANE(PolarCoordinatePlane, AbstractCoordinatePlane) 0124 0125 } 0126 0127 #endif /* KCHARTBARDIAGRAM_P_H */