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