KD Chart 2  [rev.2.5.1]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
KDChartPieDiagram.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 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  virtual ~PieDiagram();
46 
47 protected:
48  // Implement AbstractDiagram
50  virtual void paint( PaintContext* paintContext );
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 
68  void setLabelCollisionAvoidanceEnabled( bool enabled );
70  bool isLabelCollisionAvoidanceEnabled() const;
71 
73  virtual void resize ( const QSizeF& area );
74 
75  // Implement AbstractPolarDiagram
77  virtual qreal valueTotals () const;
79  virtual qreal numberOfValuesPerDataset() const;
81  virtual qreal numberOfGridRings() const;
82 
83  virtual PieDiagram * clone() const;
84 
85 protected:
87  virtual const QPair<QPointF, QPointF> calculateDataBoundaries() const;
88  void paintEvent( QPaintEvent* );
89  void resizeEvent( QResizeEvent* );
90 
91 private:
92  // ### move to private class?
93  void placeLabels( PaintContext* paintContext );
94  // Solve problems with label overlap by changing label positions inside d->labelPaintCache.
95  void shuffleLabels( QRectF* textBoundingRect );
96  void paintInternal( PaintContext* paintContext );
97  void drawSlice( QPainter* painter, const QRectF& drawPosition, uint slice );
98  void drawSliceSurface( QPainter* painter, const QRectF& drawPosition, uint slice );
99  void addSliceLabel( LabelPaintCache* lpc, const QRectF& drawPosition, uint slice );
100  void draw3DEffect( QPainter* painter, const QRectF& drawPosition, uint slice );
101  void draw3dCutSurface( QPainter* painter,
102  const QRectF& rect,
103  qreal threeDHeight,
104  qreal angle );
105  void draw3dOuterRim( QPainter* painter,
106  const QRectF& rect,
107  qreal threeDHeight,
108  qreal startAngle,
109  qreal endAngle );
110  void calcSliceAngles();
111  void calcPieSize( const QRectF &contentsRect );
112  QRectF twoDPieRect( const QRectF &contentsRect, const ThreeDPieAttributes& threeDAttrs ) const;
113  QRectF explodedDrawPosition( const QRectF& drawPosition, uint slice ) const;
114  uint findSliceAt( qreal angle, int columnCount );
115  uint findLeftSlice( uint slice, int columnCount );
116  uint findRightSlice( uint slice, int columnCount );
117  QPointF pointOnEllipse( const QRectF& boundingBox, qreal angle );
118 }; // End of class KDChartPieDiagram
119 
120 Q_DECLARE_OPERATORS_FOR_FLAGS( PieDiagram::LabelDecorations )
121 
122 }
123 #endif // KDCHARTPIEDIAGRAM_H

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/