00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00049 return false;
00050 }
00051
00052
00053
00054
00055
00056
00057
00058 return
00059 ( static_cast<const AbstractDiagram*>(this)->compare( other ) ) &&
00060
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
00122 AbstractCoordinatePlane* plane = coordinatePlane();
00123 if( plane ){
00124 plane->layoutPlanes();
00125
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
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
00161
00162
00163
00164
00165
00166
00167
00168
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 }