00001 /**************************************************************************** 00002 ** Copyright (C) 2006 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 00047 void AbstractCartesianDiagram::init() 00048 { 00049 } 00050 00051 00052 bool AbstractCartesianDiagram::compare( const AbstractCartesianDiagram* other )const 00053 { 00054 if( other == this ) return true; 00055 if( ! other ){ 00056 //qDebug() << "AbstractCartesianDiagram::compare() cannot compare to Null pointer"; 00057 return false; 00058 } 00059 /* 00060 qDebug() << "\n AbstractCartesianDiagram::compare():"; 00061 // compare own properties 00062 qDebug() << 00063 ((referenceDiagram() == other->referenceDiagram()) && 00064 ((! referenceDiagram()) || (referenceDiagramOffset() == other->referenceDiagramOffset()))); 00065 */ 00066 return // compare the base class 00067 ( static_cast<const AbstractDiagram*>(this)->compare( other ) ) && 00068 // compare own properties 00069 (referenceDiagram() == other->referenceDiagram()) && 00070 ((! referenceDiagram()) || (referenceDiagramOffset() == other->referenceDiagramOffset())); 00071 } 00072 00073 00074 #define d d_func() 00075 00076 AbstractCartesianDiagram::AbstractCartesianDiagram ( QWidget* parent, CartesianCoordinatePlane* plane ) 00077 : AbstractDiagram ( new Private(), parent, plane ) 00078 { 00079 } 00080 00081 KDChart::AbstractCartesianDiagram::~AbstractCartesianDiagram() 00082 { 00083 Q_FOREACH( CartesianAxis* axis, d->axesList ) { 00084 axis->deleteObserver( this ); 00085 } 00086 d->axesList.clear(); 00087 } 00088 00089 void AbstractCartesianDiagram::addAxis( CartesianAxis *axis ) 00090 { 00091 if ( !d->axesList.contains( axis ) ) { 00092 d->axesList.append( axis ); 00093 axis->createObserver( this ); 00094 layoutPlanes(); 00095 } 00096 } 00097 00098 void AbstractCartesianDiagram::takeAxis( CartesianAxis *axis ) 00099 { 00100 const int idx = d->axesList.indexOf( axis ); 00101 if( idx != -1 ) 00102 d->axesList.takeAt( idx ); 00103 axis->deleteObserver( this ); 00104 axis->setParentWidget( 0 ); 00105 layoutPlanes(); 00106 } 00107 00108 KDChart::CartesianAxisList AbstractCartesianDiagram::axes( ) const 00109 { 00110 return d->axesList; 00111 } 00112 00113 void KDChart::AbstractCartesianDiagram::layoutPlanes() 00114 { 00115 //qDebug() << "KDChart::AbstractCartesianDiagram::layoutPlanes()"; 00116 AbstractCoordinatePlane* plane = coordinatePlane(); 00117 if( plane ){ 00118 plane->layoutPlanes(); 00119 //qDebug() << "KDChart::AbstractCartesianDiagram::layoutPlanes() OK"; 00120 } 00121 } 00122 00123 void KDChart::AbstractCartesianDiagram::setCoordinatePlane( AbstractCoordinatePlane* plane ) 00124 { 00125 if( coordinatePlane() ) disconnect( coordinatePlane() ); 00126 AbstractDiagram::setCoordinatePlane(plane); 00127 00128 // show the axes, after all have been adjusted 00129 // (because they might be dependend on each other) 00130 /* 00131 if( plane ) 00132 Q_FOREACH( CartesianAxis* axis, d->axesList ) 00133 axis->show(); 00134 else 00135 Q_FOREACH( CartesianAxis* axis, d->axesList ) 00136 axis->hide(); 00137 */ 00138 } 00139 00140 void AbstractCartesianDiagram::setReferenceDiagram( AbstractCartesianDiagram* diagram, const QPointF& offset ) 00141 { 00142 d->referenceDiagram = diagram; 00143 d->referenceDiagramOffset = offset; 00144 } 00145 00146 AbstractCartesianDiagram* AbstractCartesianDiagram::referenceDiagram() const 00147 { 00148 return d->referenceDiagram; 00149 } 00150 00151 QPointF AbstractCartesianDiagram::referenceDiagramOffset() const 00152 { 00153 return d->referenceDiagramOffset; 00154 }