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