KDChartAbstractAxis.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 "KDChartAbstractAxis.h"
00027 #include "KDChartAbstractAxis_p.h"
00028 #include "KDChartAbstractDiagram.h"
00029 #include "KDChartAbstractCartesianDiagram.h"
00030 #include "KDChartEnums.h"
00031 #include "KDChartMeasure.h"
00032 
00033 #include <QDebug>
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     // Note: We do NOT call setDiagram( diagram, axis );
00047     //       but it is called in AbstractAxis::delayedInit() instead!
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     // do not set a diagram again that was already set
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 //qDebug() << "axis" << (axis != 0);
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     // We call setDiagram() here, because the c'tor of Private
00137     // only has stored the pointers, but it did not call setDiagram().
00138     if( d )
00139         d->setDiagram( 0, true /* delayedInit */ );
00140 }
00141 
00142 bool AbstractAxis::compare( const AbstractAxis* other )const
00143 {
00144     if( other == this ) return true;
00145     if( ! other ){
00146         //qDebug() << "CartesianAxis::compare() cannot compare to Null pointer";
00147         return false;
00148     }
00149     /*
00150     qDebug() << (textAttributes() == other->textAttributes());
00151     qDebug() << (labels()         == other->labels());
00152     qDebug() << (shortLabels()    == other->shortLabels());
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     if( d->textAttributes == a )
00234         return;
00235 
00236     d->textAttributes = a;
00237     update();
00238 }
00239 
00245 TextAttributes AbstractAxis::textAttributes() const
00246 {
00247     return d->textAttributes;
00248 }
00249 
00250 
00259 void AbstractAxis::setRulerAttributes( const RulerAttributes &a )
00260 {
00261         d->rulerAttributes = a;
00262         update();
00263 }
00264 
00270 RulerAttributes AbstractAxis::rulerAttributes() const
00271 {
00272         return d->rulerAttributes;
00273 }
00274 
00292 void AbstractAxis::setLabels( const QStringList& list )
00293 {
00294     if( d->hardLabels == list )
00295         return;
00296 
00297     d->hardLabels = list;
00298     update();
00299 }
00300 
00306 QStringList AbstractAxis::labels() const
00307 {
00308     return d->hardLabels;
00309 }
00310 
00322 void AbstractAxis::setShortLabels( const QStringList& list )
00323 {
00324     if( d->hardShortLabels == list )
00325         return;
00326 
00327     d->hardShortLabels = list;
00328     update();
00329 }
00330 
00339 QStringList AbstractAxis::shortLabels() const
00340 {
00341     return d->hardShortLabels;
00342 }
00343 
00349 const AbstractCoordinatePlane* AbstractAxis::coordinatePlane() const
00350 {
00351     if( d->diagram() )
00352         return d->diagram()->coordinatePlane();
00353     return 0;
00354 }
00355 
00356 const AbstractDiagram * KDChart::AbstractAxis::diagram() const
00357 {
00358     return d->diagram();
00359 }
00360 
00361 bool KDChart::AbstractAxis::observedBy( AbstractDiagram * diagram ) const
00362 {
00363     return d->hasDiagram( diagram );
00364 }
00365 
00366 void KDChart::AbstractAxis::update()
00367 {
00368     if( d->diagram() )
00369         d->diagram()->update();
00370 }

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