KD Chart 2 [rev.2.4]
|
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 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_UNUSED( con ) //not read in release builds 00157 Q_ASSERT( con ); 00158 con = connect( plane, SIGNAL( viewportCoordinateSystemChanged() ), this, SLOT( update() ) ); 00159 Q_ASSERT( con ); 00160 } 00161 // show the axes, after all have been layoutPlanes 00162 // (because they might depend on each other) 00163 /* 00164 if( plane ) 00165 Q_FOREACH( CartesianAxis* axis, d->axesList ) 00166 axis->show(); 00167 else 00168 Q_FOREACH( CartesianAxis* axis, d->axesList ) 00169 axis->hide(); 00170 */ 00171 } 00172 00173 void AbstractCartesianDiagram::setReferenceDiagram( AbstractCartesianDiagram* diagram, const QPointF& offset ) 00174 { 00175 d->referenceDiagram = diagram; 00176 d->referenceDiagramOffset = offset; 00177 } 00178 00179 AbstractCartesianDiagram* AbstractCartesianDiagram::referenceDiagram() const 00180 { 00181 return d->referenceDiagram; 00182 } 00183 00184 QPointF AbstractCartesianDiagram::referenceDiagramOffset() const 00185 { 00186 return d->referenceDiagramOffset; 00187 } 00188 00189 void AbstractCartesianDiagram::setRootIndex( const QModelIndex& index ) 00190 { 00191 AbstractDiagram::setRootIndex( index ); 00192 d->compressor.setRootIndex( attributesModel()->mapFromSource( index ) ); 00193 } 00194 00195 void AbstractCartesianDiagram::setModel( QAbstractItemModel* model ) 00196 { 00197 AbstractDiagram::setModel( model ); 00198 d->compressor.setModel( attributesModel() ); 00199 } 00200 00201 void AbstractCartesianDiagram::setAttributesModel( AttributesModel* model ) 00202 { 00203 AbstractDiagram::setAttributesModel( model ); 00204 d->compressor.setModel( attributesModel() ); 00205 }