KChart

KChartPieDiagram.h
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KD Chart library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#ifndef KCHARTPIEDIAGRAM_H
10#define KCHARTPIEDIAGRAM_H
11
12#include "KChartAbstractPieDiagram.h"
13
14namespace KChart {
15
16 class LabelPaintCache;
17
18/**
19 * @brief PieDiagram defines a common pie diagram
20 */
21class KCHART_EXPORT PieDiagram : public AbstractPieDiagram
22{
23 Q_OBJECT
24
25 Q_DISABLE_COPY( PieDiagram )
26 KCHART_DECLARE_DERIVED_DIAGRAM( PieDiagram, PolarCoordinatePlane )
27
28public:
29 explicit PieDiagram(
30 QWidget* parent = nullptr, PolarCoordinatePlane* plane = nullptr );
31 ~PieDiagram() override;
32
33protected:
34 // Implement AbstractDiagram
35 /** \reimpl */
36 void paint( PaintContext* paintContext ) override;
37
38public:
39 /**
40 * Describes which decorations are painted around data labels.
41 */
43 NoDecoration = 0, ///< No decoration
44 FrameDecoration = 1, ///< A rectangular frame is painted around the label text
45 LineFromSliceDecoration = 2 ///< A line is drawn from the pie slice to its label
46 };
47 Q_DECLARE_FLAGS( LabelDecorations, LabelDecoration )
48 /// Set the decorations to be painted around data labels according to @p decorations.
49 void setLabelDecorations( LabelDecorations decorations );
50 /// Return the decorations to be painted around data labels.
51 LabelDecorations labelDecorations() const;
52
53 /// If @p enabled is set to true, labels that would overlap will be shuffled to avoid overlap.
54 /// \note Collision avoidance may allow labels to be closer than AbstractDiagram with
55 /// allowOverlappingDataValueTexts() == false, so you should usually also call
56 /// setAllowOverlappingDataValueTexts( true ) if you enable this feature.
57 void setLabelCollisionAvoidanceEnabled( bool enabled );
58 /// Return whether overlapping labels will be moved to until they don't overlap anymore.
59 bool isLabelCollisionAvoidanceEnabled() const;
60
61 /** \reimpl */
62 void resize ( const QSizeF& area ) override;
63
64 // Implement AbstractPolarDiagram
65 /** \reimpl */
66 qreal valueTotals () const override;
67 /** \reimpl */
68 qreal numberOfValuesPerDataset() const override;
69 /** \reimpl */
70 qreal numberOfGridRings() const override;
71
72
73 /**
74 * Creates an exact copy of this diagram.
75 */
76 virtual PieDiagram * clone() const;
77
78protected:
79 /** \reimpl */
80 const QPair<QPointF, QPointF> calculateDataBoundaries() const override;
81 void paintEvent( QPaintEvent* ) override;
82 void resizeEvent( QResizeEvent* ) override;
83
84private:
85 // ### move to private class?
86 void placeLabels( PaintContext* paintContext );
87 // Solve problems with label overlap by changing label positions inside d->labelPaintCache.
88 void shuffleLabels( QRectF* textBoundingRect );
89 void paintInternal( PaintContext* paintContext );
90
91 /**
92 Internal method that draws one of the slices in a pie chart.
93
94 \param painter the QPainter to draw in
95 \param dataset the dataset to draw the pie for
96 \param slice the slice to draw
97 \param threeDPieHeight the height of the three dimensional effect
98 */
99 void drawSlice( QPainter* painter, const QRectF& drawPosition, uint slice );
100
101 /**
102 Internal method that draws the surface of one of the slices in a pie chart.
103
104 \param painter the QPainter to draw in
105 \param dataset the dataset to draw the slice for
106 \param slice the slice to draw
107 */
108 void drawSliceSurface( QPainter* painter, const QRectF& drawPosition, uint slice );
109 void addSliceLabel( LabelPaintCache* lpc, const QRectF& drawPosition, uint slice );
110
111 /**
112 Internal method that draws the shadow creating the 3D effect of a pie
113
114 \param painter the QPainter to draw in
115 \param drawPosition the position to draw at
116 \param slice the slice to draw the shadow for
117 */
118 void draw3DEffect( QPainter* painter, const QRectF& drawPosition, uint slice );
119
120 /**
121 Internal method that draws the cut surface of a slice (think of a real pie cut into slices)
122 in 3D mode, for surfaces that are facing the observer.
123
124 \param painter the QPainter to draw in
125 \param rect the position to draw at
126 \param threeDHeight the height of the shadow
127 \param angle the angle of the segment
128 */
129 void draw3dCutSurface( QPainter* painter,
130 const QRectF& rect,
131 qreal threeDHeight,
132 qreal angle );
133
134 /**
135 Internal method that draws the outer rim of a slice when the rim is facing the observer.
136
137 \param painter the QPainter to draw in
138 \param rect the position to draw at
139 \param threeDHeight the height of the shadow
140 \param startAngle the starting angle of the segment
141 \param endAngle the ending angle of the segment
142 */
143 void draw3dOuterRim( QPainter* painter,
144 const QRectF& rect,
145 qreal threeDHeight,
146 qreal startAngle,
147 qreal endAngle );
148 void calcSliceAngles();
149 void calcPieSize( const QRectF &contentsRect );
150 QRectF twoDPieRect( const QRectF &contentsRect, const ThreeDPieAttributes& threeDAttrs ) const;
151 QRectF explodedDrawPosition( const QRectF& drawPosition, uint slice ) const;
152
153 /**
154 Internal method that finds the slice that is located at the position specified by \c angle.
155
156 \param angle the angle at which to search for a slice
157 \return the number of the slice found
158 */
159 uint findSliceAt( qreal angle, int columnCount );
160
161 /**
162 Internal method that finds the slice that is located to the left of \c slice.
163
164 \param slice the slice to start the search from
165 \return the number of the pie to the left of \c pie
166 */
167 uint findLeftSlice( uint slice, int columnCount );
168
169 /**
170 Internal method that finds the slice that is located to the right of \c slice.
171
172 \param slice the slice to start the search from
173 \return the number of the slice to the right of \c slice
174 */
175 uint findRightSlice( uint slice, int columnCount );
176
177 /**
178 * Auxiliary method returning a point to a given boundary
179 * rectangle of the enclosed ellipse and an angle.
180 */
181 QPointF pointOnEllipse( const QRectF& boundingBox, qreal angle );
182}; // End of class KChartPieDiagram
183
184Q_DECLARE_OPERATORS_FOR_FLAGS( PieDiagram::LabelDecorations )
185
186}
187#endif // KCHARTPIEDIAGRAM_H
Base class for any diagram type.
Stores information about painting diagrams.
PieDiagram defines a common pie diagram.
LabelDecoration
Describes which decorations are painted around data labels.
A set of 3D pie attributes.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.