KDChartAbstractCartesianDiagram.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 "KDChartAbstractCartesianDiagram.h"
00027 #include "KDChartAbstractCartesianDiagram_p.h"
00028 #include "KDChartPaintContext.h"
00029 #include <QDebug>
00030 #include <QPainter>
00031 
00032 #include <KDABLibFakes>
00033 
00034 
00035 using namespace KDChart;
00036 
00037 AbstractCartesianDiagram::Private::Private()
00038     : referenceDiagram( 0 )
00039 {
00040 }
00041 
00042 AbstractCartesianDiagram::Private::~Private()
00043 {
00044 }
00045 
00046 bool AbstractCartesianDiagram::compare( const AbstractCartesianDiagram* other )const
00047 {
00048     if( other == this ) return true;
00049     if( ! other ){
00050         //qDebug() << "AbstractCartesianDiagram::compare() cannot compare to Null pointer";
00051         return false;
00052     }
00053     /*
00054     qDebug() << "\n             AbstractCartesianDiagram::compare():";
00055             // compare own properties
00056     qDebug() <<
00057             ((referenceDiagram() == other->referenceDiagram()) &&
00058             ((! referenceDiagram()) || (referenceDiagramOffset() == other->referenceDiagramOffset())));
00059     */
00060     return  // compare the base class
00061             ( static_cast<const AbstractDiagram*>(this)->compare( other ) ) &&
00062             // compare own properties
00063             (referenceDiagram() == other->referenceDiagram()) &&
00064             ((! referenceDiagram()) || (referenceDiagramOffset() == other->referenceDiagramOffset()));
00065 }
00066 
00067 
00068 #define d d_func()
00069 
00070 AbstractCartesianDiagram::AbstractCartesianDiagram ( QWidget* parent, CartesianCoordinatePlane* plane )
00071     : AbstractDiagram ( new Private(), parent, plane )
00072 {
00073     init();
00074 }
00075 
00076 KDChart::AbstractCartesianDiagram::~AbstractCartesianDiagram()
00077 {
00078     Q_FOREACH( CartesianAxis* axis, d->axesList ) {
00079         axis->deleteObserver( this );
00080     }
00081     d->axesList.clear();
00082 }
00083 
00084 void AbstractCartesianDiagram::init()
00085 {
00086     d->compressor.setModel( attributesModel() );
00087     connect( this, SIGNAL( layoutChanged( AbstractDiagram* ) ),
00088              &( d->compressor ), SLOT( slotDiagramLayoutChanged( AbstractDiagram* ) ) );
00089 }
00090 
00091 void AbstractCartesianDiagram::addAxis( CartesianAxis *axis )
00092 {
00093     if ( !d->axesList.contains( axis ) ) {
00094         d->axesList.append( axis );
00095         axis->createObserver( this );
00096         layoutPlanes();
00097     }
00098 }
00099 
00100 void AbstractCartesianDiagram::takeAxis( CartesianAxis *axis )
00101 {
00102     const int idx = d->axesList.indexOf( axis );
00103     if( idx != -1 )
00104         d->axesList.takeAt( idx );
00105     axis->deleteObserver( this );
00106     axis->setParentWidget( 0 );
00107     layoutPlanes();
00108 }
00109 
00110 KDChart::CartesianAxisList AbstractCartesianDiagram::axes( ) const
00111 {
00112     return d->axesList;
00113 }
00114 
00115 void KDChart::AbstractCartesianDiagram::layoutPlanes()
00116 {
00117     //qDebug() << "KDChart::AbstractCartesianDiagram::layoutPlanes()";
00118     AbstractCoordinatePlane* plane = coordinatePlane();
00119     if( plane ){
00120         plane->layoutPlanes();
00121         //qDebug() << "KDChart::AbstractCartesianDiagram::layoutPlanes() OK";
00122     }
00123 }
00124 
00125 void KDChart::AbstractCartesianDiagram::setCoordinatePlane( AbstractCoordinatePlane* plane )
00126 {
00127     if( coordinatePlane() ) disconnect( coordinatePlane() );
00128     AbstractDiagram::setCoordinatePlane(plane);
00129 
00130     // show the axes, after all have been adjusted
00131     // (because they might be dependend on each other)
00132     /*
00133     if( plane )
00134         Q_FOREACH( CartesianAxis* axis, d->axesList )
00135             axis->show();
00136     else
00137         Q_FOREACH( CartesianAxis* axis, d->axesList )
00138             axis->hide();
00139     */
00140 }
00141 
00142 void AbstractCartesianDiagram::setReferenceDiagram( AbstractCartesianDiagram* diagram, const QPointF& offset )
00143 {
00144     d->referenceDiagram = diagram;
00145     d->referenceDiagramOffset = offset;
00146 }
00147 
00148 AbstractCartesianDiagram* AbstractCartesianDiagram::referenceDiagram() const
00149 {
00150     return d->referenceDiagram;
00151 }
00152 
00153 QPointF AbstractCartesianDiagram::referenceDiagramOffset() const
00154 {
00155     return d->referenceDiagramOffset;
00156 }
00157 
00158 void AbstractCartesianDiagram::setRootIndex( const QModelIndex& index )
00159 {
00160     d->compressor.setRootIndex( index );
00161     AbstractDiagram::setRootIndex( index );
00162 }
00163 
00164 void AbstractCartesianDiagram::setModel( QAbstractItemModel* model )
00165 {
00166     AbstractDiagram::setModel( model );
00167     d->compressor.setModel( attributesModel() );
00168 }
00169 
00170 void AbstractCartesianDiagram::setAttributesModel( AttributesModel* model )
00171 {
00172     AbstractDiagram::setAttributesModel( model );
00173     d->compressor.setModel( attributesModel() );
00174 }

Generated on Mon Sep 17 16:16:49 2007 for KD Chart 2 by  doxygen 1.5.1