24 #include "KDChartPolarCoordinatePlane_p.h"
26 #include "KDChartPainterSaver_p.h"
41 #include <KDABLibFakes>
43 using namespace KDChart;
58 void PolarCoordinatePlane::init()
65 Q_ASSERT_X ( dynamic_cast<AbstractPolarDiagram*> ( diagram ),
66 "PolarCoordinatePlane::addDiagram",
"Only polar"
67 "diagrams can be added to a polar coordinate plane!" );
77 if (
d->coordinateTransformations.size() != diags.size() ) {
82 Q_ASSERT( !
d->coordinateTransformations.isEmpty() );
86 ctx.setCoordinatePlane (
this );
93 d->newZoomX = oldZoomX;
94 d->newZoomY = oldZoomY;
95 for (
int i = 0; i < diags.size(); i++ ) {
96 d->currentTransformation = & (
d->coordinateTransformations[i] );
101 polarDia->
paint( &ctx,
true, zoomX, zoomY );
102 d->newZoomX = qMin(
d->newZoomX, zoomX );
103 d->newZoomY = qMin(
d->newZoomY, zoomY );
107 if (
d->newZoomX != oldZoomX ||
d->newZoomY != oldZoomY ) {
109 d->currentTransformation = 0;
110 QMetaObject::invokeMethod(
this,
"adjustZoomAndRepaint", Qt::QueuedConnection );
117 d->currentTransformation = &
d->coordinateTransformations.first();
118 d->grid->drawGrid( &ctx );
121 for (
int i = 0; i < diags.size(); i++ ) {
122 d->currentTransformation = & (
d->coordinateTransformations[i] );
123 PainterSaver painterSaver( painter );
126 qreal dummy1, dummy2;
127 polarDia->
paint( &ctx,
false, dummy1, dummy2 );
129 diags[i]->paint( &ctx );
132 d->currentTransformation = 0;
138 const qreal newZoom = qMin(
d->newZoomX,
d->newZoomY);
146 d->initialResizeEventReceived =
true;
159 d->contentRect = QRectF ( 1, 1, rect.width() - 3, rect.height() - 3 );
162 :
d->coordinateTransformations.front().zoom;
165 d->coordinateTransformations.clear();
169 Q_ASSERT( polarDiagram );
174 const qreal radius = qAbs( dataBoundariesPair.first.y() ) + dataBoundariesPair.second.y();
176 const qreal diagramWidth = radius * 2;
177 const qreal planeWidth =
d->contentRect.width();
178 const qreal planeHeight =
d->contentRect.height();
179 const qreal
radiusUnit = qMin( planeWidth, planeHeight ) / diagramWidth;
181 QPointF coordinateOrigin = QPointF ( planeWidth / 2, planeHeight / 2 );
182 coordinateOrigin +=
d->contentRect.topLeft();
184 CoordinateTransformation diagramTransposition;
185 diagramTransposition.originTranslation = coordinateOrigin;
187 diagramTransposition.angleUnit =
angleUnit;
188 diagramTransposition.startPosition = oldStartPosition;
189 diagramTransposition.zoom = zoom;
190 diagramTransposition.minValue = dataBoundariesPair.first.y() < 0 ? dataBoundariesPair.first.y() : 0.0;
191 d->coordinateTransformations.append( diagramTransposition );
198 Q_ASSERT_X (
d->currentTransformation != 0,
"PolarCoordinatePlane::translate",
199 "Only call translate() from within paint()." );
200 return d->currentTransformation->translate ( diagramPoint );
205 Q_ASSERT_X (
d->currentTransformation != 0,
"PolarCoordinatePlane::translate",
206 "Only call translate() from within paint()." );
207 return d->currentTransformation->translatePolar ( diagramPoint );
212 Q_ASSERT_X (
d->currentTransformation != 0,
"PolarCoordinatePlane::angleUnit",
213 "Only call angleUnit() from within paint()." );
214 return d->currentTransformation->angleUnit;
219 Q_ASSERT_X (
d->currentTransformation != 0,
"PolarCoordinatePlane::radiusUnit",
220 "Only call radiusUnit() from within paint()." );
221 return d->currentTransformation->radiusUnit;
231 Q_ASSERT_X (
diagram(),
"PolarCoordinatePlane::setStartPosition",
232 "setStartPosition() needs a diagram to be associated to the plane." );
233 for ( CoordinateTransformationList::iterator it =
d->coordinateTransformations.begin();
234 it !=
d->coordinateTransformations.end();
237 CoordinateTransformation& trans = *it;
238 trans.startPosition = degrees;
244 return d->coordinateTransformations.isEmpty()
246 :
d->coordinateTransformations.first().startPosition;
251 return d->coordinateTransformations.isEmpty()
253 :
d->coordinateTransformations.first().zoom.xFactor;
258 return d->coordinateTransformations.isEmpty()
260 :
d->coordinateTransformations.first().zoom.yFactor;
271 for ( CoordinateTransformationList::iterator it =
d->coordinateTransformations.begin();
272 it !=
d->coordinateTransformations.end();
275 CoordinateTransformation& trans = *it;
276 trans.zoom.xFactor = factor;
282 for ( CoordinateTransformationList::iterator it =
d->coordinateTransformations.begin();
283 it !=
d->coordinateTransformations.end();
286 CoordinateTransformation& trans = *it;
287 trans.zoom.yFactor = factor;
293 return d->coordinateTransformations.isEmpty()
294 ? QPointF( 0.5, 0.5 )
295 : QPointF(
d->coordinateTransformations.first().zoom.xCenter,
d->coordinateTransformations.first().zoom.yCenter );
300 for ( CoordinateTransformationList::iterator it =
d->coordinateTransformations.begin();
301 it !=
d->coordinateTransformations.end();
304 CoordinateTransformation& trans = *it;
305 trans.zoom.xCenter = center.x();
306 trans.zoom.yCenter = center.y();
324 d->gridAttributesCircular = a;
326 d->gridAttributesSagittal = a;
327 setHasOwnGridAttributes( circular,
true );
329 emit propertiesChanged();
335 setHasOwnGridAttributes( circular,
false );
340 bool circular )
const
342 if ( hasOwnGridAttributes( circular ) ) {
344 return d->gridAttributesCircular;
346 return d->gridAttributesSagittal;
348 return globalGridAttributes();
355 QPointF referencePointAtTop = plane->
translate( QPointF( 1, 0 ) );
356 QPointF temp = plane->
translate( QPointF( 0, 0 ) ) - referencePointAtTop;
357 const qreal offset = temp.y();
358 referencePointAtTop.setX( referencePointAtTop.x() - offset );
359 contentsRect.setTopLeft( referencePointAtTop );
360 contentsRect.setBottomRight( referencePointAtTop + QPointF( 2.0 * offset, 2.0 * offset) );
364 void KDChart::PolarCoordinatePlane::setHasOwnGridAttributes(
365 bool circular,
bool on )
368 d->hasOwnGridAttributesCircular = on;
370 d->hasOwnGridAttributesSagittal = on;
371 emit propertiesChanged();
375 bool circular )
const
379 ?
d->hasOwnGridAttributesCircular
380 :
d->hasOwnGridAttributesSagittal;