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
00067 RingDiagram * RingDiagram::clone() const
00068 {
00069 return new RingDiagram( new Private( *d ) );
00070 }
00071
00072 void RingDiagram::setRelativeThickness( bool relativeThickness )
00073 {
00074 d->relativeThickness = relativeThickness;
00075 }
00076
00077 bool RingDiagram::relativeThickness() const
00078 {
00079 return d->relativeThickness;
00080 }
00081
00082 const QPair<QPointF, QPointF> RingDiagram::calculateDataBoundaries () const
00083 {
00084 if ( !checkInvariants(true) ) return QPair<QPointF, QPointF>( QPointF( 0, 0 ), QPointF( 0, 0 ) );
00085
00086 QPointF bottomLeft ( QPointF( 0, 0 ) );
00087 QPointF topRight ( QPointF( 1, 1 ) );
00088 return QPair<QPointF, QPointF> ( bottomLeft, topRight );
00089 }
00090
00091 void RingDiagram::paintEvent( QPaintEvent* )
00092 {
00093 QPainter painter ( viewport() );
00094 PaintContext ctx;
00095 ctx.setPainter ( &painter );
00096 ctx.setRectangle( QRectF ( 0, 0, width(), height() ) );
00097 paint ( &ctx );
00098 }
00099
00100 void RingDiagram::resizeEvent ( QResizeEvent*)
00101 {
00102 }
00103
00104 void RingDiagram::paint( PaintContext* ctx )
00105 {
00106
00107
00108 if ( !checkInvariants(true) )
00109 return;
00110
00111 const int colCount = model()->columnCount(rootIndex());
00112 DataValueTextInfoList list;
00113 for ( int j=0; j<colCount; ++j ) {
00114 QBrush brush = qVariantValue<QBrush>( attributesModel()->headerData( j, Qt::Vertical, KDChart::DatasetBrushRole ) );
00115 PainterSaver painterSaver( ctx->painter() );
00116 ctx->painter()->setRenderHint ( QPainter::Antialiasing );
00117 ctx->painter()->setBrush( brush );
00118 QPen p( ctx->painter()->pen() );
00119 p.setColor( brush.color() );
00120 p.setWidth( 2 );
00121 ctx->painter()->setPen( p );
00122
00123 }
00124 DataValueTextInfoListIterator it( list );
00125 while ( it.hasNext() ) {
00126 const DataValueTextInfo& info = it.next();
00127 paintDataValueText( ctx->painter(), info.index, info.pos, info.value );
00128 }
00129 }
00130
00131 void RingDiagram::resize ( const QSizeF& )
00132 {
00133 }
00134
00135
00136 double RingDiagram::valueTotals () const
00137 {
00138 double total = 0;
00139 const int colCount = model()->columnCount(rootIndex());
00140 for ( int j=0; j<colCount; ++j ) {
00141 total += model()->data( model()->index( 0, j, rootIndex() ) ).toDouble();
00142 }
00143 return total;
00144 }
00145
00146
00147 double RingDiagram::numberOfValuesPerDataset() const
00148 {
00149 return model() ? model()->columnCount(rootIndex()) : 0.0;
00150 }
00151
00152
00153 double RingDiagram::numberOfGridRings() const
00154 {
00155 return 1;
00156 }
00157