KD Chart 2  [rev.2.5.1]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
KDChartAbstractCartesianDiagram.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
24 #include "KDChartAbstractCartesianDiagram_p.h"
25 
26 #include <KDABLibFakes>
27 
28 
29 using namespace KDChart;
30 
31 AbstractCartesianDiagram::Private::Private()
32  : referenceDiagram( 0 )
33 {
34 }
35 
36 AbstractCartesianDiagram::Private::~Private()
37 {
38 }
39 
41 {
42  if ( other == this ) return true;
43  if ( ! other ) {
44  return false;
45  }
46  return // compare the base class
47  ( static_cast<const AbstractDiagram*>(this)->compare( other ) ) &&
48  // compare own properties
49  (referenceDiagram() == other->referenceDiagram()) &&
51 }
52 
53 
54 #define d d_func()
55 
57  : AbstractDiagram ( new Private(), parent, plane )
58 {
59  init();
60 }
61 
63 {
64  Q_FOREACH( CartesianAxis* axis, d->axesList ) {
65  axis->deleteObserver( this );
66  }
67  d->axesList.clear();
68 }
69 
70 void AbstractCartesianDiagram::init()
71 {
72  d->compressor.setModel( attributesModel() );
73  connect( this, SIGNAL( layoutChanged( AbstractDiagram* ) ),
74  &( d->compressor ), SLOT( slotDiagramLayoutChanged( AbstractDiagram* ) ) );
75  if ( d->plane )
76  {
77  const bool res = connect( d->plane, SIGNAL( viewportCoordinateSystemChanged() ),
78  this, SIGNAL( viewportCoordinateSystemChanged() ) );
79  Q_UNUSED( res )
80  Q_ASSERT( res );
81  }
82 }
83 
85 {
86  if ( !d->axesList.contains( axis ) ) {
87  d->axesList.append( axis );
88  axis->createObserver( this );
89  layoutPlanes();
90  }
91 }
92 
94 {
95  const int idx = d->axesList.indexOf( axis );
96  if ( idx != -1 )
97  d->axesList.takeAt( idx );
98  axis->deleteObserver( this );
99  axis->setParentWidget( 0 );
100  layoutPlanes();
101 }
102 
104 {
105  return d->axesList;
106 }
107 
109 {
111  if ( plane ) {
112  plane->layoutPlanes();
113  }
114 }
115 
117 {
118  if ( coordinatePlane() ) {
119  disconnect( attributesModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
120  coordinatePlane(), SLOT( relayout() ) );
121  disconnect( attributesModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
122  coordinatePlane(), SLOT( relayout() ) );
123  disconnect( attributesModel(), SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
124  coordinatePlane(), SLOT( relayout() ) );
125  disconnect( attributesModel(), SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
126  coordinatePlane(), SLOT( relayout() ) );
127  disconnect( coordinatePlane() );
128  }
129 
131  if ( plane ) {
132  // Readjust the layout when the dataset count changes
133  connect( attributesModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
134  plane, SLOT( relayout() ), Qt::QueuedConnection );
135  connect( attributesModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
136  plane, SLOT( relayout() ), Qt::QueuedConnection );
137  connect( attributesModel(), SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
138  plane, SLOT( relayout() ), Qt::QueuedConnection );
139  connect( attributesModel(), SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
140  plane, SLOT( relayout() ), Qt::QueuedConnection );
141  Q_ASSERT( plane );
142  bool con = connect( plane, SIGNAL( viewportCoordinateSystemChanged() ), this, SIGNAL( viewportCoordinateSystemChanged() ) );
143  Q_ASSERT( con );
144  con = connect( plane, SIGNAL( viewportCoordinateSystemChanged() ), this, SLOT( update() ) );
145  Q_ASSERT( con );
146  Q_UNUSED( con );
147  }
148 }
149 
151 {
152  d->referenceDiagram = diagram;
153  d->referenceDiagramOffset = offset;
154 }
155 
157 {
158  return d->referenceDiagram;
159 }
160 
162 {
163  return d->referenceDiagramOffset;
164 }
165 
166 void AbstractCartesianDiagram::setRootIndex( const QModelIndex& index )
167 {
169  d->compressor.setRootIndex( attributesModel()->mapFromSource( index ) );
170 }
171 
172 void AbstractCartesianDiagram::setModel( QAbstractItemModel* model )
173 {
174  AbstractDiagram::setModel( model );
175  d->compressor.setModel( attributesModel() );
176 }
177 
179 {
181  d->compressor.setModel( attributesModel() );
182 }

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/