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