KDChartAbstractCartesianDiagram.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 "KDChartAbstractCartesianDiagram.h"
00024 #include "KDChartAbstractCartesianDiagram_p.h"
00025 #include "KDChartPaintContext.h"
00026 #include <QDebug>
00027 #include <QPainter>
00028 
00029 #include <KDABLibFakes>
00030 
00031 
00032 using namespace KDChart;
00033 
00034 AbstractCartesianDiagram::Private::Private()
00035     : referenceDiagram( 0 )
00036 {
00037     qRegisterMetaType< QModelIndex >( "QModelIndex" );
00038 }
00039 
00040 AbstractCartesianDiagram::Private::~Private()
00041 {
00042 }
00043 
00044 bool AbstractCartesianDiagram::compare( const AbstractCartesianDiagram* other )const
00045 {
00046     if( other == this ) return true;
00047     if( ! other ){
00048         //qDebug() << "AbstractCartesianDiagram::compare() cannot compare to Null pointer";
00049         return false;
00050     }
00051     /*
00052     qDebug() << "\n             AbstractCartesianDiagram::compare():";
00053             // compare own properties
00054     qDebug() <<
00055             ((referenceDiagram() == other->referenceDiagram()) &&
00056             ((! referenceDiagram()) || (referenceDiagramOffset() == other->referenceDiagramOffset())));
00057     */
00058     return  // compare the base class
00059             ( static_cast<const AbstractDiagram*>(this)->compare( other ) ) &&
00060             // compare own properties
00061             (referenceDiagram() == other->referenceDiagram()) &&
00062             ((! referenceDiagram()) || (referenceDiagramOffset() == other->referenceDiagramOffset()));
00063 }
00064 
00065 
00066 #define d d_func()
00067 
00068 AbstractCartesianDiagram::AbstractCartesianDiagram ( QWidget* parent, CartesianCoordinatePlane* plane )
00069     : AbstractDiagram ( new Private(), parent, plane )
00070 {
00071     init();
00072 }
00073 
00074 KDChart::AbstractCartesianDiagram::~AbstractCartesianDiagram()
00075 {
00076     Q_FOREACH( CartesianAxis* axis, d->axesList ) {
00077         axis->deleteObserver( this );
00078     }
00079     d->axesList.clear();
00080 }
00081 
00082 void AbstractCartesianDiagram::init()
00083 {
00084     d->compressor.setModel( attributesModel() );
00085     connect( this, SIGNAL( layoutChanged( AbstractDiagram* ) ),
00086              &( d->compressor ), SLOT( slotDiagramLayoutChanged( AbstractDiagram* ) ) );
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() ) {
00126         disconnect( attributesModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
00127                  coordinatePlane(), SLOT( relayout() ) );
00128         disconnect( attributesModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
00129                  coordinatePlane(), SLOT( relayout() ) );
00130         disconnect( attributesModel(), SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
00131                  coordinatePlane(), SLOT( relayout() ) );
00132         disconnect( attributesModel(), SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
00133                  coordinatePlane(), SLOT( relayout() ) );
00134         disconnect( coordinatePlane() );
00135     }
00136     
00137     AbstractDiagram::setCoordinatePlane(plane);
00138     if ( plane ) {
00139         // Readjust the layout when the dataset count changes
00140         connect( attributesModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
00141                  plane, SLOT( relayout() ), Qt::QueuedConnection );
00142         connect( attributesModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
00143                  plane, SLOT( relayout() ), Qt::QueuedConnection );
00144         connect( attributesModel(), SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
00145                  plane, SLOT( relayout() ), Qt::QueuedConnection );
00146         connect( attributesModel(), SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
00147                  plane, SLOT( relayout() ), Qt::QueuedConnection );
00148     }
00149     // show the axes, after all have been layoutPlanes
00150     // (because they might depend on each other)
00151     /*
00152     if( plane )
00153         Q_FOREACH( CartesianAxis* axis, d->axesList )
00154             axis->show();
00155     else
00156         Q_FOREACH( CartesianAxis* axis, d->axesList )
00157             axis->hide();
00158     */
00159 }
00160 
00161 void AbstractCartesianDiagram::setReferenceDiagram( AbstractCartesianDiagram* diagram, const QPointF& offset )
00162 {
00163     d->referenceDiagram = diagram;
00164     d->referenceDiagramOffset = offset;
00165 }
00166 
00167 AbstractCartesianDiagram* AbstractCartesianDiagram::referenceDiagram() const
00168 {
00169     return d->referenceDiagram;
00170 }
00171 
00172 QPointF AbstractCartesianDiagram::referenceDiagramOffset() const
00173 {
00174     return d->referenceDiagramOffset;
00175 }
00176 
00177 void AbstractCartesianDiagram::setRootIndex( const QModelIndex& index )
00178 {
00179     AbstractDiagram::setRootIndex( index );
00180     d->compressor.setRootIndex( attributesModel()->mapFromSource( index ) );
00181 }
00182 
00183 void AbstractCartesianDiagram::setModel( QAbstractItemModel* model )
00184 {
00185     AbstractDiagram::setModel( model );
00186     d->compressor.setModel( attributesModel() );
00187 }
00188 
00189 void AbstractCartesianDiagram::setAttributesModel( AttributesModel* model )
00190 {
00191     AbstractDiagram::setAttributesModel( model );
00192     d->compressor.setModel( attributesModel() );
00193 }
 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/