00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <QPainter>
00027
00028 #include "KDChartAttributesModel.h"
00029 #include "KDChartPaintContext.h"
00030 #include "KDChartRingDiagram.h"
00031 #include "KDChartRingDiagram_p.h"
00032 #include "KDChartPainterSaver_p.h"
00033 #include "KDChartPieAttributes.h"
00034 #include "KDChartThreeDPieAttributes.h"
00035 #include "KDChartDataValueAttributes.h"
00036
00037 #include <KDABLibFakes>
00038
00039 using namespace KDChart;
00040
00041 RingDiagram::Private::Private() :
00042 relativeThickness( false )
00043 {
00044 }
00045
00046 RingDiagram::Private::~Private() {}
00047
00048 #define d d_func()
00049
00050 RingDiagram::RingDiagram( QWidget* parent, PolarCoordinatePlane* plane ) :
00051 AbstractPieDiagram( new Private(), parent, plane )
00052 {
00053 init();
00054 }
00055
00056 RingDiagram::~RingDiagram()
00057 {
00058 }
00059
00060 void RingDiagram::init()
00061 {
00062 }
00063
00064 RingDiagram * RingDiagram::clone() const
00065 {
00066 return new RingDiagram( new Private( *d ) );
00067 }
00068
00069 void RingDiagram::setRelativeThickness( bool relativeThickness )
00070 {
00071 d->relativeThickness = relativeThickness;
00072 }
00073
00074 bool RingDiagram::relativeThickness() const
00075 {
00076 return d->relativeThickness;
00077 }
00078
00079 const QPair<QPointF, QPointF> RingDiagram::calculateDataBoundaries () const
00080 {
00081 if ( !checkInvariants(true) ) return QPair<QPointF, QPointF>( QPointF( 0, 0 ), QPointF( 0, 0 ) );
00082
00083 QPointF bottomLeft ( QPointF( 0, 0 ) );
00084 QPointF topRight ( QPointF( 1, 1 ) );
00085 return QPair<QPointF, QPointF> ( bottomLeft, topRight );
00086 }
00087
00088 void RingDiagram::paintEvent( QPaintEvent* )
00089 {
00090 QPainter painter ( viewport() );
00091 PaintContext ctx;
00092 ctx.setPainter ( &painter );
00093 ctx.setRectangle( QRectF ( 0, 0, width(), height() ) );
00094 paint ( &ctx );
00095 }
00096
00097 void RingDiagram::resizeEvent ( QResizeEvent*)
00098 {
00099 }
00100
00101 void RingDiagram::paint( PaintContext* ctx )
00102 {
00103
00104
00105 if ( !checkInvariants(true) )
00106 return;
00107
00108 const int colCount = model()->columnCount(rootIndex());
00109 DataValueTextInfoList list;
00110 for ( int j=0; j<colCount; ++j ) {
00111 QBrush brush = qVariantValue<QBrush>( attributesModel()->headerData( j, Qt::Vertical, KDChart::DatasetBrushRole ) );
00112 PainterSaver painterSaver( ctx->painter() );
00113 ctx->painter()->setRenderHint ( QPainter::Antialiasing );
00114 ctx->painter()->setBrush( brush );
00115 QPen p( ctx->painter()->pen() );
00116 p.setColor( brush.color() );
00117 p.setWidth( 2 );
00118 ctx->painter()->setPen( p );
00119
00120 }
00121 DataValueTextInfoListIterator it( list );
00122 while ( it.hasNext() ) {
00123 const DataValueTextInfo& info = it.next();
00124 paintDataValueText( ctx->painter(), info.index, info.pos, info.value );
00125 }
00126 }
00127
00128 void RingDiagram::resize ( const QSizeF& )
00129 {
00130 }
00131
00132
00133 double RingDiagram::valueTotals () const
00134 {
00135 double total = 0;
00136 const int colCount = model()->columnCount(rootIndex());
00137 for ( int j=0; j<colCount; ++j ) {
00138 total += model()->data( model()->index( 0, j, rootIndex() ) ).toDouble();
00139 }
00140 return total;
00141 }
00142
00143
00144 double RingDiagram::numberOfValuesPerDataset() const
00145 {
00146 return model() ? model()->columnCount(rootIndex()) : 0.0;
00147 }
00148
00149
00150 double RingDiagram::numberOfGridRings() const
00151 {
00152 return 1;
00153 }
00154