KD Chart 2  [rev.2.7]
KDChartPieDiagram.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #ifndef KDCHARTPIEDIAGRAM_H
24 #define KDCHARTPIEDIAGRAM_H
25 
27 
28 namespace KDChart {
29 
30  class LabelPaintCache;
31 
35 class KDCHART_EXPORT PieDiagram : public AbstractPieDiagram
36 {
37  Q_OBJECT
38 
39  Q_DISABLE_COPY( PieDiagram )
41 
42 public:
43  explicit PieDiagram(
44  QWidget* parent = 0, PolarCoordinatePlane* plane = 0 );
45  ~PieDiagram() override;
46 
47 protected:
48  // Implement AbstractDiagram
50  void paint( PaintContext* paintContext ) override;
51 
52 public:
57  NoDecoration = 0,
58  FrameDecoration = 1,
59  LineFromSliceDecoration = 2
60  };
61  Q_DECLARE_FLAGS( LabelDecorations, LabelDecoration )
63  void setLabelDecorations( LabelDecorations decorations );
65  LabelDecorations labelDecorations() const;
66 
71  void setLabelCollisionAvoidanceEnabled( bool enabled );
73  bool isLabelCollisionAvoidanceEnabled() const;
74 
76  void resize ( const QSizeF& area ) override;
77 
78  // Implement AbstractPolarDiagram
80  qreal valueTotals () const override;
82  qreal numberOfValuesPerDataset() const override;
84  qreal numberOfGridRings() const override;
85 
86  virtual PieDiagram * clone() const;
87 
88 protected:
90  const QPair<QPointF, QPointF> calculateDataBoundaries() const override;
91  void paintEvent( QPaintEvent* ) override;
92  void resizeEvent( QResizeEvent* ) override;
93 
94 private:
95  // ### move to private class?
96  void placeLabels( PaintContext* paintContext );
97  // Solve problems with label overlap by changing label positions inside d->labelPaintCache.
98  void shuffleLabels( QRectF* textBoundingRect );
99  void paintInternal( PaintContext* paintContext );
100  void drawSlice( QPainter* painter, const QRectF& drawPosition, uint slice );
101  void drawSliceSurface( QPainter* painter, const QRectF& drawPosition, uint slice );
102  void addSliceLabel( LabelPaintCache* lpc, const QRectF& drawPosition, uint slice );
103  void draw3DEffect( QPainter* painter, const QRectF& drawPosition, uint slice );
104  void draw3dCutSurface( QPainter* painter,
105  const QRectF& rect,
106  qreal threeDHeight,
107  qreal angle );
108  void draw3dOuterRim( QPainter* painter,
109  const QRectF& rect,
110  qreal threeDHeight,
111  qreal startAngle,
112  qreal endAngle );
113  void calcSliceAngles();
114  void calcPieSize( const QRectF &contentsRect );
115  QRectF twoDPieRect( const QRectF &contentsRect, const ThreeDPieAttributes& threeDAttrs ) const;
116  QRectF explodedDrawPosition( const QRectF& drawPosition, uint slice ) const;
117  uint findSliceAt( qreal angle, int columnCount );
118  uint findLeftSlice( uint slice, int columnCount );
119  uint findRightSlice( uint slice, int columnCount );
120  QPointF pointOnEllipse( const QRectF& boundingBox, qreal angle );
121 }; // End of class KDChartPieDiagram
122 
123 Q_DECLARE_OPERATORS_FOR_FLAGS( PieDiagram::LabelDecorations )
124 
125 }
126 #endif // KDCHARTPIEDIAGRAM_H
LabelDecoration
Describes which decorations are painted around data labels.
Stores information about painting diagrams.
A set of 3D pie attributes.
Base class for any diagram type.
#define KDCHART_DECLARE_DERIVED_DIAGRAM(X, PLANE)
PieDiagram defines a common pie diagram.
Class only listed here to document inheritance of some KDChart classes.

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/