KDChartAbstractPieDiagram.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002  ** Copyright (C) 2007 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 "KDChartAbstractPieDiagram.h"
00027 #include "KDChartAbstractPieDiagram_p.h"
00028 
00029 #include "KDChartAttributesModel.h"
00030 #include "KDChartPieAttributes.h"
00031 #include "KDChartThreeDPieAttributes.h"
00032 
00033 #include <QMap>
00034 
00035 #include <KDABLibFakes>
00036 
00037 
00038 using namespace KDChart;
00039 
00040 AbstractPieDiagram::Private::Private() :
00041     granularity( 1.0 )
00042 {
00043 }
00044 
00045 AbstractPieDiagram::Private::~Private() {}
00046 
00047 AbstractPieDiagram::AbstractPieDiagram( QWidget* parent, PolarCoordinatePlane *plane ) :
00048     AbstractPolarDiagram( new Private(), parent, plane )
00049 {
00050     init();
00051 }
00052 
00053 AbstractPieDiagram::~AbstractPieDiagram()
00054 {
00055 }
00056 
00057 
00058 void AbstractPieDiagram::init()
00059 {
00060 }
00061 
00062 
00063 bool AbstractPieDiagram::compare( const AbstractPieDiagram* other )const
00064 {
00065     if( other == this ) return true;
00066     if( ! other ){
00067         //qDebug() << "AbstractPieDiagram::compare() cannot compare to Null pointer";
00068         return false;
00069     }
00070     /*
00071     qDebug() << "\n             AbstractPieDiagram::compare():";
00072             // compare own properties
00073     qDebug() <<
00074             (granularity() == other->granularity()) &&
00075             (startPosition() == other->startPosition());
00076     */
00077     return  // compare the base class
00078             ( static_cast<const AbstractPolarDiagram*>(this)->compare( other ) ) &&
00079             // compare own properties
00080             (granularity() == other->granularity()) &&
00081             (startPosition() == other->startPosition());
00082 }
00083 
00084 
00085 #define d d_func()
00086 
00087 void AbstractPieDiagram::setGranularity( qreal value )
00088 {
00089     d->granularity = value;
00090 }
00091 
00092 qreal AbstractPieDiagram::granularity() const
00093 {
00094     return (d->granularity < 0.05 || d->granularity > 36.0)
00095             ? 1.0
00096     : d->granularity;
00097 }
00098 
00099 
00100 void AbstractPieDiagram::setStartPosition( int degrees )
00101 {
00102     Q_UNUSED( degrees );
00103     qWarning() << "Deprecated AbstractPieDiagram::setStartPosition() called, setting ignored.";
00104 }
00105 
00106 int AbstractPieDiagram::startPosition() const
00107 {
00108     qWarning() << "Deprecated AbstractPieDiagram::startPosition() called.";
00109     return 0;
00110 }
00111 
00112 void AbstractPieDiagram::setPieAttributes( const PieAttributes & attrs )
00113 {
00114     d->attributesModel->setModelData( qVariantFromValue( attrs ), PieAttributesRole );
00115     emit layoutChanged( this );
00116 }
00117 
00118 void AbstractPieDiagram::setPieAttributes( int column, const PieAttributes & attrs )
00119 {
00120     d->attributesModel->setHeaderData(
00121         column, Qt::Vertical, qVariantFromValue( attrs ), PieAttributesRole );
00122     emit layoutChanged( this );
00123 }
00124 
00125 void AbstractPieDiagram::setPieAttributes( const QModelIndex & index, const PieAttributes & attrs )
00126 {
00127         d->attributesModel->setData( index, qVariantFromValue( attrs), PieAttributesRole );
00128         emit layoutChanged( this );
00129 }
00130 
00131 // Note: Our users NEED this method - even if
00132 //       we do not need it at drawing time!
00133 //       (khz, 2006-07-28)
00134 PieAttributes AbstractPieDiagram::pieAttributes() const
00135 {
00136     return qVariantValue<PieAttributes>(
00137         d->attributesModel->data( PieAttributesRole ) );
00138 }
00139 
00140 // Note: Our users NEED this method - even if
00141 //       we do not need it at drawing time!
00142 //       (khz, 2006-07-28)
00143 PieAttributes AbstractPieDiagram::pieAttributes( int column ) const
00144 {
00145     const QVariant attrs(
00146             d->attributesModel->headerData( column, Qt::Vertical,
00147                                             PieAttributesRole ) );
00148     if( attrs.isValid() )
00149         return qVariantValue< PieAttributes >( attrs );
00150     return pieAttributes();
00151 }
00152 
00153 PieAttributes AbstractPieDiagram::pieAttributes( const QModelIndex & index ) const
00154 {
00155     return qVariantValue<PieAttributes>(
00156         d->attributesModel->data(
00157             d->attributesModel->mapFromSource( index ),
00158             PieAttributesRole ) );
00159 }
00160 
00161 
00162 void AbstractPieDiagram::setThreeDPieAttributes( const ThreeDPieAttributes & tda )
00163 {
00164     d->attributesModel->setModelData( qVariantFromValue( tda ), ThreeDPieAttributesRole );
00165     emit layoutChanged( this );
00166 }
00167 
00168 void AbstractPieDiagram::setThreeDPieAttributes( int column, const ThreeDPieAttributes & tda )
00169 {
00170     d->attributesModel->setHeaderData(
00171         column, Qt::Vertical, qVariantFromValue( tda ), ThreeDPieAttributesRole );
00172     emit layoutChanged( this );
00173 }
00174 
00175 void AbstractPieDiagram::setThreeDPieAttributes( const QModelIndex & index, const ThreeDPieAttributes & tda )
00176 {
00177     model()->setData( index, qVariantFromValue( tda ), ThreeDPieAttributesRole );
00178     emit layoutChanged( this );
00179 }
00180 
00181 // Note: Our users NEED this method - even if
00182 //       we do not need it at drawing time!
00183 //       (khz, 2006-07-28)
00184 ThreeDPieAttributes AbstractPieDiagram::threeDPieAttributes() const
00185 {
00186     return qVariantValue<ThreeDPieAttributes>(
00187         d->attributesModel->data( ThreeDPieAttributesRole ) );
00188 }
00189 
00190 // Note: Our users NEED this method - even if
00191 //       we do not need it at drawing time!
00192 //       (khz, 2006-07-28)
00193 ThreeDPieAttributes AbstractPieDiagram::threeDPieAttributes( int column ) const
00194 {
00195     const QVariant attrs(
00196             d->attributesModel->headerData( column, Qt::Vertical,
00197                                             ThreeDPieAttributesRole ) );
00198     if( attrs.isValid() )
00199         return qVariantValue< ThreeDPieAttributes >( attrs );
00200     return threeDPieAttributes();
00201 }
00202 
00203 ThreeDPieAttributes AbstractPieDiagram::threeDPieAttributes( const QModelIndex & index ) const
00204 {
00205     return qVariantValue<ThreeDPieAttributes>(
00206         d->attributesModel->data(
00207             d->attributesModel->mapFromSource( index ),
00208             ThreeDPieAttributesRole ) );
00209 }
00210 

Generated on Thu Mar 4 23:19:09 2010 for KD Chart 2 by  doxygen 1.5.4