KD Chart 2  [rev.2.5.1]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
KDChartAbstractAxis.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 
23 #include "KDChartAbstractAxis.h"
24 #include "KDChartAbstractAxis_p.h"
25 #include "KDChartAbstractDiagram.h"
27 #include "KDChartEnums.h"
28 #include "KDChartMeasure.h"
29 
30 #include <KDABLibFakes>
31 
32 using namespace KDChart;
33 
34 #define d d_func()
35 
36 AbstractAxis::Private::Private( AbstractDiagram* diagram, AbstractAxis* axis )
37  : observer( 0 )
38  , mDiagram( diagram )
39  , mAxis( axis )
40 {
41  // Note: We do NOT call setDiagram( diagram, axis );
42  // but it is called in AbstractAxis::delayedInit() instead!
43 }
44 
45 AbstractAxis::Private::~Private()
46 {
47  delete observer;
48  observer = 0;
49 }
50 
51 bool AbstractAxis::Private::setDiagram(
52  AbstractDiagram* diagram_,
53  bool delayedInit )
54 {
55  AbstractDiagram* diagram = delayedInit ? mDiagram : diagram_;
56  if ( delayedInit ) {
57  mDiagram = 0;
58  }
59 
60  // do not set a diagram again that was already set
61  if ( diagram &&
62  ((diagram == mDiagram) || secondaryDiagrams.contains( diagram )) )
63  return false;
64 
65  bool bNewDiagramStored = false;
66  if ( ! mDiagram ) {
67  mDiagram = diagram;
68  delete observer;
69  if ( mDiagram ) {
70  observer = new DiagramObserver( mDiagram, mAxis );
71  const bool con = connect( observer, SIGNAL( diagramDataChanged( AbstractDiagram *) ),
72  mAxis, SIGNAL( coordinateSystemChanged() ) );
73  Q_UNUSED( con )
74  Q_ASSERT( con );
75  bNewDiagramStored = true;
76  } else {
77  observer = 0;
78  }
79  } else {
80  if ( diagram )
81  secondaryDiagrams.enqueue( diagram );
82  }
83  return bNewDiagramStored;
84 }
85 
86 void AbstractAxis::Private::unsetDiagram( AbstractDiagram* diagram )
87 {
88  if ( diagram == mDiagram ) {
89  mDiagram = 0;
90  delete observer;
91  observer = 0;
92  } else {
93  secondaryDiagrams.removeAll( diagram );
94  }
95  if ( !secondaryDiagrams.isEmpty() ) {
96  AbstractDiagram *nextDiagram = secondaryDiagrams.dequeue();
97  setDiagram( nextDiagram );
98  }
99 }
100 
101 bool AbstractAxis::Private::hasDiagram( AbstractDiagram* diagram ) const
102 {
103  return diagram == mDiagram || secondaryDiagrams.contains( diagram );
104 }
105 
106 AbstractAxis::AbstractAxis ( AbstractDiagram* diagram )
107  : AbstractArea( new Private( diagram, this ) )
108 {
109  init();
110  QTimer::singleShot(0, this, SLOT(delayedInit()));
111 }
112 
114 {
115  d->mDiagram = 0;
116  d->secondaryDiagrams.clear();
117 }
118 
119 
120 void AbstractAxis::init()
121 {
123  d->textAttributes.setFontSize( m );
124  m.setValue( 6 );
125  m.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
126  d->textAttributes.setMinimalFontSize( m );
127  if ( d->diagram() )
128  createObserver( d->diagram() );
129 }
130 
132 {
133  // We call setDiagram() here, because the c'tor of Private
134  // only has stored the pointers, but it did not call setDiagram().
135  if ( d )
136  d->setDiagram( 0, true /* delayedInit */ );
137 }
138 
139 bool AbstractAxis::compare( const AbstractAxis* other ) const
140 {
141  if ( other == this ) {
142  return true;
143  }
144  if ( !other ) {
145  return false;
146  }
147 
148  return ( static_cast<const AbstractAreaBase*>(this)->compare( other ) ) &&
149  (textAttributes() == other->textAttributes()) &&
150  (labels() == other->labels()) &&
151  (shortLabels() == other->shortLabels());
152 }
153 
154 
155 const QString AbstractAxis::customizedLabel( const QString& label ) const
156 {
157  return label;
158 }
159 
160 
162 {
163  d->setDiagram( diagram );
164 }
165 
167 {
168  d->unsetDiagram( diagram );
169 }
170 
172 {
173  if ( d->observer ) {
174  const bool con = connect( d->observer, SIGNAL( diagramDataChanged( AbstractDiagram *) ),
175  this, SIGNAL( coordinateSystemChanged() ) );
176  Q_UNUSED( con );
177  Q_ASSERT( con );
178  }
179 }
180 
182 {
183  if ( d->textAttributes == a )
184  return;
185 
186  d->textAttributes = a;
187  update();
188 }
189 
191 {
192  return d->textAttributes;
193 }
194 
195 
197 {
198  d->rulerAttributes = a;
199  update();
200 }
201 
203 {
204  return d->rulerAttributes;
205 }
206 
207 void AbstractAxis::setLabels( const QStringList& list )
208 {
209  if ( d->hardLabels == list )
210  return;
211 
212  d->hardLabels = list;
213  update();
214 }
215 
216 QStringList AbstractAxis::labels() const
217 {
218  return d->hardLabels;
219 }
220 
221 void AbstractAxis::setShortLabels( const QStringList& list )
222 {
223  if ( d->hardShortLabels == list )
224  return;
225 
226  d->hardShortLabels = list;
227  update();
228 }
229 
230 QStringList AbstractAxis::shortLabels() const
231 {
232  return d->hardShortLabels;
233 }
234 
236 {
237  if ( d->diagram() )
238  return d->diagram()->coordinatePlane();
239  return 0;
240 }
241 
243 {
244  return d->diagram();
245 }
246 
248 {
249  return d->hasDiagram( diagram );
250 }
251 
253 {
254  if ( d->diagram() )
255  d->diagram()->update();
256 }

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