24 #include "KDChartPolarCoordinatePlane_p.h" 26 #include "KDChartPainterSaver_p.h" 41 #include <KDABLibFakes> 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 );
335 setHasOwnGridAttributes( circular,
false );
340 bool circular )
const 344 return d->gridAttributesCircular;
346 return d->gridAttributesSagittal;
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;
375 bool circular )
const 379 ?
d->hasOwnGridAttributesCircular
380 :
d->hasOwnGridAttributesSagittal;
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane, TernaryCoordinatePlane.
void setZoomCenter(const QPointF ¢er) override
Set the point (in value coordinates) to be used as the center point in zoom operations.
void setStartPosition(qreal degrees)
Specify the rotation of the coordinate plane.
void resetGridAttributes(bool circular)
Reset the attributes to be used for grid lines drawn in circular direction (or in sagittal direction...
void resizeEvent(QResizeEvent *)
void setPainter(QPainter *painter)
bool hasOwnGridAttributes(bool circular) const
const QPointF translate(const QPointF &diagramPoint) const override
Translate the given point in value space coordinates to a position in pixel space.
QRect geometry() const override
pure virtual in QLayoutItem
virtual qreal valueTotals() const =0
A chart with one or more diagrams.
ZoomParameters stores the center and the factor of zooming internally.
DataDimensionsList getDataDimensionsList() const override
PolarDiagram defines a common polar diagram.
Base class for diagrams based on a polar coordinate system.
qreal zoomFactorX() const override
void update()
Calling update() on the plane triggers the global KDChart::Chart::update()
AbstractDiagram defines the interface for diagram classes.
void adjustZoomAndRepaint()
const GridAttributes gridAttributes(bool circular) const
void setZoomFactors(qreal factorX, qreal factorY) override
Sets both zoom factors in one go.
void addDiagram(AbstractDiagram *diagram) override
Adds a diagram to this coordinate plane.
const QPair< QPointF, QPointF > dataBoundaries() const
Return the bottom left and top right data point, that the diagram will display (unless the grid adjus...
PolarCoordinatePlane(Chart *parent=0)
AbstractDiagram * diagram()
void paint(PaintContext *paintContext) override
[reimplemented]
~PolarCoordinatePlane() override
void setZoomFactorY(qreal factor) override
Sets the zoom factor in vertical direction, that is applied to all coordinate transformations.
QPointF zoomCenter() const override
Stores information about painting diagrams.
void layoutDiagrams() override
Distribute the available space among the diagrams and axes.
qreal zoomFactorY() const override
A set of attributes controlling the appearance of grids.
void paint(QPainter *) override
reimpl
qreal startPosition() const
Retrieve the rotation of the coordinate plane.
void propertiesChanged()
Emitted upon change of a property of the Coordinate Plane or any of its components.
GridAttributes globalGridAttributes() const
void setZoomFactorX(qreal factor) override
Sets the zoom factor in horizontal direction, that is applied to all coordinate transformations.
AbstractDiagramList diagrams()
virtual void addDiagram(AbstractDiagram *diagram)
Adds a diagram to this coordinate plane.
void slotLayoutChanged(AbstractDiagram *diagram)
QRect areaGeometry() const override
const QPointF translatePolar(const QPointF &diagramPoint) const
void setGridAttributes(bool circular, const GridAttributes &)
Set the attributes to be used for grid lines drawn in circular direction (or in sagittal direction...