Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

KDChartRingDiagram.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002  ** Copyright (C) 2006 Klarälvdalens Datakonsult AB.  All rights reserved.
00003  **
00004  ** This file is part of the KD Chart library.
00005  **
00006  ** This file may be distributed and/or modified under the terms of the
00007  ** GNU General Public License version 2 as published by the Free Software
00008  ** Foundation and appearing in the file LICENSE.GPL included in the
00009  ** packaging of this file.
00010  **
00011  ** Licensees holding valid commercial KD Chart licenses may use this file in
00012  ** accordance with the KD Chart Commercial License Agreement provided with
00013  ** the Software.
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  ** See http://www.kdab.net/kdchart for
00019  **   information about KDChart Commercial License Agreements.
00020  **
00021  ** Contact info@kdab.net if any conditions of this
00022  ** licensing are not clear to you.
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     // note: Not having any data model assigned is no bug
00104     //       but we can not draw a diagram then either.
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 );// FIXME properties, use DatasetPenRole
00118         ctx->painter()->setPen( p );
00119         //ctx->painter()->drawPolyline( polygon );
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 /*virtual*/
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 /*virtual*/
00144 double RingDiagram::numberOfValuesPerDataset() const
00145 {
00146     return model() ? model()->columnCount(rootIndex()) : 0.0;
00147 }
00148 
00149 /*virtual*/
00150 double RingDiagram::numberOfGridRings() const
00151 {
00152     return 1;
00153 }
00154 

Generated on Thu May 10 11:06:25 2007 for KD Chart 2 by doxygen 1.3.6