@@ -1,90 +1,90 | |||||
1 | /*! |
|
1 | /*! | |
2 | \page classes.html |
|
2 | \page classes.html | |
3 | \title QtCommercial Charts API |
|
3 | \title QtCommercial Charts API | |
4 | \keyword All Classes |
|
4 | \keyword All Classes | |
5 |
|
5 | |||
6 | Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However |
|
6 | Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However | |
7 | there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget. |
|
7 | there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget. | |
8 |
|
8 | |||
9 | Each chart type is represented by QAbstractSeries derived class. To create given chart type users have to use instance of related series class and add it to QChart instance. |
|
9 | Each chart type is represented by QAbstractSeries derived class. To create given chart type users have to use instance of related series class and add it to QChart instance. | |
10 | \code |
|
10 | \code | |
11 | QLineSeries* series = new QLineSeries(); |
|
11 | QLineSeries* series = new QLineSeries(); | |
12 | series->add(0, 6); |
|
12 | series->add(0, 6); | |
13 | series->add(2, 4); |
|
13 | series->add(2, 4); | |
14 | ... |
|
14 | ... | |
15 | chartView->chart()->addSeries(series); |
|
15 | chartView->chart()->addSeries(series); | |
16 | chartView->chart()->createDefaultAxes(); |
|
16 | chartView->chart()->createDefaultAxes(); | |
17 | \endcode |
|
17 | \endcode | |
18 |
|
18 | |||
19 | \raw HTML |
|
19 | \raw HTML | |
20 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> |
|
20 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> | |
21 | <tr> |
|
21 | <tr> | |
22 | <th class="titleheader" width="25%"> |
|
22 | <th class="titleheader" width="25%"> | |
23 | Common and global |
|
23 | Common and global | |
24 | </th> |
|
24 | </th> | |
25 | <th class="titleheader" width="25%"> |
|
25 | <th class="titleheader" width="25%"> | |
26 | XY chart |
|
26 | XY chart | |
27 | </th> |
|
27 | </th> | |
28 | </tr> |
|
28 | </tr> | |
29 | <tr> |
|
29 | <tr> | |
30 | <td valign="top"> |
|
30 | <td valign="top"> | |
31 | <ul> |
|
31 | <ul> | |
32 | <li><a href="qchart.html">QChart</a></li> |
|
32 | <li><a href="qchart.html">QChart</a></li> | |
33 | <li><a href="qchartview.html">QChartView</a></li> |
|
33 | <li><a href="qchartview.html">QChartView</a></li> | |
34 | <li><a href="qabstractaxis.html">QAbstractAxis</a></li> |
|
34 | <li><a href="qabstractaxis.html">QAbstractAxis</a></li> | |
35 | <li><a href="qvalueaxis.html">QValueAxis</a></li> |
|
35 | <li><a href="qvalueaxis.html">QValueAxis</a></li> | |
36 | <li><a href="qbarcategoryaxis.html">QBarCategoryAxis</a></li> |
|
36 | <li><a href="qbarcategoryaxis.html">QBarCategoryAxis</a></li> | |
37 |
<li><a href="q |
|
37 | <li><a href="qcategoryaxis.html">QCategoryAxis</a></li> | |
38 | <li><a href="qlegend.html">QLegend</a></li> |
|
38 | <li><a href="qlegend.html">QLegend</a></li> | |
39 | <li><a href="qabstractseries.html">QAbstractSeries</a></li> |
|
39 | <li><a href="qabstractseries.html">QAbstractSeries</a></li> | |
40 | <li><a href="qchartglobal.html">QChartGlobal</a></li> |
|
40 | <li><a href="qchartglobal.html">QChartGlobal</a></li> | |
41 | </ul> |
|
41 | </ul> | |
42 | </td> |
|
42 | </td> | |
43 | <td valign="top"> |
|
43 | <td valign="top"> | |
44 | <ul> |
|
44 | <ul> | |
45 | <li><a href="qxyseries.html">QXYSeries</a></li> |
|
45 | <li><a href="qxyseries.html">QXYSeries</a></li> | |
46 | <li><a href="qlineseries.html">QLineSeries</a></li> |
|
46 | <li><a href="qlineseries.html">QLineSeries</a></li> | |
47 | <li><a href="qareaseries.html">QAreaSeries</a></li> |
|
47 | <li><a href="qareaseries.html">QAreaSeries</a></li> | |
48 | <li><a href="qscatterseries.html">QScatterSeries</a></li> |
|
48 | <li><a href="qscatterseries.html">QScatterSeries</a></li> | |
49 | <li><a href="qsplineseries.html">QSplineSeries</a></li> |
|
49 | <li><a href="qsplineseries.html">QSplineSeries</a></li> | |
50 | <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li> |
|
50 | <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li> | |
51 | <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li> |
|
51 | <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li> | |
52 | </ul> |
|
52 | </ul> | |
53 | </td> |
|
53 | </td> | |
54 | </tr> |
|
54 | </tr> | |
55 | </table> |
|
55 | </table> | |
56 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> |
|
56 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> | |
57 | <tr> |
|
57 | <tr> | |
58 | <th class="titleheader" width="25%"> |
|
58 | <th class="titleheader" width="25%"> | |
59 | Pie chart |
|
59 | Pie chart | |
60 | </th> |
|
60 | </th> | |
61 | <th class="titleheader" width="25%"> |
|
61 | <th class="titleheader" width="25%"> | |
62 | Bar chart |
|
62 | Bar chart | |
63 | </th> |
|
63 | </th> | |
64 | <tr> |
|
64 | <tr> | |
65 | <td valign="top"> |
|
65 | <td valign="top"> | |
66 | <ul> |
|
66 | <ul> | |
67 | <li><a href="qpieseries.html">QPieSeries</a></li> |
|
67 | <li><a href="qpieseries.html">QPieSeries</a></li> | |
68 | <li><a href="qpieslice.html">QPieSlice</a></li> |
|
68 | <li><a href="qpieslice.html">QPieSlice</a></li> | |
69 | <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li> |
|
69 | <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li> | |
70 | <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li> |
|
70 | <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li> | |
71 | </ul> |
|
71 | </ul> | |
72 | </td> |
|
72 | </td> | |
73 | <td valign="top"> |
|
73 | <td valign="top"> | |
74 | <ul> |
|
74 | <ul> | |
75 | <li><a href="qbarseries.html">QBarSeries</a></li> |
|
75 | <li><a href="qbarseries.html">QBarSeries</a></li> | |
76 | <li><a href="qbarset.html">QBarSet</a></li> |
|
76 | <li><a href="qbarset.html">QBarSet</a></li> | |
77 | <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li> |
|
77 | <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li> | |
78 | <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li> |
|
78 | <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li> | |
79 | <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li> |
|
79 | <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li> | |
80 | <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li> |
|
80 | <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li> | |
81 | <li><a href="qhorizontalbarseries.html">QHorizontalBarSeries</a></li> |
|
81 | <li><a href="qhorizontalbarseries.html">QHorizontalBarSeries</a></li> | |
82 | <li><a href="qhorizontalstackedbarseries.html">QHorizontalStackedBarSeries</a></li> |
|
82 | <li><a href="qhorizontalstackedbarseries.html">QHorizontalStackedBarSeries</a></li> | |
83 | <li><a href="qhorizontalpercentbarseries.html">QHorizontalPercentBarSeries</a></li> |
|
83 | <li><a href="qhorizontalpercentbarseries.html">QHorizontalPercentBarSeries</a></li> | |
84 | </ul> |
|
84 | </ul> | |
85 | </td> |
|
85 | </td> | |
86 | </tr> |
|
86 | </tr> | |
87 | </table> |
|
87 | </table> | |
88 | \endraw |
|
88 | \endraw | |
89 |
|
89 | |||
90 | */ |
|
90 | */ |
@@ -1,52 +1,52 | |||||
1 | #Subdirectiores are defined here, because qt creator doesn't handle nested include(foo.pri) chains very well. |
|
1 | #Subdirectiores are defined here, because qt creator doesn't handle nested include(foo.pri) chains very well. | |
2 |
|
2 | |||
3 | INCLUDEPATH += $$PWD \ |
|
3 | INCLUDEPATH += $$PWD \ | |
4 | $$PWD/valueaxis \ |
|
4 | $$PWD/valueaxis \ | |
5 | $$PWD/barcategoryaxis \ |
|
5 | $$PWD/barcategoryaxis \ | |
6 |
$$PWD/ |
|
6 | $$PWD/categoryaxis \ | |
7 | $$PWD/datetimeaxis |
|
7 | $$PWD/datetimeaxis | |
8 |
|
8 | |||
9 | DEPENDPATH += $$PWD \ |
|
9 | DEPENDPATH += $$PWD \ | |
10 | $$PWD/valueaxis \ |
|
10 | $$PWD/valueaxis \ | |
11 | $$PWD/barcategoryaxis \ |
|
11 | $$PWD/barcategoryaxis \ | |
12 |
$$PWD/ |
|
12 | $$PWD/categoryaxis \ | |
13 | $$PWD/datetimeaxis |
|
13 | $$PWD/datetimeaxis | |
14 |
|
14 | |||
15 | SOURCES += \ |
|
15 | SOURCES += \ | |
16 | $$PWD/chartaxis.cpp \ |
|
16 | $$PWD/chartaxis.cpp \ | |
17 | $$PWD/qabstractaxis.cpp \ |
|
17 | $$PWD/qabstractaxis.cpp \ | |
18 | $$PWD/valueaxis/chartvalueaxisx.cpp \ |
|
18 | $$PWD/valueaxis/chartvalueaxisx.cpp \ | |
19 | $$PWD/valueaxis/chartvalueaxisy.cpp \ |
|
19 | $$PWD/valueaxis/chartvalueaxisy.cpp \ | |
20 | $$PWD/valueaxis/qvalueaxis.cpp \ |
|
20 | $$PWD/valueaxis/qvalueaxis.cpp \ | |
21 | $$PWD/barcategoryaxis/chartbarcategoryaxisx.cpp \ |
|
21 | $$PWD/barcategoryaxis/chartbarcategoryaxisx.cpp \ | |
22 | $$PWD/barcategoryaxis/chartbarcategoryaxisy.cpp \ |
|
22 | $$PWD/barcategoryaxis/chartbarcategoryaxisy.cpp \ | |
23 | $$PWD/barcategoryaxis/qbarcategoryaxis.cpp \ |
|
23 | $$PWD/barcategoryaxis/qbarcategoryaxis.cpp \ | |
24 |
$$PWD/ |
|
24 | $$PWD/categoryaxis/chartcategoryaxisx.cpp \ | |
25 |
$$PWD/ |
|
25 | $$PWD/categoryaxis/chartcategoryaxisy.cpp \ | |
26 |
$$PWD/ |
|
26 | $$PWD/categoryaxis/qcategoryaxis.cpp \ | |
27 | $$PWD/datetimeaxis/chartdatetimeaxisx.cpp \ |
|
27 | $$PWD/datetimeaxis/chartdatetimeaxisx.cpp \ | |
28 | $$PWD/datetimeaxis/chartdatetimeaxisy.cpp \ |
|
28 | $$PWD/datetimeaxis/chartdatetimeaxisy.cpp \ | |
29 | $$PWD/datetimeaxis/qdatetimeaxis.cpp |
|
29 | $$PWD/datetimeaxis/qdatetimeaxis.cpp | |
30 |
|
30 | |||
31 | PRIVATE_HEADERS += \ |
|
31 | PRIVATE_HEADERS += \ | |
32 | $$PWD/chartaxis_p.h \ |
|
32 | $$PWD/chartaxis_p.h \ | |
33 | $$PWD/qabstractaxis_p.h \ |
|
33 | $$PWD/qabstractaxis_p.h \ | |
34 | $$PWD/valueaxis/chartvalueaxisx_p.h \ |
|
34 | $$PWD/valueaxis/chartvalueaxisx_p.h \ | |
35 | $$PWD/valueaxis/chartvalueaxisy_p.h \ |
|
35 | $$PWD/valueaxis/chartvalueaxisy_p.h \ | |
36 | $$PWD/valueaxis/qvalueaxis_p.h \ |
|
36 | $$PWD/valueaxis/qvalueaxis_p.h \ | |
37 | $$PWD/barcategoryaxis/chartbarcategoryaxisx_p.h \ |
|
37 | $$PWD/barcategoryaxis/chartbarcategoryaxisx_p.h \ | |
38 | $$PWD/barcategoryaxis/chartbarcategoryaxisy_p.h \ |
|
38 | $$PWD/barcategoryaxis/chartbarcategoryaxisy_p.h \ | |
39 | $$PWD/barcategoryaxis/qbarcategoryaxis_p.h \ |
|
39 | $$PWD/barcategoryaxis/qbarcategoryaxis_p.h \ | |
40 |
$$PWD/ |
|
40 | $$PWD/categoryaxis/chartcategoryaxisx_p.h \ | |
41 |
$$PWD/ |
|
41 | $$PWD/categoryaxis/chartcategoryaxisy_p.h \ | |
42 |
$$PWD/ |
|
42 | $$PWD/categoryaxis/qcategoryaxis_p.h \ | |
43 | $$PWD/datetimeaxis/chartdatetimeaxisx_p.h \ |
|
43 | $$PWD/datetimeaxis/chartdatetimeaxisx_p.h \ | |
44 | $$PWD/datetimeaxis/chartdatetimeaxisy_p.h \ |
|
44 | $$PWD/datetimeaxis/chartdatetimeaxisy_p.h \ | |
45 | $$PWD/datetimeaxis/qdatetimeaxis_p.h |
|
45 | $$PWD/datetimeaxis/qdatetimeaxis_p.h | |
46 |
|
46 | |||
47 | PUBLIC_HEADERS += \ |
|
47 | PUBLIC_HEADERS += \ | |
48 | $$PWD/qabstractaxis.h \ |
|
48 | $$PWD/qabstractaxis.h \ | |
49 | $$PWD/valueaxis/qvalueaxis.h \ |
|
49 | $$PWD/valueaxis/qvalueaxis.h \ | |
50 | $$PWD/barcategoryaxis/qbarcategoryaxis.h \ |
|
50 | $$PWD/barcategoryaxis/qbarcategoryaxis.h \ | |
51 |
$$PWD/ |
|
51 | $$PWD/categoryaxis/qcategoryaxis.h \ | |
52 | $$PWD/datetimeaxis/qdatetimeaxis.h |
|
52 | $$PWD/datetimeaxis/qdatetimeaxis.h |
@@ -1,130 +1,130 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
#include "chart |
|
21 | #include "chartcategoryaxisx_p.h" | |
22 |
#include "q |
|
22 | #include "qcategoryaxis.h" | |
23 | #include "qabstractaxis.h" |
|
23 | #include "qabstractaxis.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | static int label_padding = 5; |
|
29 | static int label_padding = 5; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 |
Chart |
|
33 | ChartCategoryAxisX::ChartCategoryAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) | |
34 | { |
|
34 | { | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 |
Chart |
|
37 | ChartCategoryAxisX::~ChartCategoryAxisX() | |
38 | { |
|
38 | { | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 |
QVector<qreal> Chart |
|
41 | QVector<qreal> ChartCategoryAxisX::calculateLayout() const | |
42 | { |
|
42 | { | |
43 | QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
43 | QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis); | |
44 | int tickCount = axis->intervalsLabels().count() + 1; |
|
44 | int tickCount = axis->intervalsLabels().count() + 1; | |
45 | QVector<qreal> points; |
|
45 | QVector<qreal> points; | |
46 |
|
46 | |||
47 | if (tickCount < 2) |
|
47 | if (tickCount < 2) | |
48 | return points; |
|
48 | return points; | |
49 |
|
49 | |||
50 | points.resize(tickCount); |
|
50 | points.resize(tickCount); | |
51 |
|
51 | |||
52 | qreal scale = m_rect.width() / axis->max(); |
|
52 | qreal scale = m_rect.width() / axis->max(); | |
53 | for (int i = 0; i < tickCount; ++i) |
|
53 | for (int i = 0; i < tickCount; ++i) | |
54 | if (i < tickCount - 1) { |
|
54 | if (i < tickCount - 1) { | |
55 | int x = axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.left(); |
|
55 | int x = axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.left(); | |
56 | points[i] = x; |
|
56 | points[i] = x; | |
57 | } else { |
|
57 | } else { | |
58 | int x = axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.left(); |
|
58 | int x = axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.left(); | |
59 | points[i] = x; |
|
59 | points[i] = x; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | return points; |
|
62 | return points; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 |
void Chart |
|
65 | void ChartCategoryAxisX::updateGeometry() | |
66 | { |
|
66 | { | |
67 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
67 | const QVector<qreal>& layout = ChartAxis::layout(); | |
68 |
|
68 | |||
69 | m_minWidth = 0; |
|
69 | m_minWidth = 0; | |
70 | m_minHeight = 0; |
|
70 | m_minHeight = 0; | |
71 |
|
71 | |||
72 | if(layout.isEmpty()) return; |
|
72 | if(layout.isEmpty()) return; | |
73 |
|
73 | |||
74 | QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
74 | QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); | |
75 |
|
75 | |||
76 | QStringList ticksList = intervalAxis->intervalsLabels(); |
|
76 | QStringList ticksList = intervalAxis->intervalsLabels(); | |
77 |
|
77 | |||
78 | // createNumberLabels(ticksList,m_min,m_max,layout.size()); |
|
78 | // createNumberLabels(ticksList,m_min,m_max,layout.size()); | |
79 |
|
79 | |||
80 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
80 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
81 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
81 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
82 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
82 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
83 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
83 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
84 |
|
84 | |||
85 | // Q_ASSERT(labels.size() == ticksList.size()); |
|
85 | // Q_ASSERT(labels.size() == ticksList.size()); | |
86 | // Q_ASSERT(layout.size() == ticksList.size()); |
|
86 | // Q_ASSERT(layout.size() == ticksList.size()); | |
87 |
|
87 | |||
88 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
88 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
89 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
89 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
90 |
|
90 | |||
91 | // qreal width = 0; |
|
91 | // qreal width = 0; | |
92 | for (int i = 0; i < layout.size(); ++i) { |
|
92 | for (int i = 0; i < layout.size(); ++i) { | |
93 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
93 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
94 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
94 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
95 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
95 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
96 | if (i < ticksList.count()) { |
|
96 | if (i < ticksList.count()) { | |
97 | labelItem->setText(ticksList.at(i)); |
|
97 | labelItem->setText(ticksList.at(i)); | |
98 | } |
|
98 | } | |
99 | const QRectF& rect = labelItem->boundingRect(); |
|
99 | const QRectF& rect = labelItem->boundingRect(); | |
100 | QPointF center = rect.center(); |
|
100 | QPointF center = rect.center(); | |
101 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
101 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
102 | if (i < ticksList.count()) |
|
102 | if (i < ticksList.count()) | |
103 | labelItem->setPos(layout[i] + (layout[i + 1] - layout[i]) / 2 - center.x(), m_rect.bottom() + label_padding); |
|
103 | labelItem->setPos(layout[i] + (layout[i + 1] - layout[i]) / 2 - center.x(), m_rect.bottom() + label_padding); | |
104 | else |
|
104 | else | |
105 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); |
|
105 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
106 |
|
106 | |||
107 | if(labelItem->pos().x() > m_rect.width() + m_rect.left() - rect.width() / 2){ |
|
107 | if(labelItem->pos().x() > m_rect.width() + m_rect.left() - rect.width() / 2){ | |
108 | labelItem->setVisible(false); |
|
108 | labelItem->setVisible(false); | |
109 | lineItem->setVisible(false); |
|
109 | lineItem->setVisible(false); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | m_minWidth += rect.width(); |
|
112 | m_minWidth += rect.width(); | |
113 | m_minHeight = qMax(rect.height(), m_minHeight); |
|
113 | m_minHeight = qMax(rect.height(), m_minHeight); | |
114 |
|
114 | |||
115 | if ((i + 1) % 2 && i > 1) { |
|
115 | if ((i + 1) % 2 && i > 1) { | |
116 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i / 2 - 1)); |
|
116 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i / 2 - 1)); | |
117 | rectItem->setRect(layout[i - 1],m_rect.top(),layout[i]-layout[i - 1],m_rect.height()); |
|
117 | rectItem->setRect(layout[i - 1],m_rect.top(),layout[i]-layout[i - 1],m_rect.height()); | |
118 | } |
|
118 | } | |
119 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
119 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
120 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i], m_rect.bottom() + 5); |
|
120 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i], m_rect.bottom() + 5); | |
121 | } |
|
121 | } | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 |
void Chart |
|
124 | void ChartCategoryAxisX::handleAxisUpdated() | |
125 | { |
|
125 | { | |
126 | updateGeometry(); |
|
126 | updateGeometry(); | |
127 | ChartAxis::handleAxisUpdated(); |
|
127 | ChartAxis::handleAxisUpdated(); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | QTCOMMERCIALCHART_END_NAMESPACE |
|
130 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,58 +1,58 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTINTERVALAXISX_H |
|
30 | #ifndef CHARTINTERVALAXISX_H | |
31 | #define CHARTINTERVALAXISX_H |
|
31 | #define CHARTINTERVALAXISX_H | |
32 |
|
32 | |||
33 | #include "chartaxis_p.h" |
|
33 | #include "chartaxis_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAbstractAxis; |
|
37 | class QAbstractAxis; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 |
|
39 | |||
40 |
class Chart |
|
40 | class ChartCategoryAxisX : public ChartAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 |
Chart |
|
43 | ChartCategoryAxisX(QAbstractAxis *axis, ChartPresenter *presenter); | |
44 |
~Chart |
|
44 | ~ChartCategoryAxisX(); | |
45 |
|
45 | |||
46 | AxisType axisType() const { return X_AXIS;} |
|
46 | AxisType axisType() const { return X_AXIS;} | |
47 |
|
47 | |||
48 | protected: |
|
48 | protected: | |
49 | QVector<qreal> calculateLayout() const; |
|
49 | QVector<qreal> calculateLayout() const; | |
50 | void updateGeometry(); |
|
50 | void updateGeometry(); | |
51 |
|
51 | |||
52 | Q_SLOTS |
|
52 | Q_SLOTS | |
53 | void handleAxisUpdated(); |
|
53 | void handleAxisUpdated(); | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | QTCOMMERCIALCHART_END_NAMESPACE | |
57 |
|
57 | |||
58 | #endif /* CHARTINTERVALAXISX_H */ |
|
58 | #endif /* CHARTINTERVALAXISX_H */ |
@@ -1,137 +1,137 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
#include "chart |
|
21 | #include "chartcategoryaxisy_p.h" | |
22 |
#include "q |
|
22 | #include "qcategoryaxis.h" | |
23 | #include "qabstractaxis.h" |
|
23 | #include "qabstractaxis.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | static int label_padding = 5; |
|
30 | static int label_padding = 5; | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 |
Chart |
|
34 | ChartCategoryAxisY::ChartCategoryAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 |
Chart |
|
38 | ChartCategoryAxisY::~ChartCategoryAxisY() | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 |
QVector<qreal> Chart |
|
42 | QVector<qreal> ChartCategoryAxisY::calculateLayout() const | |
43 | { |
|
43 | { | |
44 | QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
44 | QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis); | |
45 | int tickCount = axis->intervalsLabels().count() + 1; |
|
45 | int tickCount = axis->intervalsLabels().count() + 1; | |
46 | QVector<qreal> points; |
|
46 | QVector<qreal> points; | |
47 |
|
47 | |||
48 | if (tickCount < 2) |
|
48 | if (tickCount < 2) | |
49 | return points; |
|
49 | return points; | |
50 |
|
50 | |||
51 | points.resize(tickCount); |
|
51 | points.resize(tickCount); | |
52 |
|
52 | |||
53 | qreal scale = m_rect.height() / axis->max(); |
|
53 | qreal scale = m_rect.height() / axis->max(); | |
54 | for (int i = 0; i < tickCount; ++i) |
|
54 | for (int i = 0; i < tickCount; ++i) | |
55 | if (i < tickCount - 1) { |
|
55 | if (i < tickCount - 1) { | |
56 | int y = -axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.bottom(); |
|
56 | int y = -axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.bottom(); | |
57 | points[i] = y; |
|
57 | points[i] = y; | |
58 | } else { |
|
58 | } else { | |
59 | int y = -axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.bottom(); |
|
59 | int y = -axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.bottom(); | |
60 | points[i] = y; |
|
60 | points[i] = y; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | return points; |
|
63 | return points; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 |
void Chart |
|
66 | void ChartCategoryAxisY::updateGeometry() | |
67 | { |
|
67 | { | |
68 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
68 | const QVector<qreal> &layout = ChartAxis::layout(); | |
69 | m_minWidth = 0; |
|
69 | m_minWidth = 0; | |
70 | m_minHeight = 0; |
|
70 | m_minHeight = 0; | |
71 |
|
71 | |||
72 | if(layout.isEmpty()) return; |
|
72 | if(layout.isEmpty()) return; | |
73 |
|
73 | |||
74 | QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
74 | QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); | |
75 |
|
75 | |||
76 | QStringList ticksList = intervalAxis->intervalsLabels(); |
|
76 | QStringList ticksList = intervalAxis->intervalsLabels(); | |
77 |
|
77 | |||
78 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
78 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
79 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
79 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
80 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
80 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
81 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
81 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
82 |
|
82 | |||
83 | // Q_ASSERT(labels.size() == ticksList.size()); |
|
83 | // Q_ASSERT(labels.size() == ticksList.size()); | |
84 | // Q_ASSERT(layout.size() == ticksList.size()); |
|
84 | // Q_ASSERT(layout.size() == ticksList.size()); | |
85 |
|
85 | |||
86 | qreal height = 2*m_rect.bottom(); |
|
86 | qreal height = 2*m_rect.bottom(); | |
87 |
|
87 | |||
88 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
88 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
89 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
89 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
90 |
|
90 | |||
91 | for (int i = 0; i < layout.size(); ++i) { |
|
91 | for (int i = 0; i < layout.size(); ++i) { | |
92 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
92 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
93 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
93 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); | |
94 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
94 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
95 |
|
95 | |||
96 | if (i < ticksList.count()) { |
|
96 | if (i < ticksList.count()) { | |
97 | labelItem->setText(ticksList.at(i)); |
|
97 | labelItem->setText(ticksList.at(i)); | |
98 | } |
|
98 | } | |
99 | const QRectF& rect = labelItem->boundingRect(); |
|
99 | const QRectF& rect = labelItem->boundingRect(); | |
100 |
|
100 | |||
101 | QPointF center = rect.center(); |
|
101 | QPointF center = rect.center(); | |
102 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
102 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
103 |
|
103 | |||
104 | if (i < ticksList.count()) |
|
104 | if (i < ticksList.count()) | |
105 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] + (layout[i + 1] - layout[i]) / 2 - center.y()); |
|
105 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] + (layout[i + 1] - layout[i]) / 2 - center.y()); | |
106 | else |
|
106 | else | |
107 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); |
|
107 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
108 |
|
108 | |||
109 | if(labelItem->pos().y()+rect.height()>height) { |
|
109 | if(labelItem->pos().y()+rect.height()>height) { | |
110 | labelItem->setVisible(false); |
|
110 | labelItem->setVisible(false); | |
111 | lineItem->setVisible(false); |
|
111 | lineItem->setVisible(false); | |
112 | } |
|
112 | } | |
113 | else { |
|
113 | else { | |
114 | labelItem->setVisible(true); |
|
114 | labelItem->setVisible(true); | |
115 | lineItem->setVisible(true); |
|
115 | lineItem->setVisible(true); | |
116 | height=labelItem->pos().y(); |
|
116 | height=labelItem->pos().y(); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); |
|
119 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); | |
120 | m_minHeight+=rect.height(); |
|
120 | m_minHeight+=rect.height(); | |
121 |
|
121 | |||
122 | if ((i+1)%2 && i>1) { |
|
122 | if ((i+1)%2 && i>1) { | |
123 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
123 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
124 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); |
|
124 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); | |
125 | } |
|
125 | } | |
126 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
126 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
127 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
127 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); | |
128 | } |
|
128 | } | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 |
void Chart |
|
131 | void ChartCategoryAxisY::handleAxisUpdated() | |
132 | { |
|
132 | { | |
133 | updateGeometry(); |
|
133 | updateGeometry(); | |
134 | ChartAxis::handleAxisUpdated(); |
|
134 | ChartAxis::handleAxisUpdated(); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | QTCOMMERCIALCHART_END_NAMESPACE |
|
137 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,58 +1,58 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTINTERVALAXISY_H |
|
30 | #ifndef CHARTINTERVALAXISY_H | |
31 | #define CHARTINTERVALAXISY_H |
|
31 | #define CHARTINTERVALAXISY_H | |
32 |
|
32 | |||
33 | #include "chartaxis_p.h" |
|
33 | #include "chartaxis_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAbstractAxis; |
|
37 | class QAbstractAxis; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 |
|
39 | |||
40 |
class Chart |
|
40 | class ChartCategoryAxisY : public ChartAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 |
Chart |
|
43 | ChartCategoryAxisY(QAbstractAxis *axis, ChartPresenter *presenter); | |
44 |
~Chart |
|
44 | ~ChartCategoryAxisY(); | |
45 |
|
45 | |||
46 | AxisType axisType() const { return Y_AXIS;} |
|
46 | AxisType axisType() const { return Y_AXIS;} | |
47 |
|
47 | |||
48 | protected: |
|
48 | protected: | |
49 | QVector<qreal> calculateLayout() const; |
|
49 | QVector<qreal> calculateLayout() const; | |
50 | void updateGeometry(); |
|
50 | void updateGeometry(); | |
51 |
|
51 | |||
52 | Q_SLOTS |
|
52 | Q_SLOTS | |
53 | void handleAxisUpdated(); |
|
53 | void handleAxisUpdated(); | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | QTCOMMERCIALCHART_END_NAMESPACE | |
57 |
|
57 | |||
58 | #endif /* CHARTINTERVALAXISY_H */ |
|
58 | #endif /* CHARTINTERVALAXISY_H */ |
@@ -1,249 +1,242 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
#include "q |
|
21 | #include "qcategoryaxis.h" | |
22 |
#include "q |
|
22 | #include "qcategoryaxis_p.h" | |
23 |
#include "chart |
|
23 | #include "chartcategoryaxisx_p.h" | |
24 |
#include "chart |
|
24 | #include "chartcategoryaxisy_p.h" | |
25 | #include <qmath.h> |
|
25 | #include <qmath.h> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 | /*! |
|
29 | /*! | |
30 | \class QCategoryAxis |
|
30 | \class QCategoryAxis | |
31 | \brief The QCategoryAxis class is used for manipulating chart's axis. |
|
31 | \brief The QCategoryAxis class is used for manipulating chart's axis. | |
32 | \mainclass |
|
32 | \mainclass | |
33 | */ |
|
33 | */ | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | \qmlclass Axis QCategoryAxis |
|
36 | \qmlclass CategoryAxis QCategoryAxis | |
37 | \brief The Axis element is used for manipulating chart's axes. |
|
37 | \brief The Axis element is used for manipulating chart's axes. | |
38 |
|
||||
39 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
|||
40 |
|
||||
41 | To access Axes you can use ChartView API. For example: |
|
|||
42 | \code |
|
|||
43 | // TODO :) |
|
|||
44 | \endcode |
|
|||
45 | */ |
|
38 | */ | |
46 |
|
39 | |||
47 | /*! |
|
40 | /*! | |
48 | Constructs an axis object which is a child of \a parent. |
|
41 | Constructs an axis object which is a child of \a parent. | |
49 | */ |
|
42 | */ | |
50 | QCategoryAxis::QCategoryAxis(QObject *parent): |
|
43 | QCategoryAxis::QCategoryAxis(QObject *parent): | |
51 | QValueAxis(*new QCategoryAxisPrivate(this),parent) |
|
44 | QValueAxis(*new QCategoryAxisPrivate(this),parent) | |
52 | { |
|
45 | { | |
53 | } |
|
46 | } | |
54 |
|
47 | |||
55 | /*! |
|
48 | /*! | |
56 | Destroys the object |
|
49 | Destroys the object | |
57 | */ |
|
50 | */ | |
58 | QCategoryAxis::~QCategoryAxis() |
|
51 | QCategoryAxis::~QCategoryAxis() | |
59 | { |
|
52 | { | |
60 | // Q_D(QValueAxis); |
|
53 | // Q_D(QValueAxis); | |
61 | // if(d->m_dataset) { |
|
54 | // if(d->m_dataset) { | |
62 | // d->m_dataset->removeAxis(this); |
|
55 | // d->m_dataset->removeAxis(this); | |
63 | // } |
|
56 | // } | |
64 | } |
|
57 | } | |
65 |
|
58 | |||
66 | /*! |
|
59 | /*! | |
67 | \internal |
|
60 | \internal | |
68 | */ |
|
61 | */ | |
69 | QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent) |
|
62 | QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent) | |
70 | { |
|
63 | { | |
71 |
|
64 | |||
72 | } |
|
65 | } | |
73 |
|
66 | |||
74 | /*! |
|
67 | /*! | |
75 | Appends new interval to the axis with an \a intervalLabel. |
|
68 | Appends new interval to the axis with an \a intervalLabel. | |
76 | Interval label has to be unique. |
|
69 | Interval label has to be unique. | |
77 | Parameter \a intervalEnd specifies the high end limit of the interval. |
|
70 | Parameter \a intervalEnd specifies the high end limit of the interval. | |
78 | It has to be greater than the high end limit of the previous interval. |
|
71 | It has to be greater than the high end limit of the previous interval. | |
79 | Otherwise the method returns without adding a new interval. |
|
72 | Otherwise the method returns without adding a new interval. | |
80 | */ |
|
73 | */ | |
81 | void QCategoryAxis::append(const QString& intervalLabel, qreal intervalEnd) |
|
74 | void QCategoryAxis::append(const QString& intervalLabel, qreal intervalEnd) | |
82 | { |
|
75 | { | |
83 | Q_D(QCategoryAxis); |
|
76 | Q_D(QCategoryAxis); | |
84 |
|
77 | |||
85 | if (!d->m_intervals.contains(intervalLabel)) |
|
78 | if (!d->m_intervals.contains(intervalLabel)) | |
86 | { |
|
79 | { | |
87 | if(d->m_intervals.isEmpty()){ |
|
80 | if(d->m_intervals.isEmpty()){ | |
88 | Range range(d->m_categoryMinimum, intervalEnd); |
|
81 | Range range(d->m_categoryMinimum, intervalEnd); | |
89 | d->m_intervalsMap.insert(intervalLabel, range); |
|
82 | d->m_intervalsMap.insert(intervalLabel, range); | |
90 | d->m_intervals.append(intervalLabel); |
|
83 | d->m_intervals.append(intervalLabel); | |
91 | }else if (intervalEnd > intervalMax(d->m_intervals.last())){ |
|
84 | }else if (intervalEnd > intervalMax(d->m_intervals.last())){ | |
92 | Range range = d->m_intervalsMap.value(d->m_intervals.last()); |
|
85 | Range range = d->m_intervalsMap.value(d->m_intervals.last()); | |
93 | d->m_intervalsMap.insert(intervalLabel, Range(range.second, intervalEnd)); |
|
86 | d->m_intervalsMap.insert(intervalLabel, Range(range.second, intervalEnd)); | |
94 | d->m_intervals.append(intervalLabel); |
|
87 | d->m_intervals.append(intervalLabel); | |
95 | } |
|
88 | } | |
96 | } |
|
89 | } | |
97 | } |
|
90 | } | |
98 |
|
91 | |||
99 | /*! |
|
92 | /*! | |
100 | Sets to \a min the low end limit of the first interval on the axis. |
|
93 | Sets to \a min the low end limit of the first interval on the axis. | |
101 | */ |
|
94 | */ | |
102 | void QCategoryAxis::setFisrtIntervalMinimum(qreal min) |
|
95 | void QCategoryAxis::setFisrtIntervalMinimum(qreal min) | |
103 | { |
|
96 | { | |
104 | Q_D(QCategoryAxis); |
|
97 | Q_D(QCategoryAxis); | |
105 | if(d->m_intervals.isEmpty()){ |
|
98 | if(d->m_intervals.isEmpty()){ | |
106 | d->m_categoryMinimum = min; |
|
99 | d->m_categoryMinimum = min; | |
107 | }else{ |
|
100 | }else{ | |
108 | Range range = d->m_intervalsMap.value(d->m_intervals.first()); |
|
101 | Range range = d->m_intervalsMap.value(d->m_intervals.first()); | |
109 | d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second)); |
|
102 | d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second)); | |
110 | } |
|
103 | } | |
111 | } |
|
104 | } | |
112 |
|
105 | |||
113 | /*! |
|
106 | /*! | |
114 | Returns the low end limit of the interval specified by an \a intervalLabel |
|
107 | Returns the low end limit of the interval specified by an \a intervalLabel | |
115 | */ |
|
108 | */ | |
116 | qreal QCategoryAxis::intervalMin(const QString& intervalLabel) const |
|
109 | qreal QCategoryAxis::intervalMin(const QString& intervalLabel) const | |
117 | { |
|
110 | { | |
118 | Q_D(const QCategoryAxis); |
|
111 | Q_D(const QCategoryAxis); | |
119 | return d->m_intervalsMap.value(intervalLabel).first; |
|
112 | return d->m_intervalsMap.value(intervalLabel).first; | |
120 | } |
|
113 | } | |
121 |
|
114 | |||
122 | /*! |
|
115 | /*! | |
123 | Returns the high end limit of the interval specified by an \a intervalLabel |
|
116 | Returns the high end limit of the interval specified by an \a intervalLabel | |
124 | */ |
|
117 | */ | |
125 | qreal QCategoryAxis::intervalMax(const QString& intervalLabel) const |
|
118 | qreal QCategoryAxis::intervalMax(const QString& intervalLabel) const | |
126 | { |
|
119 | { | |
127 | Q_D(const QCategoryAxis); |
|
120 | Q_D(const QCategoryAxis); | |
128 | return d->m_intervalsMap.value(intervalLabel).second; |
|
121 | return d->m_intervalsMap.value(intervalLabel).second; | |
129 | } |
|
122 | } | |
130 |
|
123 | |||
131 | /*! |
|
124 | /*! | |
132 | Removes an interval specified by the \a intervalLabel from the axis |
|
125 | Removes an interval specified by the \a intervalLabel from the axis | |
133 | */ |
|
126 | */ | |
134 | void QCategoryAxis::remove(const QString &intervalLabel) |
|
127 | void QCategoryAxis::remove(const QString &intervalLabel) | |
135 | { |
|
128 | { | |
136 | Q_D(QCategoryAxis); |
|
129 | Q_D(QCategoryAxis); | |
137 | int labelIndex = d->m_intervals.indexOf(intervalLabel); |
|
130 | int labelIndex = d->m_intervals.indexOf(intervalLabel); | |
138 |
|
131 | |||
139 | // check if such label exists |
|
132 | // check if such label exists | |
140 | if (labelIndex != -1) { |
|
133 | if (labelIndex != -1) { | |
141 | d->m_intervals.removeAt(labelIndex); |
|
134 | d->m_intervals.removeAt(labelIndex); | |
142 | d->m_intervalsMap.remove(intervalLabel); |
|
135 | d->m_intervalsMap.remove(intervalLabel); | |
143 |
|
136 | |||
144 | // the range of the interval that follows (if exists) needs to be updated |
|
137 | // the range of the interval that follows (if exists) needs to be updated | |
145 | if (labelIndex < d->m_intervals.count()) { |
|
138 | if (labelIndex < d->m_intervals.count()) { | |
146 | QString label = d->m_intervals.at(labelIndex); |
|
139 | QString label = d->m_intervals.at(labelIndex); | |
147 | Range range = d->m_intervalsMap.value(label); |
|
140 | Range range = d->m_intervalsMap.value(label); | |
148 |
|
141 | |||
149 | // set the range |
|
142 | // set the range | |
150 | if (labelIndex == 0) { |
|
143 | if (labelIndex == 0) { | |
151 | range.first = d->m_categoryMinimum; |
|
144 | range.first = d->m_categoryMinimum; | |
152 | d->m_intervalsMap.insert(label, range); |
|
145 | d->m_intervalsMap.insert(label, range); | |
153 | } else { |
|
146 | } else { | |
154 | range.first = d->m_intervalsMap.value(d->m_intervals.at(labelIndex - 1)).second; |
|
147 | range.first = d->m_intervalsMap.value(d->m_intervals.at(labelIndex - 1)).second; | |
155 | d->m_intervalsMap.insert(label, range); |
|
148 | d->m_intervalsMap.insert(label, range); | |
156 | } |
|
149 | } | |
157 | } |
|
150 | } | |
158 | d->emitUpdated(); |
|
151 | d->emitUpdated(); | |
159 | } |
|
152 | } | |
160 | } |
|
153 | } | |
161 |
|
154 | |||
162 | /*! |
|
155 | /*! | |
163 | Replaces \a oldLabel of an existing interval with a \a newLabel |
|
156 | Replaces \a oldLabel of an existing interval with a \a newLabel | |
164 | If the old label does not exist the method returns without making any changes. |
|
157 | If the old label does not exist the method returns without making any changes. | |
165 | */ |
|
158 | */ | |
166 | void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel) |
|
159 | void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel) | |
167 | { |
|
160 | { | |
168 | Q_D(QCategoryAxis); |
|
161 | Q_D(QCategoryAxis); | |
169 | int labelIndex = d->m_intervals.indexOf(oldLabel); |
|
162 | int labelIndex = d->m_intervals.indexOf(oldLabel); | |
170 |
|
163 | |||
171 | // check if such label exists |
|
164 | // check if such label exists | |
172 | if (labelIndex != -1) { |
|
165 | if (labelIndex != -1) { | |
173 | d->m_intervals.replace(labelIndex, newLabel); |
|
166 | d->m_intervals.replace(labelIndex, newLabel); | |
174 | Range range = d->m_intervalsMap.value(oldLabel); |
|
167 | Range range = d->m_intervalsMap.value(oldLabel); | |
175 | d->m_intervalsMap.remove(oldLabel); |
|
168 | d->m_intervalsMap.remove(oldLabel); | |
176 | d->m_intervalsMap.insert(newLabel, range); |
|
169 | d->m_intervalsMap.insert(newLabel, range); | |
177 | d->emitUpdated(); |
|
170 | d->emitUpdated(); | |
178 | } |
|
171 | } | |
179 |
|
172 | |||
180 | } |
|
173 | } | |
181 |
|
174 | |||
182 | /*! |
|
175 | /*! | |
183 | Returns the list of the intervals labels |
|
176 | Returns the list of the intervals labels | |
184 | */ |
|
177 | */ | |
185 | QStringList QCategoryAxis::intervalsLabels() |
|
178 | QStringList QCategoryAxis::intervalsLabels() | |
186 | { |
|
179 | { | |
187 | Q_D(QCategoryAxis); |
|
180 | Q_D(QCategoryAxis); | |
188 | return d->m_intervals; |
|
181 | return d->m_intervals; | |
189 | } |
|
182 | } | |
190 |
|
183 | |||
191 | /*! |
|
184 | /*! | |
192 | Returns number of intervals. |
|
185 | Returns number of intervals. | |
193 | */ |
|
186 | */ | |
194 | int QCategoryAxis::count() const |
|
187 | int QCategoryAxis::count() const | |
195 | { |
|
188 | { | |
196 | Q_D(const QCategoryAxis); |
|
189 | Q_D(const QCategoryAxis); | |
197 | return d->m_intervals.count(); |
|
190 | return d->m_intervals.count(); | |
198 | } |
|
191 | } | |
199 |
|
192 | |||
200 | /*! |
|
193 | /*! | |
201 | Returns the type of the axis |
|
194 | Returns the type of the axis | |
202 | */ |
|
195 | */ | |
203 | QAbstractAxis::AxisType QCategoryAxis::type() const |
|
196 | QAbstractAxis::AxisType QCategoryAxis::type() const | |
204 | { |
|
197 | { | |
205 | return QAbstractAxis::AxisTypeIntervals; |
|
198 | return QAbstractAxis::AxisTypeIntervals; | |
206 | } |
|
199 | } | |
207 |
|
200 | |||
208 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
201 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
209 |
|
202 | |||
210 | QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q): |
|
203 | QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q): | |
211 | QValueAxisPrivate(q), |
|
204 | QValueAxisPrivate(q), | |
212 | m_categoryMinimum(0) |
|
205 | m_categoryMinimum(0) | |
213 | { |
|
206 | { | |
214 |
|
207 | |||
215 | } |
|
208 | } | |
216 |
|
209 | |||
217 | QCategoryAxisPrivate::~QCategoryAxisPrivate() |
|
210 | QCategoryAxisPrivate::~QCategoryAxisPrivate() | |
218 | { |
|
211 | { | |
219 |
|
212 | |||
220 | } |
|
213 | } | |
221 |
|
214 | |||
222 | int QCategoryAxisPrivate::ticksCount() const |
|
215 | int QCategoryAxisPrivate::ticksCount() const | |
223 | { |
|
216 | { | |
224 | return m_intervals.count() + 1; |
|
217 | return m_intervals.count() + 1; | |
225 | } |
|
218 | } | |
226 |
|
219 | |||
227 | void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
220 | void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) | |
228 | { |
|
221 | { | |
229 | Q_UNUSED(count); |
|
222 | Q_UNUSED(count); | |
230 | Q_UNUSED(min); |
|
223 | Q_UNUSED(min); | |
231 | Q_UNUSED(max); |
|
224 | Q_UNUSED(max); | |
232 | //m_min = min; |
|
225 | //m_min = min; | |
233 | //m_max = max; |
|
226 | //m_max = max; | |
234 | } |
|
227 | } | |
235 |
|
228 | |||
236 | ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
229 | ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter) | |
237 | { |
|
230 | { | |
238 | Q_Q(QCategoryAxis); |
|
231 | Q_Q(QCategoryAxis); | |
239 | if(m_orientation == Qt::Vertical){ |
|
232 | if(m_orientation == Qt::Vertical){ | |
240 |
return new Chart |
|
233 | return new ChartCategoryAxisY(q,presenter); | |
241 | }else{ |
|
234 | }else{ | |
242 |
return new Chart |
|
235 | return new ChartCategoryAxisX(q,presenter); | |
243 | } |
|
236 | } | |
244 | } |
|
237 | } | |
245 |
|
238 | |||
246 |
#include "moc_q |
|
239 | #include "moc_qcategoryaxis.cpp" | |
247 |
#include "moc_q |
|
240 | #include "moc_qcategoryaxis_p.cpp" | |
248 |
|
241 | |||
249 | QTCOMMERCIALCHART_END_NAMESPACE |
|
242 | QTCOMMERCIALCHART_END_NAMESPACE |
1 | NO CONTENT: file renamed from src/axis/intervalsaxis/qintervalsaxis.h to src/axis/categoryaxis/qcategoryaxis.h |
|
NO CONTENT: file renamed from src/axis/intervalsaxis/qintervalsaxis.h to src/axis/categoryaxis/qcategoryaxis.h |
@@ -1,70 +1,70 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QCATEGORYAXIS_P_H |
|
30 | #ifndef QCATEGORYAXIS_P_H | |
31 | #define QCATEGORYAXIS_P_H |
|
31 | #define QCATEGORYAXIS_P_H | |
32 |
|
32 | |||
33 |
#include "q |
|
33 | #include "qcategoryaxis.h" | |
34 | #include "qvalueaxis_p.h" |
|
34 | #include "qvalueaxis_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | typedef QPair<qreal, qreal> Range; |
|
38 | typedef QPair<qreal, qreal> Range; | |
39 |
|
39 | |||
40 | class QCategoryAxisPrivate : public QValueAxisPrivate |
|
40 | class QCategoryAxisPrivate : public QValueAxisPrivate | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 |
|
43 | |||
44 | public: |
|
44 | public: | |
45 | QCategoryAxisPrivate(QCategoryAxis *q); |
|
45 | QCategoryAxisPrivate(QCategoryAxis *q); | |
46 | ~QCategoryAxisPrivate(); |
|
46 | ~QCategoryAxisPrivate(); | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | public: |
|
49 | public: | |
50 | ChartAxis* createGraphics(ChartPresenter* presenter); |
|
50 | ChartAxis* createGraphics(ChartPresenter* presenter); | |
51 | int ticksCount() const; |
|
51 | int ticksCount() const; | |
52 |
|
52 | |||
53 | Q_SIGNALS: |
|
53 | Q_SIGNALS: | |
54 | void changed(qreal min, qreal max, int tickCount,bool niceNumbers); |
|
54 | void changed(qreal min, qreal max, int tickCount,bool niceNumbers); | |
55 |
|
55 | |||
56 | public Q_SLOTS: |
|
56 | public Q_SLOTS: | |
57 | void handleAxisRangeChanged(qreal min, qreal max,int count); |
|
57 | void handleAxisRangeChanged(qreal min, qreal max,int count); | |
58 |
|
58 | |||
59 | private: |
|
59 | private: | |
60 | QMap<QString , Range> m_intervalsMap; |
|
60 | QMap<QString , Range> m_intervalsMap; | |
61 | QStringList m_intervals; |
|
61 | QStringList m_intervals; | |
62 | qreal m_categoryMinimum; |
|
62 | qreal m_categoryMinimum; | |
63 |
|
63 | |||
64 | private: |
|
64 | private: | |
65 | Q_DECLARE_PUBLIC(QCategoryAxis) |
|
65 | Q_DECLARE_PUBLIC(QCategoryAxis) | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
69 | |||
70 | #endif // QCATEGORYAXIS_P_H |
|
70 | #endif // QCATEGORYAXIS_P_H |
@@ -1,491 +1,491 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qvalueaxis.h" |
|
23 | #include "qvalueaxis.h" | |
24 | #include "qbarcategoryaxis.h" |
|
24 | #include "qbarcategoryaxis.h" | |
25 | #include "qvalueaxis_p.h" |
|
25 | #include "qvalueaxis_p.h" | |
26 |
#include "q |
|
26 | #include "qcategoryaxis.h" | |
27 | #include "qdatetimeaxis.h" |
|
27 | #include "qdatetimeaxis.h" | |
28 | #include "qabstractseries_p.h" |
|
28 | #include "qabstractseries_p.h" | |
29 | #include "qabstractbarseries.h" |
|
29 | #include "qabstractbarseries.h" | |
30 | #include "qstackedbarseries.h" |
|
30 | #include "qstackedbarseries.h" | |
31 | #include "qpercentbarseries.h" |
|
31 | #include "qpercentbarseries.h" | |
32 | #include "qpieseries.h" |
|
32 | #include "qpieseries.h" | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent) |
|
36 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent) | |
37 | { |
|
37 | { | |
38 |
|
38 | |||
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | ChartDataSet::~ChartDataSet() |
|
41 | ChartDataSet::~ChartDataSet() | |
42 | { |
|
42 | { | |
43 | removeAllSeries(); |
|
43 | removeAllSeries(); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void ChartDataSet::addSeries(QAbstractSeries* series) |
|
46 | void ChartDataSet::addSeries(QAbstractSeries* series) | |
47 | { |
|
47 | { | |
48 | Domain* domain = m_seriesDomainMap.value(series); |
|
48 | Domain* domain = m_seriesDomainMap.value(series); | |
49 |
|
49 | |||
50 | if(domain) { |
|
50 | if(domain) { | |
51 | qWarning() << "Can not add series. Series already on the chart"; |
|
51 | qWarning() << "Can not add series. Series already on the chart"; | |
52 | return; |
|
52 | return; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | domain = new Domain(series); |
|
55 | domain = new Domain(series); | |
56 | m_seriesDomainMap.insert(series,domain); |
|
56 | m_seriesDomainMap.insert(series,domain); | |
57 | series->d_ptr->scaleDomain(*domain); |
|
57 | series->d_ptr->scaleDomain(*domain); | |
58 |
|
58 | |||
59 | createSeriesIndex(series); |
|
59 | createSeriesIndex(series); | |
60 |
|
60 | |||
61 | series->setParent(this); // take ownership |
|
61 | series->setParent(this); // take ownership | |
62 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
62 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); | |
63 | series->d_ptr->m_dataset = this; |
|
63 | series->d_ptr->m_dataset = this; | |
64 |
|
64 | |||
65 | emit seriesAdded(series,domain); |
|
65 | emit seriesAdded(series,domain); | |
66 |
|
66 | |||
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void ChartDataSet::removeSeries(QAbstractSeries* series) |
|
69 | void ChartDataSet::removeSeries(QAbstractSeries* series) | |
70 | { |
|
70 | { | |
71 |
|
71 | |||
72 | if(!m_seriesDomainMap.contains(series)) { |
|
72 | if(!m_seriesDomainMap.contains(series)) { | |
73 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
73 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
74 | return; |
|
74 | return; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | emit seriesRemoved(series); |
|
77 | emit seriesRemoved(series); | |
78 |
|
78 | |||
79 | Domain* domain = m_seriesDomainMap.take(series); |
|
79 | Domain* domain = m_seriesDomainMap.take(series); | |
80 | delete domain; |
|
80 | delete domain; | |
81 | domain = 0; |
|
81 | domain = 0; | |
82 |
|
82 | |||
83 | removeSeriesIndex(series); |
|
83 | removeSeriesIndex(series); | |
84 |
|
84 | |||
85 | series->setParent(0); |
|
85 | series->setParent(0); | |
86 | series->d_ptr->m_chart = 0; |
|
86 | series->d_ptr->m_chart = 0; | |
87 | series->d_ptr->m_dataset = 0; |
|
87 | series->d_ptr->m_dataset = 0; | |
88 |
|
88 | |||
89 | removeAxes(series); |
|
89 | removeAxes(series); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 |
|
92 | |||
93 |
|
93 | |||
94 | void ChartDataSet::createSeriesIndex(QAbstractSeries* series) |
|
94 | void ChartDataSet::createSeriesIndex(QAbstractSeries* series) | |
95 | { |
|
95 | { | |
96 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
96 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
97 |
|
97 | |||
98 | int key=0; |
|
98 | int key=0; | |
99 | while (i.hasNext()) { |
|
99 | while (i.hasNext()) { | |
100 | i.next(); |
|
100 | i.next(); | |
101 | if(i.key()!=key) { |
|
101 | if(i.key()!=key) { | |
102 | break; |
|
102 | break; | |
103 | } |
|
103 | } | |
104 | key++; |
|
104 | key++; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | m_indexSeriesMap.insert(key,series); |
|
107 | m_indexSeriesMap.insert(key,series); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void ChartDataSet::removeSeriesIndex(QAbstractSeries* series) |
|
110 | void ChartDataSet::removeSeriesIndex(QAbstractSeries* series) | |
111 | { |
|
111 | { | |
112 | int key = seriesIndex(series); |
|
112 | int key = seriesIndex(series); | |
113 | Q_ASSERT(key!=-1); |
|
113 | Q_ASSERT(key!=-1); | |
114 | m_indexSeriesMap.remove(key); |
|
114 | m_indexSeriesMap.remove(key); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void ChartDataSet::createDefaultAxes() |
|
117 | void ChartDataSet::createDefaultAxes() | |
118 | { |
|
118 | { | |
119 | if (m_seriesDomainMap.isEmpty()) |
|
119 | if (m_seriesDomainMap.isEmpty()) | |
120 | return; |
|
120 | return; | |
121 |
|
121 | |||
122 | QAbstractAxis::AxisTypes typeX(0); |
|
122 | QAbstractAxis::AxisTypes typeX(0); | |
123 | QAbstractAxis::AxisTypes typeY(0); |
|
123 | QAbstractAxis::AxisTypes typeY(0); | |
124 |
|
124 | |||
125 | // Remove possibly existing axes |
|
125 | // Remove possibly existing axes | |
126 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
126 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
127 | while (i.hasNext()) { |
|
127 | while (i.hasNext()) { | |
128 | i.next(); |
|
128 | i.next(); | |
129 | removeAxes(i.key()); |
|
129 | removeAxes(i.key()); | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | i.toFront(); |
|
132 | i.toFront(); | |
133 |
|
133 | |||
134 | // Select the required axis x and axis y types based on the types of the current series |
|
134 | // Select the required axis x and axis y types based on the types of the current series | |
135 | while (i.hasNext()) { |
|
135 | while (i.hasNext()) { | |
136 | i.next(); |
|
136 | i.next(); | |
137 |
|
137 | |||
138 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
138 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
139 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
139 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
140 | if(axisX) typeX&=axisX->type(); |
|
140 | if(axisX) typeX&=axisX->type(); | |
141 | else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal); |
|
141 | else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal); | |
142 | if(axisY) typeY&=axisY->type(); |
|
142 | if(axisY) typeY&=axisY->type(); | |
143 | else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical); |
|
143 | else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | // Create the axes of the types selected |
|
146 | // Create the axes of the types selected | |
147 | createAxes(typeX, Qt::Horizontal); |
|
147 | createAxes(typeX, Qt::Horizontal); | |
148 | createAxes(typeY, Qt::Vertical); |
|
148 | createAxes(typeY, Qt::Vertical); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) |
|
151 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) | |
152 | { |
|
152 | { | |
153 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
153 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
154 |
|
154 | |||
155 | // TODO: Add a descriptive comment of what happens here |
|
155 | // TODO: Add a descriptive comment of what happens here | |
156 | if (type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories)) { |
|
156 | if (type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories)) { | |
157 | while (i.hasNext()) { |
|
157 | while (i.hasNext()) { | |
158 | i.next(); |
|
158 | i.next(); | |
159 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation), orientation); |
|
159 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation), orientation); | |
160 | if (axis) { |
|
160 | if (axis) { | |
161 | initializeAxis(axis, i.key()); |
|
161 | initializeAxis(axis, i.key()); | |
162 | emit axisAdded(axis, i.value()); |
|
162 | emit axisAdded(axis, i.value()); | |
163 | } |
|
163 | } | |
164 | } |
|
164 | } | |
165 | } else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { |
|
165 | } else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { | |
166 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)), orientation); |
|
166 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)), orientation); | |
167 | i.toFront(); |
|
167 | i.toFront(); | |
168 | while (i.hasNext()) { |
|
168 | while (i.hasNext()) { | |
169 | i.next(); |
|
169 | i.next(); | |
170 | initializeAxis(axis,i.key()); |
|
170 | initializeAxis(axis,i.key()); | |
171 | } |
|
171 | } | |
172 | emit axisAdded(axis,i.value()); |
|
172 | emit axisAdded(axis,i.value()); | |
173 | } |
|
173 | } | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation) |
|
176 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation) | |
177 | { |
|
177 | { | |
178 | QAbstractAxis* axis = 0; |
|
178 | QAbstractAxis* axis = 0; | |
179 |
|
179 | |||
180 | switch(type) { |
|
180 | switch(type) { | |
181 | case QAbstractAxis::AxisTypeValues: |
|
181 | case QAbstractAxis::AxisTypeValues: | |
182 | axis = new QValueAxis(this); |
|
182 | axis = new QValueAxis(this); | |
183 | break; |
|
183 | break; | |
184 | case QAbstractAxis::AxisTypeCategories: |
|
184 | case QAbstractAxis::AxisTypeCategories: | |
185 | axis = new QBarCategoryAxis(this); |
|
185 | axis = new QBarCategoryAxis(this); | |
186 | break; |
|
186 | break; | |
187 | case QAbstractAxis::AxisTypeIntervals: |
|
187 | case QAbstractAxis::AxisTypeIntervals: | |
188 | axis = new QCategoryAxis(this); |
|
188 | axis = new QCategoryAxis(this); | |
189 | break; |
|
189 | break; | |
190 | case QAbstractAxis::AxisTypeDateTime: |
|
190 | case QAbstractAxis::AxisTypeDateTime: | |
191 | axis = new QDateTimeAxis(this); |
|
191 | axis = new QDateTimeAxis(this); | |
192 | break; |
|
192 | break; | |
193 | default: |
|
193 | default: | |
194 | axis = 0; |
|
194 | axis = 0; | |
195 | break; |
|
195 | break; | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | if(axis) |
|
198 | if(axis) | |
199 | axis->d_ptr->setOrientation(orientation); |
|
199 | axis->d_ptr->setOrientation(orientation); | |
200 |
|
200 | |||
201 | return axis; |
|
201 | return axis; | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) |
|
204 | void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) | |
205 | { |
|
205 | { | |
206 | Domain* domain = m_seriesDomainMap.value(series); |
|
206 | Domain* domain = m_seriesDomainMap.value(series); | |
207 | axis->d_ptr->m_dataset = this; |
|
207 | axis->d_ptr->m_dataset = this; | |
208 | series->d_ptr->initializeAxis(axis); |
|
208 | series->d_ptr->initializeAxis(axis); | |
209 | axis->d_ptr->intializeDomain(domain); |
|
209 | axis->d_ptr->intializeDomain(domain); | |
210 | if(axis->orientation()==Qt::Horizontal) { |
|
210 | if(axis->orientation()==Qt::Horizontal) { | |
211 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); |
|
211 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); | |
212 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); |
|
212 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); | |
213 | m_seriesAxisXMap.insert(series,axis); |
|
213 | m_seriesAxisXMap.insert(series,axis); | |
214 | } |
|
214 | } | |
215 | else { |
|
215 | else { | |
216 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); |
|
216 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); | |
217 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); |
|
217 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); | |
218 | m_seriesAxisYMap.insert(series,axis); |
|
218 | m_seriesAxisYMap.insert(series,axis); | |
219 | } |
|
219 | } | |
220 | axis->d_ptr->emitUpdated(); |
|
220 | axis->d_ptr->emitUpdated(); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | void ChartDataSet::removeAxes(QAbstractSeries* series) |
|
223 | void ChartDataSet::removeAxes(QAbstractSeries* series) | |
224 | { |
|
224 | { | |
225 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); |
|
225 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); | |
226 |
|
226 | |||
227 | if(axisX) { |
|
227 | if(axisX) { | |
228 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
228 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
229 | int x = axesX.indexOf(axisX); |
|
229 | int x = axesX.indexOf(axisX); | |
230 |
|
230 | |||
231 | if(x==-1) { |
|
231 | if(x==-1) { | |
232 | emit axisRemoved(axisX); |
|
232 | emit axisRemoved(axisX); | |
233 | axisX->d_ptr->m_dataset=0; |
|
233 | axisX->d_ptr->m_dataset=0; | |
234 | axisX->deleteLater(); |
|
234 | axisX->deleteLater(); | |
235 | } |
|
235 | } | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); |
|
238 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); | |
239 |
|
239 | |||
240 | if(axisY) { |
|
240 | if(axisY) { | |
241 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
241 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
242 |
|
242 | |||
243 | int y = axesY.indexOf(axisY); |
|
243 | int y = axesY.indexOf(axisY); | |
244 |
|
244 | |||
245 | if(y==-1) { |
|
245 | if(y==-1) { | |
246 | emit axisRemoved(axisY); |
|
246 | emit axisRemoved(axisY); | |
247 | axisY->d_ptr->m_dataset=0; |
|
247 | axisY->d_ptr->m_dataset=0; | |
248 | axisY->deleteLater(); |
|
248 | axisY->deleteLater(); | |
249 | } |
|
249 | } | |
250 | } |
|
250 | } | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | void ChartDataSet::removeAxis(QAbstractAxis* axis) |
|
253 | void ChartDataSet::removeAxis(QAbstractAxis* axis) | |
254 | { |
|
254 | { | |
255 | if(!axis->d_ptr->m_dataset) { |
|
255 | if(!axis->d_ptr->m_dataset) { | |
256 | qWarning()<<"UnBound axis found !"; |
|
256 | qWarning()<<"UnBound axis found !"; | |
257 | return; |
|
257 | return; | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; |
|
260 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; | |
261 |
|
261 | |||
262 | if(axis->orientation()==Qt::Vertical) { |
|
262 | if(axis->orientation()==Qt::Vertical) { | |
263 | seriesAxisMap= &m_seriesAxisYMap; |
|
263 | seriesAxisMap= &m_seriesAxisYMap; | |
264 | } |
|
264 | } | |
265 | else { |
|
265 | else { | |
266 | seriesAxisMap= &m_seriesAxisXMap; |
|
266 | seriesAxisMap= &m_seriesAxisXMap; | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap); |
|
269 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap); | |
270 |
|
270 | |||
271 | while (i.hasNext()) { |
|
271 | while (i.hasNext()) { | |
272 | i.next(); |
|
272 | i.next(); | |
273 | if(i.value()==axis) { |
|
273 | if(i.value()==axis) { | |
274 | removeSeries(i.key()); |
|
274 | removeSeries(i.key()); | |
275 | } |
|
275 | } | |
276 | } |
|
276 | } | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | void ChartDataSet::removeAllSeries() |
|
279 | void ChartDataSet::removeAllSeries() | |
280 | { |
|
280 | { | |
281 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
281 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); | |
282 | foreach(QAbstractSeries *s , series) { |
|
282 | foreach(QAbstractSeries *s , series) { | |
283 | removeSeries(s); |
|
283 | removeSeries(s); | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
286 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
287 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
287 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
288 | Q_ASSERT(m_seriesDomainMap.count()==0); |
|
288 | Q_ASSERT(m_seriesDomainMap.count()==0); | |
289 |
|
289 | |||
290 | qDeleteAll(series); |
|
290 | qDeleteAll(series); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
293 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
294 | { |
|
294 | { | |
295 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
295 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates | |
296 |
|
296 | |||
297 |
|
297 | |||
298 | blockAxisSignals(true); |
|
298 | blockAxisSignals(true); | |
299 |
|
299 | |||
300 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
300 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
301 |
|
301 | |||
302 | while (i.hasNext()) { |
|
302 | while (i.hasNext()) { | |
303 | i.next(); |
|
303 | i.next(); | |
304 | i.value()->zoomIn(rect,size); |
|
304 | i.value()->zoomIn(rect,size); | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | blockAxisSignals(false); |
|
307 | blockAxisSignals(false); | |
308 |
|
308 | |||
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
311 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
312 | { |
|
312 | { | |
313 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
313 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates | |
314 |
|
314 | |||
315 | blockAxisSignals(true); |
|
315 | blockAxisSignals(true); | |
316 |
|
316 | |||
317 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
317 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
318 |
|
318 | |||
319 | while (i.hasNext()) { |
|
319 | while (i.hasNext()) { | |
320 | i.next(); |
|
320 | i.next(); | |
321 | i.value()->zoomOut(rect,size); |
|
321 | i.value()->zoomOut(rect,size); | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | blockAxisSignals(false); |
|
324 | blockAxisSignals(false); | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | void ChartDataSet::blockAxisSignals(bool enabled) |
|
327 | void ChartDataSet::blockAxisSignals(bool enabled) | |
328 | { |
|
328 | { | |
329 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
329 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
330 | while (i.hasNext()) { |
|
330 | while (i.hasNext()) { | |
331 | i.next(); |
|
331 | i.next(); | |
332 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
332 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
333 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
333 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
334 | if(axisX) { |
|
334 | if(axisX) { | |
335 | axisX->d_ptr->blockSignals(enabled); |
|
335 | axisX->d_ptr->blockSignals(enabled); | |
336 | if(!enabled) { |
|
336 | if(!enabled) { | |
337 | axisX->d_ptr->setDirty(false); |
|
337 | axisX->d_ptr->setDirty(false); | |
338 | axisX->d_ptr->emitUpdated(); |
|
338 | axisX->d_ptr->emitUpdated(); | |
339 | } |
|
339 | } | |
340 | } |
|
340 | } | |
341 | if(axisY) { |
|
341 | if(axisY) { | |
342 | axisY->d_ptr->blockSignals(enabled); |
|
342 | axisY->d_ptr->blockSignals(enabled); | |
343 | if(!enabled) { |
|
343 | if(!enabled) { | |
344 | axisY->d_ptr->setDirty(false); |
|
344 | axisY->d_ptr->setDirty(false); | |
345 | axisY->d_ptr->emitUpdated(); |
|
345 | axisY->d_ptr->emitUpdated(); | |
346 | } |
|
346 | } | |
347 | } |
|
347 | } | |
348 | } |
|
348 | } | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
351 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
352 | { |
|
352 | { | |
353 | int count=0; |
|
353 | int count=0; | |
354 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
354 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
355 | while (i.hasNext()) { |
|
355 | while (i.hasNext()) { | |
356 | i.next(); |
|
356 | i.next(); | |
357 | if(i.key()->type()==type) count++; |
|
357 | if(i.key()->type()==type) count++; | |
358 | } |
|
358 | } | |
359 | return count; |
|
359 | return count; | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
362 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
363 | { |
|
363 | { | |
364 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
364 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
365 | while (i.hasNext()) { |
|
365 | while (i.hasNext()) { | |
366 | i.next(); |
|
366 | i.next(); | |
367 | if (i.value() == series) |
|
367 | if (i.value() == series) | |
368 | return i.key(); |
|
368 | return i.key(); | |
369 | } |
|
369 | } | |
370 | return -1; |
|
370 | return -1; | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
373 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const | |
374 | { |
|
374 | { | |
375 | if(series == 0) { |
|
375 | if(series == 0) { | |
376 |
|
376 | |||
377 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap); |
|
377 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap); | |
378 |
|
378 | |||
379 | while (i.hasNext()) { |
|
379 | while (i.hasNext()) { | |
380 | i.next(); |
|
380 | i.next(); | |
381 | if(i.value()->isVisible()) return i.value(); |
|
381 | if(i.value()->isVisible()) return i.value(); | |
382 | } |
|
382 | } | |
383 | return 0; |
|
383 | return 0; | |
384 | } |
|
384 | } | |
385 | return m_seriesAxisXMap.value(series); |
|
385 | return m_seriesAxisXMap.value(series); | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
388 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
389 | { |
|
389 | { | |
390 | if(series == 0) { |
|
390 | if(series == 0) { | |
391 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap); |
|
391 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap); | |
392 |
|
392 | |||
393 | while (i.hasNext()) { |
|
393 | while (i.hasNext()) { | |
394 | i.next(); |
|
394 | i.next(); | |
395 | if(i.value()->isVisible()) return i.value(); |
|
395 | if(i.value()->isVisible()) return i.value(); | |
396 | } |
|
396 | } | |
397 | return 0; |
|
397 | return 0; | |
398 | } |
|
398 | } | |
399 | return m_seriesAxisYMap.value(series); |
|
399 | return m_seriesAxisYMap.value(series); | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 | void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation) |
|
402 | void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation) | |
403 | { |
|
403 | { | |
404 | Q_ASSERT(axis); |
|
404 | Q_ASSERT(axis); | |
405 |
|
405 | |||
406 | if(!series) { |
|
406 | if(!series) { | |
407 | qWarning() << "Series not found on the chart."; |
|
407 | qWarning() << "Series not found on the chart."; | |
408 | return; |
|
408 | return; | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | Domain* domain = m_seriesDomainMap.value(series); |
|
411 | Domain* domain = m_seriesDomainMap.value(series); | |
412 |
|
412 | |||
413 | if(!domain) { |
|
413 | if(!domain) { | |
414 | qWarning() << "Series not found on the chart."; |
|
414 | qWarning() << "Series not found on the chart."; | |
415 | return; |
|
415 | return; | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) { |
|
418 | if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) { | |
419 | qWarning()<<"Axis already defined as axis Y"; |
|
419 | qWarning()<<"Axis already defined as axis Y"; | |
420 | return; |
|
420 | return; | |
421 | } |
|
421 | } | |
422 |
|
422 | |||
423 | if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) { |
|
423 | if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) { | |
424 | qWarning()<<"Axis already defined as axis X"; |
|
424 | qWarning()<<"Axis already defined as axis X"; | |
425 | return; |
|
425 | return; | |
426 | } |
|
426 | } | |
427 |
|
427 | |||
428 | axis->d_ptr->setOrientation(orientation); |
|
428 | axis->d_ptr->setOrientation(orientation); | |
429 |
|
429 | |||
430 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; |
|
430 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; | |
431 |
|
431 | |||
432 | if(orientation==Qt::Vertical) { |
|
432 | if(orientation==Qt::Vertical) { | |
433 | seriesAxisMap= &m_seriesAxisYMap; |
|
433 | seriesAxisMap= &m_seriesAxisYMap; | |
434 | }else{ |
|
434 | }else{ | |
435 | seriesAxisMap= &m_seriesAxisXMap; |
|
435 | seriesAxisMap= &m_seriesAxisXMap; | |
436 | } |
|
436 | } | |
437 |
|
437 | |||
438 | if (seriesAxisMap->value(series) == axis) { |
|
438 | if (seriesAxisMap->value(series) == axis) { | |
439 | qWarning() << "The axis already set for the series"; |
|
439 | qWarning() << "The axis already set for the series"; | |
440 | return; |
|
440 | return; | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
443 | QAbstractAxis *oldAxis = seriesAxisMap->take(series); |
|
443 | QAbstractAxis *oldAxis = seriesAxisMap->take(series); | |
444 | QList<QAbstractAxis*> axes = seriesAxisMap->values(); |
|
444 | QList<QAbstractAxis*> axes = seriesAxisMap->values(); | |
445 | if(oldAxis) { |
|
445 | if(oldAxis) { | |
446 | if(axes.indexOf(oldAxis)==-1) { |
|
446 | if(axes.indexOf(oldAxis)==-1) { | |
447 | emit axisRemoved(oldAxis); |
|
447 | emit axisRemoved(oldAxis); | |
448 | oldAxis->disconnect(); |
|
448 | oldAxis->disconnect(); | |
449 | QObject::disconnect(domain,0,oldAxis,0); |
|
449 | QObject::disconnect(domain,0,oldAxis,0); | |
450 | oldAxis->d_ptr->m_dataset=0; |
|
450 | oldAxis->d_ptr->m_dataset=0; | |
451 | oldAxis->deleteLater(); |
|
451 | oldAxis->deleteLater(); | |
452 | } |
|
452 | } | |
453 | } |
|
453 | } | |
454 |
|
454 | |||
455 | if(axes.indexOf(axis)==-1) { |
|
455 | if(axes.indexOf(axis)==-1) { | |
456 | initializeAxis(axis,series); |
|
456 | initializeAxis(axis,series); | |
457 | emit axisAdded(axis,domain); |
|
457 | emit axisAdded(axis,domain); | |
458 | }else{ |
|
458 | }else{ | |
459 | initializeAxis(axis,series); |
|
459 | initializeAxis(axis,series); | |
460 | } |
|
460 | } | |
461 | } |
|
461 | } | |
462 |
|
462 | |||
463 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
463 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
464 | { |
|
464 | { | |
465 | return m_seriesDomainMap.value(series); |
|
465 | return m_seriesDomainMap.value(series); | |
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
468 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) | |
469 | { |
|
469 | { | |
470 | blockAxisSignals(true); |
|
470 | blockAxisSignals(true); | |
471 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
471 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
472 | while (i.hasNext()) { |
|
472 | while (i.hasNext()) { | |
473 | i.next(); |
|
473 | i.next(); | |
474 | i.value()->move(dx,dy,size); |
|
474 | i.value()->move(dx,dy,size); | |
475 | } |
|
475 | } | |
476 | blockAxisSignals(false); |
|
476 | blockAxisSignals(false); | |
477 | } |
|
477 | } | |
478 |
|
478 | |||
479 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
479 | QList<QAbstractSeries*> ChartDataSet::series() const | |
480 | { |
|
480 | { | |
481 | return m_seriesDomainMap.keys(); |
|
481 | return m_seriesDomainMap.keys(); | |
482 | } |
|
482 | } | |
483 |
|
483 | |||
484 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
484 | void ChartDataSet::updateSeries(QAbstractSeries *series) | |
485 | { |
|
485 | { | |
486 | emit seriesUpdated(series); |
|
486 | emit seriesUpdated(series); | |
487 | } |
|
487 | } | |
488 |
|
488 | |||
489 | #include "moc_chartdataset_p.cpp" |
|
489 | #include "moc_chartdataset_p.cpp" | |
490 |
|
490 | |||
491 | QTCOMMERCIALCHART_END_NAMESPACE |
|
491 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,30 +1,30 | |||||
1 | !include( ../tests.pri ) { |
|
1 | !include( ../tests.pri ) { | |
2 | error( "Couldn't find the tests.pri file!" ) |
|
2 | error( "Couldn't find the tests.pri file!" ) | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | TEMPLATE = subdirs |
|
5 | TEMPLATE = subdirs | |
6 | SUBDIRS += \ |
|
6 | SUBDIRS += \ | |
7 | qchartview \ |
|
7 | qchartview \ | |
8 | qchart \ |
|
8 | qchart \ | |
9 | qlineseries \ |
|
9 | qlineseries \ | |
10 | qbarset \ |
|
10 | qbarset \ | |
11 | qbarseries \ |
|
11 | qbarseries \ | |
12 | qstackedbarseries \ |
|
12 | qstackedbarseries \ | |
13 | qpercentbarseries \ |
|
13 | qpercentbarseries \ | |
14 | qpieslice qpieseries \ |
|
14 | qpieslice qpieseries \ | |
15 | qpiemodelmapper \ |
|
15 | qpiemodelmapper \ | |
16 | qsplineseries \ |
|
16 | qsplineseries \ | |
17 | qscatterseries \ |
|
17 | qscatterseries \ | |
18 | qxymodelmapper \ |
|
18 | qxymodelmapper \ | |
19 | qbarmodelmapper \ |
|
19 | qbarmodelmapper \ | |
20 | qhorizontalbarseries \ |
|
20 | qhorizontalbarseries \ | |
21 | qhorizontalstackedbarseries \ |
|
21 | qhorizontalstackedbarseries \ | |
22 | qhorizontalpercentbarseries \ |
|
22 | qhorizontalpercentbarseries \ | |
23 | qvalueaxis \ |
|
23 | qvalueaxis \ | |
24 |
q |
|
24 | qcategoryaxis \ | |
25 | qdatetimeaxis \ |
|
25 | qdatetimeaxis \ | |
26 | qbarcategoryaxis |
|
26 | qbarcategoryaxis | |
27 |
|
27 | |||
28 | test_private:{ |
|
28 | test_private:{ | |
29 | SUBDIRS += domain chartdataset |
|
29 | SUBDIRS += domain chartdataset | |
30 | } |
|
30 | } |
@@ -1,5 +1,5 | |||||
1 | !include( ../auto.pri ) { |
|
1 | !include( ../auto.pri ) { | |
2 | error( "Couldn't find the auto.pri file!" ) |
|
2 | error( "Couldn't find the auto.pri file!" ) | |
3 | } |
|
3 | } | |
4 | HEADERS += ../qabstractaxis/tst_qabstractaxis.h |
|
4 | HEADERS += ../qabstractaxis/tst_qabstractaxis.h | |
5 |
SOURCES += tst_q |
|
5 | SOURCES += tst_qcategoryaxis.cpp ../qabstractaxis/tst_qabstractaxis.cpp |
@@ -1,304 +1,304 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "../qabstractaxis/tst_qabstractaxis.h" |
|
21 | #include "../qabstractaxis/tst_qabstractaxis.h" | |
22 |
#include "q |
|
22 | #include "qcategoryaxis.h" | |
23 | #include <qlineseries.h> |
|
23 | #include <qlineseries.h> | |
24 |
|
24 | |||
25 | class tst_QCategoryAxis: public tst_QAbstractAxis |
|
25 | class tst_QCategoryAxis: public tst_QAbstractAxis | |
26 | { |
|
26 | { | |
27 | Q_OBJECT |
|
27 | Q_OBJECT | |
28 |
|
28 | |||
29 | public slots: |
|
29 | public slots: | |
30 | void initTestCase(); |
|
30 | void initTestCase(); | |
31 | void cleanupTestCase(); |
|
31 | void cleanupTestCase(); | |
32 | void init(); |
|
32 | void init(); | |
33 | void cleanup(); |
|
33 | void cleanup(); | |
34 |
|
34 | |||
35 | private slots: |
|
35 | private slots: | |
36 |
void q |
|
36 | void qcategoryaxis_data(); | |
37 |
void q |
|
37 | void qcategoryaxis(); | |
38 |
|
38 | |||
39 | void max_raw_data(); |
|
39 | void max_raw_data(); | |
40 | void max_raw(); |
|
40 | void max_raw(); | |
41 | void max_data(); |
|
41 | void max_data(); | |
42 | void max(); |
|
42 | void max(); | |
43 | void max_animation_data(); |
|
43 | void max_animation_data(); | |
44 | void max_animation(); |
|
44 | void max_animation(); | |
45 | void min_raw_data(); |
|
45 | void min_raw_data(); | |
46 | void min_raw(); |
|
46 | void min_raw(); | |
47 | void min_data(); |
|
47 | void min_data(); | |
48 | void min(); |
|
48 | void min(); | |
49 | void min_animation_data(); |
|
49 | void min_animation_data(); | |
50 | void min_animation(); |
|
50 | void min_animation(); | |
51 | void range_raw_data(); |
|
51 | void range_raw_data(); | |
52 | void range_raw(); |
|
52 | void range_raw(); | |
53 | void range_data(); |
|
53 | void range_data(); | |
54 | void range(); |
|
54 | void range(); | |
55 | void range_animation_data(); |
|
55 | void range_animation_data(); | |
56 | void range_animation(); |
|
56 | void range_animation(); | |
57 |
|
57 | |||
58 | void interval_data(); |
|
58 | void interval_data(); | |
59 | void interval(); |
|
59 | void interval(); | |
60 |
|
60 | |||
61 | private: |
|
61 | private: | |
62 | QCategoryAxis* m_intervalsaxis; |
|
62 | QCategoryAxis* m_intervalsaxis; | |
63 | QLineSeries* m_series; |
|
63 | QLineSeries* m_series; | |
64 | }; |
|
64 | }; | |
65 |
|
65 | |||
66 | void tst_QCategoryAxis::initTestCase() |
|
66 | void tst_QCategoryAxis::initTestCase() | |
67 | { |
|
67 | { | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void tst_QCategoryAxis::cleanupTestCase() |
|
70 | void tst_QCategoryAxis::cleanupTestCase() | |
71 | { |
|
71 | { | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void tst_QCategoryAxis::init() |
|
74 | void tst_QCategoryAxis::init() | |
75 | { |
|
75 | { | |
76 | m_intervalsaxis = new QCategoryAxis(); |
|
76 | m_intervalsaxis = new QCategoryAxis(); | |
77 | m_series = new QLineSeries(); |
|
77 | m_series = new QLineSeries(); | |
78 | *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100); |
|
78 | *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100); | |
79 | tst_QAbstractAxis::init(m_intervalsaxis, m_series); |
|
79 | tst_QAbstractAxis::init(m_intervalsaxis, m_series); | |
80 | m_chart->addSeries(m_series); |
|
80 | m_chart->addSeries(m_series); | |
81 | m_chart->createDefaultAxes(); |
|
81 | m_chart->createDefaultAxes(); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | void tst_QCategoryAxis::cleanup() |
|
84 | void tst_QCategoryAxis::cleanup() | |
85 | { |
|
85 | { | |
86 | delete m_series; |
|
86 | delete m_series; | |
87 | delete m_intervalsaxis; |
|
87 | delete m_intervalsaxis; | |
88 | m_series = 0; |
|
88 | m_series = 0; | |
89 | m_intervalsaxis = 0; |
|
89 | m_intervalsaxis = 0; | |
90 | tst_QAbstractAxis::cleanup(); |
|
90 | tst_QAbstractAxis::cleanup(); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 |
void tst_QCategoryAxis::q |
|
93 | void tst_QCategoryAxis::qcategoryaxis_data() | |
94 | { |
|
94 | { | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 |
void tst_QCategoryAxis::q |
|
97 | void tst_QCategoryAxis::qcategoryaxis() | |
98 | { |
|
98 | { | |
99 | qabstractaxis(); |
|
99 | qabstractaxis(); | |
100 |
|
100 | |||
101 | QVERIFY(qFuzzyIsNull(m_intervalsaxis->max())); |
|
101 | QVERIFY(qFuzzyIsNull(m_intervalsaxis->max())); | |
102 | QVERIFY(qFuzzyIsNull(m_intervalsaxis->min())); |
|
102 | QVERIFY(qFuzzyIsNull(m_intervalsaxis->min())); | |
103 | QCOMPARE(m_intervalsaxis->type(), QAbstractAxis::AxisTypeIntervals); |
|
103 | QCOMPARE(m_intervalsaxis->type(), QAbstractAxis::AxisTypeIntervals); | |
104 |
|
104 | |||
105 | m_chart->setAxisX(m_intervalsaxis, m_series); |
|
105 | m_chart->setAxisX(m_intervalsaxis, m_series); | |
106 | m_view->show(); |
|
106 | m_view->show(); | |
107 | QTest::qWaitForWindowShown(m_view); |
|
107 | QTest::qWaitForWindowShown(m_view); | |
108 |
|
108 | |||
109 | QVERIFY(!qFuzzyIsNull(m_intervalsaxis->max())); |
|
109 | QVERIFY(!qFuzzyIsNull(m_intervalsaxis->max())); | |
110 | QVERIFY(!qFuzzyIsNull(m_intervalsaxis->min())); |
|
110 | QVERIFY(!qFuzzyIsNull(m_intervalsaxis->min())); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void tst_QCategoryAxis::max_raw_data() |
|
113 | void tst_QCategoryAxis::max_raw_data() | |
114 | { |
|
114 | { | |
115 | QTest::addColumn<qreal>("max"); |
|
115 | QTest::addColumn<qreal>("max"); | |
116 | QTest::newRow("1.0") << 1.0; |
|
116 | QTest::newRow("1.0") << 1.0; | |
117 | QTest::newRow("50.0") << 50.0; |
|
117 | QTest::newRow("50.0") << 50.0; | |
118 | QTest::newRow("101.0") << 101.0; |
|
118 | QTest::newRow("101.0") << 101.0; | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void tst_QCategoryAxis::max_raw() |
|
121 | void tst_QCategoryAxis::max_raw() | |
122 | { |
|
122 | { | |
123 | QFETCH(qreal, max); |
|
123 | QFETCH(qreal, max); | |
124 |
|
124 | |||
125 | QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal))); |
|
125 | QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal))); | |
126 | QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal))); |
|
126 | QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal))); | |
127 | QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
127 | QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
128 |
|
128 | |||
129 | m_intervalsaxis->setMax(max); |
|
129 | m_intervalsaxis->setMax(max); | |
130 | QVERIFY2(qFuzzyIsNull(m_intervalsaxis->max() - max), "Not equal"); |
|
130 | QVERIFY2(qFuzzyIsNull(m_intervalsaxis->max() - max), "Not equal"); | |
131 |
|
131 | |||
132 | QCOMPARE(spy0.count(), 1); |
|
132 | QCOMPARE(spy0.count(), 1); | |
133 | QCOMPARE(spy1.count(), 0); |
|
133 | QCOMPARE(spy1.count(), 0); | |
134 | QCOMPARE(spy2.count(), 1); |
|
134 | QCOMPARE(spy2.count(), 1); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | void tst_QCategoryAxis::max_data() |
|
137 | void tst_QCategoryAxis::max_data() | |
138 | { |
|
138 | { | |
139 | max_raw_data(); |
|
139 | max_raw_data(); | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | void tst_QCategoryAxis::max() |
|
142 | void tst_QCategoryAxis::max() | |
143 | { |
|
143 | { | |
144 | m_chart->setAxisX(m_intervalsaxis, m_series); |
|
144 | m_chart->setAxisX(m_intervalsaxis, m_series); | |
145 | m_view->show(); |
|
145 | m_view->show(); | |
146 | QTest::qWaitForWindowShown(m_view); |
|
146 | QTest::qWaitForWindowShown(m_view); | |
147 | max_raw(); |
|
147 | max_raw(); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | void tst_QCategoryAxis::max_animation_data() |
|
150 | void tst_QCategoryAxis::max_animation_data() | |
151 | { |
|
151 | { | |
152 | max_data(); |
|
152 | max_data(); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void tst_QCategoryAxis::max_animation() |
|
155 | void tst_QCategoryAxis::max_animation() | |
156 | { |
|
156 | { | |
157 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
157 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |
158 | max(); |
|
158 | max(); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void tst_QCategoryAxis::min_raw_data() |
|
161 | void tst_QCategoryAxis::min_raw_data() | |
162 | { |
|
162 | { | |
163 | QTest::addColumn<qreal>("min"); |
|
163 | QTest::addColumn<qreal>("min"); | |
164 | QTest::newRow("-1.0") << -1.0; |
|
164 | QTest::newRow("-1.0") << -1.0; | |
165 | QTest::newRow("-50.0") << -50.0; |
|
165 | QTest::newRow("-50.0") << -50.0; | |
166 | QTest::newRow("-101.0") << -101.0; |
|
166 | QTest::newRow("-101.0") << -101.0; | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | void tst_QCategoryAxis::min_raw() |
|
169 | void tst_QCategoryAxis::min_raw() | |
170 | { |
|
170 | { | |
171 | QFETCH(qreal, min); |
|
171 | QFETCH(qreal, min); | |
172 |
|
172 | |||
173 | QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal))); |
|
173 | QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal))); | |
174 | QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal))); |
|
174 | QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal))); | |
175 | QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
175 | QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
176 |
|
176 | |||
177 | m_intervalsaxis->setMin(min); |
|
177 | m_intervalsaxis->setMin(min); | |
178 | QVERIFY2(qFuzzyIsNull(m_intervalsaxis->min() - min), "Not equal"); |
|
178 | QVERIFY2(qFuzzyIsNull(m_intervalsaxis->min() - min), "Not equal"); | |
179 |
|
179 | |||
180 | QCOMPARE(spy0.count(), 0); |
|
180 | QCOMPARE(spy0.count(), 0); | |
181 | QCOMPARE(spy1.count(), 1); |
|
181 | QCOMPARE(spy1.count(), 1); | |
182 | QCOMPARE(spy2.count(), 1); |
|
182 | QCOMPARE(spy2.count(), 1); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void tst_QCategoryAxis::min_data() |
|
185 | void tst_QCategoryAxis::min_data() | |
186 | { |
|
186 | { | |
187 | min_raw_data(); |
|
187 | min_raw_data(); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | void tst_QCategoryAxis::min() |
|
190 | void tst_QCategoryAxis::min() | |
191 | { |
|
191 | { | |
192 | m_chart->setAxisX(m_intervalsaxis, m_series); |
|
192 | m_chart->setAxisX(m_intervalsaxis, m_series); | |
193 | m_view->show(); |
|
193 | m_view->show(); | |
194 | QTest::qWaitForWindowShown(m_view); |
|
194 | QTest::qWaitForWindowShown(m_view); | |
195 | min_raw(); |
|
195 | min_raw(); | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | void tst_QCategoryAxis::min_animation_data() |
|
198 | void tst_QCategoryAxis::min_animation_data() | |
199 | { |
|
199 | { | |
200 | min_data(); |
|
200 | min_data(); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | void tst_QCategoryAxis::min_animation() |
|
203 | void tst_QCategoryAxis::min_animation() | |
204 | { |
|
204 | { | |
205 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
205 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |
206 | min(); |
|
206 | min(); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | void tst_QCategoryAxis::range_raw_data() |
|
209 | void tst_QCategoryAxis::range_raw_data() | |
210 | { |
|
210 | { | |
211 | QTest::addColumn<qreal>("min"); |
|
211 | QTest::addColumn<qreal>("min"); | |
212 | QTest::addColumn<qreal>("max"); |
|
212 | QTest::addColumn<qreal>("max"); | |
213 | QTest::newRow("1.0 - 101.0") << -1.0 << 101.0; |
|
213 | QTest::newRow("1.0 - 101.0") << -1.0 << 101.0; | |
214 | QTest::newRow("25.0 - 75.0") << 25.0 << 75.0; |
|
214 | QTest::newRow("25.0 - 75.0") << 25.0 << 75.0; | |
215 | QTest::newRow("101.0") << 40.0 << 60.0; |
|
215 | QTest::newRow("101.0") << 40.0 << 60.0; | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | void tst_QCategoryAxis::range_raw() |
|
218 | void tst_QCategoryAxis::range_raw() | |
219 | { |
|
219 | { | |
220 | QFETCH(qreal, min); |
|
220 | QFETCH(qreal, min); | |
221 | QFETCH(qreal, max); |
|
221 | QFETCH(qreal, max); | |
222 |
|
222 | |||
223 | QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal))); |
|
223 | QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal))); | |
224 | QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal))); |
|
224 | QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal))); | |
225 | QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
225 | QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
226 |
|
226 | |||
227 | m_intervalsaxis->setRange(min, max); |
|
227 | m_intervalsaxis->setRange(min, max); | |
228 | QVERIFY2(qFuzzyIsNull(m_intervalsaxis->min() - min), "Min not equal"); |
|
228 | QVERIFY2(qFuzzyIsNull(m_intervalsaxis->min() - min), "Min not equal"); | |
229 | QVERIFY2(qFuzzyIsNull(m_intervalsaxis->max() - max), "Max not equal"); |
|
229 | QVERIFY2(qFuzzyIsNull(m_intervalsaxis->max() - max), "Max not equal"); | |
230 |
|
230 | |||
231 | QCOMPARE(spy0.count(), 1); |
|
231 | QCOMPARE(spy0.count(), 1); | |
232 | QCOMPARE(spy1.count(), 1); |
|
232 | QCOMPARE(spy1.count(), 1); | |
233 | QCOMPARE(spy2.count(), 1); |
|
233 | QCOMPARE(spy2.count(), 1); | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | void tst_QCategoryAxis::range_data() |
|
236 | void tst_QCategoryAxis::range_data() | |
237 | { |
|
237 | { | |
238 | range_raw_data(); |
|
238 | range_raw_data(); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | void tst_QCategoryAxis::range() |
|
241 | void tst_QCategoryAxis::range() | |
242 | { |
|
242 | { | |
243 | m_chart->setAxisX(m_intervalsaxis, m_series); |
|
243 | m_chart->setAxisX(m_intervalsaxis, m_series); | |
244 | m_view->show(); |
|
244 | m_view->show(); | |
245 | QTest::qWaitForWindowShown(m_view); |
|
245 | QTest::qWaitForWindowShown(m_view); | |
246 | range_raw(); |
|
246 | range_raw(); | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | void tst_QCategoryAxis::range_animation_data() |
|
249 | void tst_QCategoryAxis::range_animation_data() | |
250 | { |
|
250 | { | |
251 | range_data(); |
|
251 | range_data(); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | void tst_QCategoryAxis::range_animation() |
|
254 | void tst_QCategoryAxis::range_animation() | |
255 | { |
|
255 | { | |
256 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
256 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |
257 | range(); |
|
257 | range(); | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | void tst_QCategoryAxis::interval_data() |
|
260 | void tst_QCategoryAxis::interval_data() | |
261 | { |
|
261 | { | |
262 | // |
|
262 | // | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | void tst_QCategoryAxis::interval() |
|
265 | void tst_QCategoryAxis::interval() | |
266 | { |
|
266 | { | |
267 | // append one correct interval |
|
267 | // append one correct interval | |
268 | m_intervalsaxis->append("first", (qreal)45); |
|
268 | m_intervalsaxis->append("first", (qreal)45); | |
269 | QCOMPARE(m_intervalsaxis->intervalMin("first"), (qreal)0); |
|
269 | QCOMPARE(m_intervalsaxis->intervalMin("first"), (qreal)0); | |
270 | QCOMPARE(m_intervalsaxis->intervalMax("first"), (qreal)45); |
|
270 | QCOMPARE(m_intervalsaxis->intervalMax("first"), (qreal)45); | |
271 |
|
271 | |||
272 | // append one more correct interval |
|
272 | // append one more correct interval | |
273 | m_intervalsaxis->append("second", (qreal)75); |
|
273 | m_intervalsaxis->append("second", (qreal)75); | |
274 | QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)45); |
|
274 | QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)45); | |
275 | QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75); |
|
275 | QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75); | |
276 |
|
276 | |||
277 | // append one incorrect interval |
|
277 | // append one incorrect interval | |
278 | m_intervalsaxis->append("third", (qreal)15); |
|
278 | m_intervalsaxis->append("third", (qreal)15); | |
279 | QCOMPARE(m_intervalsaxis->count(), 2); |
|
279 | QCOMPARE(m_intervalsaxis->count(), 2); | |
280 | QCOMPARE(m_intervalsaxis->intervalMax(m_intervalsaxis->intervalsLabels().last()), (qreal)75); |
|
280 | QCOMPARE(m_intervalsaxis->intervalMax(m_intervalsaxis->intervalsLabels().last()), (qreal)75); | |
281 | // QCOMPARE(intervalMax("first"), (qreal)75); |
|
281 | // QCOMPARE(intervalMax("first"), (qreal)75); | |
282 |
|
282 | |||
283 | // append one more correct interval |
|
283 | // append one more correct interval | |
284 | m_intervalsaxis->append("third", (qreal)100); |
|
284 | m_intervalsaxis->append("third", (qreal)100); | |
285 | QCOMPARE(m_intervalsaxis->count(), 3); |
|
285 | QCOMPARE(m_intervalsaxis->count(), 3); | |
286 | QCOMPARE(m_intervalsaxis->intervalMin("third"), (qreal)75); |
|
286 | QCOMPARE(m_intervalsaxis->intervalMin("third"), (qreal)75); | |
287 | QCOMPARE(m_intervalsaxis->intervalMax("third"), (qreal)100); |
|
287 | QCOMPARE(m_intervalsaxis->intervalMax("third"), (qreal)100); | |
288 |
|
288 | |||
289 | // remove one interval |
|
289 | // remove one interval | |
290 | m_intervalsaxis->remove("first"); |
|
290 | m_intervalsaxis->remove("first"); | |
291 | QCOMPARE(m_intervalsaxis->count(), 2); |
|
291 | QCOMPARE(m_intervalsaxis->count(), 2); | |
292 | QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)0); // second interval should extend to firstInterval minimum |
|
292 | QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)0); // second interval should extend to firstInterval minimum | |
293 | QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75); |
|
293 | QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75); | |
294 |
|
294 | |||
295 | // remove one interval |
|
295 | // remove one interval | |
296 | m_intervalsaxis->replaceLabel("second", "replaced"); |
|
296 | m_intervalsaxis->replaceLabel("second", "replaced"); | |
297 | QCOMPARE(m_intervalsaxis->count(), 2); |
|
297 | QCOMPARE(m_intervalsaxis->count(), 2); | |
298 | QCOMPARE(m_intervalsaxis->intervalMin("replaced"), (qreal)0); // second interval should extend to firstInterval minimum |
|
298 | QCOMPARE(m_intervalsaxis->intervalMin("replaced"), (qreal)0); // second interval should extend to firstInterval minimum | |
299 | QCOMPARE(m_intervalsaxis->intervalMax("replaced"), (qreal)75); |
|
299 | QCOMPARE(m_intervalsaxis->intervalMax("replaced"), (qreal)75); | |
300 | } |
|
300 | } | |
301 |
|
301 | |||
302 | QTEST_MAIN(tst_QCategoryAxis) |
|
302 | QTEST_MAIN(tst_QCategoryAxis) | |
303 |
#include "tst_q |
|
303 | #include "tst_qcategoryaxis.moc" | |
304 |
|
304 |
General Comments 0
You need to be logged in to leave comments.
Login now