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