KDChartAbstractAxis.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2011 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 "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     // Note: We do NOT call setDiagram( diagram, axis );
00044     //       but it is called in AbstractAxis::delayedInit() instead!
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     // do not set a diagram again that was already set
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 //qDebug() << "axis" << (axis != 0);
00073             observer = new DiagramObserver( mDiagram, mAxis );
00074             bNewDiagramStored = true;
00075         }else{
00076             observer = 0;
00077         }
00078     } else {
00079         if ( diagram )
00080             secondaryDiagrams.enqueue( diagram );
00081     }
00082     return bNewDiagramStored;
00083 }
00084 
00085 void AbstractAxis::Private::unsetDiagram( AbstractDiagram* diagram )
00086 {
00087     if ( diagram == mDiagram ) {
00088         mDiagram = 0;
00089         delete observer;
00090         observer = 0;
00091     } else {
00092         secondaryDiagrams.removeAll( diagram );
00093     }
00094     if( !secondaryDiagrams.isEmpty() ) {
00095         AbstractDiagram *nextDiagram = secondaryDiagrams.dequeue();
00096         setDiagram( nextDiagram );
00097     }
00098 }
00099 
00100 bool AbstractAxis::Private::hasDiagram( AbstractDiagram* diagram ) const
00101 {
00102     return diagram == mDiagram || secondaryDiagrams.contains( diagram );
00103 }
00104 
00105 AbstractAxis::AbstractAxis ( AbstractDiagram* diagram )
00106     : AbstractArea( new Private( diagram, this ) )
00107 {
00108     init();
00109     QTimer::singleShot(0, this, SLOT(delayedInit()));
00110 }
00111 
00112 AbstractAxis::~AbstractAxis()
00113 {
00114     d->mDiagram = 0;
00115     d->secondaryDiagrams.clear();
00116 }
00117 
00118 
00119 void AbstractAxis::init()
00120 {
00121     Measure m(
00122         12.5,
00123         KDChartEnums::MeasureCalculationModeAuto,
00124         KDChartEnums::MeasureOrientationAuto );
00125     d->textAttributes.setFontSize( m  );
00126     m.setValue( 5 );
00127     m.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
00128     d->textAttributes.setMinimalFontSize( m  );
00129 }
00130 
00131 void AbstractAxis::delayedInit()
00132 {
00133     // We call setDiagram() here, because the c'tor of Private
00134     // only has stored the pointers, but it did not call setDiagram().
00135     if( d )
00136         d->setDiagram( 0, true /* delayedInit */ );
00137 }
00138 
00139 bool AbstractAxis::compare( const AbstractAxis* other )const
00140 {
00141     if( other == this ) return true;
00142     if( ! other ){
00143         //qDebug() << "CartesianAxis::compare() cannot compare to Null pointer";
00144         return false;
00145     }
00146     /*
00147     qDebug() << (textAttributes() == other->textAttributes());
00148     qDebug() << (labels()         == other->labels());
00149     qDebug() << (shortLabels()    == other->shortLabels());
00150     */
00151     return  ( static_cast<const AbstractAreaBase*>(this)->compare( other ) ) &&
00152             (textAttributes() == other->textAttributes()) &&
00153             (labels()         == other->labels()) &&
00154             (shortLabels()    == other->shortLabels());
00155 }
00156 
00157 
00158 const QString AbstractAxis::customizedLabel( const QString& label )const
00159 {
00160     return label;
00161 }
00162 
00163 
00164 void AbstractAxis::createObserver( AbstractDiagram* diagram )
00165 {
00166     if( d->setDiagram( diagram ) )
00167         connectSignals();
00168 }
00169 
00170 void AbstractAxis::deleteObserver( AbstractDiagram* diagram )
00171 {
00172     d->unsetDiagram( diagram );
00173 }
00174 
00175 void AbstractAxis::connectSignals()
00176 {
00177     if( d->observer ){
00178         connect( d->observer, SIGNAL( diagramDataChanged( AbstractDiagram *) ),
00179                 this, SLOT( update() ) );
00180     }
00181 }
00182 
00183 
00184 void AbstractAxis::setTextAttributes( const TextAttributes &a )
00185 {
00186     if( d->textAttributes == a )
00187         return;
00188 
00189     d->textAttributes = a;
00190     update();
00191 }
00192 
00193 TextAttributes AbstractAxis::textAttributes() const
00194 {
00195     return d->textAttributes;
00196 }
00197 
00198 
00199 void AbstractAxis::setRulerAttributes( const RulerAttributes &a )
00200 {
00201         d->rulerAttributes = a;
00202         update();
00203 }
00204 
00205 RulerAttributes AbstractAxis::rulerAttributes() const
00206 {
00207         return d->rulerAttributes;
00208 }
00209 
00210 void AbstractAxis::setLabels( const QStringList& list )
00211 {
00212     if( d->hardLabels == list )
00213         return;
00214 
00215     d->hardLabels = list;
00216     update();
00217 }
00218 
00219 QStringList AbstractAxis::labels() const
00220 {
00221     return d->hardLabels;
00222 }
00223 
00224 void AbstractAxis::setShortLabels( const QStringList& list )
00225 {
00226     if( d->hardShortLabels == list )
00227         return;
00228 
00229     d->hardShortLabels = list;
00230     update();
00231 }
00232 
00233 QStringList AbstractAxis::shortLabels() const
00234 {
00235     return d->hardShortLabels;
00236 }
00237 
00238 const AbstractCoordinatePlane* AbstractAxis::coordinatePlane() const
00239 {
00240     if( d->diagram() )
00241         return d->diagram()->coordinatePlane();
00242     return 0;
00243 }
00244 
00245 const AbstractDiagram * KDChart::AbstractAxis::diagram() const
00246 {
00247     return d->diagram();
00248 }
00249 
00250 bool KDChart::AbstractAxis::observedBy( AbstractDiagram * diagram ) const
00251 {
00252     return d->hasDiagram( diagram );
00253 }
00254 
00255 void KDChart::AbstractAxis::update()
00256 {
00257     if( d->diagram() )
00258         d->diagram()->update();
00259 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/