##// END OF EJS Templates
Refactor QChart API...
Michal Klocek -
r1577:779eeed6a402
parent child
Show More
@@ -228,7 +228,7 QChart* ThemeWidget::createBarChart(int valueCount) const
228 series->append(set);
228 series->append(set);
229 }
229 }
230 chart->addSeries(series);
230 chart->addSeries(series);
231 chart->setAxisX(series,axis);
231 chart->createDefaultAxes();
232
232
233 return chart;
233 return chart;
234 }
234 }
@@ -249,6 +249,8 QChart* ThemeWidget::createLineChart() const
249 series->setName(name + QString::number(nameIndex));
249 series->setName(name + QString::number(nameIndex));
250 nameIndex++;
250 nameIndex++;
251 chart->addSeries(series);
251 chart->addSeries(series);
252 chart->createDefaultAxes();
253
252 }
254 }
253
255
254 return chart;
256 return chart;
@@ -60,6 +60,7 int main(int argc, char *argv[])
60 QChart* chart = new QChart();
60 QChart* chart = new QChart();
61 chart->addSeries(series);
61 chart->addSeries(series);
62 chart->setTitle("Simple areachart example");
62 chart->setTitle("Simple areachart example");
63 chart->createDefaultAxes();
63 chart->axisX()->setRange(0, 20);
64 chart->axisX()->setRange(0, 20);
64 chart->axisY()->setRange(0, 10);
65 chart->axisY()->setRange(0, 10);
65 //![4]
66 //![4]
@@ -90,7 +90,7 TableWidget::TableWidget(QWidget *parent)
90 categories << "April" << "May" << "June" << "July" << "August";
90 categories << "April" << "May" << "June" << "July" << "August";
91 QCategoriesAxis* axis = new QCategoriesAxis();
91 QCategoriesAxis* axis = new QCategoriesAxis();
92 axis->append(categories);
92 axis->append(categories);
93 chart->setAxisX(series,axis);
93 chart->createDefaultAxes();
94 //! [6]
94 //! [6]
95
95
96 //! [7]
96 //! [7]
@@ -67,7 +67,7 int main(int argc, char *argv[])
67 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
67 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
68 QCategoriesAxis* axis = new QCategoriesAxis();
68 QCategoriesAxis* axis = new QCategoriesAxis();
69 axis->append(categories);
69 axis->append(categories);
70 chart->setAxisX(series,axis);
70 chart->createDefaultAxes();
71 //![4]
71 //![4]
72
72
73 //![5]
73 //![5]
@@ -46,6 +46,7 int main(int argc, char *argv[])
46 QChart* chart = new QChart();
46 QChart* chart = new QChart();
47 chart->legend()->hide();
47 chart->legend()->hide();
48 chart->addSeries(series);
48 chart->addSeries(series);
49 chart->createDefaultAxes();
49 chart->setTitle("Simple line chart example");
50 chart->setTitle("Simple line chart example");
50 //![3]
51 //![3]
51
52
@@ -54,6 +55,7 int main(int argc, char *argv[])
54 chartView->setRenderHint(QPainter::Antialiasing);
55 chartView->setRenderHint(QPainter::Antialiasing);
55 //![4]
56 //![4]
56
57
58
57 //![5]
59 //![5]
58 QMainWindow window;
60 QMainWindow window;
59 window.setCentralWidget(chartView);
61 window.setCentralWidget(chartView);
@@ -66,7 +66,8 int main(int argc, char *argv[])
66 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
66 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
67 QCategoriesAxis* axis = new QCategoriesAxis();
67 QCategoriesAxis* axis = new QCategoriesAxis();
68 axis->append(categories);
68 axis->append(categories);
69 chart->setAxisX(series,axis);
69 chart->createDefaultAxes();
70 chart->setAxisX(axis,series);
70 //![4]
71 //![4]
71
72
72 //![5]
73 //![5]
@@ -66,10 +66,7 int main(int argc, char *argv[])
66 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
66 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
67 QCategoriesAxis* axis = new QCategoriesAxis();
67 QCategoriesAxis* axis = new QCategoriesAxis();
68 axis->append(categories);
68 axis->append(categories);
69 chart->setAxisX(series,axis);
69 chart->setAxisX(axis,series);
70 // axis->setMinCategory(QString("Feb"));
71 // axis->setMaxCategory(QString("May"));
72 // axis->setRange(QString("Feb"), QString("Apr"));
73 //![4]
70 //![4]
74
71
75 //![5]
72 //![5]
@@ -43,7 +43,7 void DrilldownChart::changeSeries(DrilldownBarSeries *series)
43
43
44 addSeries(series);
44 addSeries(series);
45
45
46 setAxisX(series,axis);
46 createDefaultAxes();
47
47
48 setTitle(series->name());
48 setTitle(series->name());
49 }
49 }
@@ -32,7 +32,7 DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) :
32
32
33 void DeclarativeAreaSeries::setAxisX(QAbstractAxis *axis)
33 void DeclarativeAreaSeries::setAxisX(QAbstractAxis *axis)
34 {
34 {
35 chart()->setAxisX(this, axis);
35 chart()->setAxisX(axis,this);
36 }
36 }
37
37
38 QAbstractAxis *DeclarativeAreaSeries::axisX()
38 QAbstractAxis *DeclarativeAreaSeries::axisX()
@@ -42,7 +42,7 QAbstractAxis *DeclarativeAreaSeries::axisX()
42
42
43 void DeclarativeAreaSeries::setAxisY(QAbstractAxis *axis)
43 void DeclarativeAreaSeries::setAxisY(QAbstractAxis *axis)
44 {
44 {
45 chart()->setAxisY(this, axis);
45 chart()->setAxisY(axis,this);
46 }
46 }
47
47
48 QAbstractAxis *DeclarativeAreaSeries::axisY()
48 QAbstractAxis *DeclarativeAreaSeries::axisY()
@@ -106,7 +106,7 void DeclarativeBarSeries::componentComplete()
106
106
107 void DeclarativeBarSeries::setAxisX(QAbstractAxis *axis)
107 void DeclarativeBarSeries::setAxisX(QAbstractAxis *axis)
108 {
108 {
109 chart()->setAxisX(this, axis);
109 chart()->setAxisX(axis, this);
110 }
110 }
111
111
112 QAbstractAxis *DeclarativeBarSeries::axisX()
112 QAbstractAxis *DeclarativeBarSeries::axisX()
@@ -116,7 +116,7 QAbstractAxis *DeclarativeBarSeries::axisX()
116
116
117 void DeclarativeBarSeries::setAxisY(QAbstractAxis *axis)
117 void DeclarativeBarSeries::setAxisY(QAbstractAxis *axis)
118 {
118 {
119 chart()->setAxisY(this, axis);
119 chart()->setAxisY(axis, this);
120 }
120 }
121
121
122 QAbstractAxis *DeclarativeBarSeries::axisY()
122 QAbstractAxis *DeclarativeBarSeries::axisY()
@@ -188,7 +188,7 void DeclarativeGroupedBarSeries::componentComplete()
188
188
189 void DeclarativeGroupedBarSeries::setAxisX(QAbstractAxis *axis)
189 void DeclarativeGroupedBarSeries::setAxisX(QAbstractAxis *axis)
190 {
190 {
191 chart()->setAxisX(this, axis);
191 chart()->setAxisX(axis, this);
192 }
192 }
193
193
194 QAbstractAxis *DeclarativeGroupedBarSeries::axisX()
194 QAbstractAxis *DeclarativeGroupedBarSeries::axisX()
@@ -198,7 +198,7 QAbstractAxis *DeclarativeGroupedBarSeries::axisX()
198
198
199 void DeclarativeGroupedBarSeries::setAxisY(QAbstractAxis *axis)
199 void DeclarativeGroupedBarSeries::setAxisY(QAbstractAxis *axis)
200 {
200 {
201 chart()->setAxisY(this, axis);
201 chart()->setAxisY(axis, this);
202 }
202 }
203
203
204 QAbstractAxis *DeclarativeGroupedBarSeries::axisY()
204 QAbstractAxis *DeclarativeGroupedBarSeries::axisY()
@@ -264,7 +264,7 void DeclarativeStackedBarSeries::componentComplete()
264
264
265 void DeclarativeStackedBarSeries::setAxisX(QAbstractAxis *axis)
265 void DeclarativeStackedBarSeries::setAxisX(QAbstractAxis *axis)
266 {
266 {
267 chart()->setAxisX(this, axis);
267 chart()->setAxisX(axis, this);
268 }
268 }
269
269
270 QAbstractAxis *DeclarativeStackedBarSeries::axisX()
270 QAbstractAxis *DeclarativeStackedBarSeries::axisX()
@@ -274,7 +274,7 QAbstractAxis *DeclarativeStackedBarSeries::axisX()
274
274
275 void DeclarativeStackedBarSeries::setAxisY(QAbstractAxis *axis)
275 void DeclarativeStackedBarSeries::setAxisY(QAbstractAxis *axis)
276 {
276 {
277 chart()->setAxisY(this, axis);
277 chart()->setAxisY(axis, this);
278 }
278 }
279
279
280 QAbstractAxis *DeclarativeStackedBarSeries::axisY()
280 QAbstractAxis *DeclarativeStackedBarSeries::axisY()
@@ -340,7 +340,7 void DeclarativePercentBarSeries::componentComplete()
340
340
341 void DeclarativePercentBarSeries::setAxisX(QAbstractAxis *axis)
341 void DeclarativePercentBarSeries::setAxisX(QAbstractAxis *axis)
342 {
342 {
343 chart()->setAxisX(this, axis);
343 chart()->setAxisX(axis, this);
344 }
344 }
345
345
346 QAbstractAxis *DeclarativePercentBarSeries::axisX()
346 QAbstractAxis *DeclarativePercentBarSeries::axisX()
@@ -350,7 +350,7 QAbstractAxis *DeclarativePercentBarSeries::axisX()
350
350
351 void DeclarativePercentBarSeries::setAxisY(QAbstractAxis *axis)
351 void DeclarativePercentBarSeries::setAxisY(QAbstractAxis *axis)
352 {
352 {
353 chart()->setAxisY(this, axis);
353 chart()->setAxisY(axis, this);
354 }
354 }
355
355
356 QAbstractAxis *DeclarativePercentBarSeries::axisY()
356 QAbstractAxis *DeclarativePercentBarSeries::axisY()
@@ -39,7 +39,7 QXYSeries *DeclarativeLineSeries::xySeries()
39
39
40 void DeclarativeLineSeries::setAxisX(QAbstractAxis *axis)
40 void DeclarativeLineSeries::setAxisX(QAbstractAxis *axis)
41 {
41 {
42 chart()->setAxisX(this, axis);
42 chart()->setAxisX(axis,this);
43 }
43 }
44
44
45 QAbstractAxis *DeclarativeLineSeries::axisX()
45 QAbstractAxis *DeclarativeLineSeries::axisX()
@@ -49,7 +49,7 QAbstractAxis *DeclarativeLineSeries::axisX()
49
49
50 void DeclarativeLineSeries::setAxisY(QAbstractAxis *axis)
50 void DeclarativeLineSeries::setAxisY(QAbstractAxis *axis)
51 {
51 {
52 chart()->setAxisY(this, axis);
52 chart()->setAxisY(axis,this);
53 }
53 }
54
54
55 QAbstractAxis *DeclarativeLineSeries::axisY()
55 QAbstractAxis *DeclarativeLineSeries::axisY()
@@ -39,7 +39,7 QXYSeries *DeclarativeScatterSeries::xySeries()
39
39
40 void DeclarativeScatterSeries::setAxisX(QAbstractAxis *axis)
40 void DeclarativeScatterSeries::setAxisX(QAbstractAxis *axis)
41 {
41 {
42 chart()->setAxisX(this, axis);
42 chart()->setAxisX(axis,this);
43 }
43 }
44
44
45 QAbstractAxis *DeclarativeScatterSeries::axisX()
45 QAbstractAxis *DeclarativeScatterSeries::axisX()
@@ -49,7 +49,7 QAbstractAxis *DeclarativeScatterSeries::axisX()
49
49
50 void DeclarativeScatterSeries::setAxisY(QAbstractAxis *axis)
50 void DeclarativeScatterSeries::setAxisY(QAbstractAxis *axis)
51 {
51 {
52 chart()->setAxisY(this, axis);
52 chart()->setAxisY(axis,this);
53 }
53 }
54
54
55 QAbstractAxis *DeclarativeScatterSeries::axisY()
55 QAbstractAxis *DeclarativeScatterSeries::axisY()
@@ -39,7 +39,7 QXYSeries *DeclarativeSplineSeries::xySeries()
39
39
40 void DeclarativeSplineSeries::setAxisX(QAbstractAxis *axis)
40 void DeclarativeSplineSeries::setAxisX(QAbstractAxis *axis)
41 {
41 {
42 chart()->setAxisX(this, axis);
42 chart()->setAxisX(axis,this);
43 }
43 }
44
44
45 QAbstractAxis *DeclarativeSplineSeries::axisX()
45 QAbstractAxis *DeclarativeSplineSeries::axisX()
@@ -49,7 +49,7 QAbstractAxis *DeclarativeSplineSeries::axisX()
49
49
50 void DeclarativeSplineSeries::setAxisY(QAbstractAxis *axis)
50 void DeclarativeSplineSeries::setAxisY(QAbstractAxis *axis)
51 {
51 {
52 chart()->setAxisY(this, axis);
52 chart()->setAxisY(axis,this);
53 }
53 }
54
54
55 QAbstractAxis *DeclarativeSplineSeries::axisY()
55 QAbstractAxis *DeclarativeSplineSeries::axisY()
@@ -25,7 +25,7
25 #include "chartanimator_p.h"
25 #include "chartanimator_p.h"
26 #include <QPainter>
26 #include <QPainter>
27 #include <QDebug>
27 #include <QDebug>
28 #include <cmath>
28 #include <qmath.h>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
@@ -143,21 +143,6 void ChartAxis::updateLayout(QVector<qreal> &layout)
143 }
143 }
144 }
144 }
145
145
146 bool ChartAxis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const
147 {
148 Q_ASSERT(max>min);
149 Q_ASSERT(ticks>1);
150
151 int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0);
152 n++;
153 for (int i=0; i< ticks; i++) {
154 qreal value = min + (i * (max - min)/ (ticks-1));
155 Q_UNUSED(value);
156 labels << QString::number(value,'f',n);
157 }
158 return true;
159 }
160
161 void ChartAxis::setAxisOpacity(qreal opacity)
146 void ChartAxis::setAxisOpacity(qreal opacity)
162 {
147 {
163 m_axis->setOpacity(opacity);
148 m_axis->setOpacity(opacity);
@@ -354,6 +339,41 void ChartAxis::axisSelected()
354 qDebug()<<"TODO: axis clicked";
339 qDebug()<<"TODO: axis clicked";
355 }
340 }
356
341
342
343 void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int ticks) const
344 {
345 Q_ASSERT(max>min);
346 Q_ASSERT(ticks>1);
347
348 int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0);
349 n++;
350 for (int i=0; i< ticks; i++) {
351 qreal value = min + (i * (max - min)/ (ticks-1));
352 labels << QString::number(value,'f',n);
353 }
354 }
355
356 void ChartAxis::createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const
357 {
358 Q_ASSERT(max>min);
359 Q_UNUSED(max);
360
361 int x = qCeil(min);
362 int count = 0;
363
364 // Try to find category for x coordinate
365 while (count < m_ticksCount) {
366 if ((x < categories.count()) && (x >= 0)) {
367 labels << categories.at(x);
368 } else {
369 // No label for x coordinate
370 labels << "";
371 }
372 x++;
373 count++;
374 }
375 }
376
357 #include "moc_chartaxis_p.cpp"
377 #include "moc_chartaxis_p.cpp"
358
378
359 QTCOMMERCIALCHART_END_NAMESPACE
379 QTCOMMERCIALCHART_END_NAMESPACE
@@ -91,7 +91,8 public:
91 protected:
91 protected:
92 virtual void updateGeometry() = 0;
92 virtual void updateGeometry() = 0;
93 virtual QVector<qreal> calculateLayout() const = 0;
93 virtual QVector<qreal> calculateLayout() const = 0;
94 virtual bool createLabels(QStringList &labels,qreal min, qreal max,int ticks) const;
94 void createNumberLabels(QStringList &labels,qreal min, qreal max,int ticks) const;
95 void createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const;
95
96
96 public Q_SLOTS:
97 public Q_SLOTS:
97 void handleAxisUpdated();
98 void handleAxisUpdated();
@@ -26,7 +26,6
26 #include <QDebug>
26 #include <QDebug>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <QCategoriesAxis>
28 #include <QCategoriesAxis>
29 #include <qmath.h>
30
29
31 static int label_padding = 5;
30 static int label_padding = 5;
32
31
@@ -35,36 +34,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 ChartCategoriesAxisX::ChartCategoriesAxisX(QCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
34 ChartCategoriesAxisX::ChartCategoriesAxisX(QCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
36 m_categoriesAxis(axis)
35 m_categoriesAxis(axis)
37 {
36 {
38 }
39
37
40 ChartCategoriesAxisX::~ChartCategoriesAxisX()
41 {
42 }
38 }
43
39
44 bool ChartCategoriesAxisX::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const
40 ChartCategoriesAxisX::~ChartCategoriesAxisX()
45 {
41 {
46 Q_ASSERT(max>min);
47 Q_UNUSED(ticks);
48 Q_UNUSED(max);
49
50 QStringList categories = m_categoriesAxis->categories();
51
52 int x = qCeil(min);
53 int count = 0;
54
55 // Try to find category for x coordinate
56 while (count < ticks) {
57 if ((x < categories.count()) && (x >= 0)) {
58 labels << categories.at(x);
59 } else {
60 // No label for x coordinate
61 labels << "";
62 }
63 x++;
64 count++;
65 }
66
67 return true;
68 }
42 }
69
43
70 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
44 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
@@ -94,7 +68,7 void ChartCategoriesAxisX::updateGeometry()
94
68
95 QStringList ticksList;
69 QStringList ticksList;
96
70
97 createLabels(ticksList,m_min,m_max,layout.size());
71 createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories());
98
72
99 QList<QGraphicsItem *> lines = m_grid->childItems();
73 QList<QGraphicsItem *> lines = m_grid->childItems();
100 QList<QGraphicsItem *> labels = m_labels->childItems();
74 QList<QGraphicsItem *> labels = m_labels->childItems();
@@ -45,7 +45,6 public:
45 ~ChartCategoriesAxisX();
45 ~ChartCategoriesAxisX();
46
46
47 AxisType axisType() const { return X_AXIS;}
47 AxisType axisType() const { return X_AXIS;}
48 bool createLabels(QStringList &labels,qreal min, qreal max,int ticks) const;
49
48
50 protected:
49 protected:
51 QVector<qreal> calculateLayout() const;
50 QVector<qreal> calculateLayout() const;
@@ -25,6 +25,7
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDebug>
26 #include <QDebug>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <QCategoriesAxis>
28
29
29 static int label_padding = 5;
30 static int label_padding = 5;
30
31
@@ -65,7 +66,7 void ChartCategoriesAxisY::updateGeometry()
65
66
66 QStringList ticksList;
67 QStringList ticksList;
67
68
68 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
69 createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories());
69
70
70 QList<QGraphicsItem *> lines = m_grid->childItems();
71 QList<QGraphicsItem *> lines = m_grid->childItems();
71 QList<QGraphicsItem *> labels = m_labels->childItems();
72 QList<QGraphicsItem *> labels = m_labels->childItems();
@@ -78,30 +79,11 void ChartCategoriesAxisY::updateGeometry()
78 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
79 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
79 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
80 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
80
81
81 qreal width = 0;
82 for (int i = 1; i < layout.size(); ++i) {
82 for (int i = 0; i < layout.size(); ++i) {
83 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
83 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
84 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
84 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
85 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
85 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
86 if (!categories || i<1) {
86
87 labelItem->setText(ticksList.at(i));
88 const QRectF& rect = labelItem->boundingRect();
89 QPointF center = rect.center();
90 labelItem->setTransformOriginPoint(center.x(), center.y());
91 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
92
93 if(labelItem->pos().x()<=width){
94 labelItem->setVisible(false);
95 lineItem->setVisible(false);
96 }else{
97 labelItem->setVisible(true);
98 lineItem->setVisible(true);
99 width=rect.width()+labelItem->pos().x();
100 }
101 m_minWidth+=rect.width();
102 m_minHeight=qMax(rect.height(),m_minHeight);
103 }
104 else {
105 labelItem->setText(ticksList.at(i));
87 labelItem->setText(ticksList.at(i));
106 const QRectF& rect = labelItem->boundingRect();
88 const QRectF& rect = labelItem->boundingRect();
107 QPointF center = rect.center();
89 QPointF center = rect.center();
@@ -109,7 +91,6 void ChartCategoriesAxisY::updateGeometry()
109 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
91 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
110 m_minWidth+=rect.width();
92 m_minWidth+=rect.width();
111 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
93 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
112 }
113
94
114 if ((i+1)%2 && i>1) {
95 if ((i+1)%2 && i>1) {
115 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
96 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
@@ -35,6 +35,7
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QAbstractAxis;
37 class QAbstractAxis;
38 class QCategoriesAxis;
38 class ChartPresenter;
39 class ChartPresenter;
39
40
40 class ChartCategoriesAxisY : public ChartAxis
41 class ChartCategoriesAxisY : public ChartAxis
@@ -48,6 +49,9 public:
48 protected:
49 protected:
49 QVector<qreal> calculateLayout() const;
50 QVector<qreal> calculateLayout() const;
50 void updateGeometry();
51 void updateGeometry();
52
53 private:
54 QCategoriesAxis *m_categoriesAxis;
51 };
55 };
52
56
53 QTCOMMERCIALCHART_END_NAMESPACE
57 QTCOMMERCIALCHART_END_NAMESPACE
@@ -39,21 +39,6 ChartValuesAxisX::~ChartValuesAxisX()
39 {
39 {
40 }
40 }
41
41
42 bool ChartValuesAxisX::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const
43 {
44 Q_ASSERT(max>min);
45 Q_ASSERT(ticks>1);
46
47 int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0);
48 n++;
49 for (int i=0; i< ticks; i++) {
50 qreal value = min + (i * (max - min)/ (ticks-1));
51 Q_UNUSED(value);
52 labels << QString::number(value,'f',n);
53 }
54 return true;
55 }
56
57 QVector<qreal> ChartValuesAxisX::calculateLayout() const
42 QVector<qreal> ChartValuesAxisX::calculateLayout() const
58 {
43 {
59 Q_ASSERT(m_ticksCount>=2);
44 Q_ASSERT(m_ticksCount>=2);
@@ -80,16 +65,7 void ChartValuesAxisX::updateGeometry()
80
65
81 QStringList ticksList;
66 QStringList ticksList;
82
67
83 int ticks = layout.size();
68 createNumberLabels(ticksList,m_min,m_max,layout.size());
84 int n = qMax(int(-floor(log10((m_max-m_min)/(ticks-1)))),0);
85 n++;
86 for (int i=0; i< ticks; i++) {
87 qreal value = m_min + (i * (m_max - m_min)/ (ticks-1));
88 Q_UNUSED(value);
89 ticksList << QString::number(value,'f',n);
90 }
91
92 bool categories = false; //createLabels(ticksList,m_min,m_max,layout.size());
93
69
94 QList<QGraphicsItem *> lines = m_grid->childItems();
70 QList<QGraphicsItem *> lines = m_grid->childItems();
95 QList<QGraphicsItem *> labels = m_labels->childItems();
71 QList<QGraphicsItem *> labels = m_labels->childItems();
@@ -107,7 +83,6 void ChartValuesAxisX::updateGeometry()
107 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
83 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
108 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
84 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
109 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
85 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
110 if (!categories || i<1) {
111 labelItem->setText(ticksList.at(i));
86 labelItem->setText(ticksList.at(i));
112 const QRectF& rect = labelItem->boundingRect();
87 const QRectF& rect = labelItem->boundingRect();
113 QPointF center = rect.center();
88 QPointF center = rect.center();
@@ -124,7 +99,7 void ChartValuesAxisX::updateGeometry()
124 }
99 }
125 m_minWidth+=rect.width();
100 m_minWidth+=rect.width();
126 m_minHeight=qMax(rect.height(),m_minHeight);
101 m_minHeight=qMax(rect.height(),m_minHeight);
127 }
102
128 if ((i+1)%2 && i>1) {
103 if ((i+1)%2 && i>1) {
129 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
104 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
130 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
105 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
@@ -44,11 +44,14 public:
44 ~ChartValuesAxisX();
44 ~ChartValuesAxisX();
45
45
46 AxisType axisType() const { return X_AXIS;}
46 AxisType axisType() const { return X_AXIS;}
47 bool createLabels(QStringList &labels,qreal min, qreal max,int ticks) const;
48
47
49 protected:
48 protected:
50 QVector<qreal> calculateLayout() const;
49 QVector<qreal> calculateLayout() const;
51 void updateGeometry();
50 void updateGeometry();
51
52 private:
53 void createLabels(QStringList &labels,qreal min, qreal max,int ticks) const;
54
52 };
55 };
53
56
54 QTCOMMERCIALCHART_END_NAMESPACE
57 QTCOMMERCIALCHART_END_NAMESPACE
@@ -65,18 +65,7 void ChartValuesAxisY::updateGeometry()
65
65
66 QStringList ticksList;
66 QStringList ticksList;
67
67
68 int ticks = layout.size();
68 createNumberLabels(ticksList,m_min,m_max,layout.size());
69 int n = qMax(int(-floor(log10((m_max-m_min)/(ticks-1)))),0);
70 n++;
71 for (int i=0; i< ticks; i++) {
72 qreal value = m_min + (i * (m_max - m_min)/ (ticks-1));
73 Q_UNUSED(value);
74 ticksList << QString::number(value,'f',n);
75 }
76
77 bool categories = false;
78
79 // bool categories = createLabels(ticksList,m_min,m_max,layout.size());
80
69
81 QList<QGraphicsItem *> lines = m_grid->childItems();
70 QList<QGraphicsItem *> lines = m_grid->childItems();
82 QList<QGraphicsItem *> labels = m_labels->childItems();
71 QList<QGraphicsItem *> labels = m_labels->childItems();
@@ -96,7 +85,6 void ChartValuesAxisY::updateGeometry()
96 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
85 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
97 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
86 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
98
87
99 if (!categories || i<1) {
100 labelItem->setText(ticksList.at(i));
88 labelItem->setText(ticksList.at(i));
101 const QRectF& rect = labelItem->boundingRect();
89 const QRectF& rect = labelItem->boundingRect();
102
90
@@ -116,16 +104,6 void ChartValuesAxisY::updateGeometry()
116
104
117 m_minWidth=qMax(rect.width()+label_padding,m_minWidth);
105 m_minWidth=qMax(rect.width()+label_padding,m_minWidth);
118 m_minHeight+=rect.height();
106 m_minHeight+=rect.height();
119 }
120 else {
121 labelItem->setText(ticksList.at(i));
122 const QRectF& rect = labelItem->boundingRect();
123 m_minWidth=qMax(rect.width(),m_minWidth);
124 m_minHeight+=rect.height();
125 QPointF center = rect.center();
126 labelItem->setTransformOriginPoint(center.x(), center.y());
127 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y());
128 }
129
107
130 if ((i+1)%2 && i>1) {
108 if ((i+1)%2 && i>1) {
131 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
109 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
@@ -43,35 +43,16 ChartDataSet::~ChartDataSet()
43
43
44 void ChartDataSet::addSeries(QAbstractSeries* series)
44 void ChartDataSet::addSeries(QAbstractSeries* series)
45 {
45 {
46 QAbstractAxis* axis = m_seriesAxisXMap.value(series);
46 Domain* domain = m_seriesDomainMap.value(series);
47
47
48 if(axis) {
48 if(domain) {
49 qWarning() << "Can not add series. Series already on the chart";
49 qWarning() << "Can not add series. Series already on the chart";
50 return;
50 return;
51 }
51 }
52
52
53 QAbstractAxis* axisX = series->d_ptr->createAxisX(this);
54 QAbstractAxis* axisY = series->d_ptr->createAxisY(this);
55
56 series->setParent(this); // take ownership
53 series->setParent(this); // take ownership
57
54
58 Domain* domain = new Domain(series);
55 domain = new Domain(series);
59
60 if(axisX){
61 QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
62 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
63 axisX->d_ptr->m_orientation=Qt::Horizontal;
64 emit axisAdded(axisX,domain);
65 m_seriesAxisXMap.insert(series,axisX);
66 }
67
68 if(axisY){
69 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
70 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
71 axisY->d_ptr->m_orientation=Qt::Vertical;
72 emit axisAdded(axisY,domain);
73 m_seriesAxisYMap.insert(series,axisY);
74 }
75
56
76 m_seriesDomainMap.insert(series,domain);
57 m_seriesDomainMap.insert(series,domain);
77
58
@@ -97,6 +78,44 void ChartDataSet::addSeries(QAbstractSeries* series)
97
78
98 }
79 }
99
80
81 void ChartDataSet::createDefaultAxes()
82 {
83 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
84
85 while (i.hasNext()) {
86 i.next();
87
88 if(!m_seriesAxisXMap.value(i.key()))
89 {
90
91 QAbstractAxis* axisX = i.key()->d_ptr->createAxisX(this);
92
93 if(axisX) {
94 QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),i.value(),SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
95 QObject::connect(i.value(),SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
96 axisX->d_ptr->m_orientation=Qt::Horizontal;
97 emit axisAdded(axisX,i.value());
98 m_seriesAxisXMap.insert(i.key(),axisX);
99 }
100
101 }
102
103 if(!m_seriesAxisYMap.value(i.key()))
104 {
105 QAbstractAxis* axisY = i.key()->d_ptr->createAxisY(this);
106
107 if(axisY) {
108 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),i.value(),SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
109 QObject::connect(i.value(),SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
110 axisY->d_ptr->m_orientation=Qt::Vertical;
111 emit axisAdded(axisY,i.value());
112 m_seriesAxisYMap.insert(i.key(),axisY);
113 }
114 }
115 }
116 }
117
118
100 void ChartDataSet::removeSeries(QAbstractSeries* series)
119 void ChartDataSet::removeSeries(QAbstractSeries* series)
101 {
120 {
102 Domain* domain = m_seriesDomainMap.take(series);
121 Domain* domain = m_seriesDomainMap.take(series);
@@ -180,7 +199,7 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
180 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
199 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
181 {
200 {
182 int count=0;
201 int count=0;
183 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisXMap);
202 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
184 while (i.hasNext()) {
203 while (i.hasNext()) {
185 i.next();
204 i.next();
186 if(i.key()->type()==type) count++;
205 if(i.key()->type()==type) count++;
@@ -213,11 +232,10 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
213
232
214 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
233 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
215 {
234 {
216
217 Q_ASSERT(axis);
235 Q_ASSERT(axis);
218 QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series);
236 Domain* domain = m_seriesDomainMap.value(series);
219
237
220 if(!oldAxis) {
238 if(!domain) {
221 qWarning()<<"Series not found on the chart.";
239 qWarning() << "Series not found on the chart.";
222 return;
240 return;
223 }
241 }
@@ -227,20 +245,22 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
227 return;
245 return;
228 }
246 }
229
247
248 QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series);
230 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
249 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
250
251 if(oldAxis) {
252
231 int x = axesX.indexOf(oldAxis);
253 int x = axesX.indexOf(oldAxis);
232 if(x==-1) {
254 if(x==-1) {
233 emit axisRemoved(oldAxis);
255 emit axisRemoved(oldAxis);
234 oldAxis->deleteLater();
256 oldAxis->deleteLater();
235 }
257 }
236
258 }
237 Domain* domain = m_seriesDomainMap.value(series);
238 Q_ASSERT(domain);
239
259
240 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
260 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
241 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
261 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
242
262
243 x = axesX.indexOf(axis);
263 int x = axesX.indexOf(axis);
244 if(x==-1) {
264 if(x==-1) {
245 axis->d_ptr->m_orientation=Qt::Horizontal;
265 axis->d_ptr->m_orientation=Qt::Horizontal;
246 emit axisAdded(axis,domain);
266 emit axisAdded(axis,domain);
@@ -255,10 +275,10 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
255 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
275 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
256 {
276 {
257 Q_ASSERT(axis);
277 Q_ASSERT(axis);
258 QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series);
278 Domain* domain = m_seriesDomainMap.value(series);
259
279
260 if(!oldAxis) {
280 if(!domain) {
261 qWarning()<<"Series not found on the chart or axis is unsupported for given series type";
281 qWarning() << "Series not found on the chart.";
262 return;
282 return;
263 }
283 }
264
284
@@ -267,20 +287,21 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
267 return;
287 return;
268 }
288 }
269
289
290 QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series);
270 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
291 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
292
293 if(oldAxis) {
271 int y = axesY.indexOf(oldAxis);
294 int y = axesY.indexOf(oldAxis);
272 if(y==-1) {
295 if(y==-1) {
273 emit axisRemoved(oldAxis);
296 emit axisRemoved(oldAxis);
274 oldAxis->deleteLater();
297 oldAxis->deleteLater();
275 }
298 }
276
299 }
277 Domain* domain = m_seriesDomainMap.value(series);
278 Q_ASSERT(domain);
279
300
280 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
301 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
281 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
302 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
282
303
283 y = axesY.indexOf(axis);
304 int y = axesY.indexOf(axis);
284 if(y==-1) {
305 if(y==-1) {
285 axis->d_ptr->m_orientation=Qt::Vertical;
306 axis->d_ptr->m_orientation=Qt::Vertical;
286 emit axisAdded(axis,domain);
307 emit axisAdded(axis,domain);
@@ -66,6 +66,8 public:
66 QList<QAbstractSeries*> series() const;
66 QList<QAbstractSeries*> series() const;
67 Domain* domain(QAbstractSeries *series) const;
67 Domain* domain(QAbstractSeries *series) const;
68
68
69 void createDefaultAxes();
70
69 Q_SIGNALS:
71 Q_SIGNALS:
70 void seriesAdded(QAbstractSeries* series, Domain* domain);
72 void seriesAdded(QAbstractSeries* series, Domain* domain);
71 void seriesRemoved(QAbstractSeries* series);
73 void seriesRemoved(QAbstractSeries* series);
@@ -322,6 +322,11 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
322 return d_ptr->m_dataset->axisY(series);
322 return d_ptr->m_dataset->axisY(series);
323 }
323 }
324
324
325 void QChart::createDefaultAxes()
326 {
327 d_ptr->m_dataset->createDefaultAxes();
328 }
329
325 /*!
330 /*!
326 Returns the legend object of the chart. Ownership stays in chart.
331 Returns the legend object of the chart. Ownership stays in chart.
327 */
332 */
@@ -396,12 +401,12 void QChart::setMarginsMinimum(const QRectF& margins)
396 d_ptr->m_presenter->setMarginsMinimum(margins);
401 d_ptr->m_presenter->setMarginsMinimum(margins);
397 }
402 }
398
403
399 void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis)
404 void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series)
400 {
405 {
401 d_ptr->m_dataset->setAxisX(series, axis);
406 d_ptr->m_dataset->setAxisX(series,axis);
402 }
407 }
403
408
404 void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis)
409 void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series)
405 {
410 {
406 d_ptr->m_dataset->setAxisY(series, axis);
411 d_ptr->m_dataset->setAxisY(series,axis);
407 }
412 }
@@ -75,12 +75,14 public:
75 void removeAllSeries();
75 void removeAllSeries();
76 QList<QAbstractSeries*> series() const;
76 QList<QAbstractSeries*> series() const;
77
77
78 void setAxisX(QAbstractSeries *series, QAbstractAxis* axis);
78 void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0);
79 void setAxisY(QAbstractSeries *series, QAbstractAxis* axis);
79 void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0);
80
80
81 QAbstractAxis* axisX(QAbstractSeries* series = 0) const;
81 QAbstractAxis* axisX(QAbstractSeries* series = 0) const;
82 QAbstractAxis* axisY(QAbstractSeries* series = 0) const;
82 QAbstractAxis* axisY(QAbstractSeries* series = 0) const;
83
83
84 void createDefaultAxes();
85
84 void setTheme(QChart::ChartTheme theme);
86 void setTheme(QChart::ChartTheme theme);
85 QChart::ChartTheme theme() const;
87 QChart::ChartTheme theme() const;
86
88
@@ -123,6 +123,7 void tst_ChartDataSet::chartdataset()
123 QVERIFY(m_dataset->domain(series) == 0);
123 QVERIFY(m_dataset->domain(series) == 0);
124 QVERIFY(m_dataset->axisX(series) == 0);
124 QVERIFY(m_dataset->axisX(series) == 0);
125 QVERIFY(m_dataset->axisY(series) == 0);
125 QVERIFY(m_dataset->axisY(series) == 0);
126 m_dataset->createDefaultAxes();
126 }
127 }
127
128
128
129
@@ -160,7 +161,7 void tst_ChartDataSet::addSeries()
160 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
161 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
161
162
162 m_dataset->addSeries(series);
163 m_dataset->addSeries(series);
163
164 m_dataset->createDefaultAxes();
164 if(series->type()==QAbstractSeries::SeriesTypePie){
165 if(series->type()==QAbstractSeries::SeriesTypePie){
165 TRY_COMPARE(spy0.count(), 0);
166 TRY_COMPARE(spy0.count(), 0);
166 }else{
167 }else{
@@ -221,7 +222,7 void tst_ChartDataSet::setAxisX()
221 m_dataset->addSeries(series);
222 m_dataset->addSeries(series);
222 }
223 }
223
224
224 TRY_COMPARE(spy0.count(), seriesList.count()*2);
225 TRY_COMPARE(spy0.count(), 0);
225 TRY_COMPARE(spy1.count(), 0);
226 TRY_COMPARE(spy1.count(), 0);
226 TRY_COMPARE(spy2.count(), seriesList.count());
227 TRY_COMPARE(spy2.count(), seriesList.count());
227 TRY_COMPARE(spy3.count(), 0);
228 TRY_COMPARE(spy3.count(), 0);
@@ -236,7 +237,7 void tst_ChartDataSet::setAxisX()
236 }
237 }
237
238
238 TRY_COMPARE(spy4.count(), axisCount);
239 TRY_COMPARE(spy4.count(), axisCount);
239 TRY_COMPARE(spy5.count(), seriesList.count());
240 TRY_COMPARE(spy5.count(), 0);
240 TRY_COMPARE(spy6.count(), 0);
241 TRY_COMPARE(spy6.count(), 0);
241 TRY_COMPARE(spy7.count(), 0);
242 TRY_COMPARE(spy7.count(), 0);
242
243
@@ -267,7 +268,7 void tst_ChartDataSet::setAxisY()
267 m_dataset->addSeries(series);
268 m_dataset->addSeries(series);
268 }
269 }
269
270
270 TRY_COMPARE(spy0.count(), seriesList.count()*2);
271 TRY_COMPARE(spy0.count(), 0);
271 TRY_COMPARE(spy1.count(), 0);
272 TRY_COMPARE(spy1.count(), 0);
272 TRY_COMPARE(spy2.count(), seriesList.count());
273 TRY_COMPARE(spy2.count(), seriesList.count());
273 TRY_COMPARE(spy3.count(), 0);
274 TRY_COMPARE(spy3.count(), 0);
@@ -282,7 +283,7 void tst_ChartDataSet::setAxisY()
282 }
283 }
283
284
284 TRY_COMPARE(spy4.count(), axisCount);
285 TRY_COMPARE(spy4.count(), axisCount);
285 TRY_COMPARE(spy5.count(), seriesList.count());
286 TRY_COMPARE(spy5.count(), 0);
286 TRY_COMPARE(spy6.count(), 0);
287 TRY_COMPARE(spy6.count(), 0);
287 TRY_COMPARE(spy7.count(), 0);
288 TRY_COMPARE(spy7.count(), 0);
288
289
@@ -301,6 +302,7 void tst_ChartDataSet::removeSeries()
301 QFETCH(QAbstractSeries*, series);
302 QFETCH(QAbstractSeries*, series);
302
303
303 m_dataset->addSeries(series);
304 m_dataset->addSeries(series);
305 m_dataset->createDefaultAxes();
304
306
305 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
307 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
306 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
308 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
@@ -356,7 +358,7 void tst_ChartDataSet::removeAllSeries()
356 m_dataset->removeAllSeries();
358 m_dataset->removeAllSeries();
357
359
358 TRY_COMPARE(spy0.count(), 0);
360 TRY_COMPARE(spy0.count(), 0);
359 TRY_COMPARE(spy1.count(), axisCount + seriesList.count());
361 TRY_COMPARE(spy1.count(), axisCount);
360 TRY_COMPARE(spy2.count(), 0);
362 TRY_COMPARE(spy2.count(), 0);
361 TRY_COMPARE(spy3.count(), seriesList.count());
363 TRY_COMPARE(spy3.count(), seriesList.count());
362 }
364 }
@@ -503,10 +505,8 void tst_ChartDataSet::domain()
503 m_dataset->addSeries(series);
505 m_dataset->addSeries(series);
504 QVERIFY(m_dataset->domain(series));
506 QVERIFY(m_dataset->domain(series));
505
507
506 if(series->type()!=QAbstractSeries::SeriesTypePie){
507 TRY_COMPARE(spy0.count(), 2);
508 }
509
508
509 TRY_COMPARE(spy0.count(), 0);
510 TRY_COMPARE(spy1.count(), 0);
510 TRY_COMPARE(spy1.count(), 0);
511 TRY_COMPARE(spy2.count(), 1);
511 TRY_COMPARE(spy2.count(), 1);
512
512
@@ -532,9 +532,14 void tst_ChartDataSet::zoomInDomain()
532 m_dataset->addSeries(series);
532 m_dataset->addSeries(series);
533 }
533 }
534
534
535 for (int i = 1; i < seriesList.count(); i++) {
535 /*
536 m_dataset->setAxisX(seriesList.at(i), m_dataset->axisX(seriesList.at(0)));
536 QValuesAxis* axis = new QValuesAxis();
537
538 for (int i = 0; i < seriesList.count(); i++) {
539 m_dataset->setAxisX(seriesList.at(i), axis);
537 }
540 }
541 */
542 m_dataset->createDefaultAxes();
538
543
539 QList<QSignalSpy*> spyList;
544 QList<QSignalSpy*> spyList;
540
545
@@ -212,7 +212,7 void tst_QChart::addSeries()
212 QVERIFY(!series->chart());
212 QVERIFY(!series->chart());
213 QCOMPARE(m_chart->series().count(), 0);
213 QCOMPARE(m_chart->series().count(), 0);
214 m_chart->addSeries(series);
214 m_chart->addSeries(series);
215 m_chart->setAxisY(series,axis);
215 m_chart->setAxisY(axis,series);
216 QCOMPARE(m_chart->series().count(), 1);
216 QCOMPARE(m_chart->series().count(), 1);
217 QCOMPARE(m_chart->series().first(), series);
217 QCOMPARE(m_chart->series().first(), series);
218 QVERIFY(series->chart() == m_chart);
218 QVERIFY(series->chart() == m_chart);
@@ -275,15 +275,15 void tst_QChart::axisY()
275
275
276 QLineSeries* series0 = new QLineSeries();
276 QLineSeries* series0 = new QLineSeries();
277 m_chart->addSeries(series0);
277 m_chart->addSeries(series0);
278 m_chart->setAxisY(series0,axis0);
278 m_chart->setAxisY(axis0,series0);
279
279
280 QLineSeries* series1 = new QLineSeries();
280 QLineSeries* series1 = new QLineSeries();
281 m_chart->addSeries(series1);
281 m_chart->addSeries(series1);
282 m_chart->setAxisY(series1,axis1);
282 m_chart->setAxisY(axis1,series1);
283
283
284 QLineSeries* series2 = new QLineSeries();
284 QLineSeries* series2 = new QLineSeries();
285 m_chart->addSeries(series2);
285 m_chart->addSeries(series2);
286 m_chart->setAxisY(series2,axis2);
286 m_chart->setAxisY(axis2,series2);
287
287
288 if (!axis0)
288 if (!axis0)
289 axis0 = defaultAxisY;
289 axis0 = defaultAxisY;
@@ -452,7 +452,7 void tst_QChart::removeSeries()
452 QTest::qWaitForWindowShown(m_view);
452 QTest::qWaitForWindowShown(m_view);
453 if(!axis) axis = m_chart->axisY();
453 if(!axis) axis = m_chart->axisY();
454 m_chart->addSeries(series);
454 m_chart->addSeries(series);
455 m_chart->setAxisY(series,axis);
455 m_chart->setAxisY(axis,series);
456 QCOMPARE(m_chart->axisY(series),axis);
456 QCOMPARE(m_chart->axisY(series),axis);
457 m_chart->removeSeries(series);
457 m_chart->removeSeries(series);
458 QVERIFY(m_chart->axisY(series)==0);
458 QVERIFY(m_chart->axisY(series)==0);
@@ -279,22 +279,22 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
279 series = new QBarSeries(this);
279 series = new QBarSeries(this);
280 QCategoriesAxis* axis = new QCategoriesAxis();
280 QCategoriesAxis* axis = new QCategoriesAxis();
281 axis->append(category);
281 axis->append(category);
282 m_chart->setAxisX(series,axis);
282 m_chart->setAxisX(axis,series);
283 } else if (seriesName == "Grouped bar") {
283 } else if (seriesName == "Grouped bar") {
284 series = new QGroupedBarSeries(this);
284 series = new QGroupedBarSeries(this);
285 QCategoriesAxis* axis = new QCategoriesAxis();
285 QCategoriesAxis* axis = new QCategoriesAxis();
286 axis->append(category);
286 axis->append(category);
287 m_chart->setAxisX(series,axis);
287 m_chart->setAxisX(axis,series);
288 } else if (seriesName == "Stacked bar") {
288 } else if (seriesName == "Stacked bar") {
289 series = new QStackedBarSeries(this);
289 series = new QStackedBarSeries(this);
290 QCategoriesAxis* axis = new QCategoriesAxis();
290 QCategoriesAxis* axis = new QCategoriesAxis();
291 axis->append(category);
291 axis->append(category);
292 m_chart->setAxisX(series,axis);
292 m_chart->setAxisX(axis,series);
293 } else {
293 } else {
294 series = new QPercentBarSeries(this);
294 series = new QPercentBarSeries(this);
295 QCategoriesAxis* axis = new QCategoriesAxis();
295 QCategoriesAxis* axis = new QCategoriesAxis();
296 axis->append(category);
296 axis->append(category);
297 m_chart->setAxisX(series,axis);
297 m_chart->setAxisX(axis,series);
298 }
298 }
299
299
300 for (int j(0); j < data.count(); j++) {
300 for (int j(0); j < data.count(); j++) {
General Comments 0
You need to be logged in to leave comments. Login now