KD Chart 2
[rev.2.5]
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2012 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Chart library. 00005 ** 00006 ** Licensees holding valid commercial KD Chart licenses may use this file in 00007 ** accordance with the KD Chart Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 00020 ** 00021 **********************************************************************/ 00022 00023 #ifndef KDCHARTPIEDIAGRAM_H 00024 #define KDCHARTPIEDIAGRAM_H 00025 00026 #include "KDChartAbstractPieDiagram.h" 00027 00028 namespace KDChart { 00029 00030 class LabelPaintCache; 00031 00035 class KDCHART_EXPORT PieDiagram : public AbstractPieDiagram 00036 { 00037 Q_OBJECT 00038 00039 Q_DISABLE_COPY( PieDiagram ) 00040 KDCHART_DECLARE_DERIVED_DIAGRAM( PieDiagram, PolarCoordinatePlane ) 00041 00042 public: 00043 explicit PieDiagram( 00044 QWidget* parent = 0, PolarCoordinatePlane* plane = 0 ); 00045 virtual ~PieDiagram(); 00046 00047 protected: 00048 // Implement AbstractDiagram 00050 virtual void paint( PaintContext* paintContext ); 00051 00052 public: 00056 enum LabelDecoration { 00057 NoDecoration = 0, 00058 FrameDecoration = 1, 00059 LineFromSliceDecoration = 2 00060 }; 00061 Q_DECLARE_FLAGS( LabelDecorations, LabelDecoration ) 00063 void setLabelDecorations( LabelDecorations decorations ); 00065 LabelDecorations labelDecorations() const; 00066 00068 void setLabelCollisionAvoidanceEnabled( bool enabled ); 00070 bool isLabelCollisionAvoidanceEnabled() const; 00071 00073 virtual void resize ( const QSizeF& area ); 00074 00075 // Implement AbstractPolarDiagram 00077 virtual qreal valueTotals () const; 00079 virtual qreal numberOfValuesPerDataset() const; 00081 virtual qreal numberOfGridRings() const; 00082 00083 virtual PieDiagram * clone() const; 00084 00085 protected: 00087 virtual const QPair<QPointF, QPointF> calculateDataBoundaries() const; 00088 void paintEvent( QPaintEvent* ); 00089 void resizeEvent( QResizeEvent* ); 00090 00091 private: 00092 // ### move to private class? 00093 void placeLabels( PaintContext* paintContext ); 00094 // Solve problems with label overlap by changing label positions inside d->labelPaintCache. 00095 void shuffleLabels( QRectF* textBoundingRect ); 00096 void paintInternal( PaintContext* paintContext ); 00097 void drawSlice( QPainter* painter, const QRectF& drawPosition, uint slice ); 00098 void drawSliceSurface( QPainter* painter, const QRectF& drawPosition, uint slice ); 00099 void addSliceLabel( LabelPaintCache* lpc, const QRectF& drawPosition, uint slice ); 00100 void draw3DEffect( QPainter* painter, const QRectF& drawPosition, uint slice ); 00101 void draw3dCutSurface( QPainter* painter, 00102 const QRectF& rect, 00103 qreal threeDHeight, 00104 qreal angle ); 00105 void draw3dOuterRim( QPainter* painter, 00106 const QRectF& rect, 00107 qreal threeDHeight, 00108 qreal startAngle, 00109 qreal endAngle ); 00110 void calcSliceAngles(); 00111 void calcPieSize( const QRectF &contentsRect ); 00112 QRectF twoDPieRect( const QRectF &contentsRect, const ThreeDPieAttributes& threeDAttrs ) const; 00113 QRectF explodedDrawPosition( const QRectF& drawPosition, uint slice ) const; 00114 uint findSliceAt( qreal angle, int columnCount ); 00115 uint findLeftSlice( uint slice, int columnCount ); 00116 uint findRightSlice( uint slice, int columnCount ); 00117 QPointF pointOnEllipse( const QRectF& boundingBox, qreal angle ); 00118 }; // End of class KDChartPieDiagram 00119 00120 Q_DECLARE_OPERATORS_FOR_FLAGS( PieDiagram::LabelDecorations ) 00121 00122 } 00123 #endif // KDCHARTPIEDIAGRAM_H