Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "KDChartAbstractAxis.h"
00024 #include "KDChartAbstractAxis_p.h"
00025 #include "KDChartAbstractDiagram.h"
00026 #include "KDChartAbstractCartesianDiagram.h"
00027 #include "KDChartEnums.h"
00028 #include "KDChartMeasure.h"
00029
00030 #include <QDebug>
00031
00032 #include <KDABLibFakes>
00033
00034 using namespace KDChart;
00035
00036 #define d d_func()
00037
00038 AbstractAxis::Private::Private( AbstractDiagram* diagram, AbstractAxis* axis )
00039 : observer( 0 )
00040 , mDiagram( diagram )
00041 , mAxis( axis )
00042 {
00043
00044
00045 }
00046
00047 AbstractAxis::Private::~Private()
00048 {
00049 delete observer;
00050 observer = 0;
00051 }
00052
00053 bool AbstractAxis::Private::setDiagram(
00054 AbstractDiagram* diagram_,
00055 bool delayedInit )
00056 {
00057 AbstractDiagram* diagram = delayedInit ? mDiagram : diagram_;
00058 if( delayedInit ){
00059 mDiagram = 0;
00060 }
00061
00062
00063 if ( diagram &&
00064 ((diagram == mDiagram) || secondaryDiagrams.contains( diagram )) )
00065 return false;
00066
00067 bool bNewDiagramStored = false;
00068 if ( ! mDiagram ) {
00069 mDiagram = diagram;
00070 delete observer;
00071 if ( mDiagram ) {
00072
00073 observer = new DiagramObserver( mDiagram, mAxis );
00074 const bool con = connect( observer, SIGNAL( diagramDataChanged( AbstractDiagram *) ),
00075 mAxis, SIGNAL( coordinateSystemChanged() ) );
00076 Q_UNUSED( con )
00077 Q_ASSERT( con );
00078 bNewDiagramStored = true;
00079 }else{
00080 observer = 0;
00081 }
00082 } else {
00083 if ( diagram )
00084 secondaryDiagrams.enqueue( diagram );
00085 }
00086 return bNewDiagramStored;
00087 }
00088
00089 void AbstractAxis::Private::unsetDiagram( AbstractDiagram* diagram )
00090 {
00091 if ( diagram == mDiagram ) {
00092 mDiagram = 0;
00093 delete observer;
00094 observer = 0;
00095 } else {
00096 secondaryDiagrams.removeAll( diagram );
00097 }
00098 if( !secondaryDiagrams.isEmpty() ) {
00099 AbstractDiagram *nextDiagram = secondaryDiagrams.dequeue();
00100 setDiagram( nextDiagram );
00101 }
00102 }
00103
00104 bool AbstractAxis::Private::hasDiagram( AbstractDiagram* diagram ) const
00105 {
00106 return diagram == mDiagram || secondaryDiagrams.contains( diagram );
00107 }
00108
00109 AbstractAxis::AbstractAxis ( AbstractDiagram* diagram )
00110 : AbstractArea( new Private( diagram, this ) )
00111 {
00112 init();
00113 QTimer::singleShot(0, this, SLOT(delayedInit()));
00114 }
00115
00116 AbstractAxis::~AbstractAxis()
00117 {
00118 d->mDiagram = 0;
00119 d->secondaryDiagrams.clear();
00120 }
00121
00122
00123 void AbstractAxis::init()
00124 {
00125 Measure m(
00126 12.5,
00127 KDChartEnums::MeasureCalculationModeAuto,
00128 KDChartEnums::MeasureOrientationAuto );
00129 d->textAttributes.setFontSize( m );
00130 m.setValue( 5 );
00131 m.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
00132 d->textAttributes.setMinimalFontSize( m );
00133 if ( d->diagram() )
00134 createObserver( d->diagram() );
00135 }
00136
00137 void AbstractAxis::delayedInit()
00138 {
00139
00140
00141 if( d )
00142 d->setDiagram( 0, true );
00143 }
00144
00145 bool AbstractAxis::compare( const AbstractAxis* other )const
00146 {
00147 if( other == this ) return true;
00148 if( ! other ){
00149
00150 return false;
00151 }
00152
00153
00154
00155
00156
00157 return ( static_cast<const AbstractAreaBase*>(this)->compare( other ) ) &&
00158 (textAttributes() == other->textAttributes()) &&
00159 (labels() == other->labels()) &&
00160 (shortLabels() == other->shortLabels());
00161 }
00162
00163
00164 const QString AbstractAxis::customizedLabel( const QString& label )const
00165 {
00166 return label;
00167 }
00168
00169
00170 void AbstractAxis::createObserver( AbstractDiagram* diagram )
00171 {
00172 d->setDiagram( diagram );
00173 }
00174
00175 void AbstractAxis::deleteObserver( AbstractDiagram* diagram )
00176 {
00177 d->unsetDiagram( diagram );
00178 }
00179
00180 void AbstractAxis::connectSignals()
00181 {
00182 if( d->observer ){
00183 const bool con = connect( d->observer, SIGNAL( diagramDataChanged( AbstractDiagram *) ),
00184 this, SIGNAL( coordinateSystemChanged() ) );
00185 Q_UNUSED( con );
00186 Q_ASSERT( con );
00187 }
00188 }
00189
00190 void AbstractAxis::setTextAttributes( const TextAttributes &a )
00191 {
00192 if( d->textAttributes == a )
00193 return;
00194
00195 d->textAttributes = a;
00196 update();
00197 }
00198
00199 TextAttributes AbstractAxis::textAttributes() const
00200 {
00201 return d->textAttributes;
00202 }
00203
00204
00205 void AbstractAxis::setRulerAttributes( const RulerAttributes &a )
00206 {
00207 d->rulerAttributes = a;
00208 update();
00209 }
00210
00211 RulerAttributes AbstractAxis::rulerAttributes() const
00212 {
00213 return d->rulerAttributes;
00214 }
00215
00216 void AbstractAxis::setLabels( const QStringList& list )
00217 {
00218 if( d->hardLabels == list )
00219 return;
00220
00221 d->hardLabels = list;
00222 update();
00223 }
00224
00225 QStringList AbstractAxis::labels() const
00226 {
00227 return d->hardLabels;
00228 }
00229
00230 void AbstractAxis::setShortLabels( const QStringList& list )
00231 {
00232 if( d->hardShortLabels == list )
00233 return;
00234
00235 d->hardShortLabels = list;
00236 update();
00237 }
00238
00239 QStringList AbstractAxis::shortLabels() const
00240 {
00241 return d->hardShortLabels;
00242 }
00243
00244 const AbstractCoordinatePlane* AbstractAxis::coordinatePlane() const
00245 {
00246 if( d->diagram() )
00247 return d->diagram()->coordinatePlane();
00248 return 0;
00249 }
00250
00251 const AbstractDiagram * KDChart::AbstractAxis::diagram() const
00252 {
00253 return d->diagram();
00254 }
00255
00256 bool KDChart::AbstractAxis::observedBy( AbstractDiagram * diagram ) const
00257 {
00258 return d->hasDiagram( diagram );
00259 }
00260
00261 void KDChart::AbstractAxis::update()
00262 {
00263 if( d->diagram() )
00264 d->diagram()->update();
00265 }