@@ -862,6 +862,7 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options | |||||
862 | } |
|
862 | } | |
863 |
|
863 | |||
864 |
|
864 | |||
|
865 | ||||
865 | #include "moc_qabstractaxis.cpp" |
|
866 | #include "moc_qabstractaxis.cpp" | |
866 | #include "moc_qabstractaxis_p.cpp" |
|
867 | #include "moc_qabstractaxis_p.cpp" | |
867 |
|
868 |
@@ -189,6 +189,7 protected: | |||||
189 | friend class ChartAxis; |
|
189 | friend class ChartAxis; | |
190 | friend class ChartPresenter; |
|
190 | friend class ChartPresenter; | |
191 | friend class ChartThemeManager; |
|
191 | friend class ChartThemeManager; | |
|
192 | friend class AbstractDomain; | |||
192 | }; |
|
193 | }; | |
193 |
|
194 | |||
194 | QTCOMMERCIALCHART_END_NAMESPACE |
|
195 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -52,8 +52,8 ChartDataSet::ChartDataSet(QChart *chart) | |||||
52 |
|
52 | |||
53 | ChartDataSet::~ChartDataSet() |
|
53 | ChartDataSet::~ChartDataSet() | |
54 | { |
|
54 | { | |
55 |
|
|
55 | deleteAllSeries(); | |
56 |
|
|
56 | deleteAllAxes(); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | /* |
|
59 | /* | |
@@ -126,6 +126,7 void ChartDataSet::removeSeries(QAbstractSeries *series) | |||||
126 | axis->d_ptr->m_series.removeAll(series); |
|
126 | axis->d_ptr->m_series.removeAll(series); | |
127 | series->d_ptr->m_axes.removeAll(axis); |
|
127 | series->d_ptr->m_axes.removeAll(axis); | |
128 | } |
|
128 | } | |
|
129 | ||||
129 | } |
|
130 | } | |
130 |
|
131 | |||
131 | /* |
|
132 | /* | |
@@ -153,7 +154,7 void ChartDataSet::removeAxis(QAbstractAxis *axis) | |||||
153 | } |
|
154 | } | |
154 |
|
155 | |||
155 | /* |
|
156 | /* | |
156 | * This method attach axis to series, return true if success. |
|
157 | * This method attaches axis to series, return true if success. | |
157 | */ |
|
158 | */ | |
158 | bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis) |
|
159 | bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis) | |
159 | { |
|
160 | { | |
@@ -162,7 +163,6 bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis) | |||||
162 |
|
163 | |||
163 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; |
|
164 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; | |
164 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; |
|
165 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; | |
165 | QSharedPointer<AbstractDomain> domain = series->d_ptr->m_domain; |
|
|||
166 |
|
166 | |||
167 | if (!m_seriesList.contains(series)) { |
|
167 | if (!m_seriesList.contains(series)) { | |
168 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
168 | qWarning() << QObject::tr("Can not find series on the chart."); | |
@@ -179,38 +179,42 bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis) | |||||
179 | return false; |
|
179 | return false; | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 |
|
|
182 | if (attachedSeriesList.contains(series)) { | |
183 | Q_ASSERT(!domain.isNull()); |
|
183 | qWarning() << QObject::tr("Axis already attached to series."); | |
|
184 | return false; | |||
|
185 | } | |||
|
186 | ||||
|
187 | QSharedPointer<AbstractDomain> domain = series->d_ptr->domain(); | |||
|
188 | AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis); | |||
|
189 | ||||
|
190 | if(type == AbstractDomain::UndefinedDomain) return false; | |||
184 |
|
191 | |||
185 | if(attachedSeriesList.isEmpty()){ |
|
|||
186 |
|
192 | |||
187 | }else{ |
|
193 | if(domain->type()!=type){ | |
188 | domain = attachedSeriesList.first()->d_ptr->domain(); |
|
194 | domain = QSharedPointer<AbstractDomain>(createDomain(type)); | |
189 | Q_ASSERT(!domain.isNull()); |
|
|||
190 | series->d_ptr->setDomain(domain); |
|
|||
191 | } |
|
195 | } | |
192 |
|
196 | |||
|
197 | if(domain.isNull()) return false; | |||
|
198 | ||||
|
199 | if(!domain->attachAxis(axis)) return false; | |||
|
200 | ||||
193 | series->d_ptr->m_axes<<axis; |
|
201 | series->d_ptr->m_axes<<axis; | |
194 | axis->d_ptr->m_series<<series; |
|
202 | axis->d_ptr->m_series<<series; | |
195 |
|
203 | |||
|
204 | series->d_ptr->setDomain(domain); | |||
|
205 | series->d_ptr->initializeDomain(); | |||
196 | series->d_ptr->initializeAxes(); |
|
206 | series->d_ptr->initializeAxes(); | |
197 | axis->d_ptr->initializeDomain(domain.data()); |
|
207 | axis->d_ptr->initializeDomain(domain.data()); | |
198 |
|
208 | |||
199 | if(axis->orientation()==Qt::Vertical){ |
|
209 | if(attachedSeriesList.count()>0 && attachedAxisList.count()>0){ | |
200 | QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); |
|
210 | //TODO optimatization: joinDomain(attachedAxisList, attachedSeriesList); | |
201 | QObject::connect(domain.data(), SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); |
|
|||
202 | } |
|
|||
203 |
|
||||
204 | if(axis->orientation()==Qt::Horizontal){ |
|
|||
205 | QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); |
|
|||
206 | QObject::connect(domain.data(), SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); |
|
|||
207 | } |
|
211 | } | |
208 |
|
212 | |||
209 | return true; |
|
213 | return true; | |
210 | } |
|
214 | } | |
211 |
|
215 | |||
212 | /* |
|
216 | /* | |
213 | * This method detach axis to series, return true if success. |
|
217 | * This method detaches axis to series, return true if success. | |
214 | */ |
|
218 | */ | |
215 | bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis) |
|
219 | bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis) | |
216 | { |
|
220 | { | |
@@ -238,19 +242,10 bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis) | |||||
238 |
|
242 | |||
239 | Q_ASSERT(axis->d_ptr->m_series.contains(series)); |
|
243 | Q_ASSERT(axis->d_ptr->m_series.contains(series)); | |
240 |
|
244 | |||
|
245 | domain->detachAxis(axis); | |||
241 | series->d_ptr->m_axes.removeAll(axis); |
|
246 | series->d_ptr->m_axes.removeAll(axis); | |
242 | axis->d_ptr->m_series.removeAll(series); |
|
247 | axis->d_ptr->m_series.removeAll(series); | |
243 |
|
248 | |||
244 | if(axis->orientation()==Qt::Vertical){ |
|
|||
245 | QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); |
|
|||
246 | QObject::disconnect(domain.data(), SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); |
|
|||
247 | } |
|
|||
248 |
|
||||
249 | if(axis->orientation()==Qt::Horizontal){ |
|
|||
250 | QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); |
|
|||
251 | QObject::disconnect(domain.data(), SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); |
|
|||
252 | } |
|
|||
253 |
|
||||
254 | return true; |
|
249 | return true; | |
255 | } |
|
250 | } | |
256 |
|
251 | |||
@@ -263,7 +258,7 void ChartDataSet::createDefaultAxes() | |||||
263 | QAbstractAxis::AxisTypes typeY(0); |
|
258 | QAbstractAxis::AxisTypes typeY(0); | |
264 |
|
259 | |||
265 | // Remove possibly existing axes |
|
260 | // Remove possibly existing axes | |
266 |
|
|
261 | deleteAllAxes(); | |
267 |
|
262 | |||
268 | Q_ASSERT(m_axisList.isEmpty()); |
|
263 | Q_ASSERT(m_axisList.isEmpty()); | |
269 |
|
264 | |||
@@ -326,22 +321,22 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation ori | |||||
326 | } |
|
321 | } | |
327 | } |
|
322 | } | |
328 |
|
323 | |||
329 |
void ChartDataSet:: |
|
324 | void ChartDataSet::deleteAllSeries() | |
330 | { |
|
325 | { | |
331 | foreach (QAbstractSeries *s , m_seriesList) |
|
326 | foreach (QAbstractSeries *s , m_seriesList){ | |
332 | removeSeries(s); |
|
327 | removeSeries(s); | |
333 |
|
328 | delete s; | ||
|
329 | } | |||
334 | Q_ASSERT(m_seriesList.count() == 0); |
|
330 | Q_ASSERT(m_seriesList.count() == 0); | |
335 | qDeleteAll(m_seriesList); |
|
|||
336 | } |
|
331 | } | |
337 |
|
332 | |||
338 |
void ChartDataSet:: |
|
333 | void ChartDataSet::deleteAllAxes() | |
339 | { |
|
334 | { | |
340 | foreach (QAbstractAxis *a , m_axisList) |
|
335 | foreach (QAbstractAxis *a , m_axisList){ | |
341 | removeAxis(a); |
|
336 | removeAxis(a); | |
342 |
|
337 | delete a; | ||
|
338 | } | |||
343 | Q_ASSERT(m_axisList.count() == 0); |
|
339 | Q_ASSERT(m_axisList.count() == 0); | |
344 | qDeleteAll(m_axisList); |
|
|||
345 | } |
|
340 | } | |
346 |
|
341 | |||
347 | void ChartDataSet::zoomInDomain(const QRectF &rect) |
|
342 | void ChartDataSet::zoomInDomain(const QRectF &rect) | |
@@ -405,6 +400,72 QList<QAbstractSeries *> ChartDataSet::series() const | |||||
405 | return m_seriesList; |
|
400 | return m_seriesList; | |
406 | } |
|
401 | } | |
407 |
|
402 | |||
|
403 | AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis*> axes) | |||
|
404 | { | |||
|
405 | enum Type { | |||
|
406 | LogType = 0x1, | |||
|
407 | ValueType = 0x2 | |||
|
408 | }; | |||
|
409 | ||||
|
410 | int horizontal(ValueType); | |||
|
411 | int vertical(ValueType); | |||
|
412 | ||||
|
413 | foreach(QAbstractAxis* axis, axes) | |||
|
414 | { | |||
|
415 | switch(axis->type()) { | |||
|
416 | case QAbstractAxis::AxisTypeLogValue: | |||
|
417 | axis->orientation()==Qt::Horizontal?horizontal:vertical|=LogType; | |||
|
418 | break; | |||
|
419 | case QAbstractAxis::AxisTypeValue: | |||
|
420 | case QAbstractAxis::AxisTypeBarCategory: | |||
|
421 | case QAbstractAxis::AxisTypeCategory: | |||
|
422 | case QAbstractAxis::AxisTypeDateTime: | |||
|
423 | axis->orientation()==Qt::Horizontal?horizontal:vertical|=ValueType; | |||
|
424 | break; | |||
|
425 | default: | |||
|
426 | qWarning()<<"Undefined type"; | |||
|
427 | break; | |||
|
428 | } | |||
|
429 | } | |||
|
430 | ||||
|
431 | if(vertical==ValueType && horizontal== ValueType) { | |||
|
432 | return AbstractDomain::XYDomain; | |||
|
433 | } | |||
|
434 | ||||
|
435 | if(vertical==LogType && horizontal== ValueType) { | |||
|
436 | return AbstractDomain::XLogYDomain; | |||
|
437 | } | |||
|
438 | ||||
|
439 | if(vertical==ValueType && horizontal== LogType) { | |||
|
440 | return AbstractDomain::LogXYDomain; | |||
|
441 | } | |||
|
442 | ||||
|
443 | if(vertical==LogType && horizontal== LogType) { | |||
|
444 | return AbstractDomain::XLogYLogDomain; | |||
|
445 | } | |||
|
446 | ||||
|
447 | return AbstractDomain::UndefinedDomain; | |||
|
448 | } | |||
|
449 | ||||
|
450 | ||||
|
451 | //refactor create factory | |||
|
452 | AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type) | |||
|
453 | { | |||
|
454 | switch(type) | |||
|
455 | { | |||
|
456 | case AbstractDomain::XLogYLogDomain: | |||
|
457 | return 0; | |||
|
458 | case AbstractDomain::XYDomain: | |||
|
459 | return new XYDomain(); | |||
|
460 | case AbstractDomain::XLogYDomain: | |||
|
461 | return 0; | |||
|
462 | case AbstractDomain::LogXYDomain: | |||
|
463 | return 0; | |||
|
464 | default: | |||
|
465 | return 0; | |||
|
466 | } | |||
|
467 | } | |||
|
468 | ||||
408 | #include "moc_chartdataset_p.cpp" |
|
469 | #include "moc_chartdataset_p.cpp" | |
409 |
|
470 | |||
410 | QTCOMMERCIALCHART_END_NAMESPACE |
|
471 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -50,12 +50,10 public: | |||||
50 | void addSeries(QAbstractSeries *series); |
|
50 | void addSeries(QAbstractSeries *series); | |
51 | void removeSeries(QAbstractSeries *series); |
|
51 | void removeSeries(QAbstractSeries *series); | |
52 | QList<QAbstractSeries *> series() const; |
|
52 | QList<QAbstractSeries *> series() const; | |
53 | void removeAllSeries(); |
|
|||
54 |
|
53 | |||
55 | void addAxis(QAbstractAxis *axis,Qt::Alignment aligment); |
|
54 | void addAxis(QAbstractAxis *axis,Qt::Alignment aligment); | |
56 | void removeAxis(QAbstractAxis *axis); |
|
55 | void removeAxis(QAbstractAxis *axis); | |
57 | QList<QAbstractAxis*> axes() const; |
|
56 | QList<QAbstractAxis*> axes() const; | |
58 | void removeAllAxes(); |
|
|||
59 |
|
57 | |||
60 | bool attachAxis(QAbstractSeries* series,QAbstractAxis *axis); |
|
58 | bool attachAxis(QAbstractSeries* series,QAbstractAxis *axis); | |
61 | bool detachAxis(QAbstractSeries* series,QAbstractAxis *axis); |
|
59 | bool detachAxis(QAbstractSeries* series,QAbstractAxis *axis); | |
@@ -75,7 +73,10 Q_SIGNALS: | |||||
75 | private: |
|
73 | private: | |
76 | void createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation); |
|
74 | void createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation); | |
77 | QAbstractAxis *createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation); |
|
75 | QAbstractAxis *createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation); | |
78 |
|
76 | AbstractDomain::DomainType selectDomain(QList<QAbstractAxis* > axes); | ||
|
77 | AbstractDomain* createDomain(AbstractDomain::DomainType type); | |||
|
78 | void deleteAllAxes(); | |||
|
79 | void deleteAllSeries(); | |||
79 | private: |
|
80 | private: | |
80 | QList<QAbstractSeries *> m_seriesList; |
|
81 | QList<QAbstractSeries *> m_seriesList; | |
81 | QList<QAbstractAxis *> m_axisList; |
|
82 | QList<QAbstractAxis *> m_axisList; |
@@ -161,6 +161,35 qreal AbstractDomain::niceNumber(qreal x, bool ceiling) | |||||
161 | return q * z; |
|
161 | return q * z; | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
|
164 | bool AbstractDomain::attachAxis(QAbstractAxis* axis) | |||
|
165 | { | |||
|
166 | if(axis->orientation()==Qt::Vertical) { | |||
|
167 | QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); | |||
|
168 | QObject::connect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |||
|
169 | } | |||
|
170 | ||||
|
171 | if(axis->orientation()==Qt::Horizontal) { | |||
|
172 | QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); | |||
|
173 | QObject::connect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |||
|
174 | } | |||
|
175 | ||||
|
176 | return true; | |||
|
177 | } | |||
|
178 | ||||
|
179 | bool AbstractDomain::detachAxis(QAbstractAxis* axis) | |||
|
180 | { | |||
|
181 | if(axis->orientation()==Qt::Vertical) { | |||
|
182 | QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); | |||
|
183 | QObject::disconnect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |||
|
184 | } | |||
|
185 | ||||
|
186 | if(axis->orientation()==Qt::Horizontal) { | |||
|
187 | QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); | |||
|
188 | QObject::disconnect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |||
|
189 | } | |||
|
190 | ||||
|
191 | return true; | |||
|
192 | } | |||
164 |
|
193 | |||
165 | // operators |
|
194 | // operators | |
166 |
|
195 |
@@ -36,16 +36,22 | |||||
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
|
39 | class QAbstractAxis; | |||
|
40 | ||||
39 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT AbstractDomain: public QObject |
|
41 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT AbstractDomain: public QObject | |
40 | { |
|
42 | { | |
41 | Q_OBJECT |
|
43 | Q_OBJECT | |
42 | public: |
|
44 | public: | |
|
45 | enum DomainType { UndefinedDomain, XYDomain, XLogYDomain, LogXYDomain, XLogYLogDomain }; | |||
|
46 | public: | |||
43 | explicit AbstractDomain(QObject *object = 0); |
|
47 | explicit AbstractDomain(QObject *object = 0); | |
44 | virtual ~AbstractDomain(); |
|
48 | virtual ~AbstractDomain(); | |
45 |
|
49 | |||
46 | void setSize(const QSizeF& size); |
|
50 | void setSize(const QSizeF& size); | |
47 | QSizeF size() const; |
|
51 | QSizeF size() const; | |
48 |
|
52 | |||
|
53 | virtual DomainType type() = 0; | |||
|
54 | ||||
49 | virtual void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) = 0; |
|
55 | virtual void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) = 0; | |
50 | void setRangeX(qreal min, qreal max); |
|
56 | void setRangeX(qreal min, qreal max); | |
51 | void setRangeY(qreal min, qreal max); |
|
57 | void setRangeY(qreal min, qreal max); | |
@@ -63,11 +69,9 public: | |||||
63 | qreal spanY() const; |
|
69 | qreal spanY() const; | |
64 | bool isEmpty() const; |
|
70 | bool isEmpty() const; | |
65 |
|
71 | |||
66 |
|
||||
67 | void blockAxisSignals(bool block); |
|
72 | void blockAxisSignals(bool block); | |
68 | bool axisSignalsBlocked() const { return m_axisSignalsBlocked; } |
|
73 | bool axisSignalsBlocked() const { return m_axisSignalsBlocked; } | |
69 |
|
74 | |||
70 |
|
||||
71 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2); |
|
75 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2); | |
72 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const AbstractDomain &domain1, const AbstractDomain &domain2); |
|
76 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const AbstractDomain &domain1, const AbstractDomain &domain2); | |
73 | friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDomain &domain); |
|
77 | friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDomain &domain); | |
@@ -80,6 +84,9 public: | |||||
80 | virtual QPointF calculateDomainPoint(const QPointF &point) const = 0; |
|
84 | virtual QPointF calculateDomainPoint(const QPointF &point) const = 0; | |
81 | virtual QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const = 0; |
|
85 | virtual QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const = 0; | |
82 |
|
86 | |||
|
87 | virtual bool attachAxis(QAbstractAxis* axis); | |||
|
88 | virtual bool detachAxis(QAbstractAxis* axis); | |||
|
89 | ||||
83 | static void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount); |
|
90 | static void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount); | |
84 | static qreal niceNumber(qreal x, bool ceiling); |
|
91 | static qreal niceNumber(qreal x, bool ceiling); | |
85 |
|
92 |
@@ -42,6 +42,8 public: | |||||
42 | explicit XYDomain(QObject *object = 0); |
|
42 | explicit XYDomain(QObject *object = 0); | |
43 | virtual ~XYDomain(); |
|
43 | virtual ~XYDomain(); | |
44 |
|
44 | |||
|
45 | DomainType type(){ return AbstractDomain::XYDomain;} | |||
|
46 | ||||
45 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
47 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
46 |
|
48 | |||
47 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XYDomain &Domain1, const XYDomain &Domain2); |
|
49 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XYDomain &Domain1, const XYDomain &Domain2); |
@@ -38,7 +38,6 class QChart; | |||||
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 | class QAbstractSeries; |
|
39 | class QAbstractSeries; | |
40 | class LegendLayout; |
|
40 | class LegendLayout; | |
41 | class Domain; |
|
|||
42 | class QLegendMarker; |
|
41 | class QLegendMarker; | |
43 |
|
42 | |||
44 | class QLegendPrivate : public QObject |
|
43 | class QLegendPrivate : public QObject |
@@ -160,7 +160,10 void QChart::removeSeries(QAbstractSeries *series) | |||||
160 | */ |
|
160 | */ | |
161 | void QChart::removeAllSeries() |
|
161 | void QChart::removeAllSeries() | |
162 | { |
|
162 | { | |
163 | d_ptr->m_dataset->removeAllSeries(); |
|
163 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ | |
|
164 | removeSeries(s); | |||
|
165 | delete s; | |||
|
166 | } | |||
164 | } |
|
167 | } | |
165 |
|
168 | |||
166 | /*! |
|
169 | /*! |
@@ -71,6 +71,8 Q_DECLARE_METATYPE(QLineSeries *) | |||||
71 | class tst_ChartDataSet: public QObject { |
|
71 | class tst_ChartDataSet: public QObject { | |
72 |
|
72 | |||
73 | Q_OBJECT |
|
73 | Q_OBJECT | |
|
74 | public: | |||
|
75 | tst_ChartDataSet():m_dataset(0){}; | |||
74 |
|
76 | |||
75 | public Q_SLOTS: |
|
77 | public Q_SLOTS: | |
76 | void initTestCase(); |
|
78 | void initTestCase(); | |
@@ -85,14 +87,10 private Q_SLOTS: | |||||
85 | void addSeries(); |
|
87 | void addSeries(); | |
86 | void removeSeries_data(); |
|
88 | void removeSeries_data(); | |
87 | void removeSeries(); |
|
89 | void removeSeries(); | |
88 | void removeAllSeries_data(); |
|
|||
89 | void removeAllSeries(); |
|
|||
90 | void addAxis_data(); |
|
90 | void addAxis_data(); | |
91 | void addAxis(); |
|
91 | void addAxis(); | |
92 | void removeAxis_data(); |
|
92 | void removeAxis_data(); | |
93 | void removeAxis(); |
|
93 | void removeAxis(); | |
94 | void removeAllAxes_data(); |
|
|||
95 | void removeAllAxes(); |
|
|||
96 | void attachAxis_data(); |
|
94 | void attachAxis_data(); | |
97 | void attachAxis(); |
|
95 | void attachAxis(); | |
98 | void detachAxis_data(); |
|
96 | void detachAxis_data(); | |
@@ -115,17 +113,15 void tst_ChartDataSet::cleanupTestCase() | |||||
115 |
|
113 | |||
116 | void tst_ChartDataSet::init() |
|
114 | void tst_ChartDataSet::init() | |
117 | { |
|
115 | { | |
|
116 | Q_ASSERT(!m_dataset); | |||
118 | m_dataset = new ChartDataSet(0); |
|
117 | m_dataset = new ChartDataSet(0); | |
119 | } |
|
118 | } | |
120 |
|
119 | |||
121 |
|
120 | |||
122 | void tst_ChartDataSet::cleanup() |
|
121 | void tst_ChartDataSet::cleanup() | |
123 | { |
|
122 | { | |
124 | QList<QAbstractSeries*> series = m_dataset->series(); |
|
123 | delete m_dataset; | |
125 | foreach (QAbstractSeries* serie, series) |
|
124 | m_dataset=0; | |
126 | { |
|
|||
127 | m_dataset->removeSeries(serie); |
|
|||
128 | } |
|
|||
129 | } |
|
125 | } | |
130 |
|
126 | |||
131 | void tst_ChartDataSet::chartdataset_data() |
|
127 | void tst_ChartDataSet::chartdataset_data() | |
@@ -145,21 +141,27 void tst_ChartDataSet::addSeries_data() | |||||
145 | QTest::addColumn<QAbstractSeries*>("series"); |
|
141 | QTest::addColumn<QAbstractSeries*>("series"); | |
146 |
|
142 | |||
147 | QAbstractSeries* line = new QLineSeries(this); |
|
143 | QAbstractSeries* line = new QLineSeries(this); | |
148 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
|||
149 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
|||
150 | QAbstractSeries* spline = new QSplineSeries(this); |
|
|||
151 | QAbstractSeries* pie = new QPieSeries(this); |
|
|||
152 | QAbstractSeries* bar = new QBarSeries(this); |
|
|||
153 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
|||
154 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
|||
155 |
|
||||
156 | QTest::newRow("line") << line; |
|
144 | QTest::newRow("line") << line; | |
|
145 | ||||
|
146 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this))); | |||
157 | QTest::newRow("area") << area; |
|
147 | QTest::newRow("area") << area; | |
|
148 | ||||
|
149 | QAbstractSeries* scatter = new QScatterSeries(this); | |||
158 | QTest::newRow("scatter") << scatter; |
|
150 | QTest::newRow("scatter") << scatter; | |
|
151 | ||||
|
152 | QAbstractSeries* spline = new QSplineSeries(this); | |||
159 | QTest::newRow("spline") << spline; |
|
153 | QTest::newRow("spline") << spline; | |
|
154 | ||||
|
155 | QAbstractSeries* pie = new QPieSeries(this); | |||
160 | QTest::newRow("pie") << pie; |
|
156 | QTest::newRow("pie") << pie; | |
|
157 | ||||
|
158 | QAbstractSeries* bar = new QBarSeries(this); | |||
161 | QTest::newRow("bar") << bar; |
|
159 | QTest::newRow("bar") << bar; | |
|
160 | ||||
|
161 | QAbstractSeries* percent = new QPercentBarSeries(this); | |||
162 | QTest::newRow("percent") << percent; |
|
162 | QTest::newRow("percent") << percent; | |
|
163 | ||||
|
164 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |||
163 | QTest::newRow("stacked") << stacked; |
|
165 | QTest::newRow("stacked") << stacked; | |
164 | } |
|
166 | } | |
165 |
|
167 | |||
@@ -175,7 +177,6 void tst_ChartDataSet::addSeries() | |||||
175 |
|
177 | |||
176 | m_dataset->addSeries(series); |
|
178 | m_dataset->addSeries(series); | |
177 |
|
179 | |||
178 |
|
||||
179 | QCOMPARE(m_dataset->series().count(),1); |
|
180 | QCOMPARE(m_dataset->series().count(),1); | |
180 | TRY_COMPARE(spy0.count(), 0); |
|
181 | TRY_COMPARE(spy0.count(), 0); | |
181 | TRY_COMPARE(spy1.count(), 0); |
|
182 | TRY_COMPARE(spy1.count(), 0); | |
@@ -208,56 +209,6 void tst_ChartDataSet::removeSeries() | |||||
208 | TRY_COMPARE(spy3.count(), 1); |
|
209 | TRY_COMPARE(spy3.count(), 1); | |
209 | } |
|
210 | } | |
210 |
|
211 | |||
211 | void tst_ChartDataSet::removeAllSeries_data() |
|
|||
212 | { |
|
|||
213 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
|||
214 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
|||
215 |
|
||||
216 | QList<QAbstractSeries*> series; |
|
|||
217 | QList<QAbstractAxis*> axis; |
|
|||
218 |
|
||||
219 | series << new QLineSeries(this) << new QSplineSeries(this) << new QScatterSeries(this); |
|
|||
220 | axis << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this); |
|
|||
221 |
|
||||
222 | QTest::newRow("3 series , 3 axis") << series << axis; |
|
|||
223 | } |
|
|||
224 |
|
||||
225 | void tst_ChartDataSet::removeAllSeries() |
|
|||
226 | { |
|
|||
227 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
|||
228 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
|||
229 |
|
||||
230 | QCOMPARE(m_dataset->series().count(),0); |
|
|||
231 | QCOMPARE(m_dataset->axes().count(),0); |
|
|||
232 |
|
||||
233 | foreach (QAbstractSeries* series, seriesList) { |
|
|||
234 | m_dataset->addSeries(series); |
|
|||
235 | } |
|
|||
236 |
|
||||
237 | foreach (QAbstractAxis* axis, axisList) { |
|
|||
238 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
|||
239 | } |
|
|||
240 |
|
||||
241 | for (int i = 0; i < seriesList.count(); i++) { |
|
|||
242 | m_dataset->attachAxis(seriesList.at(i),axisList.at(i)); |
|
|||
243 | } |
|
|||
244 |
|
||||
245 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
|||
246 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
|||
247 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
|||
248 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
|||
249 |
|
||||
250 | m_dataset->removeAllSeries(); |
|
|||
251 |
|
||||
252 | TRY_COMPARE(spy0.count(), 0); |
|
|||
253 | TRY_COMPARE(spy1.count(), 0); |
|
|||
254 | TRY_COMPARE(spy2.count(), 0); |
|
|||
255 | TRY_COMPARE(spy3.count(), seriesList.count()); |
|
|||
256 |
|
||||
257 | QCOMPARE(m_dataset->series().count(),0); |
|
|||
258 | QCOMPARE(m_dataset->axes().count(),axisList.count()); |
|
|||
259 | } |
|
|||
260 |
|
||||
261 | void tst_ChartDataSet::addAxis_data() |
|
212 | void tst_ChartDataSet::addAxis_data() | |
262 | { |
|
213 | { | |
263 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
214 | QTest::addColumn<QAbstractAxis*>("axis"); | |
@@ -316,58 +267,9 void tst_ChartDataSet::removeAxis() | |||||
316 | TRY_COMPARE(spy3.count(), 0); |
|
267 | TRY_COMPARE(spy3.count(), 0); | |
317 | } |
|
268 | } | |
318 |
|
269 | |||
319 | void tst_ChartDataSet::removeAllAxes_data() |
|
|||
320 | { |
|
|||
321 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
|||
322 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
|||
323 |
|
||||
324 | QList<QAbstractSeries*> series; |
|
|||
325 | QList<QAbstractAxis*> axis; |
|
|||
326 |
|
||||
327 | series << new QLineSeries(this) << new QSplineSeries(this) << new QScatterSeries(this); |
|
|||
328 | axis << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this); |
|
|||
329 |
|
||||
330 | QTest::newRow("3 series , 3 axis") << series << axis; |
|
|||
331 | } |
|
|||
332 |
|
||||
333 | void tst_ChartDataSet::removeAllAxes() |
|
|||
334 | { |
|
|||
335 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
|||
336 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
|||
337 |
|
||||
338 | QCOMPARE(m_dataset->series().count(),0); |
|
|||
339 | QCOMPARE(m_dataset->axes().count(),0); |
|
|||
340 |
|
||||
341 | foreach (QAbstractSeries* series, seriesList) { |
|
|||
342 | m_dataset->addSeries(series); |
|
|||
343 | } |
|
|||
344 |
|
||||
345 | foreach (QAbstractAxis* axis, axisList) { |
|
|||
346 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
|||
347 | } |
|
|||
348 |
|
||||
349 | for (int i = 0; i < seriesList.count(); i++) { |
|
|||
350 | m_dataset->attachAxis(seriesList.at(i),axisList.at(i)); |
|
|||
351 | } |
|
|||
352 |
|
||||
353 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
|||
354 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
|||
355 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
|||
356 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
|||
357 |
|
||||
358 | m_dataset->removeAllAxes(); |
|
|||
359 |
|
||||
360 | TRY_COMPARE(spy0.count(), 0); |
|
|||
361 | TRY_COMPARE(spy1.count(), axisList.count()); |
|
|||
362 | TRY_COMPARE(spy2.count(), 0); |
|
|||
363 | TRY_COMPARE(spy3.count(), 0); |
|
|||
364 |
|
||||
365 | QCOMPARE(m_dataset->series().count(),seriesList.count()); |
|
|||
366 | QCOMPARE(m_dataset->axes().count(),0); |
|
|||
367 | } |
|
|||
368 |
|
||||
369 | void tst_ChartDataSet::attachAxis_data() |
|
270 | void tst_ChartDataSet::attachAxis_data() | |
370 | { |
|
271 | { | |
|
272 | ||||
371 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
273 | QTest::addColumn<QList<QAbstractSeries*> >("series"); | |
372 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
274 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); | |
373 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); |
|
275 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); | |
@@ -375,12 +277,7 void tst_ChartDataSet::attachAxis_data() | |||||
375 | QTest::addColumn<QAbstractAxis*>("attachAxis"); |
|
277 | QTest::addColumn<QAbstractAxis*>("attachAxis"); | |
376 | QTest::addColumn<bool>("success"); |
|
278 | QTest::addColumn<bool>("success"); | |
377 |
|
279 | |||
378 | QList<QAbstractSeries*> series; |
|
280 | //QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
379 | QList<QAbstractAxis*> axes; |
|
|||
380 | QList<Qt::Alignment> alignment; |
|
|||
381 |
|
||||
382 | QAbstractSeries* line = new QLineSeries(this); |
|
|||
383 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
|||
384 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
281 | QAbstractSeries* scatter = new QScatterSeries(this); | |
385 | QAbstractSeries* spline = new QSplineSeries(this); |
|
282 | QAbstractSeries* spline = new QSplineSeries(this); | |
386 | QAbstractSeries* pie = new QPieSeries(this); |
|
283 | QAbstractSeries* pie = new QPieSeries(this); | |
@@ -388,17 +285,35 void tst_ChartDataSet::attachAxis_data() | |||||
388 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
285 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
389 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
286 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
390 |
|
287 | |||
391 | QAbstractAxis* value1 = new QValueAxis(this); |
|
|||
392 | QAbstractAxis* value2 = new QValueAxis(this); |
|
|||
393 | QAbstractAxis* category = new QCategoryAxis(this); |
|
288 | QAbstractAxis* category = new QCategoryAxis(this); | |
394 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); |
|
289 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); | |
395 | QAbstractAxis* datetime = new QDateTimeAxis(this); |
|
290 | QAbstractAxis* datetime = new QDateTimeAxis(this); | |
396 |
|
291 | |||
|
292 | { | |||
|
293 | QList<QAbstractSeries*> series; | |||
|
294 | QList<QAbstractAxis*> axes; | |||
|
295 | QList<Qt::Alignment> alignment; | |||
|
296 | QAbstractSeries* line = new QLineSeries(this); | |||
|
297 | QAbstractAxis* value1 = new QValueAxis(this); | |||
|
298 | QAbstractAxis* value2 = new QValueAxis(this); | |||
|
299 | series << line << 0; | |||
|
300 | axes << value1 << value2; | |||
|
301 | alignment << Qt::AlignBottom << Qt::AlignLeft; | |||
|
302 | QTest::newRow("first") << series << axes << alignment << line << value2 << true ; | |||
|
303 | } | |||
397 |
|
304 | |||
398 | series << line << 0; |
|
305 | { | |
399 | axes << value1 << value2; |
|
306 | QList<QAbstractSeries*> series; | |
400 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
307 | QList<QAbstractAxis*> axes; | |
401 | QTest::newRow("line + two axes") << series << axes << alignment << line << value2 << true; |
|
308 | QList<Qt::Alignment> alignment; | |
|
309 | QAbstractSeries* line = new QLineSeries(this); | |||
|
310 | QAbstractAxis* value1 = new QValueAxis(this); | |||
|
311 | QAbstractAxis* value2 = new QValueAxis(this); | |||
|
312 | series << 0 << line; | |||
|
313 | axes << value1 << value2; | |||
|
314 | alignment << Qt::AlignBottom << Qt::AlignLeft; | |||
|
315 | QTest::newRow("second") << series << axes << alignment << line << value1 << true; | |||
|
316 | } | |||
402 |
|
317 | |||
403 | } |
|
318 | } | |
404 |
|
319 | |||
@@ -440,15 +355,15 void tst_ChartDataSet::detachAxis_data() | |||||
440 | QTest::addColumn<QAbstractAxis*>("detachAxis"); |
|
355 | QTest::addColumn<QAbstractAxis*>("detachAxis"); | |
441 | QTest::addColumn<bool>("success"); |
|
356 | QTest::addColumn<bool>("success"); | |
442 |
|
357 | |||
|
358 | { | |||
443 | QList<QAbstractSeries*> series; |
|
359 | QList<QAbstractSeries*> series; | |
444 | QList<QAbstractAxis*> axes; |
|
360 | QList<QAbstractAxis*> axes; | |
445 |
|
||||
446 | QAbstractSeries* line = new QLineSeries(this); |
|
361 | QAbstractSeries* line = new QLineSeries(this); | |
447 | QAbstractAxis* value = new QValueAxis(this); |
|
362 | QAbstractAxis* value = new QValueAxis(this); | |
448 |
|
||||
449 | series << line; |
|
363 | series << line; | |
450 | axes << value; |
|
364 | axes << value; | |
451 |
QTest::newRow(" |
|
365 | QTest::newRow("first") << series << axes << line << value << true; | |
|
366 | } | |||
452 | } |
|
367 | } | |
453 |
|
368 | |||
454 | void tst_ChartDataSet::detachAxis() |
|
369 | void tst_ChartDataSet::detachAxis() |
General Comments 0
You need to be logged in to leave comments.
Login now