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     qRegisterMetaType< QModelIndex >( "QModelIndex" );
00041 }
00042 
00043 AbstractCartesianDiagram::Private::~Private()
00044 {
00045 }
00046 
00047 bool AbstractCartesianDiagram::compare( const AbstractCartesianDiagram* other )const
00048 {
00049     if( other == this ) return true;
00050     if( ! other ){
00051         //qDebug() << "AbstractCartesianDiagram::compare() cannot compare to Null pointer";
00052         return false;
00053     }
00054     /*
00055     qDebug() << "\n             AbstractCartesianDiagram::compare():";
00056             // compare own properties
00057     qDebug() <<
00058             ((referenceDiagram() == other->referenceDiagram()) &&
00059             ((! referenceDiagram()) || (referenceDiagramOffset() == other->referenceDiagramOffset())));
00060     */
00061     return  // compare the base class
00062             ( static_cast<const AbstractDiagram*>(this)->compare( other ) ) &&
00063             // compare own properties
00064             (referenceDiagram() == other->referenceDiagram()) &&
00065             ((! referenceDiagram()) || (referenceDiagramOffset() == other->referenceDiagramOffset()));
00066 }
00067 
00068 
00069 #define d d_func()
00070 
00071 AbstractCartesianDiagram::AbstractCartesianDiagram ( QWidget* parent, CartesianCoordinatePlane* plane )
00072     : AbstractDiagram ( new Private(), parent, plane )
00073 {
00074     init();
00075 }
00076 
00077 KDChart::AbstractCartesianDiagram::~AbstractCartesianDiagram()
00078 {
00079     Q_FOREACH( CartesianAxis* axis, d->axesList ) {
00080         axis->deleteObserver( this );
00081     }
00082     d->axesList.clear();
00083 }
00084 
00085 void AbstractCartesianDiagram::init()
00086 {
00087     d->compressor.setModel( attributesModel() );
00088     connect( this, SIGNAL( layoutChanged( AbstractDiagram* ) ),
00089              &( d->compressor ), SLOT( slotDiagramLayoutChanged( AbstractDiagram* ) ) );
00090 }
00091 
00092 void AbstractCartesianDiagram::addAxis( CartesianAxis *axis )
00093 {
00094     if ( !d->axesList.contains( axis ) ) {
00095         d->axesList.append( axis );
00096         axis->createObserver( this );
00097         layoutPlanes();
00098     }
00099 }
00100 
00101 void AbstractCartesianDiagram::takeAxis( CartesianAxis *axis )
00102 {
00103     const int idx = d->axesList.indexOf( axis );
00104     if( idx != -1 )
00105         d->axesList.takeAt( idx );
00106     axis->deleteObserver( this );
00107     axis->setParentWidget( 0 );
00108     layoutPlanes();
00109 }
00110 
00111 KDChart::CartesianAxisList AbstractCartesianDiagram::axes( ) const
00112 {
00113     return d->axesList;
00114 }
00115 
00116 void KDChart::AbstractCartesianDiagram::layoutPlanes()
00117 {
00118     //qDebug() << "KDChart::AbstractCartesianDiagram::layoutPlanes()";
00119     AbstractCoordinatePlane* plane = coordinatePlane();
00120     if( plane ){
00121         plane->layoutPlanes();
00122         //qDebug() << "KDChart::AbstractCartesianDiagram::layoutPlanes() OK";
00123     }
00124 }
00125 
00126 void KDChart::AbstractCartesianDiagram::setCoordinatePlane( AbstractCoordinatePlane* plane )
00127 {
00128     if( coordinatePlane() ) {
00129         disconnect( attributesModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
00130                  coordinatePlane(), SLOT( relayout() ) );
00131         disconnect( attributesModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
00132                  coordinatePlane(), SLOT( relayout() ) );
00133         disconnect( attributesModel(), SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
00134                  coordinatePlane(), SLOT( relayout() ) );
00135         disconnect( attributesModel(), SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
00136                  coordinatePlane(), SLOT( relayout() ) );
00137         disconnect( coordinatePlane() );
00138     }
00139     
00140     AbstractDiagram::setCoordinatePlane(plane);
00141     if ( plane ) {
00142         // Readjust the layout when the dataset count changes
00143         connect( attributesModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
00144                  plane, SLOT( relayout() ), Qt::QueuedConnection );
00145         connect( attributesModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
00146                  plane, SLOT( relayout() ), Qt::QueuedConnection );
00147         connect( attributesModel(), SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
00148                  plane, SLOT( relayout() ), Qt::QueuedConnection );
00149         connect( attributesModel(), SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
00150                  plane, SLOT( relayout() ), Qt::QueuedConnection );
00151     }
00152     // show the axes, after all have been layoutPlanes
00153     // (because they might depend on each other)
00154     /*
00155     if( plane )
00156         Q_FOREACH( CartesianAxis* axis, d->axesList )
00157             axis->show();
00158     else
00159         Q_FOREACH( CartesianAxis* axis, d->axesList )
00160             axis->hide();
00161     */
00162 }
00163 
00164 void AbstractCartesianDiagram::setReferenceDiagram( AbstractCartesianDiagram* diagram, const QPointF& offset )
00165 {
00166     d->referenceDiagram = diagram;
00167     d->referenceDiagramOffset = offset;
00168 }
00169 
00170 AbstractCartesianDiagram* AbstractCartesianDiagram::referenceDiagram() const
00171 {
00172     return d->referenceDiagram;
00173 }
00174 
00175 QPointF AbstractCartesianDiagram::referenceDiagramOffset() const
00176 {
00177     return d->referenceDiagramOffset;
00178 }
00179 
00180 void AbstractCartesianDiagram::setRootIndex( const QModelIndex& index )
00181 {
00182     AbstractDiagram::setRootIndex( index );
00183     d->compressor.setRootIndex( attributesModel()->mapFromSource( index ) );
00184 }
00185 
00186 void AbstractCartesianDiagram::setModel( QAbstractItemModel* model )
00187 {
00188     AbstractDiagram::setModel( model );
00189     d->compressor.setModel( attributesModel() );
00190 }
00191 
00192 void AbstractCartesianDiagram::setAttributesModel( AttributesModel* model )
00193 {
00194     AbstractDiagram::setAttributesModel( model );
00195     d->compressor.setModel( attributesModel() );
00196 }

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