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     if ( d->plane )
00088     {
00089         const bool res = connect( d->plane, SIGNAL( viewportCoordinateSystemChanged() ), this, SIGNAL( viewportCoordinateSystemChanged() ) );
00090         Q_UNUSED( res )
00091         Q_ASSERT( res );
00092     }
00093 }
00094 
00095 void AbstractCartesianDiagram::addAxis( CartesianAxis *axis )
00096 {
00097     if ( !d->axesList.contains( axis ) ) {
00098         d->axesList.append( axis );
00099         axis->createObserver( this );
00100         layoutPlanes();
00101     }
00102 }
00103 
00104 void AbstractCartesianDiagram::takeAxis( CartesianAxis *axis )
00105 {
00106     const int idx = d->axesList.indexOf( axis );
00107     if( idx != -1 )
00108         d->axesList.takeAt( idx );
00109     axis->deleteObserver( this );
00110     axis->setParentWidget( 0 );
00111     layoutPlanes();
00112 }
00113 
00114 KDChart::CartesianAxisList AbstractCartesianDiagram::axes( ) const
00115 {
00116     return d->axesList;
00117 }
00118 
00119 void KDChart::AbstractCartesianDiagram::layoutPlanes()
00120 {
00121     //qDebug() << "KDChart::AbstractCartesianDiagram::layoutPlanes()";
00122     AbstractCoordinatePlane* plane = coordinatePlane();
00123     if( plane ){
00124         plane->layoutPlanes();
00125         //qDebug() << "KDChart::AbstractCartesianDiagram::layoutPlanes() OK";
00126     }
00127 }
00128 
00129 void KDChart::AbstractCartesianDiagram::setCoordinatePlane( AbstractCoordinatePlane* plane )
00130 {
00131     if( coordinatePlane() ) {
00132         disconnect( attributesModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
00133                  coordinatePlane(), SLOT( relayout() ) );
00134         disconnect( attributesModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
00135                  coordinatePlane(), SLOT( relayout() ) );
00136         disconnect( attributesModel(), SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
00137                  coordinatePlane(), SLOT( relayout() ) );
00138         disconnect( attributesModel(), SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
00139                  coordinatePlane(), SLOT( relayout() ) );
00140         disconnect( coordinatePlane() );
00141     }
00142     
00143     AbstractDiagram::setCoordinatePlane(plane);
00144     if ( plane ) {
00145         // Readjust the layout when the dataset count changes
00146         connect( attributesModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
00147                  plane, SLOT( relayout() ), Qt::QueuedConnection );
00148         connect( attributesModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
00149                  plane, SLOT( relayout() ), Qt::QueuedConnection );
00150         connect( attributesModel(), SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
00151                  plane, SLOT( relayout() ), Qt::QueuedConnection );
00152         connect( attributesModel(), SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
00153                  plane, SLOT( relayout() ), Qt::QueuedConnection );
00154         Q_ASSERT( plane );
00155         bool con = connect( plane, SIGNAL( viewportCoordinateSystemChanged() ), this, SIGNAL( viewportCoordinateSystemChanged() ) );
00156         Q_ASSERT( con );
00157         con = connect( plane, SIGNAL( viewportCoordinateSystemChanged() ), this, SLOT( update() ) );
00158         Q_ASSERT( con );
00159     }
00160     // show the axes, after all have been layoutPlanes
00161     // (because they might depend on each other)
00162     /*
00163     if( plane )
00164         Q_FOREACH( CartesianAxis* axis, d->axesList )
00165             axis->show();
00166     else
00167         Q_FOREACH( CartesianAxis* axis, d->axesList )
00168             axis->hide();
00169     */
00170 }
00171 
00172 void AbstractCartesianDiagram::setReferenceDiagram( AbstractCartesianDiagram* diagram, const QPointF& offset )
00173 {
00174     d->referenceDiagram = diagram;
00175     d->referenceDiagramOffset = offset;
00176 }
00177 
00178 AbstractCartesianDiagram* AbstractCartesianDiagram::referenceDiagram() const
00179 {
00180     return d->referenceDiagram;
00181 }
00182 
00183 QPointF AbstractCartesianDiagram::referenceDiagramOffset() const
00184 {
00185     return d->referenceDiagramOffset;
00186 }
00187 
00188 void AbstractCartesianDiagram::setRootIndex( const QModelIndex& index )
00189 {
00190     AbstractDiagram::setRootIndex( index );
00191     d->compressor.setRootIndex( attributesModel()->mapFromSource( index ) );
00192 }
00193 
00194 void AbstractCartesianDiagram::setModel( QAbstractItemModel* model )
00195 {
00196     AbstractDiagram::setModel( model );
00197     d->compressor.setModel( attributesModel() );
00198 }
00199 
00200 void AbstractCartesianDiagram::setAttributesModel( AttributesModel* model )
00201 {
00202     AbstractDiagram::setAttributesModel( model );
00203     d->compressor.setModel( attributesModel() );
00204 }
 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/