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 <QDebug>
00027
00028 #include "KDChartAbstractAxis.h"
00029 #include "KDChartAbstractAxis_p.h"
00030 #include "KDChartAbstractDiagram.h"
00031 #include "KDChartAbstractCartesianDiagram.h"
00032 #include "KDChartEnums.h"
00033 #include "KDChartMeasure.h"
00034
00035 #include <KDABLibFakes>
00036
00037 using namespace KDChart;
00038
00039 #define d d_func()
00040
00041 AbstractAxis::Private::Private( AbstractDiagram* diagram, AbstractAxis* axis )
00042 : observer( 0 )
00043 , mDiagram( diagram )
00044 , mAxis( axis )
00045 {
00046
00047
00048 }
00049
00050 AbstractAxis::Private::~Private()
00051 {
00052 delete observer;
00053 observer = 0;
00054 }
00055
00056 bool AbstractAxis::Private::setDiagram(
00057 AbstractDiagram* diagram_,
00058 bool delayedInit )
00059 {
00060 AbstractDiagram* diagram = delayedInit ? mDiagram : diagram_;
00061 if( delayedInit ){
00062 mDiagram = 0;
00063 }
00064
00065
00066 if ( diagram &&
00067 ((diagram == mDiagram) || secondaryDiagrams.contains( diagram )) )
00068 return false;
00069
00070 bool bNewDiagramStored = false;
00071 if ( ! mDiagram ) {
00072 mDiagram = diagram;
00073 delete observer;
00074 if ( mDiagram ) {
00075
00076 observer = new DiagramObserver( mDiagram, mAxis );
00077 bNewDiagramStored = true;
00078 }else{
00079 observer = 0;
00080 }
00081 } else {
00082 if ( diagram )
00083 secondaryDiagrams.enqueue( diagram );
00084 }
00085 return bNewDiagramStored;
00086 }
00087
00088 void AbstractAxis::Private::unsetDiagram( AbstractDiagram* diagram )
00089 {
00090 if ( diagram == mDiagram ) {
00091 mDiagram = 0;
00092 delete observer;
00093 observer = 0;
00094 } else {
00095 secondaryDiagrams.removeAll( diagram );
00096 }
00097 if( !secondaryDiagrams.isEmpty() ) {
00098 AbstractDiagram *nextDiagram = secondaryDiagrams.dequeue();
00099 setDiagram( nextDiagram );
00100 }
00101 }
00102
00103 bool AbstractAxis::Private::hasDiagram( AbstractDiagram* diagram ) const
00104 {
00105 return diagram == mDiagram || secondaryDiagrams.contains( diagram );
00106 }
00107
00108 AbstractAxis::AbstractAxis ( AbstractDiagram* diagram )
00109 : AbstractArea( new Private( diagram, this ) )
00110 {
00111 init();
00112 QTimer::singleShot(0, this, SLOT(delayedInit()));
00113 }
00114
00115 AbstractAxis::~AbstractAxis()
00116 {
00117 d->mDiagram = 0;
00118 d->secondaryDiagrams.clear();
00119 }
00120
00121
00122 void AbstractAxis::init()
00123 {
00124 Measure m(
00125 12.5,
00126 KDChartEnums::MeasureCalculationModeAuto,
00127 KDChartEnums::MeasureOrientationAuto );
00128 d->textAttributes.setFontSize( m );
00129 m.setValue( 5 );
00130 m.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
00131 d->textAttributes.setMinimalFontSize( m );
00132 }
00133
00134 void AbstractAxis::delayedInit()
00135 {
00136
00137
00138 if( d )
00139 d->setDiagram( 0, true );
00140 }
00141
00142 bool AbstractAxis::compare( const AbstractAxis* other )const
00143 {
00144 if( other == this ) return true;
00145 if( ! other ){
00146
00147 return false;
00148 }
00149
00150
00151
00152
00153
00154 return ( static_cast<const AbstractAreaBase*>(this)->compare( other ) ) &&
00155 (textAttributes() == other->textAttributes()) &&
00156 (labels() == other->labels()) &&
00157 (shortLabels() == other->shortLabels());
00158 }
00159
00160
00161 const QString AbstractAxis::customizedLabel( const QString& label )const
00162 {
00163 return label;
00164 }
00165
00166
00177 void AbstractAxis::createObserver( AbstractDiagram* diagram )
00178 {
00179 if( d->setDiagram( diagram ) )
00180 connectSignals();
00181 }
00182
00193 void AbstractAxis::deleteObserver( AbstractDiagram* diagram )
00194 {
00195 d->unsetDiagram( diagram );
00196 }
00197
00211 void AbstractAxis::connectSignals()
00212 {
00213 if( d->observer ){
00214 connect( d->observer, SIGNAL( diagramDataChanged( AbstractDiagram *) ),
00215 this, SLOT( update() ) );
00216 }
00217 }
00218
00219
00231 void AbstractAxis::setTextAttributes( const TextAttributes &a )
00232 {
00233 d->textAttributes = a;
00234 }
00235
00241 TextAttributes AbstractAxis::textAttributes() const
00242 {
00243 return d->textAttributes;
00244 }
00245
00263 void AbstractAxis::setLabels( const QStringList& list )
00264 {
00265 d->hardLabels = list;
00266 }
00267
00273 QStringList AbstractAxis::labels() const
00274 {
00275 return d->hardLabels;
00276 }
00277
00289 void AbstractAxis::setShortLabels( const QStringList& list )
00290 {
00291 d->hardShortLabels = list;
00292 }
00293
00302 QStringList AbstractAxis::shortLabels() const
00303 {
00304 return d->hardShortLabels;
00305 }
00306
00312 const AbstractCoordinatePlane* AbstractAxis::coordinatePlane() const
00313 {
00314 if( d->diagram() )
00315 return d->diagram()->coordinatePlane();
00316 return 0;
00317 }
00318
00319 const AbstractDiagram * KDChart::AbstractAxis::diagram() const
00320 {
00321 return d->diagram();
00322 }
00323
00324 bool KDChart::AbstractAxis::observedBy( AbstractDiagram * diagram ) const
00325 {
00326 return d->hasDiagram( diagram );
00327 }
00328
00329 void KDChart::AbstractAxis::update()
00330 {
00331 if( d->diagram() )
00332 d->diagram()->update();
00333 }