@@ -1,138 +1,138 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "chartbarcategoryaxisx_p.h" |
|
21 | #include "chartbarcategoryaxisx_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qbarcategoryaxis_p.h" |
|
23 | #include "qbarcategoryaxis_p.h" | |
24 | #include "abstractchartlayout_p.h" |
|
24 | #include "abstractchartlayout_p.h" | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 | #include <qmath.h> |
|
26 | #include <qmath.h> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | ChartBarCategoryAxisX::ChartBarCategoryAxisX(QBarCategoryAxis *axis, QGraphicsItem* item) |
|
30 | ChartBarCategoryAxisX::ChartBarCategoryAxisX(QBarCategoryAxis *axis, QGraphicsItem* item) | |
31 | : HorizontalAxis(axis, item, true), |
|
31 | : HorizontalAxis(axis, item, true), | |
32 | m_categoriesAxis(axis) |
|
32 | m_categoriesAxis(axis) | |
33 | { |
|
33 | { | |
34 | QObject::connect(m_categoriesAxis,SIGNAL(categoriesChanged()),this, SLOT(handleCategoriesChanged())); |
|
34 | QObject::connect(m_categoriesAxis,SIGNAL(categoriesChanged()),this, SLOT(handleCategoriesChanged())); | |
35 | handleCategoriesChanged(); |
|
35 | handleCategoriesChanged(); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | ChartBarCategoryAxisX::~ChartBarCategoryAxisX() |
|
38 | ChartBarCategoryAxisX::~ChartBarCategoryAxisX() | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const |
|
42 | QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const | |
43 | { |
|
43 | { | |
44 | QVector<qreal> points; |
|
44 | QVector<qreal> points; | |
45 | const QRectF& gridRect = gridGeometry(); |
|
45 | const QRectF& gridRect = gridGeometry(); | |
46 | qreal range = max() - min(); |
|
46 | qreal range = max() - min(); | |
47 | const qreal delta = gridRect.width() / range; |
|
47 | const qreal delta = gridRect.width() / range; | |
48 |
|
48 | |||
49 | if (delta < 2) |
|
49 | if (delta < 2) | |
50 | return points; |
|
50 | return points; | |
51 |
|
51 | |||
52 | qreal adjustedMin = min() + 0.5; |
|
52 | qreal adjustedMin = min() + 0.5; | |
53 | qreal offset = (ceil(adjustedMin) - adjustedMin) * delta; |
|
53 | qreal offset = (ceil(adjustedMin) - adjustedMin) * delta; | |
54 |
|
54 | |||
55 | int count = qFloor(range); |
|
55 | int count = qFloor(range); | |
56 | if (count < 1) |
|
56 | if (count < 1) | |
57 | return points; |
|
57 | return points; | |
58 |
|
58 | |||
59 | points.resize(count + 2); |
|
59 | points.resize(count + 2); | |
60 |
|
60 | |||
61 | for (int i = 0; i < count + 2; ++i) |
|
61 | for (int i = 0; i < count + 2; ++i) | |
62 | points[i] = offset + (qreal(i) * delta) + gridRect.left(); |
|
62 | points[i] = offset + (qreal(i) * delta) + gridRect.left(); | |
63 |
|
63 | |||
64 | return points; |
|
64 | return points; | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | QStringList ChartBarCategoryAxisX::createCategoryLabels(const QVector<qreal>& layout) const |
|
67 | QStringList ChartBarCategoryAxisX::createCategoryLabels(const QVector<qreal>& layout) const | |
68 | { |
|
68 | { | |
69 | QStringList result ; |
|
69 | QStringList result ; | |
70 | const QRectF &gridRect = gridGeometry(); |
|
70 | const QRectF &gridRect = gridGeometry(); | |
71 | qreal d = (max() - min()) / gridRect.width(); |
|
71 | qreal d = (max() - min()) / gridRect.width(); | |
72 |
|
72 | |||
73 | for (int i = 0; i < layout.count() - 1; ++i) { |
|
73 | for (int i = 0; i < layout.count() - 1; ++i) { | |
74 | qreal x = qFloor((((layout[i] + layout[i + 1]) / 2 - gridRect.left()) * d + min() + 0.5)); |
|
74 | qreal x = qFloor((((layout[i] + layout[i + 1]) / 2 - gridRect.left()) * d + min() + 0.5)); | |
75 | if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { |
|
75 | if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { | |
76 | result << m_categoriesAxis->categories().at(x); |
|
76 | result << m_categoriesAxis->categories().at(x); | |
77 | } else { |
|
77 | } else { | |
78 | // No label for x coordinate |
|
78 | // No label for x coordinate | |
79 | result << ""; |
|
79 | result << ""; | |
80 | } |
|
80 | } | |
81 | } |
|
81 | } | |
82 | result << ""; |
|
82 | result << ""; | |
83 | return result; |
|
83 | return result; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 |
|
86 | |||
87 | void ChartBarCategoryAxisX::updateGeometry() |
|
87 | void ChartBarCategoryAxisX::updateGeometry() | |
88 | { |
|
88 | { | |
89 | const QVector<qreal>& layout = ChartAxisElement::layout(); |
|
89 | const QVector<qreal>& layout = ChartAxisElement::layout(); | |
90 | if (layout.isEmpty()) |
|
90 | if (layout.isEmpty()) | |
91 | return; |
|
91 | return; | |
92 | setLabels(createCategoryLabels(layout)); |
|
92 | setLabels(createCategoryLabels(layout)); | |
93 | HorizontalAxis::updateGeometry(); |
|
93 | HorizontalAxis::updateGeometry(); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void ChartBarCategoryAxisX::handleCategoriesChanged() |
|
96 | void ChartBarCategoryAxisX::handleCategoriesChanged() | |
97 | { |
|
97 | { | |
98 | QGraphicsLayoutItem::updateGeometry(); |
|
98 | QGraphicsLayoutItem::updateGeometry(); | |
99 | if(presenter()) presenter()->layout()->invalidate(); |
|
99 | if(presenter()) presenter()->layout()->invalidate(); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
102 | QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
103 | { |
|
103 | { | |
104 | Q_UNUSED(constraint) |
|
104 | Q_UNUSED(constraint) | |
105 |
|
105 | |||
106 | QSizeF sh; |
|
106 | QSizeF sh; | |
107 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
107 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |
108 | QStringList ticksList = m_categoriesAxis->categories(); |
|
108 | QStringList ticksList = m_categoriesAxis->categories(); | |
109 |
|
109 | |||
110 | qreal width = 0; // Width is irrelevant for X axes with interval labels |
|
110 | qreal width = 0; // Width is irrelevant for X axes with interval labels | |
111 | qreal height = 0; |
|
111 | qreal height = 0; | |
112 |
|
112 | |||
113 | switch (which) { |
|
113 | switch (which) { | |
114 | case Qt::MinimumSize: { |
|
114 | case Qt::MinimumSize: { | |
115 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); |
|
115 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
116 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; |
|
116 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; | |
117 | sh = QSizeF(width, height); |
|
117 | sh = QSizeF(width, height); | |
118 | break; |
|
118 | break; | |
119 | } |
|
119 | } | |
120 | case Qt::PreferredSize:{ |
|
120 | case Qt::PreferredSize:{ | |
121 | qreal labelHeight = 0.0; |
|
121 | qreal labelHeight = 0.0; | |
122 | foreach (const QString& s, ticksList) { |
|
122 | foreach (const QString& s, ticksList) { | |
123 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); |
|
123 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
124 | labelHeight = qMax(rect.height(), labelHeight); |
|
124 | labelHeight = qMax(rect.height(), labelHeight); | |
125 | } |
|
125 | } | |
126 | height = labelHeight + labelPadding() + base.height() + 1.0; |
|
126 | height = labelHeight + labelPadding() + base.height() + 1.0; | |
127 | sh = QSizeF(width, height); |
|
127 | sh = QSizeF(width, height); | |
128 | break; |
|
128 | break; | |
129 | } |
|
129 | } | |
130 | default: |
|
130 | default: | |
131 | break; |
|
131 | break; | |
132 | } |
|
132 | } | |
133 | return sh; |
|
133 | return sh; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | #include "moc_chartbarcategoryaxisx_p.cpp" |
|
136 | #include "moc_chartbarcategoryaxisx_p.cpp" | |
137 |
|
137 | |||
138 | QTCOMMERCIALCHART_END_NAMESPACE |
|
138 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,140 +1,140 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "chartbarcategoryaxisy_p.h" |
|
21 | #include "chartbarcategoryaxisy_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qbarcategoryaxis_p.h" |
|
23 | #include "qbarcategoryaxis_p.h" | |
24 | #include "abstractchartlayout_p.h" |
|
24 | #include "abstractchartlayout_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 | ChartBarCategoryAxisY::ChartBarCategoryAxisY(QBarCategoryAxis *axis, QGraphicsItem* item) |
|
30 | ChartBarCategoryAxisY::ChartBarCategoryAxisY(QBarCategoryAxis *axis, QGraphicsItem* item) | |
31 | : VerticalAxis(axis, item, true), |
|
31 | : VerticalAxis(axis, item, true), | |
32 | m_categoriesAxis(axis) |
|
32 | m_categoriesAxis(axis) | |
33 | { |
|
33 | { | |
34 | QObject::connect( m_categoriesAxis,SIGNAL(categoriesChanged()),this, SLOT(handleCategoriesChanged())); |
|
34 | QObject::connect( m_categoriesAxis,SIGNAL(categoriesChanged()),this, SLOT(handleCategoriesChanged())); | |
35 | handleCategoriesChanged(); |
|
35 | handleCategoriesChanged(); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | ChartBarCategoryAxisY::~ChartBarCategoryAxisY() |
|
38 | ChartBarCategoryAxisY::~ChartBarCategoryAxisY() | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QVector<qreal> ChartBarCategoryAxisY::calculateLayout() const |
|
42 | QVector<qreal> ChartBarCategoryAxisY::calculateLayout() const | |
43 | { |
|
43 | { | |
44 | QVector<qreal> points; |
|
44 | QVector<qreal> points; | |
45 | const QRectF& gridRect = gridGeometry(); |
|
45 | const QRectF& gridRect = gridGeometry(); | |
46 | qreal range = max() - min(); |
|
46 | qreal range = max() - min(); | |
47 | const qreal delta = gridRect.height() / range; |
|
47 | const qreal delta = gridRect.height() / range; | |
48 |
|
48 | |||
49 | if (delta < 2) |
|
49 | if (delta < 2) | |
50 | return points; |
|
50 | return points; | |
51 |
|
51 | |||
52 | qreal adjustedMin = min() + 0.5; |
|
52 | qreal adjustedMin = min() + 0.5; | |
53 | qreal offset = (ceil(adjustedMin) - adjustedMin) * delta; |
|
53 | qreal offset = (ceil(adjustedMin) - adjustedMin) * delta; | |
54 |
|
54 | |||
55 | int count = qFloor(range); |
|
55 | int count = qFloor(range); | |
56 | if (count < 1) |
|
56 | if (count < 1) | |
57 | return points; |
|
57 | return points; | |
58 |
|
58 | |||
59 | points.resize(count + 2); |
|
59 | points.resize(count + 2); | |
60 |
|
60 | |||
61 | for (int i = 0; i < count + 2; ++i) |
|
61 | for (int i = 0; i < count + 2; ++i) | |
62 | points[i] = gridRect.bottom() - (qreal(i) * delta) - offset; |
|
62 | points[i] = gridRect.bottom() - (qreal(i) * delta) - offset; | |
63 |
|
63 | |||
64 | return points; |
|
64 | return points; | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | QStringList ChartBarCategoryAxisY::createCategoryLabels(const QVector<qreal>& layout) const |
|
67 | QStringList ChartBarCategoryAxisY::createCategoryLabels(const QVector<qreal>& layout) const | |
68 | { |
|
68 | { | |
69 | QStringList result; |
|
69 | QStringList result; | |
70 | const QRectF &gridRect = gridGeometry(); |
|
70 | const QRectF &gridRect = gridGeometry(); | |
71 | qreal d = (max() - min()) / gridRect.height(); |
|
71 | qreal d = (max() - min()) / gridRect.height(); | |
72 |
|
72 | |||
73 | for (int i = 0; i < layout.count() - 1; ++i) { |
|
73 | for (int i = 0; i < layout.count() - 1; ++i) { | |
74 | qreal x = qFloor(((gridRect.height() - (layout[i + 1] + layout[i]) / 2 + gridRect.top()) * d + min() + 0.5)); |
|
74 | qreal x = qFloor(((gridRect.height() - (layout[i + 1] + layout[i]) / 2 + gridRect.top()) * d + min() + 0.5)); | |
75 | if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { |
|
75 | if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { | |
76 | result << m_categoriesAxis->categories().at(x); |
|
76 | result << m_categoriesAxis->categories().at(x); | |
77 | } else { |
|
77 | } else { | |
78 | // No label for x coordinate |
|
78 | // No label for x coordinate | |
79 | result << ""; |
|
79 | result << ""; | |
80 | } |
|
80 | } | |
81 | } |
|
81 | } | |
82 | result << ""; |
|
82 | result << ""; | |
83 | return result; |
|
83 | return result; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void ChartBarCategoryAxisY::updateGeometry() |
|
86 | void ChartBarCategoryAxisY::updateGeometry() | |
87 | { |
|
87 | { | |
88 | const QVector<qreal>& layout = ChartAxisElement::layout(); |
|
88 | const QVector<qreal>& layout = ChartAxisElement::layout(); | |
89 | if (layout.isEmpty()) |
|
89 | if (layout.isEmpty()) | |
90 | return; |
|
90 | return; | |
91 | setLabels(createCategoryLabels(layout)); |
|
91 | setLabels(createCategoryLabels(layout)); | |
92 | VerticalAxis::updateGeometry(); |
|
92 | VerticalAxis::updateGeometry(); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | void ChartBarCategoryAxisY::handleCategoriesChanged() |
|
95 | void ChartBarCategoryAxisY::handleCategoriesChanged() | |
96 | { |
|
96 | { | |
97 | QGraphicsLayoutItem::updateGeometry(); |
|
97 | QGraphicsLayoutItem::updateGeometry(); | |
98 | if(presenter()) presenter()->layout()->invalidate(); |
|
98 | if(presenter()) presenter()->layout()->invalidate(); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
101 | QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
102 | { |
|
102 | { | |
103 | Q_UNUSED(constraint) |
|
103 | Q_UNUSED(constraint) | |
104 |
|
104 | |||
105 | QSizeF sh; |
|
105 | QSizeF sh; | |
106 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
106 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
107 | QStringList ticksList = m_categoriesAxis->categories(); |
|
107 | QStringList ticksList = m_categoriesAxis->categories(); | |
108 | qreal width = 0; |
|
108 | qreal width = 0; | |
109 | qreal height = 0; // Height is irrelevant for Y axes with interval labels |
|
109 | qreal height = 0; // Height is irrelevant for Y axes with interval labels | |
110 |
|
110 | |||
111 | switch (which) { |
|
111 | switch (which) { | |
112 | case Qt::MinimumSize: { |
|
112 | case Qt::MinimumSize: { | |
113 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); |
|
113 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
114 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; |
|
114 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; | |
115 | if (base.width() > 0.0) |
|
115 | if (base.width() > 0.0) | |
116 | width += labelPadding(); |
|
116 | width += labelPadding(); | |
117 | sh = QSizeF(width, height); |
|
117 | sh = QSizeF(width, height); | |
118 | break; |
|
118 | break; | |
119 | } |
|
119 | } | |
120 | case Qt::PreferredSize:{ |
|
120 | case Qt::PreferredSize:{ | |
121 | qreal labelWidth = 0.0; |
|
121 | qreal labelWidth = 0.0; | |
122 | foreach (const QString& s, ticksList) { |
|
122 | foreach (const QString& s, ticksList) { | |
123 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); |
|
123 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
124 | labelWidth = qMax(rect.width(), labelWidth); |
|
124 | labelWidth = qMax(rect.width(), labelWidth); | |
125 | } |
|
125 | } | |
126 | width = labelWidth + labelPadding() + base.width() + 1.0; |
|
126 | width = labelWidth + labelPadding() + base.width() + 1.0; | |
127 | if (base.width() > 0.0) |
|
127 | if (base.width() > 0.0) | |
128 | width += labelPadding(); |
|
128 | width += labelPadding(); | |
129 | sh = QSizeF(width, height); |
|
129 | sh = QSizeF(width, height); | |
130 | break; |
|
130 | break; | |
131 | } |
|
131 | } | |
132 | default: |
|
132 | default: | |
133 | break; |
|
133 | break; | |
134 | } |
|
134 | } | |
135 | return sh; |
|
135 | return sh; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | #include "moc_chartbarcategoryaxisy_p.cpp" |
|
138 | #include "moc_chartbarcategoryaxisy_p.cpp" | |
139 |
|
139 | |||
140 | QTCOMMERCIALCHART_END_NAMESPACE |
|
140 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,197 +1,195 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "cartesianchartaxis_p.h" |
|
21 | #include "cartesianchartaxis_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "qabstractaxis_p.h" |
|
23 | #include "qabstractaxis_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "abstractchartlayout_p.h" |
|
25 | #include "abstractchartlayout_p.h" | |
26 | #include "abstractdomain_p.h" |
|
26 | #include "abstractdomain_p.h" | |
27 | #include "linearrowitem_p.h" |
|
27 | #include "linearrowitem_p.h" | |
28 | #include <QValueAxis> |
|
28 | #include <QValueAxis> | |
29 | #include <QLogValueAxis> |
|
29 | #include <QLogValueAxis> | |
30 | #include <QGraphicsLayout> |
|
30 | #include <QGraphicsLayout> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | CartesianChartAxis::CartesianChartAxis(QAbstractAxis *axis, QGraphicsItem *item , bool intervalAxis) |
|
34 | CartesianChartAxis::CartesianChartAxis(QAbstractAxis *axis, QGraphicsItem *item , bool intervalAxis) | |
35 | : ChartAxisElement(axis, item, intervalAxis) |
|
35 | : ChartAxisElement(axis, item, intervalAxis) | |
36 | { |
|
36 | { | |
37 | Q_ASSERT(item); |
|
37 | Q_ASSERT(item); | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | CartesianChartAxis::~CartesianChartAxis() |
|
41 | CartesianChartAxis::~CartesianChartAxis() | |
42 | { |
|
42 | { | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | void CartesianChartAxis::createItems(int count) |
|
45 | void CartesianChartAxis::createItems(int count) | |
46 | { |
|
46 | { | |
47 | if (arrowItems().size() == 0) { |
|
47 | if (arrowItems().size() == 0) { | |
48 | QGraphicsLineItem *arrow = new LineArrowItem(this, this); |
|
48 | QGraphicsLineItem *arrow = new LineArrowItem(this, this); | |
49 | arrow->setPen(axis()->linePen()); |
|
49 | arrow->setPen(axis()->linePen()); | |
50 | arrowGroup()->addToGroup(arrow); |
|
50 | arrowGroup()->addToGroup(arrow); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | if (intervalAxis() && gridItems().size() == 0) { |
|
53 | if (intervalAxis() && gridItems().size() == 0) { | |
54 | for (int i = 0 ; i < 2 ; i ++){ |
|
54 | for (int i = 0 ; i < 2 ; i ++){ | |
55 | QGraphicsLineItem *item = new QGraphicsLineItem(this); |
|
55 | QGraphicsLineItem *item = new QGraphicsLineItem(this); | |
56 | item->setPen(axis()->gridLinePen()); |
|
56 | item->setPen(axis()->gridLinePen()); | |
57 | gridGroup()->addToGroup(item); |
|
57 | gridGroup()->addToGroup(item); | |
58 | } |
|
58 | } | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | for (int i = 0; i < count; ++i) { |
|
61 | for (int i = 0; i < count; ++i) { | |
62 | QGraphicsLineItem *arrow = new QGraphicsLineItem(this); |
|
62 | QGraphicsLineItem *arrow = new QGraphicsLineItem(this); | |
63 | QGraphicsLineItem *grid = new QGraphicsLineItem(this); |
|
63 | QGraphicsLineItem *grid = new QGraphicsLineItem(this); | |
64 |
QGraphics |
|
64 | QGraphicsTextItem *label = new QGraphicsTextItem(this); | |
65 |
QGraphics |
|
65 | QGraphicsTextItem *title = titleItem(); | |
66 | arrow->setPen(axis()->linePen()); |
|
66 | arrow->setPen(axis()->linePen()); | |
67 | grid->setPen(axis()->gridLinePen()); |
|
67 | grid->setPen(axis()->gridLinePen()); | |
68 | label->setFont(axis()->labelsFont()); |
|
68 | label->setFont(axis()->labelsFont()); | |
69 |
label->set |
|
69 | label->setDefaultTextColor(axis()->labelsBrush().color()); | |
70 | label->setBrush(axis()->labelsBrush()); |
|
|||
71 | label->setRotation(axis()->labelsAngle()); |
|
70 | label->setRotation(axis()->labelsAngle()); | |
72 | title->setFont(axis()->titleFont()); |
|
71 | title->setFont(axis()->titleFont()); | |
73 |
title->set |
|
72 | title->setDefaultTextColor(axis()->titleBrush().color()); | |
74 |
title->set |
|
73 | title->setHtml(axis()->titleText()); | |
75 | title->setText(axis()->titleText()); |
|
|||
76 | arrowGroup()->addToGroup(arrow); |
|
74 | arrowGroup()->addToGroup(arrow); | |
77 | gridGroup()->addToGroup(grid); |
|
75 | gridGroup()->addToGroup(grid); | |
78 | labelGroup()->addToGroup(label); |
|
76 | labelGroup()->addToGroup(label); | |
79 |
|
77 | |||
80 | if ((gridItems().size()) % 2 && gridItems().size() > 2) { |
|
78 | if ((gridItems().size()) % 2 && gridItems().size() > 2) { | |
81 | QGraphicsRectItem* shades = new QGraphicsRectItem(this); |
|
79 | QGraphicsRectItem* shades = new QGraphicsRectItem(this); | |
82 | shades->setPen(axis()->shadesPen()); |
|
80 | shades->setPen(axis()->shadesPen()); | |
83 | shades->setBrush(axis()->shadesBrush()); |
|
81 | shades->setBrush(axis()->shadesBrush()); | |
84 | shadeGroup()->addToGroup(shades); |
|
82 | shadeGroup()->addToGroup(shades); | |
85 | } |
|
83 | } | |
86 | } |
|
84 | } | |
87 |
|
85 | |||
88 | } |
|
86 | } | |
89 |
|
87 | |||
90 | void CartesianChartAxis::deleteItems(int count) |
|
88 | void CartesianChartAxis::deleteItems(int count) | |
91 | { |
|
89 | { | |
92 | QList<QGraphicsItem *> lines = gridItems(); |
|
90 | QList<QGraphicsItem *> lines = gridItems(); | |
93 | QList<QGraphicsItem *> labels = labelItems(); |
|
91 | QList<QGraphicsItem *> labels = labelItems(); | |
94 | QList<QGraphicsItem *> shades = shadeItems(); |
|
92 | QList<QGraphicsItem *> shades = shadeItems(); | |
95 | QList<QGraphicsItem *> axis = arrowItems(); |
|
93 | QList<QGraphicsItem *> axis = arrowItems(); | |
96 |
|
94 | |||
97 | for (int i = 0; i < count; ++i) { |
|
95 | for (int i = 0; i < count; ++i) { | |
98 | if (lines.size() % 2 && lines.size() > 1) |
|
96 | if (lines.size() % 2 && lines.size() > 1) | |
99 | delete(shades.takeLast()); |
|
97 | delete(shades.takeLast()); | |
100 | delete(lines.takeLast()); |
|
98 | delete(lines.takeLast()); | |
101 | delete(labels.takeLast()); |
|
99 | delete(labels.takeLast()); | |
102 | delete(axis.takeLast()); |
|
100 | delete(axis.takeLast()); | |
103 | } |
|
101 | } | |
104 | } |
|
102 | } | |
105 |
|
103 | |||
106 | void CartesianChartAxis::updateLayout(QVector<qreal> &layout) |
|
104 | void CartesianChartAxis::updateLayout(QVector<qreal> &layout) | |
107 | { |
|
105 | { | |
108 | int diff = ChartAxisElement::layout().size() - layout.size(); |
|
106 | int diff = ChartAxisElement::layout().size() - layout.size(); | |
109 |
|
107 | |||
110 | if (diff > 0) |
|
108 | if (diff > 0) | |
111 | deleteItems(diff); |
|
109 | deleteItems(diff); | |
112 | else if (diff < 0) |
|
110 | else if (diff < 0) | |
113 | createItems(-diff); |
|
111 | createItems(-diff); | |
114 |
|
112 | |||
115 | if (animation()) { |
|
113 | if (animation()) { | |
116 | switch (presenter()->state()) { |
|
114 | switch (presenter()->state()) { | |
117 | case ChartPresenter::ZoomInState: |
|
115 | case ChartPresenter::ZoomInState: | |
118 | animation()->setAnimationType(AxisAnimation::ZoomInAnimation); |
|
116 | animation()->setAnimationType(AxisAnimation::ZoomInAnimation); | |
119 | animation()->setAnimationPoint(presenter()->statePoint()); |
|
117 | animation()->setAnimationPoint(presenter()->statePoint()); | |
120 | break; |
|
118 | break; | |
121 | case ChartPresenter::ZoomOutState: |
|
119 | case ChartPresenter::ZoomOutState: | |
122 | animation()->setAnimationType(AxisAnimation::ZoomOutAnimation); |
|
120 | animation()->setAnimationType(AxisAnimation::ZoomOutAnimation); | |
123 | animation()->setAnimationPoint(presenter()->statePoint()); |
|
121 | animation()->setAnimationPoint(presenter()->statePoint()); | |
124 | break; |
|
122 | break; | |
125 | case ChartPresenter::ScrollUpState: |
|
123 | case ChartPresenter::ScrollUpState: | |
126 | case ChartPresenter::ScrollLeftState: |
|
124 | case ChartPresenter::ScrollLeftState: | |
127 | animation()->setAnimationType(AxisAnimation::MoveBackwordAnimation); |
|
125 | animation()->setAnimationType(AxisAnimation::MoveBackwordAnimation); | |
128 | break; |
|
126 | break; | |
129 | case ChartPresenter::ScrollDownState: |
|
127 | case ChartPresenter::ScrollDownState: | |
130 | case ChartPresenter::ScrollRightState: |
|
128 | case ChartPresenter::ScrollRightState: | |
131 | animation()->setAnimationType(AxisAnimation::MoveForwardAnimation); |
|
129 | animation()->setAnimationType(AxisAnimation::MoveForwardAnimation); | |
132 | break; |
|
130 | break; | |
133 | case ChartPresenter::ShowState: |
|
131 | case ChartPresenter::ShowState: | |
134 | animation()->setAnimationType(AxisAnimation::DefaultAnimation); |
|
132 | animation()->setAnimationType(AxisAnimation::DefaultAnimation); | |
135 | break; |
|
133 | break; | |
136 | } |
|
134 | } | |
137 | animation()->setValues(ChartAxisElement::layout(), layout); |
|
135 | animation()->setValues(ChartAxisElement::layout(), layout); | |
138 | presenter()->startAnimation(animation()); |
|
136 | presenter()->startAnimation(animation()); | |
139 | } else { |
|
137 | } else { | |
140 | setLayout(layout); |
|
138 | setLayout(layout); | |
141 | updateGeometry(); |
|
139 | updateGeometry(); | |
142 | } |
|
140 | } | |
143 | } |
|
141 | } | |
144 |
|
142 | |||
145 | bool CartesianChartAxis::isEmpty() |
|
143 | bool CartesianChartAxis::isEmpty() | |
146 | { |
|
144 | { | |
147 | return axisGeometry().isEmpty() |
|
145 | return axisGeometry().isEmpty() | |
148 | || gridGeometry().isEmpty() |
|
146 | || gridGeometry().isEmpty() | |
149 | || qFuzzyCompare(min(), max()); |
|
147 | || qFuzzyCompare(min(), max()); | |
150 | } |
|
148 | } | |
151 |
|
149 | |||
152 | void CartesianChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) |
|
150 | void CartesianChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) | |
153 | { |
|
151 | { | |
154 | m_gridRect = grid; |
|
152 | m_gridRect = grid; | |
155 | setAxisGeometry(axis); |
|
153 | setAxisGeometry(axis); | |
156 |
|
154 | |||
157 | if (isEmpty()) |
|
155 | if (isEmpty()) | |
158 | return; |
|
156 | return; | |
159 |
|
157 | |||
160 | QVector<qreal> layout = calculateLayout(); |
|
158 | QVector<qreal> layout = calculateLayout(); | |
161 | updateLayout(layout); |
|
159 | updateLayout(layout); | |
162 | } |
|
160 | } | |
163 |
|
161 | |||
164 | QSizeF CartesianChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
162 | QSizeF CartesianChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
165 | { |
|
163 | { | |
166 | Q_UNUSED(which); |
|
164 | Q_UNUSED(which); | |
167 | Q_UNUSED(constraint); |
|
165 | Q_UNUSED(constraint); | |
168 | return QSizeF(); |
|
166 | return QSizeF(); | |
169 | } |
|
167 | } | |
170 |
|
168 | |||
171 | void CartesianChartAxis::handleArrowPenChanged(const QPen &pen) |
|
169 | void CartesianChartAxis::handleArrowPenChanged(const QPen &pen) | |
172 | { |
|
170 | { | |
173 | foreach (QGraphicsItem *item, arrowItems()) |
|
171 | foreach (QGraphicsItem *item, arrowItems()) | |
174 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
172 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
175 | } |
|
173 | } | |
176 |
|
174 | |||
177 | void CartesianChartAxis::handleGridPenChanged(const QPen &pen) |
|
175 | void CartesianChartAxis::handleGridPenChanged(const QPen &pen) | |
178 | { |
|
176 | { | |
179 | foreach (QGraphicsItem *item, gridItems()) |
|
177 | foreach (QGraphicsItem *item, gridItems()) | |
180 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
178 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
181 | } |
|
179 | } | |
182 |
|
180 | |||
183 | void CartesianChartAxis::handleShadesBrushChanged(const QBrush &brush) |
|
181 | void CartesianChartAxis::handleShadesBrushChanged(const QBrush &brush) | |
184 | { |
|
182 | { | |
185 | foreach (QGraphicsItem *item, shadeItems()) |
|
183 | foreach (QGraphicsItem *item, shadeItems()) | |
186 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); |
|
184 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); | |
187 | } |
|
185 | } | |
188 |
|
186 | |||
189 | void CartesianChartAxis::handleShadesPenChanged(const QPen &pen) |
|
187 | void CartesianChartAxis::handleShadesPenChanged(const QPen &pen) | |
190 | { |
|
188 | { | |
191 | foreach (QGraphicsItem *item, shadeItems()) |
|
189 | foreach (QGraphicsItem *item, shadeItems()) | |
192 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); |
|
190 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); | |
193 | } |
|
191 | } | |
194 |
|
192 | |||
195 | #include "moc_cartesianchartaxis_p.cpp" |
|
193 | #include "moc_cartesianchartaxis_p.cpp" | |
196 |
|
194 | |||
197 | QTCOMMERCIALCHART_END_NAMESPACE |
|
195 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,118 +1,118 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "chartcategoryaxisx_p.h" |
|
21 | #include "chartcategoryaxisx_p.h" | |
22 | #include "qcategoryaxis.h" |
|
22 | #include "qcategoryaxis.h" | |
23 | #include "qabstractaxis.h" |
|
23 | #include "qabstractaxis.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "abstractchartlayout_p.h" |
|
25 | #include "abstractchartlayout_p.h" | |
26 | #include <QGraphicsLayout> |
|
26 | #include <QGraphicsLayout> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item) |
|
31 | ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item) | |
32 | : HorizontalAxis(axis, item, true), |
|
32 | : HorizontalAxis(axis, item, true), | |
33 | m_axis(axis) |
|
33 | m_axis(axis) | |
34 | { |
|
34 | { | |
35 | QObject::connect(axis, SIGNAL(categoriesChanged()), this, SLOT(handleCategoriesChanged())); |
|
35 | QObject::connect(axis, SIGNAL(categoriesChanged()), this, SLOT(handleCategoriesChanged())); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | ChartCategoryAxisX::~ChartCategoryAxisX() |
|
38 | ChartCategoryAxisX::~ChartCategoryAxisX() | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QVector<qreal> ChartCategoryAxisX::calculateLayout() const |
|
42 | QVector<qreal> ChartCategoryAxisX::calculateLayout() const | |
43 | { |
|
43 | { | |
44 | int tickCount = m_axis->categoriesLabels().count() + 1; |
|
44 | int tickCount = m_axis->categoriesLabels().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 | const QRectF &gridRect = gridGeometry(); |
|
50 | const QRectF &gridRect = gridGeometry(); | |
51 | qreal range = max() - min(); |
|
51 | qreal range = max() - min(); | |
52 | if (range > 0) { |
|
52 | if (range > 0) { | |
53 | points.resize(tickCount); |
|
53 | points.resize(tickCount); | |
54 | qreal scale = gridRect.width() / range; |
|
54 | qreal scale = gridRect.width() / range; | |
55 | for (int i = 0; i < tickCount; ++i) { |
|
55 | for (int i = 0; i < tickCount; ++i) { | |
56 | if (i < tickCount - 1) { |
|
56 | if (i < tickCount - 1) { | |
57 | qreal x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left(); |
|
57 | qreal x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left(); | |
58 | points[i] = x; |
|
58 | points[i] = x; | |
59 | } else { |
|
59 | } else { | |
60 | qreal x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left(); |
|
60 | qreal x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left(); | |
61 | points[i] = x; |
|
61 | points[i] = x; | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | return points; |
|
66 | return points; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void ChartCategoryAxisX::updateGeometry() |
|
69 | void ChartCategoryAxisX::updateGeometry() | |
70 | { |
|
70 | { | |
71 | //TODO: this is not optimal when many categories :( , create only visible lables |
|
71 | //TODO: this is not optimal when many categories :( , create only visible lables | |
72 | setLabels(m_axis->categoriesLabels() << ""); |
|
72 | setLabels(m_axis->categoriesLabels() << ""); | |
73 | HorizontalAxis::updateGeometry(); |
|
73 | HorizontalAxis::updateGeometry(); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
76 | QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
77 | { |
|
77 | { | |
78 | Q_UNUSED(constraint) |
|
78 | Q_UNUSED(constraint) | |
79 |
|
79 | |||
80 | QSizeF sh; |
|
80 | QSizeF sh; | |
81 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
81 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |
82 | QStringList ticksList = m_axis->categoriesLabels(); |
|
82 | QStringList ticksList = m_axis->categoriesLabels(); | |
83 | qreal width = 0; // Width is irrelevant for X axes with interval labels |
|
83 | qreal width = 0; // Width is irrelevant for X axes with interval labels | |
84 | qreal height = 0; |
|
84 | qreal height = 0; | |
85 |
|
85 | |||
86 | switch (which) { |
|
86 | switch (which) { | |
87 | case Qt::MinimumSize: { |
|
87 | case Qt::MinimumSize: { | |
88 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); |
|
88 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
89 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; |
|
89 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; | |
90 | sh = QSizeF(width, height); |
|
90 | sh = QSizeF(width, height); | |
91 | break; |
|
91 | break; | |
92 | } |
|
92 | } | |
93 | case Qt::PreferredSize: { |
|
93 | case Qt::PreferredSize: { | |
94 | qreal labelHeight = 0.0; |
|
94 | qreal labelHeight = 0.0; | |
95 | foreach (const QString& s, ticksList) { |
|
95 | foreach (const QString& s, ticksList) { | |
96 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); |
|
96 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
97 | labelHeight = qMax(rect.height(), labelHeight); |
|
97 | labelHeight = qMax(rect.height(), labelHeight); | |
98 | } |
|
98 | } | |
99 | height = labelHeight + labelPadding() + base.height() + 1.0; |
|
99 | height = labelHeight + labelPadding() + base.height() + 1.0; | |
100 | sh = QSizeF(width, height); |
|
100 | sh = QSizeF(width, height); | |
101 | break; |
|
101 | break; | |
102 | } |
|
102 | } | |
103 | default: |
|
103 | default: | |
104 | break; |
|
104 | break; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | return sh; |
|
107 | return sh; | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void ChartCategoryAxisX::handleCategoriesChanged() |
|
110 | void ChartCategoryAxisX::handleCategoriesChanged() | |
111 | { |
|
111 | { | |
112 | QGraphicsLayoutItem::updateGeometry(); |
|
112 | QGraphicsLayoutItem::updateGeometry(); | |
113 | presenter()->layout()->invalidate(); |
|
113 | presenter()->layout()->invalidate(); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | #include "moc_chartcategoryaxisx_p.cpp" |
|
116 | #include "moc_chartcategoryaxisx_p.cpp" | |
117 |
|
117 | |||
118 | QTCOMMERCIALCHART_END_NAMESPACE |
|
118 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,117 +1,117 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "chartcategoryaxisy_p.h" |
|
21 | #include "chartcategoryaxisy_p.h" | |
22 | #include "qcategoryaxis.h" |
|
22 | #include "qcategoryaxis.h" | |
23 | #include "qabstractaxis.h" |
|
23 | #include "qabstractaxis.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "abstractchartlayout_p.h" |
|
25 | #include "abstractchartlayout_p.h" | |
26 | #include <QGraphicsLayout> |
|
26 | #include <QGraphicsLayout> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 | #include <QDebug> |
|
28 | #include <QDebug> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ChartCategoryAxisY::ChartCategoryAxisY(QCategoryAxis *axis, QGraphicsItem* item) |
|
32 | ChartCategoryAxisY::ChartCategoryAxisY(QCategoryAxis *axis, QGraphicsItem* item) | |
33 | : VerticalAxis(axis, item, true), |
|
33 | : VerticalAxis(axis, item, true), | |
34 | m_axis(axis) |
|
34 | m_axis(axis) | |
35 | { |
|
35 | { | |
36 | QObject::connect(axis, SIGNAL(categoriesChanged()), this, SLOT(handleCategoriesChanged())); |
|
36 | QObject::connect(axis, SIGNAL(categoriesChanged()), this, SLOT(handleCategoriesChanged())); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartCategoryAxisY::~ChartCategoryAxisY() |
|
39 | ChartCategoryAxisY::~ChartCategoryAxisY() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QVector<qreal> ChartCategoryAxisY::calculateLayout() const |
|
43 | QVector<qreal> ChartCategoryAxisY::calculateLayout() const | |
44 | { |
|
44 | { | |
45 | int tickCount = m_axis->categoriesLabels().count() + 1; |
|
45 | int tickCount = m_axis->categoriesLabels().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 | const QRectF &gridRect = gridGeometry(); |
|
51 | const QRectF &gridRect = gridGeometry(); | |
52 | qreal range = max() - min(); |
|
52 | qreal range = max() - min(); | |
53 | if (range > 0) { |
|
53 | if (range > 0) { | |
54 | points.resize(tickCount); |
|
54 | points.resize(tickCount); | |
55 | qreal scale = gridRect.height() / range; |
|
55 | qreal scale = gridRect.height() / range; | |
56 | for (int i = 0; i < tickCount; ++i) { |
|
56 | for (int i = 0; i < tickCount; ++i) { | |
57 | if (i < tickCount - 1) { |
|
57 | if (i < tickCount - 1) { | |
58 | qreal y = -(m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.bottom(); |
|
58 | qreal y = -(m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.bottom(); | |
59 | points[i] = y; |
|
59 | points[i] = y; | |
60 | } else { |
|
60 | } else { | |
61 | qreal y = -(m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.bottom(); |
|
61 | qreal y = -(m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.bottom(); | |
62 | points[i] = y; |
|
62 | points[i] = y; | |
63 | } |
|
63 | } | |
64 | } |
|
64 | } | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | return points; |
|
67 | return points; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void ChartCategoryAxisY::updateGeometry() |
|
70 | void ChartCategoryAxisY::updateGeometry() | |
71 | { |
|
71 | { | |
72 | setLabels(m_axis->categoriesLabels() << ""); |
|
72 | setLabels(m_axis->categoriesLabels() << ""); | |
73 | VerticalAxis::updateGeometry(); |
|
73 | VerticalAxis::updateGeometry(); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
76 | QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
77 | { |
|
77 | { | |
78 | Q_UNUSED(constraint) |
|
78 | Q_UNUSED(constraint) | |
79 |
|
79 | |||
80 | QSizeF sh; |
|
80 | QSizeF sh; | |
81 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
81 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
82 | QStringList ticksList = m_axis->categoriesLabels(); |
|
82 | QStringList ticksList = m_axis->categoriesLabels(); | |
83 | qreal width = 0; |
|
83 | qreal width = 0; | |
84 | qreal height = 0; // Height is irrelevant for Y axes with interval labels |
|
84 | qreal height = 0; // Height is irrelevant for Y axes with interval labels | |
85 |
|
85 | |||
86 | switch (which) { |
|
86 | switch (which) { | |
87 | case Qt::MinimumSize: { |
|
87 | case Qt::MinimumSize: { | |
88 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); |
|
88 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
89 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; |
|
89 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; | |
90 | sh = QSizeF(width, height); |
|
90 | sh = QSizeF(width, height); | |
91 | break; |
|
91 | break; | |
92 | } |
|
92 | } | |
93 | case Qt::PreferredSize: { |
|
93 | case Qt::PreferredSize: { | |
94 | qreal labelWidth = 0.0; |
|
94 | qreal labelWidth = 0.0; | |
95 | foreach (const QString& s, ticksList) { |
|
95 | foreach (const QString& s, ticksList) { | |
96 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); |
|
96 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
97 | labelWidth = qMax(rect.width(), labelWidth); |
|
97 | labelWidth = qMax(rect.width(), labelWidth); | |
98 | } |
|
98 | } | |
99 | width = labelWidth + labelPadding() + base.width() + 1.0; |
|
99 | width = labelWidth + labelPadding() + base.width() + 1.0; | |
100 | sh = QSizeF(width, height); |
|
100 | sh = QSizeF(width, height); | |
101 | break; |
|
101 | break; | |
102 | } |
|
102 | } | |
103 | default: |
|
103 | default: | |
104 | break; |
|
104 | break; | |
105 | } |
|
105 | } | |
106 | return sh; |
|
106 | return sh; | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void ChartCategoryAxisY::handleCategoriesChanged() |
|
109 | void ChartCategoryAxisY::handleCategoriesChanged() | |
110 | { |
|
110 | { | |
111 | QGraphicsLayoutItem::updateGeometry(); |
|
111 | QGraphicsLayoutItem::updateGeometry(); | |
112 | presenter()->layout()->invalidate(); |
|
112 | presenter()->layout()->invalidate(); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | #include "moc_chartcategoryaxisy_p.cpp" |
|
115 | #include "moc_chartcategoryaxisy_p.cpp" | |
116 |
|
116 | |||
117 | QTCOMMERCIALCHART_END_NAMESPACE |
|
117 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,384 +1,352 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "chartaxiselement_p.h" |
|
21 | #include "chartaxiselement_p.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "abstractchartlayout_p.h" |
|
24 | #include "abstractchartlayout_p.h" | |
25 | #include <qmath.h> |
|
25 | #include <qmath.h> | |
26 | #include <QDateTime> |
|
26 | #include <QDateTime> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | QGraphicsSimpleTextItem *dummyTextItem = 0; |
|
30 | static const char *labelFormatMatchString = "%[\\-\\+#\\s\\d\\.lhjztL]*([dicuoxfegXFEG])"; | |
31 | class StaticDeleter |
|
31 | static QRegExp *labelFormatMatcher = 0; | |
|
32 | class StaticLabelFormatMatcherDeleter | |||
32 | { |
|
33 | { | |
33 | public: |
|
34 | public: | |
34 | StaticDeleter() {} |
|
35 | StaticLabelFormatMatcherDeleter() {} | |
35 |
~StaticDeleter() { delete |
|
36 | ~StaticLabelFormatMatcherDeleter() { delete labelFormatMatcher; } | |
36 | }; |
|
37 | }; | |
37 | StaticDeleter staticDeleter; |
|
38 | StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter; | |
38 |
|
39 | |||
39 | ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) |
|
40 | ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) | |
40 | : ChartElement(item), |
|
41 | : ChartElement(item), | |
41 | m_axis(axis), |
|
42 | m_axis(axis), | |
42 | m_animation(0), |
|
43 | m_animation(0), | |
43 | m_grid(new QGraphicsItemGroup(item)), |
|
44 | m_grid(new QGraphicsItemGroup(item)), | |
44 | m_arrow(new QGraphicsItemGroup(item)), |
|
45 | m_arrow(new QGraphicsItemGroup(item)), | |
45 | m_shades(new QGraphicsItemGroup(item)), |
|
46 | m_shades(new QGraphicsItemGroup(item)), | |
46 | m_labels(new QGraphicsItemGroup(item)), |
|
47 | m_labels(new QGraphicsItemGroup(item)), | |
47 |
m_title(new QGraphics |
|
48 | m_title(new QGraphicsTextItem(item)), | |
48 | m_intervalAxis(intervalAxis) |
|
49 | m_intervalAxis(intervalAxis) | |
49 |
|
50 | |||
50 | { |
|
51 | { | |
51 | //initial initialization |
|
52 | //initial initialization | |
52 | if (!dummyTextItem) |
|
|||
53 | dummyTextItem = new QGraphicsSimpleTextItem; |
|
|||
54 | m_arrow->setHandlesChildEvents(false); |
|
53 | m_arrow->setHandlesChildEvents(false); | |
55 | m_arrow->setZValue(ChartPresenter::AxisZValue); |
|
54 | m_arrow->setZValue(ChartPresenter::AxisZValue); | |
56 | m_labels->setZValue(ChartPresenter::AxisZValue); |
|
55 | m_labels->setZValue(ChartPresenter::AxisZValue); | |
57 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
56 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
58 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
57 | m_grid->setZValue(ChartPresenter::GridZValue); | |
59 | m_title->setZValue(ChartPresenter::GridZValue); |
|
58 | m_title->setZValue(ChartPresenter::GridZValue); | |
60 | handleVisibleChanged(axis->isVisible()); |
|
59 | handleVisibleChanged(axis->isVisible()); | |
61 | connectSlots(); |
|
60 | connectSlots(); | |
62 |
|
61 | |||
63 | setFlag(QGraphicsItem::ItemHasNoContents, true); |
|
62 | setFlag(QGraphicsItem::ItemHasNoContents, true); | |
64 | } |
|
63 | } | |
65 |
|
64 | |||
66 | ChartAxisElement::~ChartAxisElement() |
|
65 | ChartAxisElement::~ChartAxisElement() | |
67 | { |
|
66 | { | |
68 | } |
|
67 | } | |
69 |
|
68 | |||
70 | void ChartAxisElement::connectSlots() |
|
69 | void ChartAxisElement::connectSlots() | |
71 | { |
|
70 | { | |
72 | QObject::connect(axis(), SIGNAL(visibleChanged(bool)), this, SLOT(handleVisibleChanged(bool))); |
|
71 | QObject::connect(axis(), SIGNAL(visibleChanged(bool)), this, SLOT(handleVisibleChanged(bool))); | |
73 | QObject::connect(axis(), SIGNAL(lineVisibleChanged(bool)), this, SLOT(handleArrowVisibleChanged(bool))); |
|
72 | QObject::connect(axis(), SIGNAL(lineVisibleChanged(bool)), this, SLOT(handleArrowVisibleChanged(bool))); | |
74 | QObject::connect(axis(), SIGNAL(gridVisibleChanged(bool)), this, SLOT(handleGridVisibleChanged(bool))); |
|
73 | QObject::connect(axis(), SIGNAL(gridVisibleChanged(bool)), this, SLOT(handleGridVisibleChanged(bool))); | |
75 | QObject::connect(axis(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); |
|
74 | QObject::connect(axis(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); | |
76 | QObject::connect(axis(), SIGNAL(shadesVisibleChanged(bool)), this, SLOT(handleShadesVisibleChanged(bool))); |
|
75 | QObject::connect(axis(), SIGNAL(shadesVisibleChanged(bool)), this, SLOT(handleShadesVisibleChanged(bool))); | |
77 | QObject::connect(axis(), SIGNAL(labelsAngleChanged(int)), this, SLOT(handleLabelsAngleChanged(int))); |
|
76 | QObject::connect(axis(), SIGNAL(labelsAngleChanged(int)), this, SLOT(handleLabelsAngleChanged(int))); | |
78 | QObject::connect(axis(), SIGNAL(linePenChanged(const QPen&)), this, SLOT(handleArrowPenChanged(const QPen&))); |
|
77 | QObject::connect(axis(), SIGNAL(linePenChanged(const QPen&)), this, SLOT(handleArrowPenChanged(const QPen&))); | |
79 | QObject::connect(axis(), SIGNAL(labelsPenChanged(const QPen&)), this, SLOT(handleLabelsPenChanged(const QPen&))); |
|
78 | QObject::connect(axis(), SIGNAL(labelsPenChanged(const QPen&)), this, SLOT(handleLabelsPenChanged(const QPen&))); | |
80 | QObject::connect(axis(), SIGNAL(labelsBrushChanged(const QBrush&)), this, SLOT(handleLabelsBrushChanged(const QBrush&))); |
|
79 | QObject::connect(axis(), SIGNAL(labelsBrushChanged(const QBrush&)), this, SLOT(handleLabelsBrushChanged(const QBrush&))); | |
81 | QObject::connect(axis(), SIGNAL(labelsFontChanged(const QFont&)), this, SLOT(handleLabelsFontChanged(const QFont&))); |
|
80 | QObject::connect(axis(), SIGNAL(labelsFontChanged(const QFont&)), this, SLOT(handleLabelsFontChanged(const QFont&))); | |
82 | QObject::connect(axis(), SIGNAL(gridLinePenChanged(const QPen&)), this, SLOT(handleGridPenChanged(const QPen&))); |
|
81 | QObject::connect(axis(), SIGNAL(gridLinePenChanged(const QPen&)), this, SLOT(handleGridPenChanged(const QPen&))); | |
83 | QObject::connect(axis(), SIGNAL(shadesPenChanged(const QPen&)), this, SLOT(handleShadesPenChanged(const QPen&))); |
|
82 | QObject::connect(axis(), SIGNAL(shadesPenChanged(const QPen&)), this, SLOT(handleShadesPenChanged(const QPen&))); | |
84 | QObject::connect(axis(), SIGNAL(shadesBrushChanged(const QBrush&)), this, SLOT(handleShadesBrushChanged(const QBrush&))); |
|
83 | QObject::connect(axis(), SIGNAL(shadesBrushChanged(const QBrush&)), this, SLOT(handleShadesBrushChanged(const QBrush&))); | |
85 | QObject::connect(axis(), SIGNAL(titleTextChanged(const QString&)), this, SLOT(handleTitleTextChanged(const QString&))); |
|
84 | QObject::connect(axis(), SIGNAL(titleTextChanged(const QString&)), this, SLOT(handleTitleTextChanged(const QString&))); | |
86 | QObject::connect(axis(), SIGNAL(titleFontChanged(const QFont&)), this, SLOT(handleTitleFontChanged(const QFont&))); |
|
85 | QObject::connect(axis(), SIGNAL(titleFontChanged(const QFont&)), this, SLOT(handleTitleFontChanged(const QFont&))); | |
87 | QObject::connect(axis(), SIGNAL(titlePenChanged(const QPen&)), this, SLOT(handleTitlePenChanged(const QPen&))); |
|
86 | QObject::connect(axis(), SIGNAL(titlePenChanged(const QPen&)), this, SLOT(handleTitlePenChanged(const QPen&))); | |
88 | QObject::connect(axis(), SIGNAL(titleBrushChanged(const QBrush&)), this, SLOT(handleTitleBrushChanged(const QBrush&))); |
|
87 | QObject::connect(axis(), SIGNAL(titleBrushChanged(const QBrush&)), this, SLOT(handleTitleBrushChanged(const QBrush&))); | |
89 | QObject::connect(axis(), SIGNAL(titleVisibleChanged(bool)), this, SLOT(handleTitleVisibleChanged(bool))); |
|
88 | QObject::connect(axis(), SIGNAL(titleVisibleChanged(bool)), this, SLOT(handleTitleVisibleChanged(bool))); | |
90 | QObject::connect(axis()->d_ptr.data(), SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(handleRangeChanged(qreal, qreal))); |
|
89 | QObject::connect(axis()->d_ptr.data(), SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(handleRangeChanged(qreal, qreal))); | |
91 | } |
|
90 | } | |
92 |
|
91 | |||
93 | void ChartAxisElement::handleArrowVisibleChanged(bool visible) |
|
92 | void ChartAxisElement::handleArrowVisibleChanged(bool visible) | |
94 | { |
|
93 | { | |
95 | m_arrow->setVisible(visible); |
|
94 | m_arrow->setVisible(visible); | |
96 | } |
|
95 | } | |
97 |
|
96 | |||
98 | void ChartAxisElement::handleGridVisibleChanged(bool visible) |
|
97 | void ChartAxisElement::handleGridVisibleChanged(bool visible) | |
99 | { |
|
98 | { | |
100 | m_grid->setVisible(visible); |
|
99 | m_grid->setVisible(visible); | |
101 | } |
|
100 | } | |
102 |
|
101 | |||
103 | void ChartAxisElement::handleLabelsVisibleChanged(bool visible) |
|
102 | void ChartAxisElement::handleLabelsVisibleChanged(bool visible) | |
104 | { |
|
103 | { | |
105 | QGraphicsLayoutItem::updateGeometry(); |
|
104 | QGraphicsLayoutItem::updateGeometry(); | |
106 | presenter()->layout()->invalidate(); |
|
105 | presenter()->layout()->invalidate(); | |
107 | m_labels->setVisible(visible); |
|
106 | m_labels->setVisible(visible); | |
108 | } |
|
107 | } | |
109 |
|
108 | |||
110 | void ChartAxisElement::handleShadesVisibleChanged(bool visible) |
|
109 | void ChartAxisElement::handleShadesVisibleChanged(bool visible) | |
111 | { |
|
110 | { | |
112 | m_shades->setVisible(visible); |
|
111 | m_shades->setVisible(visible); | |
113 | } |
|
112 | } | |
114 |
|
113 | |||
115 | void ChartAxisElement::handleTitleVisibleChanged(bool visible) |
|
114 | void ChartAxisElement::handleTitleVisibleChanged(bool visible) | |
116 | { |
|
115 | { | |
117 | QGraphicsLayoutItem::updateGeometry(); |
|
116 | QGraphicsLayoutItem::updateGeometry(); | |
118 | presenter()->layout()->invalidate(); |
|
117 | presenter()->layout()->invalidate(); | |
119 | m_title->setVisible(visible); |
|
118 | m_title->setVisible(visible); | |
120 | } |
|
119 | } | |
121 |
|
120 | |||
122 | void ChartAxisElement::handleLabelsAngleChanged(int angle) |
|
121 | void ChartAxisElement::handleLabelsAngleChanged(int angle) | |
123 | { |
|
122 | { | |
124 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
123 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
125 | item->setRotation(angle); |
|
124 | item->setRotation(angle); | |
126 |
|
125 | |||
127 | QGraphicsLayoutItem::updateGeometry(); |
|
126 | QGraphicsLayoutItem::updateGeometry(); | |
128 | presenter()->layout()->invalidate(); |
|
127 | presenter()->layout()->invalidate(); | |
129 | } |
|
128 | } | |
130 |
|
129 | |||
131 | void ChartAxisElement::handleLabelsPenChanged(const QPen &pen) |
|
130 | void ChartAxisElement::handleLabelsPenChanged(const QPen &pen) | |
132 | { |
|
131 | { | |
133 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
132 | Q_UNUSED(pen) | |
134 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); |
|
|||
135 | } |
|
133 | } | |
136 |
|
134 | |||
137 | void ChartAxisElement::handleLabelsBrushChanged(const QBrush &brush) |
|
135 | void ChartAxisElement::handleLabelsBrushChanged(const QBrush &brush) | |
138 | { |
|
136 | { | |
139 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
137 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
140 |
static_cast<QGraphics |
|
138 | static_cast<QGraphicsTextItem *>(item)->setDefaultTextColor(brush.color()); | |
141 | } |
|
139 | } | |
142 |
|
140 | |||
143 | void ChartAxisElement::handleLabelsFontChanged(const QFont &font) |
|
141 | void ChartAxisElement::handleLabelsFontChanged(const QFont &font) | |
144 | { |
|
142 | { | |
145 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
143 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
146 |
static_cast<QGraphics |
|
144 | static_cast<QGraphicsTextItem *>(item)->setFont(font); | |
147 | QGraphicsLayoutItem::updateGeometry(); |
|
145 | QGraphicsLayoutItem::updateGeometry(); | |
148 | presenter()->layout()->invalidate(); |
|
146 | presenter()->layout()->invalidate(); | |
149 | } |
|
147 | } | |
150 |
|
148 | |||
151 | void ChartAxisElement::handleTitleTextChanged(const QString &title) |
|
149 | void ChartAxisElement::handleTitleTextChanged(const QString &title) | |
152 | { |
|
150 | { | |
153 | QGraphicsLayoutItem::updateGeometry(); |
|
151 | QGraphicsLayoutItem::updateGeometry(); | |
154 | presenter()->layout()->invalidate(); |
|
152 | presenter()->layout()->invalidate(); | |
155 |
m_title->set |
|
153 | m_title->setHtml(title); | |
156 | } |
|
154 | } | |
157 |
|
155 | |||
158 | void ChartAxisElement::handleTitlePenChanged(const QPen &pen) |
|
156 | void ChartAxisElement::handleTitlePenChanged(const QPen &pen) | |
159 | { |
|
157 | { | |
160 | m_title->setPen(pen); |
|
158 | Q_UNUSED(pen) | |
161 | } |
|
159 | } | |
162 |
|
160 | |||
163 | void ChartAxisElement::handleTitleBrushChanged(const QBrush &brush) |
|
161 | void ChartAxisElement::handleTitleBrushChanged(const QBrush &brush) | |
164 | { |
|
162 | { | |
165 |
m_title->set |
|
163 | m_title->setDefaultTextColor(brush.color()); | |
166 | } |
|
164 | } | |
167 |
|
165 | |||
168 | void ChartAxisElement::handleTitleFontChanged(const QFont &font) |
|
166 | void ChartAxisElement::handleTitleFontChanged(const QFont &font) | |
169 | { |
|
167 | { | |
170 | if (m_title->font() != font) { |
|
168 | if (m_title->font() != font) { | |
171 | m_title->setFont(font); |
|
169 | m_title->setFont(font); | |
172 | QGraphicsLayoutItem::updateGeometry(); |
|
170 | QGraphicsLayoutItem::updateGeometry(); | |
173 | presenter()->layout()->invalidate(); |
|
171 | presenter()->layout()->invalidate(); | |
174 | } |
|
172 | } | |
175 | } |
|
173 | } | |
176 |
|
174 | |||
177 | void ChartAxisElement::handleVisibleChanged(bool visible) |
|
175 | void ChartAxisElement::handleVisibleChanged(bool visible) | |
178 | { |
|
176 | { | |
179 | setVisible(visible); |
|
177 | setVisible(visible); | |
180 | if (!visible) { |
|
178 | if (!visible) { | |
181 | m_grid->setVisible(visible); |
|
179 | m_grid->setVisible(visible); | |
182 | m_arrow->setVisible(visible); |
|
180 | m_arrow->setVisible(visible); | |
183 | m_shades->setVisible(visible); |
|
181 | m_shades->setVisible(visible); | |
184 | m_labels->setVisible(visible); |
|
182 | m_labels->setVisible(visible); | |
185 | m_title->setVisible(visible); |
|
183 | m_title->setVisible(visible); | |
186 | } else { |
|
184 | } else { | |
187 | m_grid->setVisible(axis()->isGridLineVisible()); |
|
185 | m_grid->setVisible(axis()->isGridLineVisible()); | |
188 | m_arrow->setVisible(axis()->isLineVisible()); |
|
186 | m_arrow->setVisible(axis()->isLineVisible()); | |
189 | m_shades->setVisible(axis()->shadesVisible()); |
|
187 | m_shades->setVisible(axis()->shadesVisible()); | |
190 | m_labels->setVisible(axis()->labelsVisible()); |
|
188 | m_labels->setVisible(axis()->labelsVisible()); | |
191 | m_title->setVisible(axis()->isTitleVisible()); |
|
189 | m_title->setVisible(axis()->isTitleVisible()); | |
192 | } |
|
190 | } | |
193 |
|
191 | |||
194 | if (presenter()) presenter()->layout()->invalidate(); |
|
192 | if (presenter()) presenter()->layout()->invalidate(); | |
195 | } |
|
193 | } | |
196 |
|
194 | |||
197 | QRectF ChartAxisElement::textBoundingRect(const QFont &font, const QString &text, qreal angle) const |
|
|||
198 | { |
|
|||
199 | dummyTextItem->setFont(font); |
|
|||
200 | dummyTextItem->setText(text); |
|
|||
201 | QRectF boundingRect = dummyTextItem->boundingRect(); |
|
|||
202 |
|
||||
203 | // Take rotation into account |
|
|||
204 | if (angle) { |
|
|||
205 | QTransform transform; |
|
|||
206 | transform.rotate(angle); |
|
|||
207 | boundingRect = transform.mapRect(boundingRect); |
|
|||
208 | } |
|
|||
209 |
|
||||
210 | return boundingRect; |
|
|||
211 | } |
|
|||
212 |
|
||||
213 | // boundingRect parameter returns the rotated bounding rect of the text |
|
|||
214 | QString ChartAxisElement::truncatedText(const QFont &font, const QString &text, qreal angle, |
|
|||
215 | qreal maxSize, Qt::Orientation constraintOrientation, |
|
|||
216 | QRectF &boundingRect) const |
|
|||
217 | { |
|
|||
218 | QString truncatedString(text); |
|
|||
219 | boundingRect = textBoundingRect(font, truncatedString, angle); |
|
|||
220 | qreal checkDimension = ((constraintOrientation == Qt::Horizontal) |
|
|||
221 | ? boundingRect.width() : boundingRect.height()); |
|
|||
222 | if (checkDimension > maxSize) { |
|
|||
223 | truncatedString.append("..."); |
|
|||
224 | while (checkDimension > maxSize && truncatedString.length() > 3) { |
|
|||
225 | truncatedString.remove(truncatedString.length() - 4, 1); |
|
|||
226 | boundingRect = textBoundingRect(font, truncatedString, angle); |
|
|||
227 | checkDimension = ((constraintOrientation == Qt::Horizontal) |
|
|||
228 | ? boundingRect.width() : boundingRect.height()); |
|
|||
229 | } |
|
|||
230 | } |
|
|||
231 |
|
||||
232 | return truncatedString; |
|
|||
233 | } |
|
|||
234 |
|
||||
235 | void ChartAxisElement::handleRangeChanged(qreal min, qreal max) |
|
195 | void ChartAxisElement::handleRangeChanged(qreal min, qreal max) | |
236 | { |
|
196 | { | |
237 | Q_UNUSED(min); |
|
197 | Q_UNUSED(min); | |
238 | Q_UNUSED(max); |
|
198 | Q_UNUSED(max); | |
239 |
|
199 | |||
240 | if (!isEmpty()) { |
|
200 | if (!isEmpty()) { | |
241 | QVector<qreal> layout = calculateLayout(); |
|
201 | QVector<qreal> layout = calculateLayout(); | |
242 | updateLayout(layout); |
|
202 | updateLayout(layout); | |
243 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); |
|
203 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); | |
244 | QSizeF after = sizeHint(Qt::PreferredSize); |
|
204 | QSizeF after = sizeHint(Qt::PreferredSize); | |
245 |
|
205 | |||
246 | if (before != after) { |
|
206 | if (before != after) { | |
247 | QGraphicsLayoutItem::updateGeometry(); |
|
207 | QGraphicsLayoutItem::updateGeometry(); | |
248 | // We don't want to call invalidate on layout, since it will change minimum size of |
|
208 | // We don't want to call invalidate on layout, since it will change minimum size of | |
249 | // component, which we would like to avoid since it causes nasty flips when scrolling |
|
209 | // component, which we would like to avoid since it causes nasty flips when scrolling | |
250 | // or zooming, instead recalculate layout and use plotArea for extra space. |
|
210 | // or zooming, instead recalculate layout and use plotArea for extra space. | |
251 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); |
|
211 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); | |
252 | } |
|
212 | } | |
253 | } |
|
213 | } | |
254 | } |
|
214 | } | |
255 |
|
215 | |||
256 | bool ChartAxisElement::isEmpty() |
|
216 | bool ChartAxisElement::isEmpty() | |
257 | { |
|
217 | { | |
258 | return axisGeometry().isEmpty() |
|
218 | return axisGeometry().isEmpty() | |
259 | || gridGeometry().isEmpty() |
|
219 | || gridGeometry().isEmpty() | |
260 | || qFuzzyCompare(min(), max()); |
|
220 | || qFuzzyCompare(min(), max()); | |
261 | } |
|
221 | } | |
262 |
|
222 | |||
263 | qreal ChartAxisElement::min() const |
|
223 | qreal ChartAxisElement::min() const | |
264 | { |
|
224 | { | |
265 | return m_axis->d_ptr->min(); |
|
225 | return m_axis->d_ptr->min(); | |
266 | } |
|
226 | } | |
267 |
|
227 | |||
268 | qreal ChartAxisElement::max() const |
|
228 | qreal ChartAxisElement::max() const | |
269 | { |
|
229 | { | |
270 | return m_axis->d_ptr->max(); |
|
230 | return m_axis->d_ptr->max(); | |
271 | } |
|
231 | } | |
272 |
|
232 | |||
|
233 | static void appendFormattedLabel(const QString &capStr, const QByteArray &array, | |||
|
234 | QStringList &labels, qreal value) | |||
|
235 | { | |||
|
236 | if (capStr.isEmpty()) { | |||
|
237 | labels << QString(); | |||
|
238 | } else if (capStr.at(0) == QLatin1Char('d') | |||
|
239 | || capStr.at(0) == QLatin1Char('i') | |||
|
240 | || capStr.at(0) == QLatin1Char('c')) { | |||
|
241 | labels << QString().sprintf(array, (qint64)value); | |||
|
242 | } else if (capStr.at(0) == QLatin1Char('u') | |||
|
243 | || capStr.at(0) == QLatin1Char('o') | |||
|
244 | || capStr.at(0) == QLatin1Char('x') | |||
|
245 | || capStr.at(0) == QLatin1Char('X')) { | |||
|
246 | labels << QString().sprintf(array, (quint64)value); | |||
|
247 | } else if (capStr.at(0) == QLatin1Char('f') | |||
|
248 | || capStr.at(0) == QLatin1Char('F') | |||
|
249 | || capStr.at(0) == QLatin1Char('e') | |||
|
250 | || capStr.at(0) == QLatin1Char('E') | |||
|
251 | || capStr.at(0) == QLatin1Char('g') | |||
|
252 | || capStr.at(0) == QLatin1Char('G')) { | |||
|
253 | labels << QString().sprintf(array, value); | |||
|
254 | } else { | |||
|
255 | labels << QString(); | |||
|
256 | } | |||
|
257 | } | |||
|
258 | ||||
273 | QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, const QString &format) |
|
259 | QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, const QString &format) | |
274 | { |
|
260 | { | |
275 | QStringList labels; |
|
261 | QStringList labels; | |
276 |
|
262 | |||
277 | if (max <= min || ticks < 1) |
|
263 | if (max <= min || ticks < 1) | |
278 | return labels; |
|
264 | return labels; | |
279 |
|
265 | |||
280 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
266 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | |
281 | n++; |
|
267 | n++; | |
282 |
|
268 | |||
283 | if (format.isNull()) { |
|
269 | if (format.isNull()) { | |
284 | for (int i = 0; i < ticks; i++) { |
|
270 | for (int i = 0; i < ticks; i++) { | |
285 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
271 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
286 | labels << QString::number(value, 'f', n); |
|
272 | labels << QString::number(value, 'f', n); | |
287 | } |
|
273 | } | |
288 | } else { |
|
274 | } else { | |
289 | QByteArray array = format.toLatin1(); |
|
275 | QByteArray array = format.toLatin1(); | |
|
276 | QString capStr; | |||
|
277 | if (!labelFormatMatcher) | |||
|
278 | labelFormatMatcher = new QRegExp(labelFormatMatchString); | |||
|
279 | if (labelFormatMatcher->indexIn(format, 0) != -1) | |||
|
280 | capStr = labelFormatMatcher->cap(1); | |||
290 | for (int i = 0; i < ticks; i++) { |
|
281 | for (int i = 0; i < ticks; i++) { | |
291 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
282 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
292 | if (format.contains("d") |
|
283 | appendFormattedLabel(capStr, array, labels, value); | |
293 | || format.contains("i") |
|
|||
294 | || format.contains("c")) { |
|
|||
295 | labels << QString().sprintf(array, (qint64)value); |
|
|||
296 | } else if (format.contains("u") |
|
|||
297 | || format.contains("o") |
|
|||
298 | || format.contains("x", Qt::CaseInsensitive)) { |
|
|||
299 | labels << QString().sprintf(array, (quint64)value); |
|
|||
300 | } else if (format.contains("f", Qt::CaseInsensitive) |
|
|||
301 | || format.contains("e", Qt::CaseInsensitive) |
|
|||
302 | || format.contains("g", Qt::CaseInsensitive)) { |
|
|||
303 | labels << QString().sprintf(array, value); |
|
|||
304 | } else { |
|
|||
305 | labels << QString(); |
|
|||
306 | } |
|
|||
307 | } |
|
284 | } | |
308 | } |
|
285 | } | |
309 |
|
286 | |||
310 | return labels; |
|
287 | return labels; | |
311 | } |
|
288 | } | |
312 |
|
289 | |||
313 | QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format) |
|
290 | QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format) | |
314 | { |
|
291 | { | |
315 | QStringList labels; |
|
292 | QStringList labels; | |
316 |
|
293 | |||
317 | if (max <= min || ticks < 1) |
|
294 | if (max <= min || ticks < 1) | |
318 | return labels; |
|
295 | return labels; | |
319 |
|
296 | |||
320 | int n = 0; |
|
297 | int n = 0; | |
321 | if (ticks > 1) |
|
298 | if (ticks > 1) | |
322 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
299 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | |
323 | n++; |
|
300 | n++; | |
324 |
|
301 | |||
325 | int firstTick; |
|
302 | int firstTick; | |
326 | if (base > 1) |
|
303 | if (base > 1) | |
327 | firstTick = ceil(log10(min) / log10(base)); |
|
304 | firstTick = ceil(log10(min) / log10(base)); | |
328 | else |
|
305 | else | |
329 | firstTick = ceil(log10(max) / log10(base)); |
|
306 | firstTick = ceil(log10(max) / log10(base)); | |
330 |
|
307 | |||
331 | if (format.isNull()) { |
|
308 | if (format.isNull()) { | |
332 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
309 | for (int i = firstTick; i < ticks + firstTick; i++) { | |
333 | qreal value = qPow(base, i); |
|
310 | qreal value = qPow(base, i); | |
334 | labels << QString::number(value, 'f', n); |
|
311 | labels << QString::number(value, 'f', n); | |
335 | } |
|
312 | } | |
336 | } else { |
|
313 | } else { | |
337 | QByteArray array = format.toLatin1(); |
|
314 | QByteArray array = format.toLatin1(); | |
|
315 | QString capStr; | |||
|
316 | if (!labelFormatMatcher) | |||
|
317 | labelFormatMatcher = new QRegExp(labelFormatMatchString); | |||
|
318 | if (labelFormatMatcher->indexIn(format, 0) != -1) | |||
|
319 | capStr = labelFormatMatcher->cap(1); | |||
338 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
320 | for (int i = firstTick; i < ticks + firstTick; i++) { | |
339 | qreal value = qPow(base, i); |
|
321 | qreal value = qPow(base, i); | |
340 | if (format.contains("d") |
|
322 | appendFormattedLabel(capStr, array, labels, value); | |
341 | || format.contains("i") |
|
|||
342 | || format.contains("c")) { |
|
|||
343 | labels << QString().sprintf(array, (qint64)value); |
|
|||
344 | } else if (format.contains("u") |
|
|||
345 | || format.contains("o") |
|
|||
346 | || format.contains("x", Qt::CaseInsensitive)) { |
|
|||
347 | labels << QString().sprintf(array, (quint64)value); |
|
|||
348 | } else if (format.contains("f", Qt::CaseInsensitive) |
|
|||
349 | || format.contains("e", Qt::CaseInsensitive) |
|
|||
350 | || format.contains("g", Qt::CaseInsensitive)) { |
|
|||
351 | labels << QString().sprintf(array, value); |
|
|||
352 | } else { |
|
|||
353 | labels << QString(); |
|
|||
354 | } |
|
|||
355 | } |
|
323 | } | |
356 | } |
|
324 | } | |
357 |
|
325 | |||
358 | return labels; |
|
326 | return labels; | |
359 | } |
|
327 | } | |
360 |
|
328 | |||
361 | QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int ticks,const QString &format) |
|
329 | QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int ticks,const QString &format) | |
362 | { |
|
330 | { | |
363 | QStringList labels; |
|
331 | QStringList labels; | |
364 |
|
332 | |||
365 | if (max <= min || ticks < 1) |
|
333 | if (max <= min || ticks < 1) | |
366 | return labels; |
|
334 | return labels; | |
367 |
|
335 | |||
368 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); |
|
336 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); | |
369 | n++; |
|
337 | n++; | |
370 | for (int i = 0; i < ticks; i++) { |
|
338 | for (int i = 0; i < ticks; i++) { | |
371 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
339 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
372 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); |
|
340 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); | |
373 | } |
|
341 | } | |
374 | return labels; |
|
342 | return labels; | |
375 | } |
|
343 | } | |
376 |
|
344 | |||
377 | void ChartAxisElement::axisSelected() |
|
345 | void ChartAxisElement::axisSelected() | |
378 | { |
|
346 | { | |
379 | emit clicked(); |
|
347 | emit clicked(); | |
380 | } |
|
348 | } | |
381 |
|
349 | |||
382 | #include "moc_chartaxiselement_p.cpp" |
|
350 | #include "moc_chartaxiselement_p.cpp" | |
383 |
|
351 | |||
384 | QTCOMMERCIALCHART_END_NAMESPACE |
|
352 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,153 +1,149 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 CHARTAXISELEMENT_H |
|
30 | #ifndef CHARTAXISELEMENT_H | |
31 | #define CHARTAXISELEMENT_H |
|
31 | #define CHARTAXISELEMENT_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "chartelement_p.h" |
|
34 | #include "chartelement_p.h" | |
35 | #include "axisanimation_p.h" |
|
35 | #include "axisanimation_p.h" | |
36 | #include <QGraphicsItem> |
|
36 | #include <QGraphicsItem> | |
37 | #include <QGraphicsLayoutItem> |
|
37 | #include <QGraphicsLayoutItem> | |
38 | #include <QFont> |
|
38 | #include <QFont> | |
39 |
|
39 | |||
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
41 |
|
41 | |||
42 | class ChartPresenter; |
|
42 | class ChartPresenter; | |
43 | class QAbstractAxis; |
|
43 | class QAbstractAxis; | |
44 |
|
44 | |||
45 | class ChartAxisElement : public ChartElement, public QGraphicsLayoutItem |
|
45 | class ChartAxisElement : public ChartElement, public QGraphicsLayoutItem | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis = false); |
|
49 | ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis = false); | |
50 | ~ChartAxisElement(); |
|
50 | ~ChartAxisElement(); | |
51 |
|
51 | |||
52 | virtual QRectF gridGeometry() const = 0; |
|
52 | virtual QRectF gridGeometry() const = 0; | |
53 | virtual void setGeometry(const QRectF &axis, const QRectF &grid) = 0; |
|
53 | virtual void setGeometry(const QRectF &axis, const QRectF &grid) = 0; | |
54 | virtual bool isEmpty() = 0; |
|
54 | virtual bool isEmpty() = 0; | |
55 |
|
55 | |||
56 | void setAnimation(AxisAnimation *animation) { m_animation = animation; } |
|
56 | void setAnimation(AxisAnimation *animation) { m_animation = animation; } | |
57 | AxisAnimation *animation() const { return m_animation; } |
|
57 | AxisAnimation *animation() const { return m_animation; } | |
58 |
|
58 | |||
59 | QAbstractAxis *axis() const { return m_axis; } |
|
59 | QAbstractAxis *axis() const { return m_axis; } | |
60 | void setLayout(QVector<qreal> &layout) { m_layout = layout; } |
|
60 | void setLayout(QVector<qreal> &layout) { m_layout = layout; } | |
61 | QVector<qreal> &layout() { return m_layout; } // Modifiable reference |
|
61 | QVector<qreal> &layout() { return m_layout; } // Modifiable reference | |
62 | int labelPadding() const { return 5; } |
|
62 | int labelPadding() const { return 5; } | |
63 | int titlePadding() const { return 3; } |
|
63 | int titlePadding() const { return 3; } | |
64 | void setLabels(const QStringList &labels) { m_labelsList = labels; } |
|
64 | void setLabels(const QStringList &labels) { m_labelsList = labels; } | |
65 | QStringList labels() const { return m_labelsList; } |
|
65 | QStringList labels() const { return m_labelsList; } | |
66 |
|
66 | |||
67 | qreal min() const; |
|
67 | qreal min() const; | |
68 | qreal max() const; |
|
68 | qreal max() const; | |
69 |
|
69 | |||
70 | QRectF axisGeometry() const { return m_axisRect; } |
|
70 | QRectF axisGeometry() const { return m_axisRect; } | |
71 | void setAxisGeometry(const QRectF &axisGeometry) { m_axisRect = axisGeometry; } |
|
71 | void setAxisGeometry(const QRectF &axisGeometry) { m_axisRect = axisGeometry; } | |
72 |
|
72 | |||
73 | QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0) const; |
|
|||
74 | QString truncatedText(const QFont &font, const QString &text, qreal angle, qreal maxSize, |
|
|||
75 | Qt::Orientation constraintOrientation, QRectF &boundingRect) const; |
|
|||
76 |
|
||||
77 | void axisSelected(); |
|
73 | void axisSelected(); | |
78 |
|
74 | |||
79 | //this flag indicates that axis is used to show intervals it means labels are in between ticks |
|
75 | //this flag indicates that axis is used to show intervals it means labels are in between ticks | |
80 | bool intervalAxis() const { return m_intervalAxis; } |
|
76 | bool intervalAxis() const { return m_intervalAxis; } | |
81 |
|
77 | |||
82 | static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format); |
|
78 | static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format); | |
83 | static QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format); |
|
79 | static QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format); | |
84 | static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format); |
|
80 | static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format); | |
85 |
|
81 | |||
86 | // from QGraphicsLayoutItem |
|
82 | // from QGraphicsLayoutItem | |
87 | QRectF boundingRect() const |
|
83 | QRectF boundingRect() const | |
88 | { |
|
84 | { | |
89 | return QRectF(); |
|
85 | return QRectF(); | |
90 | } |
|
86 | } | |
91 |
|
87 | |||
92 | // from QGraphicsLayoutItem |
|
88 | // from QGraphicsLayoutItem | |
93 | void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) |
|
89 | void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) | |
94 | { |
|
90 | { | |
95 | } |
|
91 | } | |
96 |
|
92 | |||
97 | protected: |
|
93 | protected: | |
98 | virtual QVector<qreal> calculateLayout() const = 0; |
|
94 | virtual QVector<qreal> calculateLayout() const = 0; | |
99 | virtual void updateLayout(QVector<qreal> &layout) = 0; |
|
95 | virtual void updateLayout(QVector<qreal> &layout) = 0; | |
100 |
|
96 | |||
101 | QList<QGraphicsItem *> gridItems() { return m_grid->childItems(); } |
|
97 | QList<QGraphicsItem *> gridItems() { return m_grid->childItems(); } | |
102 | QList<QGraphicsItem *> labelItems() { return m_labels->childItems(); } |
|
98 | QList<QGraphicsItem *> labelItems() { return m_labels->childItems(); } | |
103 | QList<QGraphicsItem *> shadeItems() { return m_shades->childItems(); } |
|
99 | QList<QGraphicsItem *> shadeItems() { return m_shades->childItems(); } | |
104 | QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems(); } |
|
100 | QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems(); } | |
105 |
QGraphics |
|
101 | QGraphicsTextItem *titleItem() const { return m_title.data(); } | |
106 | QGraphicsItemGroup *gridGroup() { return m_grid.data(); } |
|
102 | QGraphicsItemGroup *gridGroup() { return m_grid.data(); } | |
107 | QGraphicsItemGroup *labelGroup() { return m_labels.data(); } |
|
103 | QGraphicsItemGroup *labelGroup() { return m_labels.data(); } | |
108 | QGraphicsItemGroup *shadeGroup() { return m_shades.data(); } |
|
104 | QGraphicsItemGroup *shadeGroup() { return m_shades.data(); } | |
109 | QGraphicsItemGroup *arrowGroup() { return m_arrow.data(); } |
|
105 | QGraphicsItemGroup *arrowGroup() { return m_arrow.data(); } | |
110 |
|
106 | |||
111 | public Q_SLOTS: |
|
107 | public Q_SLOTS: | |
112 | void handleVisibleChanged(bool visible); |
|
108 | void handleVisibleChanged(bool visible); | |
113 | void handleArrowVisibleChanged(bool visible); |
|
109 | void handleArrowVisibleChanged(bool visible); | |
114 | void handleGridVisibleChanged(bool visible); |
|
110 | void handleGridVisibleChanged(bool visible); | |
115 | void handleLabelsVisibleChanged(bool visible); |
|
111 | void handleLabelsVisibleChanged(bool visible); | |
116 | void handleShadesVisibleChanged(bool visible); |
|
112 | void handleShadesVisibleChanged(bool visible); | |
117 | void handleLabelsAngleChanged(int angle); |
|
113 | void handleLabelsAngleChanged(int angle); | |
118 | virtual void handleShadesBrushChanged(const QBrush &brush) = 0; |
|
114 | virtual void handleShadesBrushChanged(const QBrush &brush) = 0; | |
119 | virtual void handleShadesPenChanged(const QPen &pen) = 0; |
|
115 | virtual void handleShadesPenChanged(const QPen &pen) = 0; | |
120 | virtual void handleArrowPenChanged(const QPen &pen) = 0; |
|
116 | virtual void handleArrowPenChanged(const QPen &pen) = 0; | |
121 | virtual void handleGridPenChanged(const QPen &pen) = 0; |
|
117 | virtual void handleGridPenChanged(const QPen &pen) = 0; | |
122 | void handleLabelsPenChanged(const QPen &pen); |
|
118 | void handleLabelsPenChanged(const QPen &pen); | |
123 | void handleLabelsBrushChanged(const QBrush &brush); |
|
119 | void handleLabelsBrushChanged(const QBrush &brush); | |
124 | void handleLabelsFontChanged(const QFont &font); |
|
120 | void handleLabelsFontChanged(const QFont &font); | |
125 | void handleTitlePenChanged(const QPen &pen); |
|
121 | void handleTitlePenChanged(const QPen &pen); | |
126 | void handleTitleBrushChanged(const QBrush &brush); |
|
122 | void handleTitleBrushChanged(const QBrush &brush); | |
127 | void handleTitleFontChanged(const QFont &font); |
|
123 | void handleTitleFontChanged(const QFont &font); | |
128 | void handleTitleTextChanged(const QString &title); |
|
124 | void handleTitleTextChanged(const QString &title); | |
129 | void handleTitleVisibleChanged(bool visible); |
|
125 | void handleTitleVisibleChanged(bool visible); | |
130 | void handleRangeChanged(qreal min, qreal max); |
|
126 | void handleRangeChanged(qreal min, qreal max); | |
131 |
|
127 | |||
132 | Q_SIGNALS: |
|
128 | Q_SIGNALS: | |
133 | void clicked(); |
|
129 | void clicked(); | |
134 |
|
130 | |||
135 | private: |
|
131 | private: | |
136 | void connectSlots(); |
|
132 | void connectSlots(); | |
137 |
|
133 | |||
138 | QAbstractAxis *m_axis; |
|
134 | QAbstractAxis *m_axis; | |
139 | AxisAnimation *m_animation; |
|
135 | AxisAnimation *m_animation; | |
140 | QVector<qreal> m_layout; |
|
136 | QVector<qreal> m_layout; | |
141 | QStringList m_labelsList; |
|
137 | QStringList m_labelsList; | |
142 | QRectF m_axisRect; |
|
138 | QRectF m_axisRect; | |
143 | QScopedPointer<QGraphicsItemGroup> m_grid; |
|
139 | QScopedPointer<QGraphicsItemGroup> m_grid; | |
144 | QScopedPointer<QGraphicsItemGroup> m_arrow; |
|
140 | QScopedPointer<QGraphicsItemGroup> m_arrow; | |
145 | QScopedPointer<QGraphicsItemGroup> m_shades; |
|
141 | QScopedPointer<QGraphicsItemGroup> m_shades; | |
146 | QScopedPointer<QGraphicsItemGroup> m_labels; |
|
142 | QScopedPointer<QGraphicsItemGroup> m_labels; | |
147 |
QScopedPointer<QGraphics |
|
143 | QScopedPointer<QGraphicsTextItem> m_title; | |
148 | bool m_intervalAxis; |
|
144 | bool m_intervalAxis; | |
149 | }; |
|
145 | }; | |
150 |
|
146 | |||
151 | QTCOMMERCIALCHART_END_NAMESPACE |
|
147 | QTCOMMERCIALCHART_END_NAMESPACE | |
152 |
|
148 | |||
153 | #endif /* CHARTAXISELEMENT_H */ |
|
149 | #endif /* CHARTAXISELEMENT_H */ |
@@ -1,131 +1,131 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "chartdatetimeaxisx_p.h" |
|
21 | #include "chartdatetimeaxisx_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qdatetimeaxis.h" |
|
23 | #include "qdatetimeaxis.h" | |
24 | #include "abstractchartlayout_p.h" |
|
24 | #include "abstractchartlayout_p.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QDateTime> |
|
26 | #include <QDateTime> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis, QGraphicsItem *item) |
|
31 | ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis, QGraphicsItem *item) | |
32 | : HorizontalAxis(axis, item), |
|
32 | : HorizontalAxis(axis, item), | |
33 | m_axis(axis) |
|
33 | m_axis(axis) | |
34 | { |
|
34 | { | |
35 | QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); |
|
35 | QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); | |
36 | QObject::connect(m_axis, SIGNAL(formatChanged(QString)), this, SLOT(handleFormatChanged(QString))); |
|
36 | QObject::connect(m_axis, SIGNAL(formatChanged(QString)), this, SLOT(handleFormatChanged(QString))); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartDateTimeAxisX::~ChartDateTimeAxisX() |
|
39 | ChartDateTimeAxisX::~ChartDateTimeAxisX() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QVector<qreal> ChartDateTimeAxisX::calculateLayout() const |
|
43 | QVector<qreal> ChartDateTimeAxisX::calculateLayout() const | |
44 | { |
|
44 | { | |
45 | int tickCount = m_axis->tickCount(); |
|
45 | int tickCount = m_axis->tickCount(); | |
46 |
|
46 | |||
47 | Q_ASSERT(tickCount >= 2); |
|
47 | Q_ASSERT(tickCount >= 2); | |
48 |
|
48 | |||
49 | QVector<qreal> points; |
|
49 | QVector<qreal> points; | |
50 | points.resize(tickCount); |
|
50 | points.resize(tickCount); | |
51 | const QRectF &gridRect = gridGeometry(); |
|
51 | const QRectF &gridRect = gridGeometry(); | |
52 | const qreal deltaX = gridRect.width() / (qreal(tickCount) - 1.0); |
|
52 | const qreal deltaX = gridRect.width() / (qreal(tickCount) - 1.0); | |
53 | for (int i = 0; i < tickCount; ++i) |
|
53 | for (int i = 0; i < tickCount; ++i) | |
54 | points[i] = qreal(i) * deltaX + gridRect.left(); |
|
54 | points[i] = qreal(i) * deltaX + gridRect.left(); | |
55 | return points; |
|
55 | return points; | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | void ChartDateTimeAxisX::updateGeometry() |
|
58 | void ChartDateTimeAxisX::updateGeometry() | |
59 | { |
|
59 | { | |
60 | const QVector<qreal>& layout = ChartAxisElement::layout(); |
|
60 | const QVector<qreal>& layout = ChartAxisElement::layout(); | |
61 | if (layout.isEmpty()) |
|
61 | if (layout.isEmpty()) | |
62 | return; |
|
62 | return; | |
63 | setLabels(createDateTimeLabels(min(), max(), layout.size(), m_axis->format())); |
|
63 | setLabels(createDateTimeLabels(min(), max(), layout.size(), m_axis->format())); | |
64 | HorizontalAxis::updateGeometry(); |
|
64 | HorizontalAxis::updateGeometry(); | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void ChartDateTimeAxisX::handleTickCountChanged(int tick) |
|
67 | void ChartDateTimeAxisX::handleTickCountChanged(int tick) | |
68 | { |
|
68 | { | |
69 | Q_UNUSED(tick) |
|
69 | Q_UNUSED(tick) | |
70 | QGraphicsLayoutItem::updateGeometry(); |
|
70 | QGraphicsLayoutItem::updateGeometry(); | |
71 | if (presenter()) |
|
71 | if (presenter()) | |
72 | presenter()->layout()->invalidate(); |
|
72 | presenter()->layout()->invalidate(); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void ChartDateTimeAxisX::handleFormatChanged(const QString &format) |
|
75 | void ChartDateTimeAxisX::handleFormatChanged(const QString &format) | |
76 | { |
|
76 | { | |
77 | Q_UNUSED(format); |
|
77 | Q_UNUSED(format); | |
78 | QGraphicsLayoutItem::updateGeometry(); |
|
78 | QGraphicsLayoutItem::updateGeometry(); | |
79 | if (presenter()) |
|
79 | if (presenter()) | |
80 | presenter()->layout()->invalidate(); |
|
80 | presenter()->layout()->invalidate(); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
83 | QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
84 | { |
|
84 | { | |
85 | Q_UNUSED(constraint) |
|
85 | Q_UNUSED(constraint) | |
86 |
|
86 | |||
87 | QSizeF sh; |
|
87 | QSizeF sh; | |
88 |
|
88 | |||
89 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
89 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |
90 | QStringList ticksList = createDateTimeLabels(min(), max(), m_axis->tickCount(), m_axis->format()); |
|
90 | QStringList ticksList = createDateTimeLabels(min(), max(), m_axis->tickCount(), m_axis->format()); | |
91 | // Width of horizontal axis sizeHint indicates the maximum distance labels can extend past |
|
91 | // Width of horizontal axis sizeHint indicates the maximum distance labels can extend past | |
92 | // first and last ticks. Base width is irrelevant. |
|
92 | // first and last ticks. Base width is irrelevant. | |
93 | qreal width = 0; |
|
93 | qreal width = 0; | |
94 | qreal height = 0; |
|
94 | qreal height = 0; | |
95 |
|
95 | |||
96 | if (ticksList.empty()) |
|
96 | if (ticksList.empty()) | |
97 | return sh; |
|
97 | return sh; | |
98 |
|
98 | |||
99 | switch (which) { |
|
99 | switch (which) { | |
100 | case Qt::MinimumSize: { |
|
100 | case Qt::MinimumSize: { | |
101 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); |
|
101 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
102 | width = boundingRect.width() / 2.0; |
|
102 | width = boundingRect.width() / 2.0; | |
103 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; |
|
103 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; | |
104 | sh = QSizeF(width, height); |
|
104 | sh = QSizeF(width, height); | |
105 | break; |
|
105 | break; | |
106 | } |
|
106 | } | |
107 | case Qt::PreferredSize: { |
|
107 | case Qt::PreferredSize: { | |
108 | qreal labelHeight = 0.0; |
|
108 | qreal labelHeight = 0.0; | |
109 | qreal firstWidth = -1.0; |
|
109 | qreal firstWidth = -1.0; | |
110 | foreach (const QString& s, ticksList) { |
|
110 | foreach (const QString& s, ticksList) { | |
111 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); |
|
111 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
112 | labelHeight = qMax(rect.height(), labelHeight); |
|
112 | labelHeight = qMax(rect.height(), labelHeight); | |
113 | width = rect.width(); |
|
113 | width = rect.width(); | |
114 | if (firstWidth < 0.0) |
|
114 | if (firstWidth < 0.0) | |
115 | firstWidth = width; |
|
115 | firstWidth = width; | |
116 | } |
|
116 | } | |
117 | height = labelHeight + labelPadding() + base.height() + 1.0; |
|
117 | height = labelHeight + labelPadding() + base.height() + 1.0; | |
118 | width = qMax(width, firstWidth) / 2.0; |
|
118 | width = qMax(width, firstWidth) / 2.0; | |
119 | sh = QSizeF(width, height); |
|
119 | sh = QSizeF(width, height); | |
120 | break; |
|
120 | break; | |
121 | } |
|
121 | } | |
122 | default: |
|
122 | default: | |
123 | break; |
|
123 | break; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | return sh; |
|
126 | return sh; | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | #include "moc_chartdatetimeaxisx_p.cpp" |
|
129 | #include "moc_chartdatetimeaxisx_p.cpp" | |
130 |
|
130 | |||
131 | QTCOMMERCIALCHART_END_NAMESPACE |
|
131 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,132 +1,132 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "chartdatetimeaxisy_p.h" |
|
21 | #include "chartdatetimeaxisy_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qdatetimeaxis.h" |
|
23 | #include "qdatetimeaxis.h" | |
24 | #include "abstractchartlayout_p.h" |
|
24 | #include "abstractchartlayout_p.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QDateTime> |
|
26 | #include <QDateTime> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis, QGraphicsItem *item) |
|
31 | ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis, QGraphicsItem *item) | |
32 | : VerticalAxis(axis, item), |
|
32 | : VerticalAxis(axis, item), | |
33 | m_axis(axis) |
|
33 | m_axis(axis) | |
34 | { |
|
34 | { | |
35 | QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); |
|
35 | QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); | |
36 | QObject::connect(m_axis, SIGNAL(formatChanged(QString)), this, SLOT(handleFormatChanged(QString))); |
|
36 | QObject::connect(m_axis, SIGNAL(formatChanged(QString)), this, SLOT(handleFormatChanged(QString))); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartDateTimeAxisY::~ChartDateTimeAxisY() |
|
39 | ChartDateTimeAxisY::~ChartDateTimeAxisY() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QVector<qreal> ChartDateTimeAxisY::calculateLayout() const |
|
43 | QVector<qreal> ChartDateTimeAxisY::calculateLayout() const | |
44 | { |
|
44 | { | |
45 | int tickCount = m_axis->tickCount(); |
|
45 | int tickCount = m_axis->tickCount(); | |
46 |
|
46 | |||
47 | Q_ASSERT(tickCount >= 2); |
|
47 | Q_ASSERT(tickCount >= 2); | |
48 |
|
48 | |||
49 | QVector<qreal> points; |
|
49 | QVector<qreal> points; | |
50 | points.resize(tickCount); |
|
50 | points.resize(tickCount); | |
51 | const QRectF &gridRect = gridGeometry(); |
|
51 | const QRectF &gridRect = gridGeometry(); | |
52 | const qreal deltaY = gridRect.height() / (qreal(tickCount) - 1.0); |
|
52 | const qreal deltaY = gridRect.height() / (qreal(tickCount) - 1.0); | |
53 | for (int i = 0; i < tickCount; ++i) |
|
53 | for (int i = 0; i < tickCount; ++i) | |
54 | points[i] = qreal(i) * -deltaY + gridRect.bottom(); |
|
54 | points[i] = qreal(i) * -deltaY + gridRect.bottom(); | |
55 |
|
55 | |||
56 | return points; |
|
56 | return points; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | void ChartDateTimeAxisY::updateGeometry() |
|
59 | void ChartDateTimeAxisY::updateGeometry() | |
60 | { |
|
60 | { | |
61 | const QVector<qreal> &layout = ChartAxisElement::layout(); |
|
61 | const QVector<qreal> &layout = ChartAxisElement::layout(); | |
62 | if (layout.isEmpty()) |
|
62 | if (layout.isEmpty()) | |
63 | return; |
|
63 | return; | |
64 | setLabels(createDateTimeLabels(min(), max(), layout.size(), m_axis->format())); |
|
64 | setLabels(createDateTimeLabels(min(), max(), layout.size(), m_axis->format())); | |
65 | VerticalAxis::updateGeometry(); |
|
65 | VerticalAxis::updateGeometry(); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void ChartDateTimeAxisY::handleTickCountChanged(int tick) |
|
68 | void ChartDateTimeAxisY::handleTickCountChanged(int tick) | |
69 | { |
|
69 | { | |
70 | Q_UNUSED(tick) |
|
70 | Q_UNUSED(tick) | |
71 | QGraphicsLayoutItem::updateGeometry(); |
|
71 | QGraphicsLayoutItem::updateGeometry(); | |
72 | if (presenter()) |
|
72 | if (presenter()) | |
73 | presenter()->layout()->invalidate(); |
|
73 | presenter()->layout()->invalidate(); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | void ChartDateTimeAxisY::handleFormatChanged(const QString &format) |
|
76 | void ChartDateTimeAxisY::handleFormatChanged(const QString &format) | |
77 | { |
|
77 | { | |
78 | Q_UNUSED(format); |
|
78 | Q_UNUSED(format); | |
79 | QGraphicsLayoutItem::updateGeometry(); |
|
79 | QGraphicsLayoutItem::updateGeometry(); | |
80 | if (presenter()) |
|
80 | if (presenter()) | |
81 | presenter()->layout()->invalidate(); |
|
81 | presenter()->layout()->invalidate(); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
84 | QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
85 | { |
|
85 | { | |
86 | Q_UNUSED(constraint) |
|
86 | Q_UNUSED(constraint) | |
87 |
|
87 | |||
88 | QSizeF sh; |
|
88 | QSizeF sh; | |
89 |
|
89 | |||
90 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
90 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
91 | QStringList ticksList = createDateTimeLabels(min(), max(), m_axis->tickCount(), m_axis->format()); |
|
91 | QStringList ticksList = createDateTimeLabels(min(), max(), m_axis->tickCount(), m_axis->format()); | |
92 | qreal width = 0; |
|
92 | qreal width = 0; | |
93 | // Height of vertical axis sizeHint indicates the maximum distance labels can extend past |
|
93 | // Height of vertical axis sizeHint indicates the maximum distance labels can extend past | |
94 | // first and last ticks. Base height is irrelevant. |
|
94 | // first and last ticks. Base height is irrelevant. | |
95 | qreal height = 0; |
|
95 | qreal height = 0; | |
96 |
|
96 | |||
97 | if (ticksList.empty()) |
|
97 | if (ticksList.empty()) | |
98 | return sh; |
|
98 | return sh; | |
99 |
|
99 | |||
100 | switch (which) { |
|
100 | switch (which) { | |
101 | case Qt::MinimumSize: { |
|
101 | case Qt::MinimumSize: { | |
102 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); |
|
102 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
103 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; |
|
103 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; | |
104 | height = boundingRect.height() / 2.0; |
|
104 | height = boundingRect.height() / 2.0; | |
105 | sh = QSizeF(width, height); |
|
105 | sh = QSizeF(width, height); | |
106 | break; |
|
106 | break; | |
107 | } |
|
107 | } | |
108 | case Qt::PreferredSize: { |
|
108 | case Qt::PreferredSize: { | |
109 | qreal labelWidth = 0.0; |
|
109 | qreal labelWidth = 0.0; | |
110 | qreal firstHeight = -1.0; |
|
110 | qreal firstHeight = -1.0; | |
111 | foreach (const QString& s, ticksList) { |
|
111 | foreach (const QString& s, ticksList) { | |
112 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); |
|
112 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
113 | labelWidth = qMax(rect.width(), labelWidth); |
|
113 | labelWidth = qMax(rect.width(), labelWidth); | |
114 | height = rect.height(); |
|
114 | height = rect.height(); | |
115 | if (firstHeight < 0.0) |
|
115 | if (firstHeight < 0.0) | |
116 | firstHeight = height; |
|
116 | firstHeight = height; | |
117 | } |
|
117 | } | |
118 | width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance |
|
118 | width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance | |
119 | height = qMax(height, firstHeight) / 2.0; |
|
119 | height = qMax(height, firstHeight) / 2.0; | |
120 | sh = QSizeF(width, height); |
|
120 | sh = QSizeF(width, height); | |
121 | break; |
|
121 | break; | |
122 | } |
|
122 | } | |
123 | default: |
|
123 | default: | |
124 | break; |
|
124 | break; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | return sh; |
|
127 | return sh; | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | #include "moc_chartdatetimeaxisy_p.cpp" |
|
130 | #include "moc_chartdatetimeaxisy_p.cpp" | |
131 |
|
131 | |||
132 | QTCOMMERCIALCHART_END_NAMESPACE |
|
132 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,205 +1,206 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "horizontalaxis_p.h" |
|
21 | #include "horizontalaxis_p.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
|
23 | #include "chartpresenter_p.h" | |||
23 | #include <qmath.h> |
|
24 | #include <qmath.h> | |
24 | #include <QDebug> |
|
25 | #include <QDebug> | |
25 |
|
26 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
28 | |||
28 | HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) |
|
29 | HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) | |
29 | : CartesianChartAxis(axis, item, intervalAxis) |
|
30 | : CartesianChartAxis(axis, item, intervalAxis) | |
30 | { |
|
31 | { | |
31 | } |
|
32 | } | |
32 |
|
33 | |||
33 | HorizontalAxis::~HorizontalAxis() |
|
34 | HorizontalAxis::~HorizontalAxis() | |
34 | { |
|
35 | { | |
35 | } |
|
36 | } | |
36 |
|
37 | |||
37 | void HorizontalAxis::updateGeometry() |
|
38 | void HorizontalAxis::updateGeometry() | |
38 | { |
|
39 | { | |
39 | const QVector<qreal> &layout = ChartAxisElement::layout(); |
|
40 | const QVector<qreal> &layout = ChartAxisElement::layout(); | |
40 |
|
41 | |||
41 | if (layout.isEmpty()) |
|
42 | if (layout.isEmpty()) | |
42 | return; |
|
43 | return; | |
43 |
|
44 | |||
44 | QStringList labelList = labels(); |
|
45 | QStringList labelList = labels(); | |
45 |
|
46 | |||
46 | QList<QGraphicsItem *> lines = gridItems(); |
|
47 | QList<QGraphicsItem *> lines = gridItems(); | |
47 | QList<QGraphicsItem *> labels = labelItems(); |
|
48 | QList<QGraphicsItem *> labels = labelItems(); | |
48 | QList<QGraphicsItem *> shades = shadeItems(); |
|
49 | QList<QGraphicsItem *> shades = shadeItems(); | |
49 | QList<QGraphicsItem *> arrow = arrowItems(); |
|
50 | QList<QGraphicsItem *> arrow = arrowItems(); | |
50 |
QGraphics |
|
51 | QGraphicsTextItem *title = titleItem(); | |
51 |
|
52 | |||
52 | Q_ASSERT(labels.size() == labelList.size()); |
|
53 | Q_ASSERT(labels.size() == labelList.size()); | |
53 | Q_ASSERT(layout.size() == labelList.size()); |
|
54 | Q_ASSERT(layout.size() == labelList.size()); | |
54 |
|
55 | |||
55 | const QRectF &axisRect = axisGeometry(); |
|
56 | const QRectF &axisRect = axisGeometry(); | |
56 | const QRectF &gridRect = gridGeometry(); |
|
57 | const QRectF &gridRect = gridGeometry(); | |
57 |
|
58 | |||
58 | //arrow |
|
59 | //arrow | |
59 | QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem *>(arrow.at(0)); |
|
60 | QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem *>(arrow.at(0)); | |
60 |
|
61 | |||
61 | if (axis()->alignment() == Qt::AlignTop) |
|
62 | if (axis()->alignment() == Qt::AlignTop) | |
62 | arrowItem->setLine(gridRect.left(), axisRect.bottom(), gridRect.right(), axisRect.bottom()); |
|
63 | arrowItem->setLine(gridRect.left(), axisRect.bottom(), gridRect.right(), axisRect.bottom()); | |
63 | else if (axis()->alignment() == Qt::AlignBottom) |
|
64 | else if (axis()->alignment() == Qt::AlignBottom) | |
64 | arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top()); |
|
65 | arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top()); | |
65 |
|
66 | |||
66 | qreal width = 0; |
|
67 | qreal width = 0; | |
67 |
|
68 | |||
68 | //title |
|
69 | //title | |
69 | int titlePad = 0; |
|
70 | int titlePad = 0; | |
70 | QRectF titleBoundingRect; |
|
71 | QRectF titleBoundingRect; | |
71 | QString titleText = axis()->titleText(); |
|
72 | QString titleText = axis()->titleText(); | |
72 | if (!titleText.isEmpty() && titleItem()->isVisible()) { |
|
73 | if (!titleText.isEmpty() && titleItem()->isVisible()) { | |
73 |
title->set |
|
74 | title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), gridRect.width(), Qt::Horizontal, QRectF())); | |
74 |
|
75 | |||
75 | titlePad = titlePadding(); |
|
76 | titlePad = titlePadding(); | |
76 | titleBoundingRect = title->boundingRect(); |
|
77 | titleBoundingRect = title->boundingRect(); | |
77 |
|
78 | |||
78 | QPointF center = gridRect.center() - titleBoundingRect.center(); |
|
79 | QPointF center = gridRect.center() - titleBoundingRect.center(); | |
79 | if (axis()->alignment() == Qt::AlignTop) { |
|
80 | if (axis()->alignment() == Qt::AlignTop) { | |
80 | title->setPos(center.x(), axisRect.top() + titlePad); |
|
81 | title->setPos(center.x(), axisRect.top() + titlePad); | |
81 | } else if (axis()->alignment() == Qt::AlignBottom) { |
|
82 | } else if (axis()->alignment() == Qt::AlignBottom) { | |
82 | title->setPos(center.x(), axisRect.bottom() - titleBoundingRect.height() - titlePad); |
|
83 | title->setPos(center.x(), axisRect.bottom() - titleBoundingRect.height() - titlePad); | |
83 | } |
|
84 | } | |
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 | for (int i = 0; i < layout.size(); ++i) { |
|
87 | for (int i = 0; i < layout.size(); ++i) { | |
87 | //items |
|
88 | //items | |
88 | QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
89 | QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
89 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(arrow.at(i + 1)); |
|
90 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(arrow.at(i + 1)); | |
90 |
QGraphics |
|
91 | QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labels.at(i)); | |
91 |
|
92 | |||
92 | //grid line |
|
93 | //grid line | |
93 | gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom()); |
|
94 | gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom()); | |
94 |
|
95 | |||
95 | //label text wrapping |
|
96 | //label text wrapping | |
96 | QString text = labelList.at(i); |
|
97 | QString text = labelList.at(i); | |
97 | QRectF boundingRect; |
|
98 | QRectF boundingRect; | |
98 | qreal size = axisRect.bottom() - axisRect.top() - labelPadding() - titleBoundingRect.height() - (titlePad * 2); |
|
99 | qreal size = axisRect.bottom() - axisRect.top() - labelPadding() - titleBoundingRect.height() - (titlePad * 2); | |
99 |
labelItem->set |
|
100 | labelItem->setHtml(ChartPresenter::truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(), | |
100 | size, Qt::Vertical, boundingRect)); |
|
101 | size, Qt::Vertical, boundingRect)); | |
101 |
|
102 | |||
102 | //label transformation origin point |
|
103 | //label transformation origin point | |
103 | const QRectF& rect = labelItem->boundingRect(); |
|
104 | const QRectF& rect = labelItem->boundingRect(); | |
104 | QPointF center = rect.center(); |
|
105 | QPointF center = rect.center(); | |
105 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
106 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
106 | int heightDiff = rect.height() - boundingRect.height(); |
|
107 | int heightDiff = rect.height() - boundingRect.height(); | |
107 |
|
108 | |||
108 | //ticks and label position |
|
109 | //ticks and label position | |
109 | if (axis()->alignment() == Qt::AlignTop) { |
|
110 | if (axis()->alignment() == Qt::AlignTop) { | |
110 | labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() + (heightDiff / 2) - labelPadding()); |
|
111 | labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() + (heightDiff / 2) - labelPadding()); | |
111 | tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding()); |
|
112 | tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding()); | |
112 | } else if (axis()->alignment() == Qt::AlignBottom) { |
|
113 | } else if (axis()->alignment() == Qt::AlignBottom) { | |
113 | labelItem->setPos(layout[i] - center.x(), axisRect.top() - (heightDiff / 2) + labelPadding()); |
|
114 | labelItem->setPos(layout[i] - center.x(), axisRect.top() - (heightDiff / 2) + labelPadding()); | |
114 | tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding()); |
|
115 | tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding()); | |
115 | } |
|
116 | } | |
116 |
|
117 | |||
117 | //label in between |
|
118 | //label in between | |
118 | bool forceHide = false; |
|
119 | bool forceHide = false; | |
119 | if (intervalAxis() && (i + 1) != layout.size()) { |
|
120 | if (intervalAxis() && (i + 1) != layout.size()) { | |
120 | qreal leftBound = qMax(layout[i], gridRect.left()); |
|
121 | qreal leftBound = qMax(layout[i], gridRect.left()); | |
121 | qreal rightBound = qMin(layout[i + 1], gridRect.right()); |
|
122 | qreal rightBound = qMin(layout[i + 1], gridRect.right()); | |
122 | const qreal delta = rightBound - leftBound; |
|
123 | const qreal delta = rightBound - leftBound; | |
123 | // Hide label in case visible part of the category at the grid edge is too narrow |
|
124 | // Hide label in case visible part of the category at the grid edge is too narrow | |
124 | if (delta < boundingRect.width() |
|
125 | if (delta < boundingRect.width() | |
125 | && (leftBound == gridRect.left() || rightBound == gridRect.right())) { |
|
126 | && (leftBound == gridRect.left() || rightBound == gridRect.right())) { | |
126 | forceHide = true; |
|
127 | forceHide = true; | |
127 | } else { |
|
128 | } else { | |
128 | labelItem->setPos(leftBound + (delta / 2.0) - center.x(), labelItem->pos().y()); |
|
129 | labelItem->setPos(leftBound + (delta / 2.0) - center.x(), labelItem->pos().y()); | |
129 | } |
|
130 | } | |
130 | } |
|
131 | } | |
131 |
|
132 | |||
132 | //label overlap detection - compensate one pixel for rounding errors |
|
133 | //label overlap detection - compensate one pixel for rounding errors | |
133 | if (labelItem->pos().x() < width || forceHide || |
|
134 | if (labelItem->pos().x() < width || forceHide || | |
134 | labelItem->pos().x() < (axisRect.left() - 1.0) || |
|
135 | labelItem->pos().x() < (axisRect.left() - 1.0) || | |
135 | (labelItem->pos().x() + boundingRect.width() - 1.0) > axisRect.right()){ |
|
136 | (labelItem->pos().x() + boundingRect.width() - 1.0) > axisRect.right()){ | |
136 | labelItem->setVisible(false); |
|
137 | labelItem->setVisible(false); | |
137 | } else { |
|
138 | } else { | |
138 | labelItem->setVisible(true); |
|
139 | labelItem->setVisible(true); | |
139 | width = boundingRect.width() + labelItem->pos().x(); |
|
140 | width = boundingRect.width() + labelItem->pos().x(); | |
140 | } |
|
141 | } | |
141 |
|
142 | |||
142 | //shades |
|
143 | //shades | |
143 | if ((i + 1) % 2 && i > 1) { |
|
144 | if ((i + 1) % 2 && i > 1) { | |
144 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1)); |
|
145 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1)); | |
145 | qreal leftBound = qMax(layout[i - 1], gridRect.left()); |
|
146 | qreal leftBound = qMax(layout[i - 1], gridRect.left()); | |
146 | qreal rightBound = qMin(layout[i], gridRect.right()); |
|
147 | qreal rightBound = qMin(layout[i], gridRect.right()); | |
147 | rectItem->setRect(leftBound, gridRect.top(), rightBound - leftBound, gridRect.height()); |
|
148 | rectItem->setRect(leftBound, gridRect.top(), rightBound - leftBound, gridRect.height()); | |
148 | if (rectItem->rect().width() <= 0.0) |
|
149 | if (rectItem->rect().width() <= 0.0) | |
149 | rectItem->setVisible(false); |
|
150 | rectItem->setVisible(false); | |
150 | else |
|
151 | else | |
151 | rectItem->setVisible(true); |
|
152 | rectItem->setVisible(true); | |
152 | } |
|
153 | } | |
153 |
|
154 | |||
154 | // check if the grid line and the axis tick should be shown |
|
155 | // check if the grid line and the axis tick should be shown | |
155 | qreal x = gridItem->line().p1().x(); |
|
156 | qreal x = gridItem->line().p1().x(); | |
156 | if (x < gridRect.left() || x > gridRect.right()) { |
|
157 | if (x < gridRect.left() || x > gridRect.right()) { | |
157 | gridItem->setVisible(false); |
|
158 | gridItem->setVisible(false); | |
158 | tickItem->setVisible(false); |
|
159 | tickItem->setVisible(false); | |
159 | } else { |
|
160 | } else { | |
160 | gridItem->setVisible(true); |
|
161 | gridItem->setVisible(true); | |
161 | tickItem->setVisible(true); |
|
162 | tickItem->setVisible(true); | |
162 | } |
|
163 | } | |
163 |
|
164 | |||
164 | } |
|
165 | } | |
165 |
|
166 | |||
166 | //begin/end grid line in case labels between |
|
167 | //begin/end grid line in case labels between | |
167 | if (intervalAxis()) { |
|
168 | if (intervalAxis()) { | |
168 | QGraphicsLineItem *gridLine; |
|
169 | QGraphicsLineItem *gridLine; | |
169 | gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size())); |
|
170 | gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size())); | |
170 | gridLine->setLine(gridRect.right(), gridRect.top(), gridRect.right(), gridRect.bottom()); |
|
171 | gridLine->setLine(gridRect.right(), gridRect.top(), gridRect.right(), gridRect.bottom()); | |
171 | gridLine->setVisible(true); |
|
172 | gridLine->setVisible(true); | |
172 | gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1)); |
|
173 | gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1)); | |
173 | gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom()); |
|
174 | gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom()); | |
174 | gridLine->setVisible(true); |
|
175 | gridLine->setVisible(true); | |
175 | } |
|
176 | } | |
176 | } |
|
177 | } | |
177 |
|
178 | |||
178 | QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
179 | QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
179 | { |
|
180 | { | |
180 | Q_UNUSED(constraint); |
|
181 | Q_UNUSED(constraint); | |
181 | QSizeF sh(0,0); |
|
182 | QSizeF sh(0,0); | |
182 |
|
183 | |||
183 | if (axis()->titleText().isEmpty() || !titleItem()->isVisible()) |
|
184 | if (axis()->titleText().isEmpty() || !titleItem()->isVisible()) | |
184 | return sh; |
|
185 | return sh; | |
185 |
|
186 | |||
186 | switch (which) { |
|
187 | switch (which) { | |
187 | case Qt::MinimumSize: { |
|
188 | case Qt::MinimumSize: { | |
188 | QRectF titleRect = textBoundingRect(axis()->titleFont(), "..."); |
|
189 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), "..."); | |
189 | sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2)); |
|
190 | sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2)); | |
190 | break; |
|
191 | break; | |
191 | } |
|
192 | } | |
192 | case Qt::MaximumSize: |
|
193 | case Qt::MaximumSize: | |
193 | case Qt::PreferredSize: { |
|
194 | case Qt::PreferredSize: { | |
194 | QRectF titleRect = textBoundingRect(axis()->titleFont(), axis()->titleText()); |
|
195 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText()); | |
195 | sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2)); |
|
196 | sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2)); | |
196 | break; |
|
197 | break; | |
197 | } |
|
198 | } | |
198 | default: |
|
199 | default: | |
199 | break; |
|
200 | break; | |
200 | } |
|
201 | } | |
201 |
|
202 | |||
202 | return sh; |
|
203 | return sh; | |
203 | } |
|
204 | } | |
204 |
|
205 | |||
205 | QTCOMMERCIALCHART_END_NAMESPACE |
|
206 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,137 +1,137 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "chartlogvalueaxisx_p.h" |
|
21 | #include "chartlogvalueaxisx_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qlogvalueaxis.h" |
|
23 | #include "qlogvalueaxis.h" | |
24 | #include "abstractchartlayout_p.h" |
|
24 | #include "abstractchartlayout_p.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <qmath.h> |
|
26 | #include <qmath.h> | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | ChartLogValueAxisX::ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem *item) |
|
31 | ChartLogValueAxisX::ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem *item) | |
32 | : HorizontalAxis(axis, item), |
|
32 | : HorizontalAxis(axis, item), | |
33 | m_axis(axis) |
|
33 | m_axis(axis) | |
34 | { |
|
34 | { | |
35 | QObject::connect(m_axis, SIGNAL(baseChanged(qreal)), this, SLOT(handleBaseChanged(qreal))); |
|
35 | QObject::connect(m_axis, SIGNAL(baseChanged(qreal)), this, SLOT(handleBaseChanged(qreal))); | |
36 | QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); |
|
36 | QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartLogValueAxisX::~ChartLogValueAxisX() |
|
39 | ChartLogValueAxisX::~ChartLogValueAxisX() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QVector<qreal> ChartLogValueAxisX::calculateLayout() const |
|
43 | QVector<qreal> ChartLogValueAxisX::calculateLayout() const | |
44 | { |
|
44 | { | |
45 | QVector<qreal> points; |
|
45 | QVector<qreal> points; | |
46 |
|
46 | |||
47 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); |
|
47 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); | |
48 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); |
|
48 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); | |
49 | qreal leftEdge = logMin < logMax ? logMin : logMax; |
|
49 | qreal leftEdge = logMin < logMax ? logMin : logMax; | |
50 | qreal ceilEdge = ceil(leftEdge); |
|
50 | qreal ceilEdge = ceil(leftEdge); | |
51 | int tickCount = qAbs(ceil(logMax) - ceil(logMin)); |
|
51 | int tickCount = qAbs(ceil(logMax) - ceil(logMin)); | |
52 |
|
52 | |||
53 | points.resize(tickCount); |
|
53 | points.resize(tickCount); | |
54 | const QRectF &gridRect = gridGeometry(); |
|
54 | const QRectF &gridRect = gridGeometry(); | |
55 | const qreal deltaX = gridRect.width() / qAbs(logMax - logMin); |
|
55 | const qreal deltaX = gridRect.width() / qAbs(logMax - logMin); | |
56 | for (int i = 0; i < tickCount; ++i) |
|
56 | for (int i = 0; i < tickCount; ++i) | |
57 | points[i] = (ceilEdge + qreal(i)) * deltaX - leftEdge * deltaX + gridRect.left(); |
|
57 | points[i] = (ceilEdge + qreal(i)) * deltaX - leftEdge * deltaX + gridRect.left(); | |
58 |
|
58 | |||
59 | return points; |
|
59 | return points; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void ChartLogValueAxisX::updateGeometry() |
|
62 | void ChartLogValueAxisX::updateGeometry() | |
63 | { |
|
63 | { | |
64 | const QVector<qreal>& layout = ChartAxisElement::layout(); |
|
64 | const QVector<qreal>& layout = ChartAxisElement::layout(); | |
65 | if (layout.isEmpty()) |
|
65 | if (layout.isEmpty()) | |
66 | return; |
|
66 | return; | |
67 | setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat())); |
|
67 | setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat())); | |
68 | HorizontalAxis::updateGeometry(); |
|
68 | HorizontalAxis::updateGeometry(); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void ChartLogValueAxisX::handleBaseChanged(qreal base) |
|
71 | void ChartLogValueAxisX::handleBaseChanged(qreal base) | |
72 | { |
|
72 | { | |
73 | Q_UNUSED(base); |
|
73 | Q_UNUSED(base); | |
74 | QGraphicsLayoutItem::updateGeometry(); |
|
74 | QGraphicsLayoutItem::updateGeometry(); | |
75 | if(presenter()) presenter()->layout()->invalidate(); |
|
75 | if(presenter()) presenter()->layout()->invalidate(); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void ChartLogValueAxisX::handleLabelFormatChanged(const QString &format) |
|
78 | void ChartLogValueAxisX::handleLabelFormatChanged(const QString &format) | |
79 | { |
|
79 | { | |
80 | Q_UNUSED(format); |
|
80 | Q_UNUSED(format); | |
81 | QGraphicsLayoutItem::updateGeometry(); |
|
81 | QGraphicsLayoutItem::updateGeometry(); | |
82 | if(presenter()) presenter()->layout()->invalidate(); |
|
82 | if(presenter()) presenter()->layout()->invalidate(); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
85 | QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
86 | { |
|
86 | { | |
87 | Q_UNUSED(constraint) |
|
87 | Q_UNUSED(constraint) | |
88 |
|
88 | |||
89 | QSizeF sh; |
|
89 | QSizeF sh; | |
90 |
|
90 | |||
91 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
91 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |
92 | QStringList ticksList; |
|
92 | QStringList ticksList; | |
93 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); |
|
93 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); | |
94 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); |
|
94 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); | |
95 | int tickCount = qAbs(ceil(logMax) - ceil(logMin)); |
|
95 | int tickCount = qAbs(ceil(logMax) - ceil(logMin)); | |
96 | if (m_axis->max() > m_axis->min() && tickCount > 0) |
|
96 | if (m_axis->max() > m_axis->min() && tickCount > 0) | |
97 | ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat()); |
|
97 | ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat()); | |
98 | else |
|
98 | else | |
99 | ticksList.append(QString(" ")); |
|
99 | ticksList.append(QString(" ")); | |
100 | // Width of horizontal axis sizeHint indicates the maximum distance labels can extend past |
|
100 | // Width of horizontal axis sizeHint indicates the maximum distance labels can extend past | |
101 | // first and last ticks. Base width is irrelevant. |
|
101 | // first and last ticks. Base width is irrelevant. | |
102 | qreal width = 0; |
|
102 | qreal width = 0; | |
103 | qreal height = 0; |
|
103 | qreal height = 0; | |
104 |
|
104 | |||
105 | switch (which) { |
|
105 | switch (which) { | |
106 | case Qt::MinimumSize:{ |
|
106 | case Qt::MinimumSize:{ | |
107 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); |
|
107 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
108 | width = boundingRect.width() / 2.0; |
|
108 | width = boundingRect.width() / 2.0; | |
109 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; |
|
109 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; | |
110 | sh = QSizeF(width, height); |
|
110 | sh = QSizeF(width, height); | |
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 | case Qt::PreferredSize: { |
|
113 | case Qt::PreferredSize: { | |
114 | qreal labelHeight = 0.0; |
|
114 | qreal labelHeight = 0.0; | |
115 | qreal firstWidth = -1.0; |
|
115 | qreal firstWidth = -1.0; | |
116 | foreach (const QString& s, ticksList) { |
|
116 | foreach (const QString& s, ticksList) { | |
117 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); |
|
117 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
118 | labelHeight = qMax(rect.height(), labelHeight); |
|
118 | labelHeight = qMax(rect.height(), labelHeight); | |
119 | width = rect.width(); |
|
119 | width = rect.width(); | |
120 | if (firstWidth < 0.0) |
|
120 | if (firstWidth < 0.0) | |
121 | firstWidth = width; |
|
121 | firstWidth = width; | |
122 | } |
|
122 | } | |
123 | height = labelHeight + labelPadding() + base.height() + 1.0; |
|
123 | height = labelHeight + labelPadding() + base.height() + 1.0; | |
124 | width = qMax(width, firstWidth) / 2.0; |
|
124 | width = qMax(width, firstWidth) / 2.0; | |
125 | sh = QSizeF(width, height); |
|
125 | sh = QSizeF(width, height); | |
126 | break; |
|
126 | break; | |
127 | } |
|
127 | } | |
128 | default: |
|
128 | default: | |
129 | break; |
|
129 | break; | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | return sh; |
|
132 | return sh; | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | #include "moc_chartlogvalueaxisx_p.cpp" |
|
135 | #include "moc_chartlogvalueaxisx_p.cpp" | |
136 |
|
136 | |||
137 | QTCOMMERCIALCHART_END_NAMESPACE |
|
137 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,137 +1,137 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "chartlogvalueaxisy_p.h" |
|
21 | #include "chartlogvalueaxisy_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qlogvalueaxis.h" |
|
23 | #include "qlogvalueaxis.h" | |
24 | #include "abstractchartlayout_p.h" |
|
24 | #include "abstractchartlayout_p.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <qmath.h> |
|
26 | #include <qmath.h> | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | ChartLogValueAxisY::ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem *item) |
|
31 | ChartLogValueAxisY::ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem *item) | |
32 | : VerticalAxis(axis, item), |
|
32 | : VerticalAxis(axis, item), | |
33 | m_axis(axis) |
|
33 | m_axis(axis) | |
34 | { |
|
34 | { | |
35 | QObject::connect(m_axis, SIGNAL(baseChanged(qreal)), this, SLOT(handleBaseChanged(qreal))); |
|
35 | QObject::connect(m_axis, SIGNAL(baseChanged(qreal)), this, SLOT(handleBaseChanged(qreal))); | |
36 | QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); |
|
36 | QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartLogValueAxisY::~ChartLogValueAxisY() |
|
39 | ChartLogValueAxisY::~ChartLogValueAxisY() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QVector<qreal> ChartLogValueAxisY::calculateLayout() const |
|
43 | QVector<qreal> ChartLogValueAxisY::calculateLayout() const | |
44 | { |
|
44 | { | |
45 | QVector<qreal> points; |
|
45 | QVector<qreal> points; | |
46 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); |
|
46 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); | |
47 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); |
|
47 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); | |
48 | qreal leftEdge = logMin < logMax ? logMin : logMax; |
|
48 | qreal leftEdge = logMin < logMax ? logMin : logMax; | |
49 | qreal ceilEdge = ceil(leftEdge); |
|
49 | qreal ceilEdge = ceil(leftEdge); | |
50 | int tickCount = qAbs(ceil(logMax) - ceil(logMin)); |
|
50 | int tickCount = qAbs(ceil(logMax) - ceil(logMin)); | |
51 |
|
51 | |||
52 | points.resize(tickCount); |
|
52 | points.resize(tickCount); | |
53 | const QRectF &gridRect = gridGeometry(); |
|
53 | const QRectF &gridRect = gridGeometry(); | |
54 | const qreal deltaY = gridRect.height() / qAbs(logMax - logMin); |
|
54 | const qreal deltaY = gridRect.height() / qAbs(logMax - logMin); | |
55 | for (int i = 0; i < tickCount; ++i) |
|
55 | for (int i = 0; i < tickCount; ++i) | |
56 | points[i] = (ceilEdge + qreal(i)) * -deltaY - leftEdge * -deltaY + gridRect.bottom(); |
|
56 | points[i] = (ceilEdge + qreal(i)) * -deltaY - leftEdge * -deltaY + gridRect.bottom(); | |
57 |
|
57 | |||
58 | return points; |
|
58 | return points; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 |
|
61 | |||
62 | void ChartLogValueAxisY::updateGeometry() |
|
62 | void ChartLogValueAxisY::updateGeometry() | |
63 | { |
|
63 | { | |
64 | const QVector<qreal> &layout = ChartAxisElement::layout(); |
|
64 | const QVector<qreal> &layout = ChartAxisElement::layout(); | |
65 | if (layout.isEmpty()) |
|
65 | if (layout.isEmpty()) | |
66 | return; |
|
66 | return; | |
67 | setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat())); |
|
67 | setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat())); | |
68 | VerticalAxis::updateGeometry(); |
|
68 | VerticalAxis::updateGeometry(); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void ChartLogValueAxisY::handleBaseChanged(qreal base) |
|
71 | void ChartLogValueAxisY::handleBaseChanged(qreal base) | |
72 | { |
|
72 | { | |
73 | Q_UNUSED(base); |
|
73 | Q_UNUSED(base); | |
74 | QGraphicsLayoutItem::updateGeometry(); |
|
74 | QGraphicsLayoutItem::updateGeometry(); | |
75 | if(presenter()) presenter()->layout()->invalidate(); |
|
75 | if(presenter()) presenter()->layout()->invalidate(); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void ChartLogValueAxisY::handleLabelFormatChanged(const QString &format) |
|
78 | void ChartLogValueAxisY::handleLabelFormatChanged(const QString &format) | |
79 | { |
|
79 | { | |
80 | Q_UNUSED(format); |
|
80 | Q_UNUSED(format); | |
81 | QGraphicsLayoutItem::updateGeometry(); |
|
81 | QGraphicsLayoutItem::updateGeometry(); | |
82 | if(presenter()) presenter()->layout()->invalidate(); |
|
82 | if(presenter()) presenter()->layout()->invalidate(); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
85 | QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
86 | { |
|
86 | { | |
87 | Q_UNUSED(constraint) |
|
87 | Q_UNUSED(constraint) | |
88 |
|
88 | |||
89 | QSizeF sh; |
|
89 | QSizeF sh; | |
90 |
|
90 | |||
91 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
91 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
92 | QStringList ticksList; |
|
92 | QStringList ticksList; | |
93 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); |
|
93 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); | |
94 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); |
|
94 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); | |
95 | int tickCount = qAbs(ceil(logMax) - ceil(logMin)); |
|
95 | int tickCount = qAbs(ceil(logMax) - ceil(logMin)); | |
96 | if (m_axis->max() > m_axis->min() && tickCount > 0) |
|
96 | if (m_axis->max() > m_axis->min() && tickCount > 0) | |
97 | ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat()); |
|
97 | ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat()); | |
98 | else |
|
98 | else | |
99 | ticksList.append(QString(" ")); |
|
99 | ticksList.append(QString(" ")); | |
100 | qreal width = 0; |
|
100 | qreal width = 0; | |
101 | // Height of vertical axis sizeHint indicates the maximum distance labels can extend past |
|
101 | // Height of vertical axis sizeHint indicates the maximum distance labels can extend past | |
102 | // first and last ticks. Base height is irrelevant. |
|
102 | // first and last ticks. Base height is irrelevant. | |
103 | qreal height = 0; |
|
103 | qreal height = 0; | |
104 |
|
104 | |||
105 | switch (which) { |
|
105 | switch (which) { | |
106 | case Qt::MinimumSize: { |
|
106 | case Qt::MinimumSize: { | |
107 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); |
|
107 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
108 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; |
|
108 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; | |
109 | height = boundingRect.height() / 2.0; |
|
109 | height = boundingRect.height() / 2.0; | |
110 | sh = QSizeF(width, height); |
|
110 | sh = QSizeF(width, height); | |
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 | case Qt::PreferredSize: { |
|
113 | case Qt::PreferredSize: { | |
114 | qreal labelWidth = 0.0; |
|
114 | qreal labelWidth = 0.0; | |
115 | qreal firstHeight = -1.0; |
|
115 | qreal firstHeight = -1.0; | |
116 | foreach (const QString& s, ticksList) { |
|
116 | foreach (const QString& s, ticksList) { | |
117 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); |
|
117 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
118 | labelWidth = qMax(rect.width(), labelWidth); |
|
118 | labelWidth = qMax(rect.width(), labelWidth); | |
119 | height = rect.height(); |
|
119 | height = rect.height(); | |
120 | if (firstHeight < 0.0) |
|
120 | if (firstHeight < 0.0) | |
121 | firstHeight = height; |
|
121 | firstHeight = height; | |
122 | } |
|
122 | } | |
123 | width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance |
|
123 | width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance | |
124 | height = qMax(height, firstHeight) / 2.0; |
|
124 | height = qMax(height, firstHeight) / 2.0; | |
125 | sh = QSizeF(width, height); |
|
125 | sh = QSizeF(width, height); | |
126 | break; |
|
126 | break; | |
127 | } |
|
127 | } | |
128 | default: |
|
128 | default: | |
129 | break; |
|
129 | break; | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | return sh; |
|
132 | return sh; | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | #include "moc_chartlogvalueaxisy_p.cpp" |
|
135 | #include "moc_chartlogvalueaxisy_p.cpp" | |
136 |
|
136 | |||
137 | QTCOMMERCIALCHART_END_NAMESPACE |
|
137 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,410 +1,408 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "polarchartaxisangular_p.h" |
|
21 | #include "polarchartaxisangular_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "abstractchartlayout_p.h" |
|
23 | #include "abstractchartlayout_p.h" | |
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 | #include "qabstractaxis_p.h" |
|
25 | #include "qabstractaxis_p.h" | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | PolarChartAxisAngular::PolarChartAxisAngular(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) |
|
30 | PolarChartAxisAngular::PolarChartAxisAngular(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) | |
31 | : PolarChartAxis(axis, item, intervalAxis) |
|
31 | : PolarChartAxis(axis, item, intervalAxis) | |
32 | { |
|
32 | { | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | PolarChartAxisAngular::~PolarChartAxisAngular() |
|
35 | PolarChartAxisAngular::~PolarChartAxisAngular() | |
36 | { |
|
36 | { | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void PolarChartAxisAngular::updateGeometry() |
|
39 | void PolarChartAxisAngular::updateGeometry() | |
40 | { |
|
40 | { | |
41 | QGraphicsLayoutItem::updateGeometry(); |
|
41 | QGraphicsLayoutItem::updateGeometry(); | |
42 |
|
42 | |||
43 | const QVector<qreal> &layout = this->layout(); |
|
43 | const QVector<qreal> &layout = this->layout(); | |
44 | if (layout.isEmpty()) |
|
44 | if (layout.isEmpty()) | |
45 | return; |
|
45 | return; | |
46 |
|
46 | |||
47 | createAxisLabels(layout); |
|
47 | createAxisLabels(layout); | |
48 | QStringList labelList = labels(); |
|
48 | QStringList labelList = labels(); | |
49 | QPointF center = axisGeometry().center(); |
|
49 | QPointF center = axisGeometry().center(); | |
50 | QList<QGraphicsItem *> arrowItemList = arrowItems(); |
|
50 | QList<QGraphicsItem *> arrowItemList = arrowItems(); | |
51 | QList<QGraphicsItem *> gridItemList = gridItems(); |
|
51 | QList<QGraphicsItem *> gridItemList = gridItems(); | |
52 | QList<QGraphicsItem *> labelItemList = labelItems(); |
|
52 | QList<QGraphicsItem *> labelItemList = labelItems(); | |
53 | QList<QGraphicsItem *> shadeItemList = shadeItems(); |
|
53 | QList<QGraphicsItem *> shadeItemList = shadeItems(); | |
54 |
QGraphics |
|
54 | QGraphicsTextItem *title = titleItem(); | |
55 |
|
55 | |||
56 | QGraphicsEllipseItem *axisLine = static_cast<QGraphicsEllipseItem *>(arrowItemList.at(0)); |
|
56 | QGraphicsEllipseItem *axisLine = static_cast<QGraphicsEllipseItem *>(arrowItemList.at(0)); | |
57 | axisLine->setRect(axisGeometry()); |
|
57 | axisLine->setRect(axisGeometry()); | |
58 |
|
58 | |||
59 | qreal radius = axisGeometry().height() / 2.0; |
|
59 | qreal radius = axisGeometry().height() / 2.0; | |
60 |
|
60 | |||
61 | QRectF previousLabelRect; |
|
61 | QRectF previousLabelRect; | |
62 | QRectF firstLabelRect; |
|
62 | QRectF firstLabelRect; | |
63 |
|
63 | |||
64 | qreal labelHeight = 0; |
|
64 | qreal labelHeight = 0; | |
65 |
|
65 | |||
66 | bool firstShade = true; |
|
66 | bool firstShade = true; | |
67 | bool nextTickVisible = false; |
|
67 | bool nextTickVisible = false; | |
68 | if (layout.size()) |
|
68 | if (layout.size()) | |
69 | nextTickVisible = !(layout.at(0) < 0.0 || layout.at(0) > 360.0); |
|
69 | nextTickVisible = !(layout.at(0) < 0.0 || layout.at(0) > 360.0); | |
70 |
|
70 | |||
71 | for (int i = 0; i < layout.size(); ++i) { |
|
71 | for (int i = 0; i < layout.size(); ++i) { | |
72 | qreal angularCoordinate = layout.at(i); |
|
72 | qreal angularCoordinate = layout.at(i); | |
73 |
|
73 | |||
74 | QGraphicsLineItem *gridLineItem = static_cast<QGraphicsLineItem *>(gridItemList.at(i)); |
|
74 | QGraphicsLineItem *gridLineItem = static_cast<QGraphicsLineItem *>(gridItemList.at(i)); | |
75 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1)); |
|
75 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1)); | |
76 |
QGraphics |
|
76 | QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labelItemList.at(i)); | |
77 | QGraphicsPathItem *shadeItem = 0; |
|
77 | QGraphicsPathItem *shadeItem = 0; | |
78 | if (i == 0) |
|
78 | if (i == 0) | |
79 | shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0)); |
|
79 | shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0)); | |
80 | else if (i % 2) |
|
80 | else if (i % 2) | |
81 | shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at((i / 2) + 1)); |
|
81 | shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at((i / 2) + 1)); | |
82 |
|
82 | |||
83 | // Ignore ticks outside valid range |
|
83 | // Ignore ticks outside valid range | |
84 | bool currentTickVisible = nextTickVisible; |
|
84 | bool currentTickVisible = nextTickVisible; | |
85 | if ((i == layout.size() - 1) |
|
85 | if ((i == layout.size() - 1) | |
86 | || layout.at(i + 1) < 0.0 |
|
86 | || layout.at(i + 1) < 0.0 | |
87 | || layout.at(i + 1) > 360.0) { |
|
87 | || layout.at(i + 1) > 360.0) { | |
88 | nextTickVisible = false; |
|
88 | nextTickVisible = false; | |
89 | } else { |
|
89 | } else { | |
90 | nextTickVisible = true; |
|
90 | nextTickVisible = true; | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | qreal labelCoordinate = angularCoordinate; |
|
93 | qreal labelCoordinate = angularCoordinate; | |
94 | qreal labelVisible = currentTickVisible; |
|
94 | qreal labelVisible = currentTickVisible; | |
95 | if (intervalAxis()) { |
|
95 | if (intervalAxis()) { | |
96 | qreal farEdge; |
|
96 | qreal farEdge; | |
97 | if (i == (layout.size() - 1)) |
|
97 | if (i == (layout.size() - 1)) | |
98 | farEdge = 360.0; |
|
98 | farEdge = 360.0; | |
99 | else |
|
99 | else | |
100 | farEdge = qMin(qreal(360.0), layout.at(i + 1)); |
|
100 | farEdge = qMin(qreal(360.0), layout.at(i + 1)); | |
101 |
|
101 | |||
102 | // Adjust the labelCoordinate to show it if next tick is visible |
|
102 | // Adjust the labelCoordinate to show it if next tick is visible | |
103 | if (nextTickVisible) |
|
103 | if (nextTickVisible) | |
104 | labelCoordinate = qMax(qreal(0.0), labelCoordinate); |
|
104 | labelCoordinate = qMax(qreal(0.0), labelCoordinate); | |
105 |
|
105 | |||
106 | labelCoordinate = (labelCoordinate + farEdge) / 2.0; |
|
106 | labelCoordinate = (labelCoordinate + farEdge) / 2.0; | |
107 | // Don't display label once the category gets too small near the axis |
|
107 | // Don't display label once the category gets too small near the axis | |
108 | if (labelCoordinate < 5.0 || labelCoordinate > 355.0) |
|
108 | if (labelCoordinate < 5.0 || labelCoordinate > 355.0) | |
109 | labelVisible = false; |
|
109 | labelVisible = false; | |
110 | else |
|
110 | else | |
111 | labelVisible = true; |
|
111 | labelVisible = true; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | // Need this also in label calculations, so determine it first |
|
114 | // Need this also in label calculations, so determine it first | |
115 | QLineF tickLine(QLineF::fromPolar(radius - tickWidth(), 90.0 - angularCoordinate).p2(), |
|
115 | QLineF tickLine(QLineF::fromPolar(radius - tickWidth(), 90.0 - angularCoordinate).p2(), | |
116 | QLineF::fromPolar(radius + tickWidth(), 90.0 - angularCoordinate).p2()); |
|
116 | QLineF::fromPolar(radius + tickWidth(), 90.0 - angularCoordinate).p2()); | |
117 | tickLine.translate(center); |
|
117 | tickLine.translate(center); | |
118 |
|
118 | |||
119 | // Angular axis label |
|
119 | // Angular axis label | |
120 | if (axis()->labelsVisible() && labelVisible) { |
|
120 | if (axis()->labelsVisible() && labelVisible) { | |
121 |
labelItem->set |
|
121 | labelItem->setHtml(labelList.at(i)); | |
122 | const QRectF &rect = labelItem->boundingRect(); |
|
122 | const QRectF &rect = labelItem->boundingRect(); | |
123 | QPointF labelCenter = rect.center(); |
|
123 | QPointF labelCenter = rect.center(); | |
124 | labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y()); |
|
124 | labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y()); | |
125 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle()); |
|
125 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle()); | |
126 | boundingRect.moveCenter(labelCenter); |
|
126 | boundingRect.moveCenter(labelCenter); | |
127 | QPointF positionDiff(rect.topLeft() - boundingRect.topLeft()); |
|
127 | QPointF positionDiff(rect.topLeft() - boundingRect.topLeft()); | |
128 |
|
128 | |||
129 | QPointF labelPoint; |
|
129 | QPointF labelPoint; | |
130 | if (intervalAxis()) { |
|
130 | if (intervalAxis()) { | |
131 | QLineF labelLine = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate); |
|
131 | QLineF labelLine = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate); | |
132 | labelLine.translate(center); |
|
132 | labelLine.translate(center); | |
133 | labelPoint = labelLine.p2(); |
|
133 | labelPoint = labelLine.p2(); | |
134 | } else { |
|
134 | } else { | |
135 | labelPoint = tickLine.p2(); |
|
135 | labelPoint = tickLine.p2(); | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | QRectF labelRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect); |
|
138 | QRectF labelRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect); | |
139 | labelItem->setPos(labelRect.topLeft() + positionDiff); |
|
139 | labelItem->setPos(labelRect.topLeft() + positionDiff); | |
140 |
|
140 | |||
141 | // Store height for title calculations |
|
141 | // Store height for title calculations | |
142 | qreal labelClearance = axisGeometry().top() - labelRect.top(); |
|
142 | qreal labelClearance = axisGeometry().top() - labelRect.top(); | |
143 | labelHeight = qMax(labelHeight, labelClearance); |
|
143 | labelHeight = qMax(labelHeight, labelClearance); | |
144 |
|
144 | |||
145 | // Label overlap detection |
|
145 | // Label overlap detection | |
146 | if (i && (previousLabelRect.intersects(labelRect) || firstLabelRect.intersects(labelRect))) { |
|
146 | if (i && (previousLabelRect.intersects(labelRect) || firstLabelRect.intersects(labelRect))) { | |
147 | labelVisible = false; |
|
147 | labelVisible = false; | |
148 | } else { |
|
148 | } else { | |
149 | // Store labelRect for future comparison. Some area is deducted to make things look |
|
149 | // Store labelRect for future comparison. Some area is deducted to make things look | |
150 | // little nicer, as usually intersection happens at label corner with angular labels. |
|
150 | // little nicer, as usually intersection happens at label corner with angular labels. | |
151 | labelRect.adjust(-2.0, -4.0, -2.0, -4.0); |
|
151 | labelRect.adjust(-2.0, -4.0, -2.0, -4.0); | |
152 | if (firstLabelRect.isEmpty()) |
|
152 | if (firstLabelRect.isEmpty()) | |
153 | firstLabelRect = labelRect; |
|
153 | firstLabelRect = labelRect; | |
154 |
|
154 | |||
155 | previousLabelRect = labelRect; |
|
155 | previousLabelRect = labelRect; | |
156 | labelVisible = true; |
|
156 | labelVisible = true; | |
157 | } |
|
157 | } | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | labelItem->setVisible(labelVisible); |
|
160 | labelItem->setVisible(labelVisible); | |
161 | if (!currentTickVisible) { |
|
161 | if (!currentTickVisible) { | |
162 | gridLineItem->setVisible(false); |
|
162 | gridLineItem->setVisible(false); | |
163 | tickItem->setVisible(false); |
|
163 | tickItem->setVisible(false); | |
164 | if (shadeItem) |
|
164 | if (shadeItem) | |
165 | shadeItem->setVisible(false); |
|
165 | shadeItem->setVisible(false); | |
166 | continue; |
|
166 | continue; | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | // Angular grid line |
|
169 | // Angular grid line | |
170 | QLineF gridLine = QLineF::fromPolar(radius, 90.0 - angularCoordinate); |
|
170 | QLineF gridLine = QLineF::fromPolar(radius, 90.0 - angularCoordinate); | |
171 | gridLine.translate(center); |
|
171 | gridLine.translate(center); | |
172 | gridLineItem->setLine(gridLine); |
|
172 | gridLineItem->setLine(gridLine); | |
173 | gridLineItem->setVisible(true); |
|
173 | gridLineItem->setVisible(true); | |
174 |
|
174 | |||
175 | // Tick |
|
175 | // Tick | |
176 | tickItem->setLine(tickLine); |
|
176 | tickItem->setLine(tickLine); | |
177 | tickItem->setVisible(true); |
|
177 | tickItem->setVisible(true); | |
178 |
|
178 | |||
179 | // Shades |
|
179 | // Shades | |
180 | if (i % 2 || (i == 0 && !nextTickVisible)) { |
|
180 | if (i % 2 || (i == 0 && !nextTickVisible)) { | |
181 | QPainterPath path; |
|
181 | QPainterPath path; | |
182 | path.moveTo(center); |
|
182 | path.moveTo(center); | |
183 | if (i == 0) { |
|
183 | if (i == 0) { | |
184 | // If first tick is also the last, we need to custom fill the first partial arc |
|
184 | // If first tick is also the last, we need to custom fill the first partial arc | |
185 | // or it won't get filled. |
|
185 | // or it won't get filled. | |
186 | path.arcTo(axisGeometry(), 90.0 - layout.at(0), layout.at(0)); |
|
186 | path.arcTo(axisGeometry(), 90.0 - layout.at(0), layout.at(0)); | |
187 | path.closeSubpath(); |
|
187 | path.closeSubpath(); | |
188 | } else { |
|
188 | } else { | |
189 | qreal nextCoordinate; |
|
189 | qreal nextCoordinate; | |
190 | if (!nextTickVisible) // Last visible tick |
|
190 | if (!nextTickVisible) // Last visible tick | |
191 | nextCoordinate = 360.0; |
|
191 | nextCoordinate = 360.0; | |
192 | else |
|
192 | else | |
193 | nextCoordinate = layout.at(i + 1); |
|
193 | nextCoordinate = layout.at(i + 1); | |
194 | qreal arcSpan = angularCoordinate - nextCoordinate; |
|
194 | qreal arcSpan = angularCoordinate - nextCoordinate; | |
195 | path.arcTo(axisGeometry(), 90.0 - angularCoordinate, arcSpan); |
|
195 | path.arcTo(axisGeometry(), 90.0 - angularCoordinate, arcSpan); | |
196 | path.closeSubpath(); |
|
196 | path.closeSubpath(); | |
197 |
|
197 | |||
198 | // Add additional arc for first shade item if there is a partial arc to be filled |
|
198 | // Add additional arc for first shade item if there is a partial arc to be filled | |
199 | if (firstShade) { |
|
199 | if (firstShade) { | |
200 | QGraphicsPathItem *specialShadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0)); |
|
200 | QGraphicsPathItem *specialShadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0)); | |
201 | if (layout.at(i - 1) > 0.0) { |
|
201 | if (layout.at(i - 1) > 0.0) { | |
202 | QPainterPath specialPath; |
|
202 | QPainterPath specialPath; | |
203 | specialPath.moveTo(center); |
|
203 | specialPath.moveTo(center); | |
204 | specialPath.arcTo(axisGeometry(), 90.0 - layout.at(i - 1), layout.at(i - 1)); |
|
204 | specialPath.arcTo(axisGeometry(), 90.0 - layout.at(i - 1), layout.at(i - 1)); | |
205 | specialPath.closeSubpath(); |
|
205 | specialPath.closeSubpath(); | |
206 | specialShadeItem->setPath(specialPath); |
|
206 | specialShadeItem->setPath(specialPath); | |
207 | specialShadeItem->setVisible(true); |
|
207 | specialShadeItem->setVisible(true); | |
208 | } else { |
|
208 | } else { | |
209 | specialShadeItem->setVisible(false); |
|
209 | specialShadeItem->setVisible(false); | |
210 | } |
|
210 | } | |
211 | } |
|
211 | } | |
212 | } |
|
212 | } | |
213 | shadeItem->setPath(path); |
|
213 | shadeItem->setPath(path); | |
214 | shadeItem->setVisible(true); |
|
214 | shadeItem->setVisible(true); | |
215 | firstShade = false; |
|
215 | firstShade = false; | |
216 | } |
|
216 | } | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | // Title, centered above the chart |
|
219 | // Title, centered above the chart | |
220 | QString titleText = axis()->titleText(); |
|
220 | QString titleText = axis()->titleText(); | |
221 | if (!titleText.isEmpty() && axis()->isTitleVisible()) { |
|
221 | if (!titleText.isEmpty() && axis()->isTitleVisible()) { | |
222 |
title->set |
|
222 | title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), axisGeometry().width(), Qt::Horizontal, QRectF())); | |
223 |
|
223 | |||
224 | QRectF titleBoundingRect = title->boundingRect(); |
|
224 | QRectF titleBoundingRect = title->boundingRect(); | |
225 | QPointF titleCenter = center - titleBoundingRect.center(); |
|
225 | QPointF titleCenter = center - titleBoundingRect.center(); | |
226 | title->setPos(titleCenter.x(), axisGeometry().top() - qreal(titlePadding()) * 2.0 - titleBoundingRect.height() - labelHeight); |
|
226 | title->setPos(titleCenter.x(), axisGeometry().top() - qreal(titlePadding()) * 2.0 - titleBoundingRect.height() - labelHeight); | |
227 | } |
|
227 | } | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | Qt::Orientation PolarChartAxisAngular::orientation() const |
|
230 | Qt::Orientation PolarChartAxisAngular::orientation() const | |
231 | { |
|
231 | { | |
232 | return Qt::Horizontal; |
|
232 | return Qt::Horizontal; | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | void PolarChartAxisAngular::createItems(int count) |
|
235 | void PolarChartAxisAngular::createItems(int count) | |
236 | { |
|
236 | { | |
237 | if (arrowItems().count() == 0) { |
|
237 | if (arrowItems().count() == 0) { | |
238 | // angular axis line |
|
238 | // angular axis line | |
239 | // TODO: need class similar to LineArrowItem for click handling? |
|
239 | // TODO: need class similar to LineArrowItem for click handling? | |
240 | QGraphicsEllipseItem *arrow = new QGraphicsEllipseItem(presenter()->rootItem()); |
|
240 | QGraphicsEllipseItem *arrow = new QGraphicsEllipseItem(presenter()->rootItem()); | |
241 | arrow->setPen(axis()->linePen()); |
|
241 | arrow->setPen(axis()->linePen()); | |
242 | arrowGroup()->addToGroup(arrow); |
|
242 | arrowGroup()->addToGroup(arrow); | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | for (int i = 0; i < count; ++i) { |
|
245 | for (int i = 0; i < count; ++i) { | |
246 | QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem()); |
|
246 | QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem()); | |
247 | QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem()); |
|
247 | QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem()); | |
248 |
QGraphics |
|
248 | QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem()); | |
249 |
QGraphics |
|
249 | QGraphicsTextItem *title = titleItem(); | |
250 | arrow->setPen(axis()->linePen()); |
|
250 | arrow->setPen(axis()->linePen()); | |
251 | grid->setPen(axis()->gridLinePen()); |
|
251 | grid->setPen(axis()->gridLinePen()); | |
252 | label->setFont(axis()->labelsFont()); |
|
252 | label->setFont(axis()->labelsFont()); | |
253 |
label->set |
|
253 | label->setDefaultTextColor(axis()->labelsBrush().color()); | |
254 | label->setBrush(axis()->labelsBrush()); |
|
|||
255 | label->setRotation(axis()->labelsAngle()); |
|
254 | label->setRotation(axis()->labelsAngle()); | |
256 | title->setFont(axis()->titleFont()); |
|
255 | title->setFont(axis()->titleFont()); | |
257 |
title->set |
|
256 | title->setDefaultTextColor(axis()->titleBrush().color()); | |
258 |
title->set |
|
257 | title->setHtml(axis()->titleText()); | |
259 | title->setText(axis()->titleText()); |
|
|||
260 | arrowGroup()->addToGroup(arrow); |
|
258 | arrowGroup()->addToGroup(arrow); | |
261 | gridGroup()->addToGroup(grid); |
|
259 | gridGroup()->addToGroup(grid); | |
262 | labelGroup()->addToGroup(label); |
|
260 | labelGroup()->addToGroup(label); | |
263 | if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) { |
|
261 | if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) { | |
264 | QGraphicsPathItem *shade = new QGraphicsPathItem(presenter()->rootItem()); |
|
262 | QGraphicsPathItem *shade = new QGraphicsPathItem(presenter()->rootItem()); | |
265 | shade->setPen(axis()->shadesPen()); |
|
263 | shade->setPen(axis()->shadesPen()); | |
266 | shade->setBrush(axis()->shadesBrush()); |
|
264 | shade->setBrush(axis()->shadesBrush()); | |
267 | shadeGroup()->addToGroup(shade); |
|
265 | shadeGroup()->addToGroup(shade); | |
268 | } |
|
266 | } | |
269 | } |
|
267 | } | |
270 | } |
|
268 | } | |
271 |
|
269 | |||
272 | void PolarChartAxisAngular::handleArrowPenChanged(const QPen &pen) |
|
270 | void PolarChartAxisAngular::handleArrowPenChanged(const QPen &pen) | |
273 | { |
|
271 | { | |
274 | bool first = true; |
|
272 | bool first = true; | |
275 | foreach (QGraphicsItem *item, arrowItems()) { |
|
273 | foreach (QGraphicsItem *item, arrowItems()) { | |
276 | if (first) { |
|
274 | if (first) { | |
277 | first = false; |
|
275 | first = false; | |
278 | // First arrow item is the outer circle of axis |
|
276 | // First arrow item is the outer circle of axis | |
279 | static_cast<QGraphicsEllipseItem *>(item)->setPen(pen); |
|
277 | static_cast<QGraphicsEllipseItem *>(item)->setPen(pen); | |
280 | } else { |
|
278 | } else { | |
281 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
279 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
282 | } |
|
280 | } | |
283 | } |
|
281 | } | |
284 | } |
|
282 | } | |
285 |
|
283 | |||
286 | void PolarChartAxisAngular::handleGridPenChanged(const QPen &pen) |
|
284 | void PolarChartAxisAngular::handleGridPenChanged(const QPen &pen) | |
287 | { |
|
285 | { | |
288 | foreach (QGraphicsItem *item, gridItems()) |
|
286 | foreach (QGraphicsItem *item, gridItems()) | |
289 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
287 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
290 | } |
|
288 | } | |
291 |
|
289 | |||
292 | QSizeF PolarChartAxisAngular::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
290 | QSizeF PolarChartAxisAngular::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
293 | { |
|
291 | { | |
294 | Q_UNUSED(which); |
|
292 | Q_UNUSED(which); | |
295 | Q_UNUSED(constraint); |
|
293 | Q_UNUSED(constraint); | |
296 | return QSizeF(-1, -1); |
|
294 | return QSizeF(-1, -1); | |
297 | } |
|
295 | } | |
298 |
|
296 | |||
299 | qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize) |
|
297 | qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize) | |
300 | { |
|
298 | { | |
301 | qreal radius = maxSize.height() / 2.0; |
|
299 | qreal radius = maxSize.height() / 2.0; | |
302 | if (maxSize.width() < maxSize.height()) |
|
300 | if (maxSize.width() < maxSize.height()) | |
303 | radius = maxSize.width() / 2.0; |
|
301 | radius = maxSize.width() / 2.0; | |
304 |
|
302 | |||
305 | if (axis()->labelsVisible()) { |
|
303 | if (axis()->labelsVisible()) { | |
306 | QVector<qreal> layout = calculateLayout(); |
|
304 | QVector<qreal> layout = calculateLayout(); | |
307 | if (layout.isEmpty()) |
|
305 | if (layout.isEmpty()) | |
308 | return radius; |
|
306 | return radius; | |
309 |
|
307 | |||
310 | createAxisLabels(layout); |
|
308 | createAxisLabels(layout); | |
311 | QStringList labelList = labels(); |
|
309 | QStringList labelList = labels(); | |
312 | QFont font = axis()->labelsFont(); |
|
310 | QFont font = axis()->labelsFont(); | |
313 |
|
311 | |||
314 | QRectF maxRect; |
|
312 | QRectF maxRect; | |
315 | maxRect.setSize(maxSize); |
|
313 | maxRect.setSize(maxSize); | |
316 | maxRect.moveCenter(QPointF(0.0, 0.0)); |
|
314 | maxRect.moveCenter(QPointF(0.0, 0.0)); | |
317 |
|
315 | |||
318 | // This is a horrible way to find out the maximum radius for angular axis and its labels. |
|
316 | // This is a horrible way to find out the maximum radius for angular axis and its labels. | |
319 | // It just increments the radius down until everyhing fits the constraint size. |
|
317 | // It just increments the radius down until everyhing fits the constraint size. | |
320 | // Proper way would be to actually calculate it but this seems to work reasonably fast as it is. |
|
318 | // Proper way would be to actually calculate it but this seems to work reasonably fast as it is. | |
321 | bool nextTickVisible = false; |
|
319 | bool nextTickVisible = false; | |
322 | for (int i = 0; i < layout.size(); ) { |
|
320 | for (int i = 0; i < layout.size(); ) { | |
323 | if ((i == layout.size() - 1) |
|
321 | if ((i == layout.size() - 1) | |
324 | || layout.at(i + 1) < 0.0 |
|
322 | || layout.at(i + 1) < 0.0 | |
325 | || layout.at(i + 1) > 360.0) { |
|
323 | || layout.at(i + 1) > 360.0) { | |
326 | nextTickVisible = false; |
|
324 | nextTickVisible = false; | |
327 | } else { |
|
325 | } else { | |
328 | nextTickVisible = true; |
|
326 | nextTickVisible = true; | |
329 | } |
|
327 | } | |
330 |
|
328 | |||
331 | qreal labelCoordinate = layout.at(i); |
|
329 | qreal labelCoordinate = layout.at(i); | |
332 | qreal labelVisible; |
|
330 | qreal labelVisible; | |
333 |
|
331 | |||
334 | if (intervalAxis()) { |
|
332 | if (intervalAxis()) { | |
335 | qreal farEdge; |
|
333 | qreal farEdge; | |
336 | if (i == (layout.size() - 1)) |
|
334 | if (i == (layout.size() - 1)) | |
337 | farEdge = 360.0; |
|
335 | farEdge = 360.0; | |
338 | else |
|
336 | else | |
339 | farEdge = qMin(qreal(360.0), layout.at(i + 1)); |
|
337 | farEdge = qMin(qreal(360.0), layout.at(i + 1)); | |
340 |
|
338 | |||
341 | // Adjust the labelCoordinate to show it if next tick is visible |
|
339 | // Adjust the labelCoordinate to show it if next tick is visible | |
342 | if (nextTickVisible) |
|
340 | if (nextTickVisible) | |
343 | labelCoordinate = qMax(qreal(0.0), labelCoordinate); |
|
341 | labelCoordinate = qMax(qreal(0.0), labelCoordinate); | |
344 |
|
342 | |||
345 | labelCoordinate = (labelCoordinate + farEdge) / 2.0; |
|
343 | labelCoordinate = (labelCoordinate + farEdge) / 2.0; | |
346 | } |
|
344 | } | |
347 |
|
345 | |||
348 | if (labelCoordinate < 0.0 || labelCoordinate > 360.0) |
|
346 | if (labelCoordinate < 0.0 || labelCoordinate > 360.0) | |
349 | labelVisible = false; |
|
347 | labelVisible = false; | |
350 | else |
|
348 | else | |
351 | labelVisible = true; |
|
349 | labelVisible = true; | |
352 |
|
350 | |||
353 | if (!labelVisible) { |
|
351 | if (!labelVisible) { | |
354 | i++; |
|
352 | i++; | |
355 | continue; |
|
353 | continue; | |
356 | } |
|
354 | } | |
357 |
|
355 | |||
358 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle()); |
|
356 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle()); | |
359 | QPointF labelPoint = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate).p2(); |
|
357 | QPointF labelPoint = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate).p2(); | |
360 |
|
358 | |||
361 | boundingRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect); |
|
359 | boundingRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect); | |
362 | if (boundingRect.isEmpty() || maxRect.intersected(boundingRect) == boundingRect) { |
|
360 | if (boundingRect.isEmpty() || maxRect.intersected(boundingRect) == boundingRect) { | |
363 | i++; |
|
361 | i++; | |
364 | } else { |
|
362 | } else { | |
365 | radius -= 1.0; |
|
363 | radius -= 1.0; | |
366 | if (radius < 1.0) // safeguard |
|
364 | if (radius < 1.0) // safeguard | |
367 | return 1.0; |
|
365 | return 1.0; | |
368 | } |
|
366 | } | |
369 | } |
|
367 | } | |
370 | } |
|
368 | } | |
371 |
|
369 | |||
372 | if (!axis()->titleText().isEmpty() && axis()->isTitleVisible()) { |
|
370 | if (!axis()->titleText().isEmpty() && axis()->isTitleVisible()) { | |
373 | QRectF titleRect = textBoundingRect(axis()->titleFont(), axis()->titleText()); |
|
371 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText()); | |
374 |
|
372 | |||
375 | radius -= titlePadding() + (titleRect.height() / 2.0); |
|
373 | radius -= titlePadding() + (titleRect.height() / 2.0); | |
376 | if (radius < 1.0) // safeguard |
|
374 | if (radius < 1.0) // safeguard | |
377 | return 1.0; |
|
375 | return 1.0; | |
378 | } |
|
376 | } | |
379 |
|
377 | |||
380 | return radius; |
|
378 | return radius; | |
381 | } |
|
379 | } | |
382 |
|
380 | |||
383 | QRectF PolarChartAxisAngular::moveLabelToPosition(qreal angularCoordinate, QPointF labelPoint, QRectF labelRect) const |
|
381 | QRectF PolarChartAxisAngular::moveLabelToPosition(qreal angularCoordinate, QPointF labelPoint, QRectF labelRect) const | |
384 | { |
|
382 | { | |
385 | // TODO use fuzzy compare for "==" cases? |
|
383 | // TODO use fuzzy compare for "==" cases? | |
386 | // TODO Adjust the rect position near 0, 90, 180, and 270 angles for smoother animation? |
|
384 | // TODO Adjust the rect position near 0, 90, 180, and 270 angles for smoother animation? | |
387 | if (angularCoordinate == 0.0) |
|
385 | if (angularCoordinate == 0.0) | |
388 | labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0)); |
|
386 | labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0)); | |
389 | else if (angularCoordinate < 90.0) |
|
387 | else if (angularCoordinate < 90.0) | |
390 | labelRect.moveBottomLeft(labelPoint); |
|
388 | labelRect.moveBottomLeft(labelPoint); | |
391 | else if (angularCoordinate == 90.0) |
|
389 | else if (angularCoordinate == 90.0) | |
392 | labelRect.moveCenter(labelPoint + QPointF(labelRect.width() / 2.0 + 2.0, 0)); // +2 so that it does not hit the radial axis |
|
390 | labelRect.moveCenter(labelPoint + QPointF(labelRect.width() / 2.0 + 2.0, 0)); // +2 so that it does not hit the radial axis | |
393 | else if (angularCoordinate < 180.0) |
|
391 | else if (angularCoordinate < 180.0) | |
394 | labelRect.moveTopLeft(labelPoint); |
|
392 | labelRect.moveTopLeft(labelPoint); | |
395 | else if (angularCoordinate == 180.0) |
|
393 | else if (angularCoordinate == 180.0) | |
396 | labelRect.moveCenter(labelPoint + QPointF(0, labelRect.height() / 2.0)); |
|
394 | labelRect.moveCenter(labelPoint + QPointF(0, labelRect.height() / 2.0)); | |
397 | else if (angularCoordinate < 270.0) |
|
395 | else if (angularCoordinate < 270.0) | |
398 | labelRect.moveTopRight(labelPoint); |
|
396 | labelRect.moveTopRight(labelPoint); | |
399 | else if (angularCoordinate == 270.0) |
|
397 | else if (angularCoordinate == 270.0) | |
400 | labelRect.moveCenter(labelPoint + QPointF(-labelRect.width() / 2.0 - 2.0, 0)); // -2 so that it does not hit the radial axis |
|
398 | labelRect.moveCenter(labelPoint + QPointF(-labelRect.width() / 2.0 - 2.0, 0)); // -2 so that it does not hit the radial axis | |
401 | else if (angularCoordinate < 360.0) |
|
399 | else if (angularCoordinate < 360.0) | |
402 | labelRect.moveBottomRight(labelPoint); |
|
400 | labelRect.moveBottomRight(labelPoint); | |
403 | else |
|
401 | else | |
404 | labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0)); |
|
402 | labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0)); | |
405 | return labelRect; |
|
403 | return labelRect; | |
406 | } |
|
404 | } | |
407 |
|
405 | |||
408 | #include "moc_polarchartaxisangular_p.cpp" |
|
406 | #include "moc_polarchartaxisangular_p.cpp" | |
409 |
|
407 | |||
410 | QTCOMMERCIALCHART_END_NAMESPACE |
|
408 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,290 +1,288 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "polarchartaxisradial_p.h" |
|
21 | #include "polarchartaxisradial_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "abstractchartlayout_p.h" |
|
23 | #include "abstractchartlayout_p.h" | |
24 | #include "qabstractaxis_p.h" |
|
24 | #include "qabstractaxis_p.h" | |
25 | #include "linearrowitem_p.h" |
|
25 | #include "linearrowitem_p.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | PolarChartAxisRadial::PolarChartAxisRadial(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) |
|
29 | PolarChartAxisRadial::PolarChartAxisRadial(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) | |
30 | : PolarChartAxis(axis, item, intervalAxis) |
|
30 | : PolarChartAxis(axis, item, intervalAxis) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | PolarChartAxisRadial::~PolarChartAxisRadial() |
|
34 | PolarChartAxisRadial::~PolarChartAxisRadial() | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void PolarChartAxisRadial::updateGeometry() |
|
38 | void PolarChartAxisRadial::updateGeometry() | |
39 | { |
|
39 | { | |
40 | const QVector<qreal> &layout = this->layout(); |
|
40 | const QVector<qreal> &layout = this->layout(); | |
41 | if (layout.isEmpty()) |
|
41 | if (layout.isEmpty()) | |
42 | return; |
|
42 | return; | |
43 |
|
43 | |||
44 | createAxisLabels(layout); |
|
44 | createAxisLabels(layout); | |
45 | QStringList labelList = labels(); |
|
45 | QStringList labelList = labels(); | |
46 | QPointF center = axisGeometry().center(); |
|
46 | QPointF center = axisGeometry().center(); | |
47 | QList<QGraphicsItem *> arrowItemList = arrowItems(); |
|
47 | QList<QGraphicsItem *> arrowItemList = arrowItems(); | |
48 | QList<QGraphicsItem *> gridItemList = gridItems(); |
|
48 | QList<QGraphicsItem *> gridItemList = gridItems(); | |
49 | QList<QGraphicsItem *> labelItemList = labelItems(); |
|
49 | QList<QGraphicsItem *> labelItemList = labelItems(); | |
50 | QList<QGraphicsItem *> shadeItemList = shadeItems(); |
|
50 | QList<QGraphicsItem *> shadeItemList = shadeItems(); | |
51 |
QGraphics |
|
51 | QGraphicsTextItem* title = titleItem(); | |
52 | qreal radius = axisGeometry().height() / 2.0; |
|
52 | qreal radius = axisGeometry().height() / 2.0; | |
53 |
|
53 | |||
54 | QLineF line(center, center + QPointF(0, -radius)); |
|
54 | QLineF line(center, center + QPointF(0, -radius)); | |
55 | QGraphicsLineItem *axisLine = static_cast<QGraphicsLineItem *>(arrowItemList.at(0)); |
|
55 | QGraphicsLineItem *axisLine = static_cast<QGraphicsLineItem *>(arrowItemList.at(0)); | |
56 | axisLine->setLine(line); |
|
56 | axisLine->setLine(line); | |
57 |
|
57 | |||
58 | QRectF previousLabelRect; |
|
58 | QRectF previousLabelRect; | |
59 | bool firstShade = true; |
|
59 | bool firstShade = true; | |
60 | bool nextTickVisible = false; |
|
60 | bool nextTickVisible = false; | |
61 | if (layout.size()) |
|
61 | if (layout.size()) | |
62 | nextTickVisible = !(layout.at(0) < 0.0 || layout.at(0) > radius); |
|
62 | nextTickVisible = !(layout.at(0) < 0.0 || layout.at(0) > radius); | |
63 |
|
63 | |||
64 | for (int i = 0; i < layout.size(); ++i) { |
|
64 | for (int i = 0; i < layout.size(); ++i) { | |
65 | qreal radialCoordinate = layout.at(i); |
|
65 | qreal radialCoordinate = layout.at(i); | |
66 |
|
66 | |||
67 | QGraphicsEllipseItem *gridItem = static_cast<QGraphicsEllipseItem *>(gridItemList.at(i)); |
|
67 | QGraphicsEllipseItem *gridItem = static_cast<QGraphicsEllipseItem *>(gridItemList.at(i)); | |
68 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1)); |
|
68 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1)); | |
69 |
QGraphics |
|
69 | QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labelItemList.at(i)); | |
70 | QGraphicsPathItem *shadeItem = 0; |
|
70 | QGraphicsPathItem *shadeItem = 0; | |
71 | if (i == 0) |
|
71 | if (i == 0) | |
72 | shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0)); |
|
72 | shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0)); | |
73 | else if (i % 2) |
|
73 | else if (i % 2) | |
74 | shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at((i / 2) + 1)); |
|
74 | shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at((i / 2) + 1)); | |
75 |
|
75 | |||
76 | // Ignore ticks outside valid range |
|
76 | // Ignore ticks outside valid range | |
77 | bool currentTickVisible = nextTickVisible; |
|
77 | bool currentTickVisible = nextTickVisible; | |
78 | if ((i == layout.size() - 1) |
|
78 | if ((i == layout.size() - 1) | |
79 | || layout.at(i + 1) < 0.0 |
|
79 | || layout.at(i + 1) < 0.0 | |
80 | || layout.at(i + 1) > radius) { |
|
80 | || layout.at(i + 1) > radius) { | |
81 | nextTickVisible = false; |
|
81 | nextTickVisible = false; | |
82 | } else { |
|
82 | } else { | |
83 | nextTickVisible = true; |
|
83 | nextTickVisible = true; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | qreal labelCoordinate = radialCoordinate; |
|
86 | qreal labelCoordinate = radialCoordinate; | |
87 | qreal labelVisible = currentTickVisible; |
|
87 | qreal labelVisible = currentTickVisible; | |
88 | qreal labelPad = labelPadding() / 2.0; |
|
88 | qreal labelPad = labelPadding() / 2.0; | |
89 | if (intervalAxis()) { |
|
89 | if (intervalAxis()) { | |
90 | qreal farEdge; |
|
90 | qreal farEdge; | |
91 | if (i == (layout.size() - 1)) |
|
91 | if (i == (layout.size() - 1)) | |
92 | farEdge = radius; |
|
92 | farEdge = radius; | |
93 | else |
|
93 | else | |
94 | farEdge = qMin(radius, layout.at(i + 1)); |
|
94 | farEdge = qMin(radius, layout.at(i + 1)); | |
95 |
|
95 | |||
96 | // Adjust the labelCoordinate to show it if next tick is visible |
|
96 | // Adjust the labelCoordinate to show it if next tick is visible | |
97 | if (nextTickVisible) |
|
97 | if (nextTickVisible) | |
98 | labelCoordinate = qMax(qreal(0.0), labelCoordinate); |
|
98 | labelCoordinate = qMax(qreal(0.0), labelCoordinate); | |
99 |
|
99 | |||
100 | labelCoordinate = (labelCoordinate + farEdge) / 2.0; |
|
100 | labelCoordinate = (labelCoordinate + farEdge) / 2.0; | |
101 | if (labelCoordinate > 0.0 && labelCoordinate < radius) |
|
101 | if (labelCoordinate > 0.0 && labelCoordinate < radius) | |
102 | labelVisible = true; |
|
102 | labelVisible = true; | |
103 | else |
|
103 | else | |
104 | labelVisible = false; |
|
104 | labelVisible = false; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | // Radial axis label |
|
107 | // Radial axis label | |
108 | if (axis()->labelsVisible() && labelVisible) { |
|
108 | if (axis()->labelsVisible() && labelVisible) { | |
109 |
labelItem->set |
|
109 | labelItem->setHtml(labelList.at(i)); | |
110 | QRectF labelRect = labelItem->boundingRect(); |
|
110 | QRectF labelRect = labelItem->boundingRect(); | |
111 | QPointF labelCenter = labelRect.center(); |
|
111 | QPointF labelCenter = labelRect.center(); | |
112 | labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y()); |
|
112 | labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y()); | |
113 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle()); |
|
113 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle()); | |
114 | boundingRect.moveCenter(labelCenter); |
|
114 | boundingRect.moveCenter(labelCenter); | |
115 | QPointF positionDiff(labelRect.topLeft() - boundingRect.topLeft()); |
|
115 | QPointF positionDiff(labelRect.topLeft() - boundingRect.topLeft()); | |
116 | QPointF labelPoint = center; |
|
116 | QPointF labelPoint = center; | |
117 | if (intervalAxis()) |
|
117 | if (intervalAxis()) | |
118 | labelPoint += QPointF(labelPad, -labelCoordinate - (boundingRect.height() / 2.0)); |
|
118 | labelPoint += QPointF(labelPad, -labelCoordinate - (boundingRect.height() / 2.0)); | |
119 | else |
|
119 | else | |
120 | labelPoint += QPointF(labelPad, labelPad - labelCoordinate); |
|
120 | labelPoint += QPointF(labelPad, labelPad - labelCoordinate); | |
121 | labelRect.moveTopLeft(labelPoint); |
|
121 | labelRect.moveTopLeft(labelPoint); | |
122 | labelItem->setPos(labelRect.topLeft() + positionDiff); |
|
122 | labelItem->setPos(labelRect.topLeft() + positionDiff); | |
123 |
|
123 | |||
124 | // Label overlap detection |
|
124 | // Label overlap detection | |
125 | labelRect.setSize(boundingRect.size()); |
|
125 | labelRect.setSize(boundingRect.size()); | |
126 | if ((i && previousLabelRect.intersects(labelRect)) |
|
126 | if ((i && previousLabelRect.intersects(labelRect)) | |
127 | || !axisGeometry().contains(labelRect)) { |
|
127 | || !axisGeometry().contains(labelRect)) { | |
128 | labelVisible = false; |
|
128 | labelVisible = false; | |
129 | } else { |
|
129 | } else { | |
130 | previousLabelRect = labelRect; |
|
130 | previousLabelRect = labelRect; | |
131 | labelVisible = true; |
|
131 | labelVisible = true; | |
132 | } |
|
132 | } | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | labelItem->setVisible(labelVisible); |
|
135 | labelItem->setVisible(labelVisible); | |
136 | if (!currentTickVisible) { |
|
136 | if (!currentTickVisible) { | |
137 | gridItem->setVisible(false); |
|
137 | gridItem->setVisible(false); | |
138 | tickItem->setVisible(false); |
|
138 | tickItem->setVisible(false); | |
139 | if (shadeItem) |
|
139 | if (shadeItem) | |
140 | shadeItem->setVisible(false); |
|
140 | shadeItem->setVisible(false); | |
141 | continue; |
|
141 | continue; | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | // Radial grid line |
|
144 | // Radial grid line | |
145 | QRectF gridRect; |
|
145 | QRectF gridRect; | |
146 | gridRect.setWidth(radialCoordinate * 2.0); |
|
146 | gridRect.setWidth(radialCoordinate * 2.0); | |
147 | gridRect.setHeight(radialCoordinate * 2.0); |
|
147 | gridRect.setHeight(radialCoordinate * 2.0); | |
148 | gridRect.moveCenter(center); |
|
148 | gridRect.moveCenter(center); | |
149 |
|
149 | |||
150 | gridItem->setRect(gridRect); |
|
150 | gridItem->setRect(gridRect); | |
151 | gridItem->setVisible(true); |
|
151 | gridItem->setVisible(true); | |
152 |
|
152 | |||
153 | // Tick |
|
153 | // Tick | |
154 | QLineF tickLine(-tickWidth(), 0.0, tickWidth(), 0.0); |
|
154 | QLineF tickLine(-tickWidth(), 0.0, tickWidth(), 0.0); | |
155 | tickLine.translate(center.rx(), gridRect.top()); |
|
155 | tickLine.translate(center.rx(), gridRect.top()); | |
156 | tickItem->setLine(tickLine); |
|
156 | tickItem->setLine(tickLine); | |
157 | tickItem->setVisible(true); |
|
157 | tickItem->setVisible(true); | |
158 |
|
158 | |||
159 | // Shades |
|
159 | // Shades | |
160 | if (i % 2 || (i == 0 && !nextTickVisible)) { |
|
160 | if (i % 2 || (i == 0 && !nextTickVisible)) { | |
161 | QPainterPath path; |
|
161 | QPainterPath path; | |
162 | if (i == 0) { |
|
162 | if (i == 0) { | |
163 | // If first tick is also the last, we need to custom fill the inner circle |
|
163 | // If first tick is also the last, we need to custom fill the inner circle | |
164 | // or it won't get filled. |
|
164 | // or it won't get filled. | |
165 | QRectF innerCircle(0.0, 0.0, layout.at(0) * 2.0, layout.at(0) * 2.0); |
|
165 | QRectF innerCircle(0.0, 0.0, layout.at(0) * 2.0, layout.at(0) * 2.0); | |
166 | innerCircle.moveCenter(center); |
|
166 | innerCircle.moveCenter(center); | |
167 | path.addEllipse(innerCircle); |
|
167 | path.addEllipse(innerCircle); | |
168 | } else { |
|
168 | } else { | |
169 | QRectF otherGridRect; |
|
169 | QRectF otherGridRect; | |
170 | if (!nextTickVisible) { // Last visible tick |
|
170 | if (!nextTickVisible) { // Last visible tick | |
171 | otherGridRect = axisGeometry(); |
|
171 | otherGridRect = axisGeometry(); | |
172 | } else { |
|
172 | } else { | |
173 | qreal otherGridRectDimension = layout.at(i + 1) * 2.0; |
|
173 | qreal otherGridRectDimension = layout.at(i + 1) * 2.0; | |
174 | otherGridRect.setWidth(otherGridRectDimension); |
|
174 | otherGridRect.setWidth(otherGridRectDimension); | |
175 | otherGridRect.setHeight(otherGridRectDimension); |
|
175 | otherGridRect.setHeight(otherGridRectDimension); | |
176 | otherGridRect.moveCenter(center); |
|
176 | otherGridRect.moveCenter(center); | |
177 | } |
|
177 | } | |
178 | path.addEllipse(gridRect); |
|
178 | path.addEllipse(gridRect); | |
179 | path.addEllipse(otherGridRect); |
|
179 | path.addEllipse(otherGridRect); | |
180 |
|
180 | |||
181 | // Add additional shading in first visible shade item if there is a partial tick |
|
181 | // Add additional shading in first visible shade item if there is a partial tick | |
182 | // to be filled at the center (log & category axes) |
|
182 | // to be filled at the center (log & category axes) | |
183 | if (firstShade) { |
|
183 | if (firstShade) { | |
184 | QGraphicsPathItem *specialShadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0)); |
|
184 | QGraphicsPathItem *specialShadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0)); | |
185 | if (layout.at(i - 1) > 0.0) { |
|
185 | if (layout.at(i - 1) > 0.0) { | |
186 | QRectF innerCircle(0.0, 0.0, layout.at(i - 1) * 2.0, layout.at(i - 1) * 2.0); |
|
186 | QRectF innerCircle(0.0, 0.0, layout.at(i - 1) * 2.0, layout.at(i - 1) * 2.0); | |
187 | innerCircle.moveCenter(center); |
|
187 | innerCircle.moveCenter(center); | |
188 | QPainterPath specialPath; |
|
188 | QPainterPath specialPath; | |
189 | specialPath.addEllipse(innerCircle); |
|
189 | specialPath.addEllipse(innerCircle); | |
190 | specialShadeItem->setPath(specialPath); |
|
190 | specialShadeItem->setPath(specialPath); | |
191 | specialShadeItem->setVisible(true); |
|
191 | specialShadeItem->setVisible(true); | |
192 | } else { |
|
192 | } else { | |
193 | specialShadeItem->setVisible(false); |
|
193 | specialShadeItem->setVisible(false); | |
194 | } |
|
194 | } | |
195 | } |
|
195 | } | |
196 | } |
|
196 | } | |
197 | shadeItem->setPath(path); |
|
197 | shadeItem->setPath(path); | |
198 | shadeItem->setVisible(true); |
|
198 | shadeItem->setVisible(true); | |
199 | firstShade = false; |
|
199 | firstShade = false; | |
200 | } |
|
200 | } | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | // Title, along the 0 axis |
|
203 | // Title, along the 0 axis | |
204 | QString titleText = axis()->titleText(); |
|
204 | QString titleText = axis()->titleText(); | |
205 | if (!titleText.isEmpty() && axis()->isTitleVisible()) { |
|
205 | if (!titleText.isEmpty() && axis()->isTitleVisible()) { | |
206 |
title->set |
|
206 | title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), radius, Qt::Horizontal, QRectF())); | |
207 |
|
207 | |||
208 | QRectF titleBoundingRect = title->boundingRect(); |
|
208 | QRectF titleBoundingRect = title->boundingRect(); | |
209 | QPointF titleCenter = titleBoundingRect.center(); |
|
209 | QPointF titleCenter = titleBoundingRect.center(); | |
210 | QPointF arrowCenter = axisLine->boundingRect().center(); |
|
210 | QPointF arrowCenter = axisLine->boundingRect().center(); | |
211 | QPointF titleCenterDiff = arrowCenter - titleCenter; |
|
211 | QPointF titleCenterDiff = arrowCenter - titleCenter; | |
212 | title->setPos(titleCenterDiff.x() - qreal(titlePadding()) - (titleBoundingRect.height() / 2.0), titleCenterDiff.y()); |
|
212 | title->setPos(titleCenterDiff.x() - qreal(titlePadding()) - (titleBoundingRect.height() / 2.0), titleCenterDiff.y()); | |
213 | title->setTransformOriginPoint(titleCenter); |
|
213 | title->setTransformOriginPoint(titleCenter); | |
214 | title->setRotation(270.0); |
|
214 | title->setRotation(270.0); | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | QGraphicsLayoutItem::updateGeometry(); |
|
217 | QGraphicsLayoutItem::updateGeometry(); | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | Qt::Orientation PolarChartAxisRadial::orientation() const |
|
220 | Qt::Orientation PolarChartAxisRadial::orientation() const | |
221 | { |
|
221 | { | |
222 | return Qt::Vertical; |
|
222 | return Qt::Vertical; | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | void PolarChartAxisRadial::createItems(int count) |
|
225 | void PolarChartAxisRadial::createItems(int count) | |
226 | { |
|
226 | { | |
227 | if (arrowItems().count() == 0) { |
|
227 | if (arrowItems().count() == 0) { | |
228 | // radial axis center line |
|
228 | // radial axis center line | |
229 | QGraphicsLineItem *arrow = new LineArrowItem(this, presenter()->rootItem()); |
|
229 | QGraphicsLineItem *arrow = new LineArrowItem(this, presenter()->rootItem()); | |
230 | arrow->setPen(axis()->linePen()); |
|
230 | arrow->setPen(axis()->linePen()); | |
231 | arrowGroup()->addToGroup(arrow); |
|
231 | arrowGroup()->addToGroup(arrow); | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | for (int i = 0; i < count; ++i) { |
|
234 | for (int i = 0; i < count; ++i) { | |
235 | QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem()); |
|
235 | QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem()); | |
236 | QGraphicsEllipseItem *grid = new QGraphicsEllipseItem(presenter()->rootItem()); |
|
236 | QGraphicsEllipseItem *grid = new QGraphicsEllipseItem(presenter()->rootItem()); | |
237 |
QGraphics |
|
237 | QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem()); | |
238 |
QGraphics |
|
238 | QGraphicsTextItem *title = titleItem(); | |
239 | arrow->setPen(axis()->linePen()); |
|
239 | arrow->setPen(axis()->linePen()); | |
240 | grid->setPen(axis()->gridLinePen()); |
|
240 | grid->setPen(axis()->gridLinePen()); | |
241 | label->setFont(axis()->labelsFont()); |
|
241 | label->setFont(axis()->labelsFont()); | |
242 |
label->set |
|
242 | label->setDefaultTextColor(axis()->labelsBrush().color()); | |
243 | label->setBrush(axis()->labelsBrush()); |
|
|||
244 | label->setRotation(axis()->labelsAngle()); |
|
243 | label->setRotation(axis()->labelsAngle()); | |
245 | title->setFont(axis()->titleFont()); |
|
244 | title->setFont(axis()->titleFont()); | |
246 |
title->set |
|
245 | title->setDefaultTextColor(axis()->titleBrush().color()); | |
247 |
title->set |
|
246 | title->setHtml(axis()->titleText()); | |
248 | title->setText(axis()->titleText()); |
|
|||
249 | arrowGroup()->addToGroup(arrow); |
|
247 | arrowGroup()->addToGroup(arrow); | |
250 | gridGroup()->addToGroup(grid); |
|
248 | gridGroup()->addToGroup(grid); | |
251 | labelGroup()->addToGroup(label); |
|
249 | labelGroup()->addToGroup(label); | |
252 | if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) { |
|
250 | if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) { | |
253 | QGraphicsPathItem *shade = new QGraphicsPathItem(presenter()->rootItem()); |
|
251 | QGraphicsPathItem *shade = new QGraphicsPathItem(presenter()->rootItem()); | |
254 | shade->setPen(axis()->shadesPen()); |
|
252 | shade->setPen(axis()->shadesPen()); | |
255 | shade->setBrush(axis()->shadesBrush()); |
|
253 | shade->setBrush(axis()->shadesBrush()); | |
256 | shadeGroup()->addToGroup(shade); |
|
254 | shadeGroup()->addToGroup(shade); | |
257 | } |
|
255 | } | |
258 | } |
|
256 | } | |
259 | } |
|
257 | } | |
260 |
|
258 | |||
261 | void PolarChartAxisRadial::handleArrowPenChanged(const QPen &pen) |
|
259 | void PolarChartAxisRadial::handleArrowPenChanged(const QPen &pen) | |
262 | { |
|
260 | { | |
263 | foreach (QGraphicsItem *item, arrowItems()) |
|
261 | foreach (QGraphicsItem *item, arrowItems()) | |
264 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
262 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
265 | } |
|
263 | } | |
266 |
|
264 | |||
267 | void PolarChartAxisRadial::handleGridPenChanged(const QPen &pen) |
|
265 | void PolarChartAxisRadial::handleGridPenChanged(const QPen &pen) | |
268 | { |
|
266 | { | |
269 | foreach (QGraphicsItem *item, gridItems()) |
|
267 | foreach (QGraphicsItem *item, gridItems()) | |
270 | static_cast<QGraphicsEllipseItem *>(item)->setPen(pen); |
|
268 | static_cast<QGraphicsEllipseItem *>(item)->setPen(pen); | |
271 | } |
|
269 | } | |
272 |
|
270 | |||
273 | QSizeF PolarChartAxisRadial::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
271 | QSizeF PolarChartAxisRadial::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
274 | { |
|
272 | { | |
275 | Q_UNUSED(which); |
|
273 | Q_UNUSED(which); | |
276 | Q_UNUSED(constraint); |
|
274 | Q_UNUSED(constraint); | |
277 | return QSizeF(-1.0, -1.0); |
|
275 | return QSizeF(-1.0, -1.0); | |
278 | } |
|
276 | } | |
279 |
|
277 | |||
280 | qreal PolarChartAxisRadial::preferredAxisRadius(const QSizeF &maxSize) |
|
278 | qreal PolarChartAxisRadial::preferredAxisRadius(const QSizeF &maxSize) | |
281 | { |
|
279 | { | |
282 | qreal radius = maxSize.height() / 2.0; |
|
280 | qreal radius = maxSize.height() / 2.0; | |
283 | if (maxSize.width() < maxSize.height()) |
|
281 | if (maxSize.width() < maxSize.height()) | |
284 | radius = maxSize.width() / 2.0; |
|
282 | radius = maxSize.width() / 2.0; | |
285 | return radius; |
|
283 | return radius; | |
286 | } |
|
284 | } | |
287 |
|
285 | |||
288 | #include "moc_polarchartaxisradial_p.cpp" |
|
286 | #include "moc_polarchartaxisradial_p.cpp" | |
289 |
|
287 | |||
290 | QTCOMMERCIALCHART_END_NAMESPACE |
|
288 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,1020 +1,1012 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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.h" |
|
21 | #include "qabstractaxis.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
23 | #include "chartdataset_p.h" |
|
23 | #include "chartdataset_p.h" | |
24 | #include "charttheme_p.h" |
|
24 | #include "charttheme_p.h" | |
25 | #include "qchart_p.h" |
|
25 | #include "qchart_p.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | \class QAbstractAxis |
|
30 | \class QAbstractAxis | |
31 | \brief The QAbstractAxis class is used for manipulating chart's axis. |
|
31 | \brief The QAbstractAxis class is used for manipulating chart's axis. | |
32 | \mainclass |
|
32 | \mainclass | |
33 |
|
33 | |||
34 | Each series can be bound to one or more horizontal and vertical axes, but mixing axis types |
|
34 | Each series can be bound to one or more horizontal and vertical axes, but mixing axis types | |
35 | that would result in different domains is not supported, such as specifying |
|
35 | that would result in different domains is not supported, such as specifying | |
36 | QValueAxis and QLogValueAxis on the same orientation. |
|
36 | QValueAxis and QLogValueAxis on the same orientation. | |
37 |
|
37 | |||
38 | Properties and visibility of various axis elements such as axis line, title, labels, grid lines, |
|
38 | Properties and visibility of various axis elements such as axis line, title, labels, grid lines, | |
39 | and shades can be individually controlled. |
|
39 | and shades can be individually controlled. | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \qmlclass AbstractAxis QAbstractAxis |
|
43 | \qmlclass AbstractAxis QAbstractAxis | |
44 | \brief The AbstractAxis is a base element used for specialized axis elements. |
|
44 | \brief The AbstractAxis is a base element used for specialized axis elements. | |
45 |
|
45 | |||
46 | Each series can be bound to only one horizontal and vertical axis. |
|
46 | Each series can be bound to only one horizontal and vertical axis. | |
47 |
|
47 | |||
48 | Properties and visibility of various axis elements such as axis line, title, labels, grid lines, |
|
48 | Properties and visibility of various axis elements such as axis line, title, labels, grid lines, | |
49 | and shades can be individually controlled. |
|
49 | and shades can be individually controlled. | |
50 | */ |
|
50 | */ | |
51 |
|
51 | |||
52 | /*! |
|
52 | /*! | |
53 | \enum QAbstractAxis::AxisType |
|
53 | \enum QAbstractAxis::AxisType | |
54 |
|
54 | |||
55 | The type of the series object. |
|
55 | The type of the series object. | |
56 |
|
56 | |||
57 | \value AxisTypeNoAxis |
|
57 | \value AxisTypeNoAxis | |
58 | \value AxisTypeValue |
|
58 | \value AxisTypeValue | |
59 | \value AxisTypeBarCategory |
|
59 | \value AxisTypeBarCategory | |
60 | \value AxisTypeCategory |
|
60 | \value AxisTypeCategory | |
61 | \value AxisTypeDateTime |
|
61 | \value AxisTypeDateTime | |
62 | \value AxisTypeLogValue |
|
62 | \value AxisTypeLogValue | |
63 | */ |
|
63 | */ | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | *\fn void QAbstractAxis::type() const |
|
66 | *\fn void QAbstractAxis::type() const | |
67 | Returns the type of the axis |
|
67 | Returns the type of the axis | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | \property QAbstractAxis::lineVisible |
|
71 | \property QAbstractAxis::lineVisible | |
72 | The visibility of the axis line |
|
72 | The visibility of the axis line | |
73 | */ |
|
73 | */ | |
74 | /*! |
|
74 | /*! | |
75 | \qmlproperty bool AbstractAxis::lineVisible |
|
75 | \qmlproperty bool AbstractAxis::lineVisible | |
76 | The visibility of the axis line |
|
76 | The visibility of the axis line | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | \property QAbstractAxis::linePen |
|
80 | \property QAbstractAxis::linePen | |
81 | The pen of the line. |
|
81 | The pen of the line. | |
82 | */ |
|
82 | */ | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | \property QAbstractAxis::labelsVisible |
|
85 | \property QAbstractAxis::labelsVisible | |
86 | Defines if axis labels are visible. |
|
86 | Defines if axis labels are visible. | |
87 | */ |
|
87 | */ | |
88 | /*! |
|
88 | /*! | |
89 | \qmlproperty bool AbstractAxis::labelsVisible |
|
89 | \qmlproperty bool AbstractAxis::labelsVisible | |
90 | Defines if axis labels are visible. |
|
90 | Defines if axis labels are visible. | |
91 | */ |
|
91 | */ | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | \property QAbstractAxis::labelsPen |
|
94 | \property QAbstractAxis::labelsPen | |
|
95 | \deprecated | |||
95 | The pen of the labels. |
|
96 | The pen of the labels. | |
96 | */ |
|
97 | */ | |
97 |
|
98 | |||
98 | /*! |
|
99 | /*! | |
99 | \property QAbstractAxis::labelsBrush |
|
100 | \property QAbstractAxis::labelsBrush | |
100 | The brush of the labels. |
|
101 | The brush of the labels. Only the color of the brush is relevant. | |
101 | */ |
|
102 | */ | |
102 |
|
103 | |||
103 | /*! |
|
104 | /*! | |
104 | \property QAbstractAxis::visible |
|
105 | \property QAbstractAxis::visible | |
105 | The visibility of the axis. |
|
106 | The visibility of the axis. | |
106 | */ |
|
107 | */ | |
107 | /*! |
|
108 | /*! | |
108 | \qmlproperty bool AbstractAxis::visible |
|
109 | \qmlproperty bool AbstractAxis::visible | |
109 | The visibility of the axis. |
|
110 | The visibility of the axis. | |
110 | */ |
|
111 | */ | |
111 |
|
112 | |||
112 | /*! |
|
113 | /*! | |
113 | \property QAbstractAxis::gridVisible |
|
114 | \property QAbstractAxis::gridVisible | |
114 | The visibility of the grid lines. |
|
115 | The visibility of the grid lines. | |
115 | */ |
|
116 | */ | |
116 | /*! |
|
117 | /*! | |
117 | \qmlproperty bool AbstractAxis::gridVisible |
|
118 | \qmlproperty bool AbstractAxis::gridVisible | |
118 | The visibility of the grid lines. |
|
119 | The visibility of the grid lines. | |
119 | */ |
|
120 | */ | |
120 |
|
121 | |||
121 | /*! |
|
122 | /*! | |
122 | \property QAbstractAxis::color |
|
123 | \property QAbstractAxis::color | |
123 | The color of the axis and ticks. |
|
124 | The color of the axis and ticks. | |
124 | */ |
|
125 | */ | |
125 | /*! |
|
126 | /*! | |
126 | \qmlproperty color AbstractAxis::color |
|
127 | \qmlproperty color AbstractAxis::color | |
127 | The color of the axis and ticks. |
|
128 | The color of the axis and ticks. | |
128 | */ |
|
129 | */ | |
129 |
|
130 | |||
130 | /*! |
|
131 | /*! | |
131 | \property QAbstractAxis::gridLinePen |
|
132 | \property QAbstractAxis::gridLinePen | |
132 | The pen of the grid line. |
|
133 | The pen of the grid line. | |
133 | */ |
|
134 | */ | |
134 |
|
135 | |||
135 | /*! |
|
136 | /*! | |
136 | \property QAbstractAxis::labelsFont |
|
137 | \property QAbstractAxis::labelsFont | |
137 | The font of the axis labels. |
|
138 | The font of the axis labels. | |
138 | */ |
|
139 | */ | |
139 |
|
140 | |||
140 | /*! |
|
141 | /*! | |
141 | \qmlproperty Font AbstractAxis::labelsFont |
|
142 | \qmlproperty Font AbstractAxis::labelsFont | |
142 | The font of the axis labels. |
|
143 | The font of the axis labels. | |
143 |
|
144 | |||
144 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
145 | See the \l {Font} {QML Font Element} for detailed documentation. | |
145 | */ |
|
146 | */ | |
146 |
|
147 | |||
147 | /*! |
|
148 | /*! | |
148 | \property QAbstractAxis::labelsColor |
|
149 | \property QAbstractAxis::labelsColor | |
149 | The color of the axis labels. |
|
150 | The color of the axis labels. | |
150 | */ |
|
151 | */ | |
151 | /*! |
|
152 | /*! | |
152 | \qmlproperty color AbstractAxis::labelsColor |
|
153 | \qmlproperty color AbstractAxis::labelsColor | |
153 | The color of the axis labels. |
|
154 | The color of the axis labels. | |
154 | */ |
|
155 | */ | |
155 |
|
156 | |||
156 | /*! |
|
157 | /*! | |
157 | \property QAbstractAxis::labelsAngle |
|
158 | \property QAbstractAxis::labelsAngle | |
158 | The angle of the axis labels in degrees. |
|
159 | The angle of the axis labels in degrees. | |
159 | */ |
|
160 | */ | |
160 | /*! |
|
161 | /*! | |
161 | \qmlproperty int AbstractAxis::labelsAngle |
|
162 | \qmlproperty int AbstractAxis::labelsAngle | |
162 | The angle of the axis labels in degrees. |
|
163 | The angle of the axis labels in degrees. | |
163 | */ |
|
164 | */ | |
164 |
|
165 | |||
165 | /*! |
|
166 | /*! | |
166 | \property QAbstractAxis::shadesVisible |
|
167 | \property QAbstractAxis::shadesVisible | |
167 | The visibility of the axis shades. |
|
168 | The visibility of the axis shades. | |
168 | */ |
|
169 | */ | |
169 | /*! |
|
170 | /*! | |
170 | \qmlproperty bool AbstractAxis::shadesVisible |
|
171 | \qmlproperty bool AbstractAxis::shadesVisible | |
171 | The visibility of the axis shades. |
|
172 | The visibility of the axis shades. | |
172 | */ |
|
173 | */ | |
173 |
|
174 | |||
174 | /*! |
|
175 | /*! | |
175 | \property QAbstractAxis::shadesColor |
|
176 | \property QAbstractAxis::shadesColor | |
176 | The fill (brush) color of the axis shades. |
|
177 | The fill (brush) color of the axis shades. | |
177 | */ |
|
178 | */ | |
178 | /*! |
|
179 | /*! | |
179 | \qmlproperty color AbstractAxis::shadesColor |
|
180 | \qmlproperty color AbstractAxis::shadesColor | |
180 | The fill (brush) color of the axis shades. |
|
181 | The fill (brush) color of the axis shades. | |
181 | */ |
|
182 | */ | |
182 |
|
183 | |||
183 | /*! |
|
184 | /*! | |
184 | \property QAbstractAxis::shadesBorderColor |
|
185 | \property QAbstractAxis::shadesBorderColor | |
185 | The border (pen) color of the axis shades. |
|
186 | The border (pen) color of the axis shades. | |
186 | */ |
|
187 | */ | |
187 | /*! |
|
188 | /*! | |
188 | \qmlproperty color AbstractAxis::shadesBorderColor |
|
189 | \qmlproperty color AbstractAxis::shadesBorderColor | |
189 | The border (pen) color of the axis shades. |
|
190 | The border (pen) color of the axis shades. | |
190 | */ |
|
191 | */ | |
191 |
|
192 | |||
192 | /*! |
|
193 | /*! | |
193 | \property QAbstractAxis::shadesPen |
|
194 | \property QAbstractAxis::shadesPen | |
194 | The pen of the axis shades (area between grid lines). |
|
195 | The pen of the axis shades (area between grid lines). | |
195 | */ |
|
196 | */ | |
196 |
|
197 | |||
197 | /*! |
|
198 | /*! | |
198 | \property QAbstractAxis::shadesBrush |
|
199 | \property QAbstractAxis::shadesBrush | |
199 | The brush of the axis shades (area between grid lines). |
|
200 | The brush of the axis shades (area between grid lines). | |
200 | */ |
|
201 | */ | |
201 |
|
202 | |||
202 | /*! |
|
203 | /*! | |
203 | \property QAbstractAxis::titleVisible |
|
204 | \property QAbstractAxis::titleVisible | |
204 | The visibility of the axis title. By default the value is true. |
|
205 | The visibility of the axis title. By default the value is true. | |
205 | */ |
|
206 | */ | |
206 | /*! |
|
207 | /*! | |
207 | \qmlproperty bool AbstractAxis::titleVisible |
|
208 | \qmlproperty bool AbstractAxis::titleVisible | |
208 | The visibility of the axis title. By default the value is true. |
|
209 | The visibility of the axis title. By default the value is true. | |
209 | */ |
|
210 | */ | |
210 |
|
211 | |||
211 | /*! |
|
212 | /*! | |
212 | \property QAbstractAxis::titleText |
|
213 | \property QAbstractAxis::titleText | |
213 | The title of the axis. Empty by default. |
|
214 | The title of the axis. Empty by default. Axis titles support html formatting. | |
214 | */ |
|
215 | */ | |
215 | /*! |
|
216 | /*! | |
216 | \qmlproperty String AbstractAxis::titleText |
|
217 | \qmlproperty String AbstractAxis::titleText | |
217 | The title of the axis. Empty by default. |
|
218 | The title of the axis. Empty by default. Axis titles support html formatting. | |
218 | */ |
|
219 | */ | |
219 |
|
220 | |||
220 | /*! |
|
221 | /*! | |
221 | \property QAbstractAxis::titlePen |
|
222 | \property QAbstractAxis::titlePen | |
|
223 | \deprecated | |||
222 | The pen of the title text. |
|
224 | The pen of the title text. | |
223 | */ |
|
225 | */ | |
224 |
|
226 | |||
225 | /*! |
|
227 | /*! | |
226 | \property QAbstractAxis::titleBrush |
|
228 | \property QAbstractAxis::titleBrush | |
227 | The brush of the title text. |
|
229 | The brush of the title text. Only the color of the brush is relevant. | |
228 | */ |
|
230 | */ | |
229 |
|
231 | |||
230 | /*! |
|
232 | /*! | |
231 | \property QAbstractAxis::titleFont |
|
233 | \property QAbstractAxis::titleFont | |
232 | The font of the title of the axis. |
|
234 | The font of the title of the axis. | |
233 | */ |
|
235 | */ | |
234 | /*! |
|
236 | /*! | |
235 | \qmlproperty Font AbstractAxis::titleFont |
|
237 | \qmlproperty Font AbstractAxis::titleFont | |
236 | The font of the title of the axis. |
|
238 | The font of the title of the axis. | |
237 | */ |
|
239 | */ | |
238 |
|
240 | |||
239 | /*! |
|
241 | /*! | |
240 | \property QAbstractAxis::orientation |
|
242 | \property QAbstractAxis::orientation | |
241 | The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart. |
|
243 | The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart. | |
242 | */ |
|
244 | */ | |
243 | /*! |
|
245 | /*! | |
244 | \qmlproperty Qt.Orientation AbstractAxis::orientation |
|
246 | \qmlproperty Qt.Orientation AbstractAxis::orientation | |
245 | The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series. |
|
247 | The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series. | |
246 | */ |
|
248 | */ | |
247 |
|
249 | |||
248 | /*! |
|
250 | /*! | |
249 | \property QAbstractAxis::alignment |
|
251 | \property QAbstractAxis::alignment | |
250 | The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop. |
|
252 | The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop. | |
251 | */ |
|
253 | */ | |
252 | /*! |
|
254 | /*! | |
253 | \qmlproperty alignment AbstractAxis::alignment |
|
255 | \qmlproperty alignment AbstractAxis::alignment | |
254 | The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop. |
|
256 | The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop. | |
255 | */ |
|
257 | */ | |
256 |
|
258 | |||
257 | /*! |
|
259 | /*! | |
258 | \fn void QAbstractAxis::visibleChanged(bool visible) |
|
260 | \fn void QAbstractAxis::visibleChanged(bool visible) | |
259 | Visibility of the axis has changed to \a visible. |
|
261 | Visibility of the axis has changed to \a visible. | |
260 | */ |
|
262 | */ | |
261 | /*! |
|
263 | /*! | |
262 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) |
|
264 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) | |
263 | Visibility of the axis has changed to \a visible. |
|
265 | Visibility of the axis has changed to \a visible. | |
264 | */ |
|
266 | */ | |
265 |
|
267 | |||
266 | /*! |
|
268 | /*! | |
267 | \fn void QAbstractAxis::linePenChanged(const QPen& pen) |
|
269 | \fn void QAbstractAxis::linePenChanged(const QPen& pen) | |
268 | The pen of the line of the axis has changed to \a pen. |
|
270 | The pen of the line of the axis has changed to \a pen. | |
269 | */ |
|
271 | */ | |
270 |
|
272 | |||
271 | /*! |
|
273 | /*! | |
272 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) |
|
274 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) | |
273 | Visibility of the axis line has changed to \a visible. |
|
275 | Visibility of the axis line has changed to \a visible. | |
274 | */ |
|
276 | */ | |
275 | /*! |
|
277 | /*! | |
276 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) |
|
278 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) | |
277 | Visibility of the axis line has changed to \a visible. |
|
279 | Visibility of the axis line has changed to \a visible. | |
278 | */ |
|
280 | */ | |
279 |
|
281 | |||
280 | /*! |
|
282 | /*! | |
281 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) |
|
283 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) | |
282 | Visibility of the labels of the axis has changed to \a visible. |
|
284 | Visibility of the labels of the axis has changed to \a visible. | |
283 | */ |
|
285 | */ | |
284 | /*! |
|
286 | /*! | |
285 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) |
|
287 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) | |
286 | Visibility of the labels of the axis has changed to \a visible. |
|
288 | Visibility of the labels of the axis has changed to \a visible. | |
287 | */ |
|
289 | */ | |
288 |
|
290 | |||
289 | /*! |
|
291 | /*! | |
290 | \fn void QAbstractAxis::labelsFontChanged(const QFont& font) |
|
292 | \fn void QAbstractAxis::labelsFontChanged(const QFont& font) | |
291 | The font of the axis labels has changed to \a font. |
|
293 | The font of the axis labels has changed to \a font. | |
292 | */ |
|
294 | */ | |
293 | /*! |
|
295 | /*! | |
294 | \qmlsignal AbstractAxis::onLabelsFontChanged(Font font) |
|
296 | \qmlsignal AbstractAxis::onLabelsFontChanged(Font font) | |
295 | The font of the axis labels has changed to \a font. |
|
297 | The font of the axis labels has changed to \a font. | |
296 | */ |
|
298 | */ | |
297 |
|
299 | |||
298 | /*! |
|
300 | /*! | |
299 | \fn void QAbstractAxis::labelsPenChanged(const QPen& pen) |
|
301 | \fn void QAbstractAxis::labelsPenChanged(const QPen& pen) | |
|
302 | \deprecated | |||
300 | The pen of the axis labels has changed to \a pen. |
|
303 | The pen of the axis labels has changed to \a pen. | |
301 | */ |
|
304 | */ | |
302 |
|
305 | |||
303 | /*! |
|
306 | /*! | |
304 | \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush) |
|
307 | \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush) | |
305 | The brush of the axis labels has changed to \a brush. |
|
308 | The brush of the axis labels has changed to \a brush. | |
306 | */ |
|
309 | */ | |
307 |
|
310 | |||
308 | /*! |
|
311 | /*! | |
309 | \fn void QAbstractAxis::labelsAngleChanged(int angle) |
|
312 | \fn void QAbstractAxis::labelsAngleChanged(int angle) | |
310 | The angle of the axis labels has changed to \a angle. |
|
313 | The angle of the axis labels has changed to \a angle. | |
311 | */ |
|
314 | */ | |
312 | /*! |
|
315 | /*! | |
313 | \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle) |
|
316 | \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle) | |
314 | The angle of the axis labels has changed to \a angle. |
|
317 | The angle of the axis labels has changed to \a angle. | |
315 | */ |
|
318 | */ | |
316 |
|
319 | |||
317 | /*! |
|
320 | /*! | |
318 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) |
|
321 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) | |
319 | Visibility of the grid lines of the axis has changed to \a visible. |
|
322 | Visibility of the grid lines of the axis has changed to \a visible. | |
320 | */ |
|
323 | */ | |
321 | /*! |
|
324 | /*! | |
322 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) |
|
325 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) | |
323 | Visibility of the grid lines of the axis has changed to \a visible. |
|
326 | Visibility of the grid lines of the axis has changed to \a visible. | |
324 | */ |
|
327 | */ | |
325 |
|
328 | |||
326 | /*! |
|
329 | /*! | |
327 | \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen) |
|
330 | \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen) | |
328 | The pen of the grid line has changed to \a pen. |
|
331 | The pen of the grid line has changed to \a pen. | |
329 | */ |
|
332 | */ | |
330 |
|
333 | |||
331 | /*! |
|
334 | /*! | |
332 | \fn void QAbstractAxis::colorChanged(QColor color) |
|
335 | \fn void QAbstractAxis::colorChanged(QColor color) | |
333 | Emitted if the \a color of the axis is changed. |
|
336 | Emitted if the \a color of the axis is changed. | |
334 | */ |
|
337 | */ | |
335 | /*! |
|
338 | /*! | |
336 | \qmlsignal AbstractAxis::onColorChanged(QColor color) |
|
339 | \qmlsignal AbstractAxis::onColorChanged(QColor color) | |
337 | Emitted if the \a color of the axis is changed. |
|
340 | Emitted if the \a color of the axis is changed. | |
338 | */ |
|
341 | */ | |
339 |
|
342 | |||
340 | /*! |
|
343 | /*! | |
341 | \fn void QAbstractAxis::labelsColorChanged(QColor color) |
|
344 | \fn void QAbstractAxis::labelsColorChanged(QColor color) | |
342 | Emitted if the \a color of the axis labels is changed. |
|
345 | Emitted if the \a color of the axis labels is changed. | |
343 | */ |
|
346 | */ | |
344 | /*! |
|
347 | /*! | |
345 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) |
|
348 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) | |
346 | Emitted if the \a color of the axis labels is changed. |
|
349 | Emitted if the \a color of the axis labels is changed. | |
347 | */ |
|
350 | */ | |
348 |
|
351 | |||
349 | /*! |
|
352 | /*! | |
350 | \fn void QAbstractAxis::titleVisibleChanged(bool visible) |
|
353 | \fn void QAbstractAxis::titleVisibleChanged(bool visible) | |
351 | Visibility of the title text of the axis has changed to \a visible. |
|
354 | Visibility of the title text of the axis has changed to \a visible. | |
352 | */ |
|
355 | */ | |
353 | /*! |
|
356 | /*! | |
354 | \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible) |
|
357 | \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible) | |
355 | Visibility of the title text of the axis has changed to \a visible. |
|
358 | Visibility of the title text of the axis has changed to \a visible. | |
356 | */ |
|
359 | */ | |
357 |
|
360 | |||
358 | /*! |
|
361 | /*! | |
359 | \fn void QAbstractAxis::titleTextChanged(const QString& text) |
|
362 | \fn void QAbstractAxis::titleTextChanged(const QString& text) | |
360 | The text of the axis title has changed to \a text. |
|
363 | The text of the axis title has changed to \a text. | |
361 | */ |
|
364 | */ | |
362 | /*! |
|
365 | /*! | |
363 | \qmlsignal AbstractAxis::onTitleTextChanged(String text) |
|
366 | \qmlsignal AbstractAxis::onTitleTextChanged(String text) | |
364 | The text of the axis title has changed to \a text. |
|
367 | The text of the axis title has changed to \a text. | |
365 | */ |
|
368 | */ | |
366 |
|
369 | |||
367 | /*! |
|
370 | /*! | |
368 | \fn void QAbstractAxis::titlePenChanged(const QPen& pen) |
|
371 | \fn void QAbstractAxis::titlePenChanged(const QPen& pen) | |
|
372 | \deprecated | |||
369 | The pen of the axis shades has changed to \a pen. |
|
373 | The pen of the axis shades has changed to \a pen. | |
370 | */ |
|
374 | */ | |
371 |
|
375 | |||
372 | /*! |
|
376 | /*! | |
373 | \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush) |
|
377 | \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush) | |
374 | The brush of the axis title has changed to \a brush. |
|
378 | The brush of the axis title has changed to \a brush. | |
375 | */ |
|
379 | */ | |
376 |
|
380 | |||
377 | /*! |
|
381 | /*! | |
378 | \fn void QAbstractAxis::titleFontChanged(const QFont& font) |
|
382 | \fn void QAbstractAxis::titleFontChanged(const QFont& font) | |
379 | The font of the axis title has changed to \a font. |
|
383 | The font of the axis title has changed to \a font. | |
380 | */ |
|
384 | */ | |
381 | /*! |
|
385 | /*! | |
382 | \qmlsignal AbstractAxis::onTitleFontChanged(Font font) |
|
386 | \qmlsignal AbstractAxis::onTitleFontChanged(Font font) | |
383 | The font of the axis title has changed to \a font. |
|
387 | The font of the axis title has changed to \a font. | |
384 | */ |
|
388 | */ | |
385 |
|
389 | |||
386 | /*! |
|
390 | /*! | |
387 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
391 | \fn void QAbstractAxis::shadesVisibleChanged(bool) | |
388 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
392 | Emitted if the visibility of the axis shades is changed to \a visible. | |
389 | */ |
|
393 | */ | |
390 | /*! |
|
394 | /*! | |
391 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) |
|
395 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) | |
392 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
396 | Emitted if the visibility of the axis shades is changed to \a visible. | |
393 | */ |
|
397 | */ | |
394 |
|
398 | |||
395 | /*! |
|
399 | /*! | |
396 | \fn void QAbstractAxis::shadesColorChanged(QColor color) |
|
400 | \fn void QAbstractAxis::shadesColorChanged(QColor color) | |
397 | Emitted if the \a color of the axis shades is changed. |
|
401 | Emitted if the \a color of the axis shades is changed. | |
398 | */ |
|
402 | */ | |
399 | /*! |
|
403 | /*! | |
400 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) |
|
404 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) | |
401 | Emitted if the \a color of the axis shades is changed. |
|
405 | Emitted if the \a color of the axis shades is changed. | |
402 | */ |
|
406 | */ | |
403 |
|
407 | |||
404 | /*! |
|
408 | /*! | |
405 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
409 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) | |
406 | Emitted if the border \a color of the axis shades is changed. |
|
410 | Emitted if the border \a color of the axis shades is changed. | |
407 | */ |
|
411 | */ | |
408 | /*! |
|
412 | /*! | |
409 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) |
|
413 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) | |
410 | Emitted if the border \a color of the axis shades is changed. |
|
414 | Emitted if the border \a color of the axis shades is changed. | |
411 | */ |
|
415 | */ | |
412 |
|
416 | |||
413 | /*! |
|
417 | /*! | |
414 | \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush) |
|
418 | \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush) | |
415 | The brush of the axis shades has changed to \a brush. |
|
419 | The brush of the axis shades has changed to \a brush. | |
416 | */ |
|
420 | */ | |
417 |
|
421 | |||
418 | /*! |
|
422 | /*! | |
419 | \fn void QAbstractAxis::shadesPenChanged(const QPen& pen) |
|
423 | \fn void QAbstractAxis::shadesPenChanged(const QPen& pen) | |
420 | The pen of the axis shades has changed to \a pen. |
|
424 | The pen of the axis shades has changed to \a pen. | |
421 | */ |
|
425 | */ | |
422 |
|
426 | |||
423 | /*! |
|
427 | /*! | |
424 | \internal |
|
428 | \internal | |
425 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
429 | Constructs new axis object which is a child of \a parent. Ownership is taken by | |
426 | QChart when axis added. |
|
430 | QChart when axis added. | |
427 | */ |
|
431 | */ | |
428 |
|
432 | |||
429 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) |
|
433 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) | |
430 | : QObject(parent), |
|
434 | : QObject(parent), | |
431 | d_ptr(&d) |
|
435 | d_ptr(&d) | |
432 | { |
|
436 | { | |
433 | } |
|
437 | } | |
434 |
|
438 | |||
435 | /*! |
|
439 | /*! | |
436 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
440 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. | |
437 | */ |
|
441 | */ | |
438 |
|
442 | |||
439 | QAbstractAxis::~QAbstractAxis() |
|
443 | QAbstractAxis::~QAbstractAxis() | |
440 | { |
|
444 | { | |
441 | if (d_ptr->m_chart) |
|
445 | if (d_ptr->m_chart) | |
442 | qFatal("Still binded axis detected !"); |
|
446 | qFatal("Still binded axis detected !"); | |
443 | } |
|
447 | } | |
444 |
|
448 | |||
445 | /*! |
|
449 | /*! | |
446 | Sets \a pen used to draw axis line and ticks. |
|
450 | Sets \a pen used to draw axis line and ticks. | |
447 | */ |
|
451 | */ | |
448 | void QAbstractAxis::setLinePen(const QPen &pen) |
|
452 | void QAbstractAxis::setLinePen(const QPen &pen) | |
449 | { |
|
453 | { | |
450 | if (d_ptr->m_axisPen != pen) { |
|
454 | if (d_ptr->m_axisPen != pen) { | |
451 | d_ptr->m_axisPen = pen; |
|
455 | d_ptr->m_axisPen = pen; | |
452 | emit linePenChanged(pen); |
|
456 | emit linePenChanged(pen); | |
453 | } |
|
457 | } | |
454 | } |
|
458 | } | |
455 |
|
459 | |||
456 | /*! |
|
460 | /*! | |
457 | Returns pen used to draw axis and ticks. |
|
461 | Returns pen used to draw axis and ticks. | |
458 | */ |
|
462 | */ | |
459 | QPen QAbstractAxis::linePen() const |
|
463 | QPen QAbstractAxis::linePen() const | |
460 | { |
|
464 | { | |
461 | if (d_ptr->m_axisPen == QChartPrivate::defaultPen()) |
|
465 | if (d_ptr->m_axisPen == QChartPrivate::defaultPen()) | |
462 | return QPen(); |
|
466 | return QPen(); | |
463 | else |
|
467 | else | |
464 | return d_ptr->m_axisPen; |
|
468 | return d_ptr->m_axisPen; | |
465 | } |
|
469 | } | |
466 |
|
470 | |||
467 | //TODO: remove me 2.0 |
|
471 | //TODO: remove me 2.0 | |
468 | void QAbstractAxis::setLinePenColor(QColor color) |
|
472 | void QAbstractAxis::setLinePenColor(QColor color) | |
469 | { |
|
473 | { | |
470 | QPen p = d_ptr->m_axisPen; |
|
474 | QPen p = d_ptr->m_axisPen; | |
471 | if (p.color() != color) { |
|
475 | if (p.color() != color) { | |
472 | p.setColor(color); |
|
476 | p.setColor(color); | |
473 | setLinePen(p); |
|
477 | setLinePen(p); | |
474 | emit colorChanged(color); |
|
478 | emit colorChanged(color); | |
475 | } |
|
479 | } | |
476 | } |
|
480 | } | |
477 |
|
481 | |||
478 | QColor QAbstractAxis::linePenColor() const |
|
482 | QColor QAbstractAxis::linePenColor() const | |
479 | { |
|
483 | { | |
480 | return linePen().color(); |
|
484 | return linePen().color(); | |
481 | } |
|
485 | } | |
482 |
|
486 | |||
483 | /*! |
|
487 | /*! | |
484 | Sets if axis and ticks are \a visible. |
|
488 | Sets if axis and ticks are \a visible. | |
485 | */ |
|
489 | */ | |
486 | void QAbstractAxis::setLineVisible(bool visible) |
|
490 | void QAbstractAxis::setLineVisible(bool visible) | |
487 | { |
|
491 | { | |
488 | if (d_ptr->m_arrowVisible != visible) { |
|
492 | if (d_ptr->m_arrowVisible != visible) { | |
489 | d_ptr->m_arrowVisible = visible; |
|
493 | d_ptr->m_arrowVisible = visible; | |
490 | emit lineVisibleChanged(visible); |
|
494 | emit lineVisibleChanged(visible); | |
491 | } |
|
495 | } | |
492 | } |
|
496 | } | |
493 |
|
497 | |||
494 | bool QAbstractAxis::isLineVisible() const |
|
498 | bool QAbstractAxis::isLineVisible() const | |
495 | { |
|
499 | { | |
496 | return d_ptr->m_arrowVisible; |
|
500 | return d_ptr->m_arrowVisible; | |
497 | } |
|
501 | } | |
498 |
|
502 | |||
499 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
503 | void QAbstractAxis::setGridLineVisible(bool visible) | |
500 | { |
|
504 | { | |
501 | if (d_ptr->m_gridLineVisible != visible) { |
|
505 | if (d_ptr->m_gridLineVisible != visible) { | |
502 | d_ptr->m_gridLineVisible = visible; |
|
506 | d_ptr->m_gridLineVisible = visible; | |
503 | emit gridVisibleChanged(visible); |
|
507 | emit gridVisibleChanged(visible); | |
504 | } |
|
508 | } | |
505 | } |
|
509 | } | |
506 |
|
510 | |||
507 | bool QAbstractAxis::isGridLineVisible() const |
|
511 | bool QAbstractAxis::isGridLineVisible() const | |
508 | { |
|
512 | { | |
509 | return d_ptr->m_gridLineVisible; |
|
513 | return d_ptr->m_gridLineVisible; | |
510 | } |
|
514 | } | |
511 |
|
515 | |||
512 | /*! |
|
516 | /*! | |
513 | Sets \a pen used to draw grid line. |
|
517 | Sets \a pen used to draw grid line. | |
514 | */ |
|
518 | */ | |
515 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
519 | void QAbstractAxis::setGridLinePen(const QPen &pen) | |
516 | { |
|
520 | { | |
517 | if (d_ptr->m_gridLinePen != pen) { |
|
521 | if (d_ptr->m_gridLinePen != pen) { | |
518 | d_ptr->m_gridLinePen = pen; |
|
522 | d_ptr->m_gridLinePen = pen; | |
519 | emit gridLinePenChanged(pen); |
|
523 | emit gridLinePenChanged(pen); | |
520 | } |
|
524 | } | |
521 | } |
|
525 | } | |
522 |
|
526 | |||
523 | /*! |
|
527 | /*! | |
524 | Returns pen used to draw grid. |
|
528 | Returns pen used to draw grid. | |
525 | */ |
|
529 | */ | |
526 | QPen QAbstractAxis::gridLinePen() const |
|
530 | QPen QAbstractAxis::gridLinePen() const | |
527 | { |
|
531 | { | |
528 | if (d_ptr->m_gridLinePen == QChartPrivate::defaultPen()) |
|
532 | if (d_ptr->m_gridLinePen == QChartPrivate::defaultPen()) | |
529 | return QPen(); |
|
533 | return QPen(); | |
530 | else |
|
534 | else | |
531 | return d_ptr->m_gridLinePen; |
|
535 | return d_ptr->m_gridLinePen; | |
532 | } |
|
536 | } | |
533 |
|
537 | |||
534 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
538 | void QAbstractAxis::setLabelsVisible(bool visible) | |
535 | { |
|
539 | { | |
536 | if (d_ptr->m_labelsVisible != visible) { |
|
540 | if (d_ptr->m_labelsVisible != visible) { | |
537 | d_ptr->m_labelsVisible = visible; |
|
541 | d_ptr->m_labelsVisible = visible; | |
538 | emit labelsVisibleChanged(visible); |
|
542 | emit labelsVisibleChanged(visible); | |
539 | } |
|
543 | } | |
540 | } |
|
544 | } | |
541 |
|
545 | |||
542 | bool QAbstractAxis::labelsVisible() const |
|
546 | bool QAbstractAxis::labelsVisible() const | |
543 | { |
|
547 | { | |
544 | return d_ptr->m_labelsVisible; |
|
548 | return d_ptr->m_labelsVisible; | |
545 | } |
|
549 | } | |
546 |
|
550 | |||
547 | /*! |
|
|||
548 | Sets \a pen used to draw labels. |
|
|||
549 | */ |
|
|||
550 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
551 | void QAbstractAxis::setLabelsPen(const QPen &pen) | |
551 | { |
|
552 | { | |
552 | if (d_ptr->m_labelsPen != pen) { |
|
553 | if (d_ptr->m_labelsPen != pen) { | |
553 | d_ptr->m_labelsPen = pen; |
|
554 | d_ptr->m_labelsPen = pen; | |
554 | emit labelsPenChanged(pen); |
|
555 | emit labelsPenChanged(pen); | |
555 | } |
|
556 | } | |
556 | } |
|
557 | } | |
557 |
|
558 | |||
558 | /*! |
|
|||
559 | Returns the pen used to labels. |
|
|||
560 | */ |
|
|||
561 | QPen QAbstractAxis::labelsPen() const |
|
559 | QPen QAbstractAxis::labelsPen() const | |
562 | { |
|
560 | { | |
563 | if (d_ptr->m_labelsPen == QChartPrivate::defaultPen()) |
|
561 | if (d_ptr->m_labelsPen == QChartPrivate::defaultPen()) | |
564 | return QPen(); |
|
562 | return QPen(); | |
565 | else |
|
563 | else | |
566 | return d_ptr->m_labelsPen; |
|
564 | return d_ptr->m_labelsPen; | |
567 | } |
|
565 | } | |
568 |
|
566 | |||
569 | /*! |
|
567 | /*! | |
570 | Sets \a brush used to draw labels. |
|
568 | Sets \a brush used to draw labels. | |
571 | */ |
|
569 | */ | |
572 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
570 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) | |
573 | { |
|
571 | { | |
574 | if (d_ptr->m_labelsBrush != brush) { |
|
572 | if (d_ptr->m_labelsBrush != brush) { | |
575 | d_ptr->m_labelsBrush = brush; |
|
573 | d_ptr->m_labelsBrush = brush; | |
576 | emit labelsBrushChanged(brush); |
|
574 | emit labelsBrushChanged(brush); | |
577 | } |
|
575 | } | |
578 | } |
|
576 | } | |
579 |
|
577 | |||
580 | /*! |
|
578 | /*! | |
581 | Returns brush used to draw labels. |
|
579 | Returns brush used to draw labels. | |
582 | */ |
|
580 | */ | |
583 | QBrush QAbstractAxis::labelsBrush() const |
|
581 | QBrush QAbstractAxis::labelsBrush() const | |
584 | { |
|
582 | { | |
585 | if (d_ptr->m_labelsBrush == QChartPrivate::defaultBrush()) |
|
583 | if (d_ptr->m_labelsBrush == QChartPrivate::defaultBrush()) | |
586 | return QBrush(); |
|
584 | return QBrush(); | |
587 | else |
|
585 | else | |
588 | return d_ptr->m_labelsBrush; |
|
586 | return d_ptr->m_labelsBrush; | |
589 | } |
|
587 | } | |
590 |
|
588 | |||
591 | /*! |
|
589 | /*! | |
592 | Sets \a font used to draw labels. |
|
590 | Sets \a font used to draw labels. | |
593 | */ |
|
591 | */ | |
594 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
592 | void QAbstractAxis::setLabelsFont(const QFont &font) | |
595 | { |
|
593 | { | |
596 | if (d_ptr->m_labelsFont != font) { |
|
594 | if (d_ptr->m_labelsFont != font) { | |
597 | d_ptr->m_labelsFont = font; |
|
595 | d_ptr->m_labelsFont = font; | |
598 | emit labelsFontChanged(font); |
|
596 | emit labelsFontChanged(font); | |
599 | } |
|
597 | } | |
600 | } |
|
598 | } | |
601 |
|
599 | |||
602 | /*! |
|
600 | /*! | |
603 | Returns font used to draw labels. |
|
601 | Returns font used to draw labels. | |
604 | */ |
|
602 | */ | |
605 | QFont QAbstractAxis::labelsFont() const |
|
603 | QFont QAbstractAxis::labelsFont() const | |
606 | { |
|
604 | { | |
607 | if (d_ptr->m_labelsFont == QChartPrivate::defaultFont()) |
|
605 | if (d_ptr->m_labelsFont == QChartPrivate::defaultFont()) | |
608 | return QFont(); |
|
606 | return QFont(); | |
609 | else |
|
607 | else | |
610 | return d_ptr->m_labelsFont; |
|
608 | return d_ptr->m_labelsFont; | |
611 | } |
|
609 | } | |
612 |
|
610 | |||
613 | void QAbstractAxis::setLabelsAngle(int angle) |
|
611 | void QAbstractAxis::setLabelsAngle(int angle) | |
614 | { |
|
612 | { | |
615 | if (d_ptr->m_labelsAngle != angle) { |
|
613 | if (d_ptr->m_labelsAngle != angle) { | |
616 | d_ptr->m_labelsAngle = angle; |
|
614 | d_ptr->m_labelsAngle = angle; | |
617 | emit labelsAngleChanged(angle); |
|
615 | emit labelsAngleChanged(angle); | |
618 | } |
|
616 | } | |
619 | } |
|
617 | } | |
620 |
|
618 | |||
621 | int QAbstractAxis::labelsAngle() const |
|
619 | int QAbstractAxis::labelsAngle() const | |
622 | { |
|
620 | { | |
623 | return d_ptr->m_labelsAngle; |
|
621 | return d_ptr->m_labelsAngle; | |
624 | } |
|
622 | } | |
625 | //TODO: remove me 2.0 |
|
623 | //TODO: remove me 2.0 | |
626 | void QAbstractAxis::setLabelsColor(QColor color) |
|
624 | void QAbstractAxis::setLabelsColor(QColor color) | |
627 | { |
|
625 | { | |
628 | QBrush b = d_ptr->m_labelsBrush; |
|
626 | QBrush b = d_ptr->m_labelsBrush; | |
629 | if (b.color() != color) { |
|
627 | if (b.color() != color) { | |
630 | b.setColor(color); |
|
628 | b.setColor(color); | |
631 | setLabelsBrush(b); |
|
629 | setLabelsBrush(b); | |
632 | emit labelsColorChanged(color); |
|
630 | emit labelsColorChanged(color); | |
633 | } |
|
631 | } | |
634 | } |
|
632 | } | |
635 |
|
633 | |||
636 | QColor QAbstractAxis::labelsColor() const |
|
634 | QColor QAbstractAxis::labelsColor() const | |
637 | { |
|
635 | { | |
638 | return labelsBrush().color(); |
|
636 | return labelsBrush().color(); | |
639 | } |
|
637 | } | |
640 |
|
638 | |||
641 | void QAbstractAxis::setTitleVisible(bool visible) |
|
639 | void QAbstractAxis::setTitleVisible(bool visible) | |
642 | { |
|
640 | { | |
643 | if (d_ptr->m_titleVisible != visible) { |
|
641 | if (d_ptr->m_titleVisible != visible) { | |
644 | d_ptr->m_titleVisible = visible; |
|
642 | d_ptr->m_titleVisible = visible; | |
645 | emit titleVisibleChanged(visible); |
|
643 | emit titleVisibleChanged(visible); | |
646 | } |
|
644 | } | |
647 | } |
|
645 | } | |
648 |
|
646 | |||
649 | bool QAbstractAxis::isTitleVisible() const |
|
647 | bool QAbstractAxis::isTitleVisible() const | |
650 | { |
|
648 | { | |
651 | return d_ptr->m_titleVisible; |
|
649 | return d_ptr->m_titleVisible; | |
652 | } |
|
650 | } | |
653 |
|
651 | |||
654 | /*! |
|
|||
655 | Sets \a pen used to draw title. |
|
|||
656 | */ |
|
|||
657 | void QAbstractAxis::setTitlePen(const QPen &pen) |
|
652 | void QAbstractAxis::setTitlePen(const QPen &pen) | |
658 | { |
|
653 | { | |
659 | if (d_ptr->m_titlePen != pen) { |
|
654 | if (d_ptr->m_titlePen != pen) { | |
660 | d_ptr->m_titlePen = pen; |
|
655 | d_ptr->m_titlePen = pen; | |
661 | emit titlePenChanged(pen); |
|
656 | emit titlePenChanged(pen); | |
662 | } |
|
657 | } | |
663 | } |
|
658 | } | |
664 |
|
659 | |||
665 | /*! |
|
|||
666 | Returns the pen used to title. |
|
|||
667 | */ |
|
|||
668 | QPen QAbstractAxis::titlePen() const |
|
660 | QPen QAbstractAxis::titlePen() const | |
669 | { |
|
661 | { | |
670 | if (d_ptr->m_titlePen == QChartPrivate::defaultPen()) |
|
662 | if (d_ptr->m_titlePen == QChartPrivate::defaultPen()) | |
671 | return QPen(); |
|
663 | return QPen(); | |
672 | else |
|
664 | else | |
673 | return d_ptr->m_titlePen; |
|
665 | return d_ptr->m_titlePen; | |
674 | } |
|
666 | } | |
675 |
|
667 | |||
676 | /*! |
|
668 | /*! | |
677 | Sets \a brush used to draw title. |
|
669 | Sets \a brush used to draw title. | |
678 | */ |
|
670 | */ | |
679 | void QAbstractAxis::setTitleBrush(const QBrush &brush) |
|
671 | void QAbstractAxis::setTitleBrush(const QBrush &brush) | |
680 | { |
|
672 | { | |
681 | if (d_ptr->m_titleBrush != brush) { |
|
673 | if (d_ptr->m_titleBrush != brush) { | |
682 | d_ptr->m_titleBrush = brush; |
|
674 | d_ptr->m_titleBrush = brush; | |
683 | emit titleBrushChanged(brush); |
|
675 | emit titleBrushChanged(brush); | |
684 | } |
|
676 | } | |
685 | } |
|
677 | } | |
686 |
|
678 | |||
687 | /*! |
|
679 | /*! | |
688 | Returns brush used to draw title. |
|
680 | Returns brush used to draw title. | |
689 | */ |
|
681 | */ | |
690 | QBrush QAbstractAxis::titleBrush() const |
|
682 | QBrush QAbstractAxis::titleBrush() const | |
691 | { |
|
683 | { | |
692 | if (d_ptr->m_titleBrush == QChartPrivate::defaultBrush()) |
|
684 | if (d_ptr->m_titleBrush == QChartPrivate::defaultBrush()) | |
693 | return QBrush(); |
|
685 | return QBrush(); | |
694 | else |
|
686 | else | |
695 | return d_ptr->m_titleBrush; |
|
687 | return d_ptr->m_titleBrush; | |
696 | } |
|
688 | } | |
697 |
|
689 | |||
698 | /*! |
|
690 | /*! | |
699 | Sets \a font used to draw title. |
|
691 | Sets \a font used to draw title. | |
700 | */ |
|
692 | */ | |
701 | void QAbstractAxis::setTitleFont(const QFont &font) |
|
693 | void QAbstractAxis::setTitleFont(const QFont &font) | |
702 | { |
|
694 | { | |
703 | if (d_ptr->m_titleFont != font) { |
|
695 | if (d_ptr->m_titleFont != font) { | |
704 | d_ptr->m_titleFont = font; |
|
696 | d_ptr->m_titleFont = font; | |
705 | emit titleFontChanged(font); |
|
697 | emit titleFontChanged(font); | |
706 | } |
|
698 | } | |
707 | } |
|
699 | } | |
708 |
|
700 | |||
709 | /*! |
|
701 | /*! | |
710 | Returns font used to draw title. |
|
702 | Returns font used to draw title. | |
711 | */ |
|
703 | */ | |
712 | QFont QAbstractAxis::titleFont() const |
|
704 | QFont QAbstractAxis::titleFont() const | |
713 | { |
|
705 | { | |
714 | if (d_ptr->m_titleFont == QChartPrivate::defaultFont()) |
|
706 | if (d_ptr->m_titleFont == QChartPrivate::defaultFont()) | |
715 | return QFont(); |
|
707 | return QFont(); | |
716 | else |
|
708 | else | |
717 | return d_ptr->m_titleFont; |
|
709 | return d_ptr->m_titleFont; | |
718 | } |
|
710 | } | |
719 |
|
711 | |||
720 | void QAbstractAxis::setTitleText(const QString &title) |
|
712 | void QAbstractAxis::setTitleText(const QString &title) | |
721 | { |
|
713 | { | |
722 | if (d_ptr->m_title != title) { |
|
714 | if (d_ptr->m_title != title) { | |
723 | d_ptr->m_title = title; |
|
715 | d_ptr->m_title = title; | |
724 | emit titleTextChanged(title); |
|
716 | emit titleTextChanged(title); | |
725 | } |
|
717 | } | |
726 | } |
|
718 | } | |
727 |
|
719 | |||
728 | QString QAbstractAxis::titleText() const |
|
720 | QString QAbstractAxis::titleText() const | |
729 | { |
|
721 | { | |
730 | return d_ptr->m_title; |
|
722 | return d_ptr->m_title; | |
731 | } |
|
723 | } | |
732 |
|
724 | |||
733 |
|
725 | |||
734 | void QAbstractAxis::setShadesVisible(bool visible) |
|
726 | void QAbstractAxis::setShadesVisible(bool visible) | |
735 | { |
|
727 | { | |
736 | if (d_ptr->m_shadesVisible != visible) { |
|
728 | if (d_ptr->m_shadesVisible != visible) { | |
737 | d_ptr->m_shadesVisible = visible; |
|
729 | d_ptr->m_shadesVisible = visible; | |
738 | emit shadesVisibleChanged(visible); |
|
730 | emit shadesVisibleChanged(visible); | |
739 | } |
|
731 | } | |
740 | } |
|
732 | } | |
741 |
|
733 | |||
742 | bool QAbstractAxis::shadesVisible() const |
|
734 | bool QAbstractAxis::shadesVisible() const | |
743 | { |
|
735 | { | |
744 | return d_ptr->m_shadesVisible; |
|
736 | return d_ptr->m_shadesVisible; | |
745 | } |
|
737 | } | |
746 |
|
738 | |||
747 | /*! |
|
739 | /*! | |
748 | Sets \a pen used to draw shades. |
|
740 | Sets \a pen used to draw shades. | |
749 | */ |
|
741 | */ | |
750 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
742 | void QAbstractAxis::setShadesPen(const QPen &pen) | |
751 | { |
|
743 | { | |
752 | if (d_ptr->m_shadesPen != pen) { |
|
744 | if (d_ptr->m_shadesPen != pen) { | |
753 | d_ptr->m_shadesPen = pen; |
|
745 | d_ptr->m_shadesPen = pen; | |
754 | emit shadesPenChanged(pen); |
|
746 | emit shadesPenChanged(pen); | |
755 | } |
|
747 | } | |
756 | } |
|
748 | } | |
757 |
|
749 | |||
758 | /*! |
|
750 | /*! | |
759 | Returns pen used to draw shades. |
|
751 | Returns pen used to draw shades. | |
760 | */ |
|
752 | */ | |
761 | QPen QAbstractAxis::shadesPen() const |
|
753 | QPen QAbstractAxis::shadesPen() const | |
762 | { |
|
754 | { | |
763 | if (d_ptr->m_shadesPen == QChartPrivate::defaultPen()) |
|
755 | if (d_ptr->m_shadesPen == QChartPrivate::defaultPen()) | |
764 | return QPen(); |
|
756 | return QPen(); | |
765 | else |
|
757 | else | |
766 | return d_ptr->m_shadesPen; |
|
758 | return d_ptr->m_shadesPen; | |
767 | } |
|
759 | } | |
768 |
|
760 | |||
769 | /*! |
|
761 | /*! | |
770 | Sets \a brush used to draw shades. |
|
762 | Sets \a brush used to draw shades. | |
771 | */ |
|
763 | */ | |
772 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
764 | void QAbstractAxis::setShadesBrush(const QBrush &brush) | |
773 | { |
|
765 | { | |
774 | if (d_ptr->m_shadesBrush != brush) { |
|
766 | if (d_ptr->m_shadesBrush != brush) { | |
775 | d_ptr->m_shadesBrush = brush; |
|
767 | d_ptr->m_shadesBrush = brush; | |
776 | emit shadesBrushChanged(brush); |
|
768 | emit shadesBrushChanged(brush); | |
777 | } |
|
769 | } | |
778 | } |
|
770 | } | |
779 |
|
771 | |||
780 | /*! |
|
772 | /*! | |
781 | Returns brush used to draw shades. |
|
773 | Returns brush used to draw shades. | |
782 | */ |
|
774 | */ | |
783 | QBrush QAbstractAxis::shadesBrush() const |
|
775 | QBrush QAbstractAxis::shadesBrush() const | |
784 | { |
|
776 | { | |
785 | if (d_ptr->m_shadesBrush == QChartPrivate::defaultBrush()) |
|
777 | if (d_ptr->m_shadesBrush == QChartPrivate::defaultBrush()) | |
786 | return QBrush(Qt::SolidPattern); |
|
778 | return QBrush(Qt::SolidPattern); | |
787 | else |
|
779 | else | |
788 | return d_ptr->m_shadesBrush; |
|
780 | return d_ptr->m_shadesBrush; | |
789 | } |
|
781 | } | |
790 |
|
782 | |||
791 | void QAbstractAxis::setShadesColor(QColor color) |
|
783 | void QAbstractAxis::setShadesColor(QColor color) | |
792 | { |
|
784 | { | |
793 | QBrush b = d_ptr->m_shadesBrush; |
|
785 | QBrush b = d_ptr->m_shadesBrush; | |
794 | if (b.color() != color) { |
|
786 | if (b.color() != color) { | |
795 | b.setColor(color); |
|
787 | b.setColor(color); | |
796 | setShadesBrush(b); |
|
788 | setShadesBrush(b); | |
797 | emit shadesColorChanged(color); |
|
789 | emit shadesColorChanged(color); | |
798 | } |
|
790 | } | |
799 | } |
|
791 | } | |
800 |
|
792 | |||
801 | QColor QAbstractAxis::shadesColor() const |
|
793 | QColor QAbstractAxis::shadesColor() const | |
802 | { |
|
794 | { | |
803 | return shadesBrush().color(); |
|
795 | return shadesBrush().color(); | |
804 | } |
|
796 | } | |
805 |
|
797 | |||
806 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
798 | void QAbstractAxis::setShadesBorderColor(QColor color) | |
807 | { |
|
799 | { | |
808 | QPen p = d_ptr->m_shadesPen; |
|
800 | QPen p = d_ptr->m_shadesPen; | |
809 | if (p.color() != color) { |
|
801 | if (p.color() != color) { | |
810 | p.setColor(color); |
|
802 | p.setColor(color); | |
811 | setShadesPen(p); |
|
803 | setShadesPen(p); | |
812 | emit shadesColorChanged(color); |
|
804 | emit shadesColorChanged(color); | |
813 | } |
|
805 | } | |
814 | } |
|
806 | } | |
815 |
|
807 | |||
816 | QColor QAbstractAxis::shadesBorderColor() const |
|
808 | QColor QAbstractAxis::shadesBorderColor() const | |
817 | { |
|
809 | { | |
818 | return shadesPen().color(); |
|
810 | return shadesPen().color(); | |
819 | } |
|
811 | } | |
820 |
|
812 | |||
821 |
|
813 | |||
822 | bool QAbstractAxis::isVisible() const |
|
814 | bool QAbstractAxis::isVisible() const | |
823 | { |
|
815 | { | |
824 | return d_ptr->m_visible; |
|
816 | return d_ptr->m_visible; | |
825 | } |
|
817 | } | |
826 |
|
818 | |||
827 | /*! |
|
819 | /*! | |
828 | Sets axis, shades, labels and grid lines to be visible. |
|
820 | Sets axis, shades, labels and grid lines to be visible. | |
829 | */ |
|
821 | */ | |
830 | void QAbstractAxis::setVisible(bool visible) |
|
822 | void QAbstractAxis::setVisible(bool visible) | |
831 | { |
|
823 | { | |
832 | if (d_ptr->m_visible != visible) { |
|
824 | if (d_ptr->m_visible != visible) { | |
833 | d_ptr->m_visible = visible; |
|
825 | d_ptr->m_visible = visible; | |
834 | emit visibleChanged(visible); |
|
826 | emit visibleChanged(visible); | |
835 | } |
|
827 | } | |
836 | } |
|
828 | } | |
837 |
|
829 | |||
838 |
|
830 | |||
839 | /*! |
|
831 | /*! | |
840 | Sets axis, shades, labels and grid lines to be visible. |
|
832 | Sets axis, shades, labels and grid lines to be visible. | |
841 | */ |
|
833 | */ | |
842 | void QAbstractAxis::show() |
|
834 | void QAbstractAxis::show() | |
843 | { |
|
835 | { | |
844 | setVisible(true); |
|
836 | setVisible(true); | |
845 | } |
|
837 | } | |
846 |
|
838 | |||
847 | /*! |
|
839 | /*! | |
848 | Sets axis, shades, labels and grid lines to not be visible. |
|
840 | Sets axis, shades, labels and grid lines to not be visible. | |
849 | */ |
|
841 | */ | |
850 | void QAbstractAxis::hide() |
|
842 | void QAbstractAxis::hide() | |
851 | { |
|
843 | { | |
852 | setVisible(false); |
|
844 | setVisible(false); | |
853 | } |
|
845 | } | |
854 |
|
846 | |||
855 | /*! |
|
847 | /*! | |
856 | Sets the minimum value shown on the axis. |
|
848 | Sets the minimum value shown on the axis. | |
857 | Depending on the actual axis type the \a min parameter is converted to appropriate type. |
|
849 | Depending on the actual axis type the \a min parameter is converted to appropriate type. | |
858 | If the conversion is impossible then the function call does nothing |
|
850 | If the conversion is impossible then the function call does nothing | |
859 | */ |
|
851 | */ | |
860 | void QAbstractAxis::setMin(const QVariant &min) |
|
852 | void QAbstractAxis::setMin(const QVariant &min) | |
861 | { |
|
853 | { | |
862 | d_ptr->setMin(min); |
|
854 | d_ptr->setMin(min); | |
863 | } |
|
855 | } | |
864 |
|
856 | |||
865 | /*! |
|
857 | /*! | |
866 | Sets the maximum value shown on the axis. |
|
858 | Sets the maximum value shown on the axis. | |
867 | Depending on the actual axis type the \a max parameter is converted to appropriate type. |
|
859 | Depending on the actual axis type the \a max parameter is converted to appropriate type. | |
868 | If the conversion is impossible then the function call does nothing |
|
860 | If the conversion is impossible then the function call does nothing | |
869 | */ |
|
861 | */ | |
870 | void QAbstractAxis::setMax(const QVariant &max) |
|
862 | void QAbstractAxis::setMax(const QVariant &max) | |
871 | { |
|
863 | { | |
872 | d_ptr->setMax(max); |
|
864 | d_ptr->setMax(max); | |
873 | } |
|
865 | } | |
874 |
|
866 | |||
875 | /*! |
|
867 | /*! | |
876 | Sets the range shown on the axis. |
|
868 | Sets the range shown on the axis. | |
877 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. |
|
869 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. | |
878 | If the conversion is impossible then the function call does nothing. |
|
870 | If the conversion is impossible then the function call does nothing. | |
879 | */ |
|
871 | */ | |
880 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
872 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) | |
881 | { |
|
873 | { | |
882 | d_ptr->setRange(min, max); |
|
874 | d_ptr->setRange(min, max); | |
883 | } |
|
875 | } | |
884 |
|
876 | |||
885 |
|
877 | |||
886 | /*! |
|
878 | /*! | |
887 | Returns the orientation in which the axis is being used (Vertical or Horizontal) |
|
879 | Returns the orientation in which the axis is being used (Vertical or Horizontal) | |
888 | */ |
|
880 | */ | |
889 | // NOTE: should have const but it breaks BC: |
|
881 | // NOTE: should have const but it breaks BC: | |
890 | // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function |
|
882 | // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function | |
891 | Qt::Orientation QAbstractAxis::orientation() |
|
883 | Qt::Orientation QAbstractAxis::orientation() | |
892 | { |
|
884 | { | |
893 | return d_ptr->orientation(); |
|
885 | return d_ptr->orientation(); | |
894 | } |
|
886 | } | |
895 |
|
887 | |||
896 | Qt::Alignment QAbstractAxis::alignment() const |
|
888 | Qt::Alignment QAbstractAxis::alignment() const | |
897 | { |
|
889 | { | |
898 | return d_ptr->alignment(); |
|
890 | return d_ptr->alignment(); | |
899 | } |
|
891 | } | |
900 |
|
892 | |||
901 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
893 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
902 |
|
894 | |||
903 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) |
|
895 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) | |
904 | : q_ptr(q), |
|
896 | : q_ptr(q), | |
905 | m_chart(0), |
|
897 | m_chart(0), | |
906 | m_alignment(0), |
|
898 | m_alignment(0), | |
907 | m_orientation(Qt::Orientation(0)), |
|
899 | m_orientation(Qt::Orientation(0)), | |
908 | m_visible(true), |
|
900 | m_visible(true), | |
909 | m_arrowVisible(true), |
|
901 | m_arrowVisible(true), | |
910 | m_axisPen(QChartPrivate::defaultPen()), |
|
902 | m_axisPen(QChartPrivate::defaultPen()), | |
911 | m_axisBrush(QChartPrivate::defaultBrush()), |
|
903 | m_axisBrush(QChartPrivate::defaultBrush()), | |
912 | m_gridLineVisible(true), |
|
904 | m_gridLineVisible(true), | |
913 | m_gridLinePen(QChartPrivate::defaultPen()), |
|
905 | m_gridLinePen(QChartPrivate::defaultPen()), | |
914 | m_labelsVisible(true), |
|
906 | m_labelsVisible(true), | |
915 | m_labelsPen(QChartPrivate::defaultPen()), |
|
907 | m_labelsPen(QChartPrivate::defaultPen()), | |
916 | m_labelsBrush(QChartPrivate::defaultBrush()), |
|
908 | m_labelsBrush(QChartPrivate::defaultBrush()), | |
917 | m_labelsFont(QChartPrivate::defaultFont()), |
|
909 | m_labelsFont(QChartPrivate::defaultFont()), | |
918 | m_labelsAngle(0), |
|
910 | m_labelsAngle(0), | |
919 | m_titleVisible(true), |
|
911 | m_titleVisible(true), | |
920 | m_titlePen(QChartPrivate::defaultPen()), |
|
912 | m_titlePen(QChartPrivate::defaultPen()), | |
921 | m_titleBrush(QChartPrivate::defaultBrush()), |
|
913 | m_titleBrush(QChartPrivate::defaultBrush()), | |
922 | m_titleFont(QChartPrivate::defaultFont()), |
|
914 | m_titleFont(QChartPrivate::defaultFont()), | |
923 | m_shadesVisible(false), |
|
915 | m_shadesVisible(false), | |
924 | m_shadesPen(QChartPrivate::defaultPen()), |
|
916 | m_shadesPen(QChartPrivate::defaultPen()), | |
925 | m_shadesBrush(QChartPrivate::defaultBrush()), |
|
917 | m_shadesBrush(QChartPrivate::defaultBrush()), | |
926 | m_shadesOpacity(1.0), |
|
918 | m_shadesOpacity(1.0), | |
927 | m_dirty(false) |
|
919 | m_dirty(false) | |
928 | { |
|
920 | { | |
929 | } |
|
921 | } | |
930 |
|
922 | |||
931 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
923 | QAbstractAxisPrivate::~QAbstractAxisPrivate() | |
932 | { |
|
924 | { | |
933 | } |
|
925 | } | |
934 |
|
926 | |||
935 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) |
|
927 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) | |
936 | { |
|
928 | { | |
937 | switch(alignment) { |
|
929 | switch(alignment) { | |
938 | case Qt::AlignTop: |
|
930 | case Qt::AlignTop: | |
939 | case Qt::AlignBottom: |
|
931 | case Qt::AlignBottom: | |
940 | m_orientation = Qt::Horizontal; |
|
932 | m_orientation = Qt::Horizontal; | |
941 | break; |
|
933 | break; | |
942 | case Qt::AlignLeft: |
|
934 | case Qt::AlignLeft: | |
943 | case Qt::AlignRight: |
|
935 | case Qt::AlignRight: | |
944 | m_orientation = Qt::Vertical; |
|
936 | m_orientation = Qt::Vertical; | |
945 | break; |
|
937 | break; | |
946 | default: |
|
938 | default: | |
947 | qWarning()<<"No alignment specified !"; |
|
939 | qWarning()<<"No alignment specified !"; | |
948 | break; |
|
940 | break; | |
949 | }; |
|
941 | }; | |
950 | m_alignment=alignment; |
|
942 | m_alignment=alignment; | |
951 | } |
|
943 | } | |
952 |
|
944 | |||
953 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) |
|
945 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) | |
954 | { |
|
946 | { | |
955 | //TODO: introduce axis brush |
|
947 | //TODO: introduce axis brush | |
956 | if (forced || QChartPrivate::defaultPen() == m_axisPen) |
|
948 | if (forced || QChartPrivate::defaultPen() == m_axisPen) | |
957 | q_ptr->setLinePen(theme->axisLinePen()); |
|
949 | q_ptr->setLinePen(theme->axisLinePen()); | |
958 |
|
950 | |||
959 | if (forced || QChartPrivate::defaultPen() == m_gridLinePen) |
|
951 | if (forced || QChartPrivate::defaultPen() == m_gridLinePen) | |
960 | q_ptr->setGridLinePen(theme->girdLinePen()); |
|
952 | q_ptr->setGridLinePen(theme->girdLinePen()); | |
961 |
|
953 | |||
962 | if (forced || QChartPrivate::defaultBrush() == m_labelsBrush) |
|
954 | if (forced || QChartPrivate::defaultBrush() == m_labelsBrush) | |
963 | q_ptr->setLabelsBrush(theme->labelBrush()); |
|
955 | q_ptr->setLabelsBrush(theme->labelBrush()); | |
964 | if (forced || QChartPrivate::defaultPen() == m_labelsPen) |
|
956 | if (forced || QChartPrivate::defaultPen() == m_labelsPen) | |
965 | q_ptr->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
957 | q_ptr->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
966 | if (forced || QChartPrivate::defaultFont() == m_labelsFont) |
|
958 | if (forced || QChartPrivate::defaultFont() == m_labelsFont) | |
967 | q_ptr->setLabelsFont(theme->labelFont()); |
|
959 | q_ptr->setLabelsFont(theme->labelFont()); | |
968 |
|
960 | |||
969 | if (forced || QChartPrivate::defaultBrush() == m_titleBrush) |
|
961 | if (forced || QChartPrivate::defaultBrush() == m_titleBrush) | |
970 | q_ptr->setTitleBrush(theme->labelBrush()); |
|
962 | q_ptr->setTitleBrush(theme->labelBrush()); | |
971 | if (forced || QChartPrivate::defaultPen() == m_titlePen) |
|
963 | if (forced || QChartPrivate::defaultPen() == m_titlePen) | |
972 | q_ptr->setTitlePen(Qt::NoPen); // NoPen for performance reasons |
|
964 | q_ptr->setTitlePen(Qt::NoPen); // NoPen for performance reasons | |
973 | if (forced || QChartPrivate::defaultFont() == m_titleFont) { |
|
965 | if (forced || QChartPrivate::defaultFont() == m_titleFont) { | |
974 | QFont font(m_labelsFont); |
|
966 | QFont font(m_labelsFont); | |
975 | font.setBold(true); |
|
967 | font.setBold(true); | |
976 | q_ptr->setTitleFont(font); |
|
968 | q_ptr->setTitleFont(font); | |
977 | } |
|
969 | } | |
978 |
|
970 | |||
979 | if (forced || QChartPrivate::defaultBrush() == m_shadesBrush) |
|
971 | if (forced || QChartPrivate::defaultBrush() == m_shadesBrush) | |
980 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); |
|
972 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); | |
981 | if (forced || QChartPrivate::defaultPen() == m_shadesPen) |
|
973 | if (forced || QChartPrivate::defaultPen() == m_shadesPen) | |
982 | q_ptr->setShadesPen(theme->backgroundShadesPen()); |
|
974 | q_ptr->setShadesPen(theme->backgroundShadesPen()); | |
983 |
|
975 | |||
984 | bool axisX = m_orientation == Qt::Horizontal; |
|
976 | bool axisX = m_orientation == Qt::Horizontal; | |
985 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth |
|
977 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth | |
986 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) |
|
978 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) | |
987 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { |
|
979 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { | |
988 | q_ptr->setShadesVisible(true); |
|
980 | q_ptr->setShadesVisible(true); | |
989 | } else if (forced) { |
|
981 | } else if (forced) { | |
990 | q_ptr->setShadesVisible(false); |
|
982 | q_ptr->setShadesVisible(false); | |
991 | } |
|
983 | } | |
992 | } |
|
984 | } | |
993 |
|
985 | |||
994 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) |
|
986 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) | |
995 | { |
|
987 | { | |
996 | setRange(min,max); |
|
988 | setRange(min,max); | |
997 | } |
|
989 | } | |
998 |
|
990 | |||
999 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
991 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
1000 | { |
|
992 | { | |
1001 | Q_UNUSED(parent); |
|
993 | Q_UNUSED(parent); | |
1002 | } |
|
994 | } | |
1003 |
|
995 | |||
1004 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
996 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) | |
1005 | { |
|
997 | { | |
1006 | ChartAxisElement *axis = m_item.data(); |
|
998 | ChartAxisElement *axis = m_item.data(); | |
1007 | Q_ASSERT(axis); |
|
999 | Q_ASSERT(axis); | |
1008 | if (options.testFlag(QChart::GridAxisAnimations)) { |
|
1000 | if (options.testFlag(QChart::GridAxisAnimations)) { | |
1009 | axis->setAnimation(new AxisAnimation(axis)); |
|
1001 | axis->setAnimation(new AxisAnimation(axis)); | |
1010 | } else { |
|
1002 | } else { | |
1011 | axis->setAnimation(0); |
|
1003 | axis->setAnimation(0); | |
1012 | } |
|
1004 | } | |
1013 | } |
|
1005 | } | |
1014 |
|
1006 | |||
1015 |
|
1007 | |||
1016 |
|
1008 | |||
1017 | #include "moc_qabstractaxis.cpp" |
|
1009 | #include "moc_qabstractaxis.cpp" | |
1018 | #include "moc_qabstractaxis_p.cpp" |
|
1010 | #include "moc_qabstractaxis_p.cpp" | |
1019 |
|
1011 | |||
1020 | QTCOMMERCIALCHART_END_NAMESPACE |
|
1012 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,128 +1,128 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "chartvalueaxisx_p.h" |
|
21 | #include "chartvalueaxisx_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "qvalueaxis.h" |
|
24 | #include "qvalueaxis.h" | |
25 | #include "abstractchartlayout_p.h" |
|
25 | #include "abstractchartlayout_p.h" | |
26 | #include <QGraphicsLayout> |
|
26 | #include <QGraphicsLayout> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 | #include <QDebug> |
|
28 | #include <QDebug> | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | ChartValueAxisX::ChartValueAxisX(QValueAxis *axis, QGraphicsItem *item ) |
|
33 | ChartValueAxisX::ChartValueAxisX(QValueAxis *axis, QGraphicsItem *item ) | |
34 | : HorizontalAxis(axis, item), |
|
34 | : HorizontalAxis(axis, item), | |
35 | m_axis(axis) |
|
35 | m_axis(axis) | |
36 | { |
|
36 | { | |
37 | QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); |
|
37 | QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); | |
38 | QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); |
|
38 | QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | ChartValueAxisX::~ChartValueAxisX() |
|
41 | ChartValueAxisX::~ChartValueAxisX() | |
42 | { |
|
42 | { | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | QVector<qreal> ChartValueAxisX::calculateLayout() const |
|
45 | QVector<qreal> ChartValueAxisX::calculateLayout() const | |
46 | { |
|
46 | { | |
47 | int tickCount = m_axis->tickCount(); |
|
47 | int tickCount = m_axis->tickCount(); | |
48 |
|
48 | |||
49 | Q_ASSERT(tickCount >= 2); |
|
49 | Q_ASSERT(tickCount >= 2); | |
50 |
|
50 | |||
51 | QVector<qreal> points; |
|
51 | QVector<qreal> points; | |
52 | points.resize(tickCount); |
|
52 | points.resize(tickCount); | |
53 |
|
53 | |||
54 | const QRectF &gridRect = gridGeometry(); |
|
54 | const QRectF &gridRect = gridGeometry(); | |
55 | const qreal deltaX = gridRect.width() / (qreal(tickCount) - 1.0); |
|
55 | const qreal deltaX = gridRect.width() / (qreal(tickCount) - 1.0); | |
56 | for (int i = 0; i < tickCount; ++i) |
|
56 | for (int i = 0; i < tickCount; ++i) | |
57 | points[i] = qreal(i) * deltaX + gridRect.left(); |
|
57 | points[i] = qreal(i) * deltaX + gridRect.left(); | |
58 | return points; |
|
58 | return points; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | void ChartValueAxisX::updateGeometry() |
|
61 | void ChartValueAxisX::updateGeometry() | |
62 | { |
|
62 | { | |
63 | const QVector<qreal>& layout = ChartAxisElement::layout(); |
|
63 | const QVector<qreal>& layout = ChartAxisElement::layout(); | |
64 | if (layout.isEmpty()) |
|
64 | if (layout.isEmpty()) | |
65 | return; |
|
65 | return; | |
66 | setLabels(createValueLabels(min(), max(), layout.size(), m_axis->labelFormat())); |
|
66 | setLabels(createValueLabels(min(), max(), layout.size(), m_axis->labelFormat())); | |
67 | HorizontalAxis::updateGeometry(); |
|
67 | HorizontalAxis::updateGeometry(); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void ChartValueAxisX::handleTickCountChanged(int tick) |
|
70 | void ChartValueAxisX::handleTickCountChanged(int tick) | |
71 | { |
|
71 | { | |
72 | Q_UNUSED(tick); |
|
72 | Q_UNUSED(tick); | |
73 | QGraphicsLayoutItem::updateGeometry(); |
|
73 | QGraphicsLayoutItem::updateGeometry(); | |
74 | if(presenter()) presenter()->layout()->invalidate(); |
|
74 | if(presenter()) presenter()->layout()->invalidate(); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void ChartValueAxisX::handleLabelFormatChanged(const QString &format) |
|
77 | void ChartValueAxisX::handleLabelFormatChanged(const QString &format) | |
78 | { |
|
78 | { | |
79 | Q_UNUSED(format); |
|
79 | Q_UNUSED(format); | |
80 | QGraphicsLayoutItem::updateGeometry(); |
|
80 | QGraphicsLayoutItem::updateGeometry(); | |
81 | if(presenter()) presenter()->layout()->invalidate(); |
|
81 | if(presenter()) presenter()->layout()->invalidate(); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
84 | QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
85 | { |
|
85 | { | |
86 | Q_UNUSED(constraint) |
|
86 | Q_UNUSED(constraint) | |
87 |
|
87 | |||
88 | QSizeF sh; |
|
88 | QSizeF sh; | |
89 |
|
89 | |||
90 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
90 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |
91 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); |
|
91 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); | |
92 | // Width of horizontal axis sizeHint indicates the maximum distance labels can extend past |
|
92 | // Width of horizontal axis sizeHint indicates the maximum distance labels can extend past | |
93 | // first and last ticks. Base width is irrelevant. |
|
93 | // first and last ticks. Base width is irrelevant. | |
94 | qreal width = 0; |
|
94 | qreal width = 0; | |
95 | qreal height = 0; |
|
95 | qreal height = 0; | |
96 |
|
96 | |||
97 | switch (which) { |
|
97 | switch (which) { | |
98 | case Qt::MinimumSize: { |
|
98 | case Qt::MinimumSize: { | |
99 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); |
|
99 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
100 | width = boundingRect.width() / 2.0; |
|
100 | width = boundingRect.width() / 2.0; | |
101 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; |
|
101 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; | |
102 | sh = QSizeF(width, height); |
|
102 | sh = QSizeF(width, height); | |
103 | break; |
|
103 | break; | |
104 | } |
|
104 | } | |
105 | case Qt::PreferredSize: { |
|
105 | case Qt::PreferredSize: { | |
106 | qreal labelHeight = 0.0; |
|
106 | qreal labelHeight = 0.0; | |
107 | qreal firstWidth = -1.0; |
|
107 | qreal firstWidth = -1.0; | |
108 | foreach (const QString& s, ticksList) { |
|
108 | foreach (const QString& s, ticksList) { | |
109 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); |
|
109 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
110 | labelHeight = qMax(rect.height(), labelHeight); |
|
110 | labelHeight = qMax(rect.height(), labelHeight); | |
111 | width = rect.width(); |
|
111 | width = rect.width(); | |
112 | if (firstWidth < 0.0) |
|
112 | if (firstWidth < 0.0) | |
113 | firstWidth = width; |
|
113 | firstWidth = width; | |
114 | } |
|
114 | } | |
115 | height = labelHeight + labelPadding() + base.height() + 1.0; |
|
115 | height = labelHeight + labelPadding() + base.height() + 1.0; | |
116 | width = qMax(width, firstWidth) / 2.0; |
|
116 | width = qMax(width, firstWidth) / 2.0; | |
117 | sh = QSizeF(width, height); |
|
117 | sh = QSizeF(width, height); | |
118 | break; |
|
118 | break; | |
119 | } |
|
119 | } | |
120 | default: |
|
120 | default: | |
121 | break; |
|
121 | break; | |
122 | } |
|
122 | } | |
123 | return sh; |
|
123 | return sh; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | #include "moc_chartvalueaxisx_p.cpp" |
|
126 | #include "moc_chartvalueaxisx_p.cpp" | |
127 |
|
127 | |||
128 | QTCOMMERCIALCHART_END_NAMESPACE |
|
128 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,128 +1,128 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "chartvalueaxisy_p.h" |
|
21 | #include "chartvalueaxisy_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "qvalueaxis.h" |
|
24 | #include "qvalueaxis.h" | |
25 | #include "abstractchartlayout_p.h" |
|
25 | #include "abstractchartlayout_p.h" | |
26 | #include <QGraphicsLayout> |
|
26 | #include <QGraphicsLayout> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 | #include <QDebug> |
|
28 | #include <QDebug> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ChartValueAxisY::ChartValueAxisY(QValueAxis *axis, QGraphicsItem *item) |
|
32 | ChartValueAxisY::ChartValueAxisY(QValueAxis *axis, QGraphicsItem *item) | |
33 | : VerticalAxis(axis, item), |
|
33 | : VerticalAxis(axis, item), | |
34 | m_axis(axis) |
|
34 | m_axis(axis) | |
35 | { |
|
35 | { | |
36 | QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); |
|
36 | QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); | |
37 | QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); |
|
37 | QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | ChartValueAxisY::~ChartValueAxisY() |
|
40 | ChartValueAxisY::~ChartValueAxisY() | |
41 | { |
|
41 | { | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | QVector<qreal> ChartValueAxisY::calculateLayout() const |
|
44 | QVector<qreal> ChartValueAxisY::calculateLayout() const | |
45 | { |
|
45 | { | |
46 | int tickCount = m_axis->tickCount(); |
|
46 | int tickCount = m_axis->tickCount(); | |
47 |
|
47 | |||
48 | Q_ASSERT(tickCount >= 2); |
|
48 | Q_ASSERT(tickCount >= 2); | |
49 |
|
49 | |||
50 | QVector<qreal> points; |
|
50 | QVector<qreal> points; | |
51 | points.resize(tickCount); |
|
51 | points.resize(tickCount); | |
52 |
|
52 | |||
53 | const QRectF &gridRect = gridGeometry(); |
|
53 | const QRectF &gridRect = gridGeometry(); | |
54 |
|
54 | |||
55 | const qreal deltaY = gridRect.height() / (qreal(tickCount) - 1.0); |
|
55 | const qreal deltaY = gridRect.height() / (qreal(tickCount) - 1.0); | |
56 | for (int i = 0; i < tickCount; ++i) |
|
56 | for (int i = 0; i < tickCount; ++i) | |
57 | points[i] = qreal(i) * -deltaY + gridRect.bottom(); |
|
57 | points[i] = qreal(i) * -deltaY + gridRect.bottom(); | |
58 |
|
58 | |||
59 | return points; |
|
59 | return points; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void ChartValueAxisY::updateGeometry() |
|
62 | void ChartValueAxisY::updateGeometry() | |
63 | { |
|
63 | { | |
64 | const QVector<qreal> &layout = ChartAxisElement::layout(); |
|
64 | const QVector<qreal> &layout = ChartAxisElement::layout(); | |
65 | if (layout.isEmpty()) |
|
65 | if (layout.isEmpty()) | |
66 | return; |
|
66 | return; | |
67 | setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat())); |
|
67 | setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat())); | |
68 | VerticalAxis::updateGeometry(); |
|
68 | VerticalAxis::updateGeometry(); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void ChartValueAxisY::handleTickCountChanged(int tick) |
|
71 | void ChartValueAxisY::handleTickCountChanged(int tick) | |
72 | { |
|
72 | { | |
73 | Q_UNUSED(tick); |
|
73 | Q_UNUSED(tick); | |
74 | QGraphicsLayoutItem::updateGeometry(); |
|
74 | QGraphicsLayoutItem::updateGeometry(); | |
75 | if(presenter()) presenter()->layout()->invalidate(); |
|
75 | if(presenter()) presenter()->layout()->invalidate(); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void ChartValueAxisY::handleLabelFormatChanged(const QString &format) |
|
78 | void ChartValueAxisY::handleLabelFormatChanged(const QString &format) | |
79 | { |
|
79 | { | |
80 | Q_UNUSED(format); |
|
80 | Q_UNUSED(format); | |
81 | QGraphicsLayoutItem::updateGeometry(); |
|
81 | QGraphicsLayoutItem::updateGeometry(); | |
82 | if(presenter()) presenter()->layout()->invalidate(); |
|
82 | if(presenter()) presenter()->layout()->invalidate(); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
85 | QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
86 | { |
|
86 | { | |
87 | Q_UNUSED(constraint) |
|
87 | Q_UNUSED(constraint) | |
88 |
|
88 | |||
89 | QSizeF sh; |
|
89 | QSizeF sh; | |
90 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
90 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
91 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); |
|
91 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); | |
92 | qreal width = 0; |
|
92 | qreal width = 0; | |
93 | // Height of vertical axis sizeHint indicates the maximum distance labels can extend past |
|
93 | // Height of vertical axis sizeHint indicates the maximum distance labels can extend past | |
94 | // first and last ticks. Base height is irrelevant. |
|
94 | // first and last ticks. Base height is irrelevant. | |
95 | qreal height = 0; |
|
95 | qreal height = 0; | |
96 |
|
96 | |||
97 | switch (which) { |
|
97 | switch (which) { | |
98 | case Qt::MinimumSize: { |
|
98 | case Qt::MinimumSize: { | |
99 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); |
|
99 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
100 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; |
|
100 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; | |
101 | height = boundingRect.height() / 2.0; |
|
101 | height = boundingRect.height() / 2.0; | |
102 | sh = QSizeF(width, height); |
|
102 | sh = QSizeF(width, height); | |
103 | break; |
|
103 | break; | |
104 | } |
|
104 | } | |
105 | case Qt::PreferredSize: { |
|
105 | case Qt::PreferredSize: { | |
106 | qreal labelWidth = 0.0; |
|
106 | qreal labelWidth = 0.0; | |
107 | qreal firstHeight = -1.0; |
|
107 | qreal firstHeight = -1.0; | |
108 | foreach (const QString& s, ticksList) { |
|
108 | foreach (const QString& s, ticksList) { | |
109 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); |
|
109 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
110 | labelWidth = qMax(rect.width(), labelWidth); |
|
110 | labelWidth = qMax(rect.width(), labelWidth); | |
111 | height = rect.height(); |
|
111 | height = rect.height(); | |
112 | if (firstHeight < 0.0) |
|
112 | if (firstHeight < 0.0) | |
113 | firstHeight = height; |
|
113 | firstHeight = height; | |
114 | } |
|
114 | } | |
115 | width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance |
|
115 | width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance | |
116 | height = qMax(height, firstHeight) / 2.0; |
|
116 | height = qMax(height, firstHeight) / 2.0; | |
117 | sh = QSizeF(width, height); |
|
117 | sh = QSizeF(width, height); | |
118 | break; |
|
118 | break; | |
119 | } |
|
119 | } | |
120 | default: |
|
120 | default: | |
121 | break; |
|
121 | break; | |
122 | } |
|
122 | } | |
123 | return sh; |
|
123 | return sh; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | #include "moc_chartvalueaxisy_p.cpp" |
|
126 | #include "moc_chartvalueaxisy_p.cpp" | |
127 |
|
127 | |||
128 | QTCOMMERCIALCHART_END_NAMESPACE |
|
128 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,210 +1,211 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "verticalaxis_p.h" |
|
21 | #include "verticalaxis_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
|
23 | #include "chartpresenter_p.h" | |||
23 | #include <QDebug> |
|
24 | #include <QDebug> | |
24 |
|
25 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
27 | |||
27 | VerticalAxis::VerticalAxis(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) |
|
28 | VerticalAxis::VerticalAxis(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) | |
28 | : CartesianChartAxis(axis, item, intervalAxis) |
|
29 | : CartesianChartAxis(axis, item, intervalAxis) | |
29 | { |
|
30 | { | |
30 | } |
|
31 | } | |
31 |
|
32 | |||
32 | VerticalAxis::~VerticalAxis() |
|
33 | VerticalAxis::~VerticalAxis() | |
33 | { |
|
34 | { | |
34 | } |
|
35 | } | |
35 |
|
36 | |||
36 | void VerticalAxis::updateGeometry() |
|
37 | void VerticalAxis::updateGeometry() | |
37 | { |
|
38 | { | |
38 | const QVector<qreal> &layout = ChartAxisElement::layout(); |
|
39 | const QVector<qreal> &layout = ChartAxisElement::layout(); | |
39 |
|
40 | |||
40 | if (layout.isEmpty()) |
|
41 | if (layout.isEmpty()) | |
41 | return; |
|
42 | return; | |
42 |
|
43 | |||
43 | QStringList labelList = labels(); |
|
44 | QStringList labelList = labels(); | |
44 |
|
45 | |||
45 | QList<QGraphicsItem *> lines = gridItems(); |
|
46 | QList<QGraphicsItem *> lines = gridItems(); | |
46 | QList<QGraphicsItem *> labels = labelItems(); |
|
47 | QList<QGraphicsItem *> labels = labelItems(); | |
47 | QList<QGraphicsItem *> shades = shadeItems(); |
|
48 | QList<QGraphicsItem *> shades = shadeItems(); | |
48 | QList<QGraphicsItem *> arrow = arrowItems(); |
|
49 | QList<QGraphicsItem *> arrow = arrowItems(); | |
49 |
QGraphics |
|
50 | QGraphicsTextItem *title = titleItem(); | |
50 |
|
51 | |||
51 | Q_ASSERT(labels.size() == labelList.size()); |
|
52 | Q_ASSERT(labels.size() == labelList.size()); | |
52 | Q_ASSERT(layout.size() == labelList.size()); |
|
53 | Q_ASSERT(layout.size() == labelList.size()); | |
53 |
|
54 | |||
54 | const QRectF &axisRect = axisGeometry(); |
|
55 | const QRectF &axisRect = axisGeometry(); | |
55 | const QRectF &gridRect = gridGeometry(); |
|
56 | const QRectF &gridRect = gridGeometry(); | |
56 |
|
57 | |||
57 | qreal height = axisRect.bottom(); |
|
58 | qreal height = axisRect.bottom(); | |
58 |
|
59 | |||
59 |
|
60 | |||
60 | //arrow |
|
61 | //arrow | |
61 | QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem*>(arrow.at(0)); |
|
62 | QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem*>(arrow.at(0)); | |
62 |
|
63 | |||
63 | //arrow position |
|
64 | //arrow position | |
64 | if (axis()->alignment() == Qt::AlignLeft) |
|
65 | if (axis()->alignment() == Qt::AlignLeft) | |
65 | arrowItem->setLine(axisRect.right(), gridRect.top(), axisRect.right(), gridRect.bottom()); |
|
66 | arrowItem->setLine(axisRect.right(), gridRect.top(), axisRect.right(), gridRect.bottom()); | |
66 | else if (axis()->alignment() == Qt::AlignRight) |
|
67 | else if (axis()->alignment() == Qt::AlignRight) | |
67 | arrowItem->setLine(axisRect.left(), gridRect.top(), axisRect.left(), gridRect.bottom()); |
|
68 | arrowItem->setLine(axisRect.left(), gridRect.top(), axisRect.left(), gridRect.bottom()); | |
68 |
|
69 | |||
69 | //title |
|
70 | //title | |
70 | int titlePad = 0; |
|
71 | int titlePad = 0; | |
71 | QRectF titleBoundingRect; |
|
72 | QRectF titleBoundingRect; | |
72 | QString titleText = axis()->titleText(); |
|
73 | QString titleText = axis()->titleText(); | |
73 | if (!titleText.isEmpty() && titleItem()->isVisible()) { |
|
74 | if (!titleText.isEmpty() && titleItem()->isVisible()) { | |
74 |
title->set |
|
75 | title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), gridRect.height(), Qt::Horizontal, QRectF())); | |
75 |
|
76 | |||
76 | titlePad = titlePadding(); |
|
77 | titlePad = titlePadding(); | |
77 | titleBoundingRect = title->boundingRect(); |
|
78 | titleBoundingRect = title->boundingRect(); | |
78 |
|
79 | |||
79 | QPointF center = gridRect.center() - titleBoundingRect.center(); |
|
80 | QPointF center = gridRect.center() - titleBoundingRect.center(); | |
80 | if (axis()->alignment() == Qt::AlignLeft) { |
|
81 | if (axis()->alignment() == Qt::AlignLeft) { | |
81 | title->setPos(axisRect.left() - titleBoundingRect.width() / 2 + titleBoundingRect.height() / 2 + titlePad, center.y()); |
|
82 | title->setPos(axisRect.left() - titleBoundingRect.width() / 2 + titleBoundingRect.height() / 2 + titlePad, center.y()); | |
82 | } |
|
83 | } | |
83 | else if (axis()->alignment() == Qt::AlignRight) { |
|
84 | else if (axis()->alignment() == Qt::AlignRight) { | |
84 | title->setPos(axisRect.right() - titleBoundingRect.width() / 2 - titleBoundingRect.height() / 2 - titlePad, center.y()); |
|
85 | title->setPos(axisRect.right() - titleBoundingRect.width() / 2 - titleBoundingRect.height() / 2 - titlePad, center.y()); | |
85 | } |
|
86 | } | |
86 | title->setTransformOriginPoint(titleBoundingRect.center()); |
|
87 | title->setTransformOriginPoint(titleBoundingRect.center()); | |
87 | title->setRotation(270); |
|
88 | title->setRotation(270); | |
88 | } |
|
89 | } | |
89 |
|
90 | |||
90 | for (int i = 0; i < layout.size(); ++i) { |
|
91 | for (int i = 0; i < layout.size(); ++i) { | |
91 | //items |
|
92 | //items | |
92 | QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i)); |
|
93 | QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i)); | |
93 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrow.at(i + 1)); |
|
94 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrow.at(i + 1)); | |
94 |
QGraphics |
|
95 | QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labels.at(i)); | |
95 |
|
96 | |||
96 | //grid line |
|
97 | //grid line | |
97 | gridItem->setLine(gridRect.left(), layout[i], gridRect.right(), layout[i]); |
|
98 | gridItem->setLine(gridRect.left(), layout[i], gridRect.right(), layout[i]); | |
98 |
|
99 | |||
99 | //label text wrapping |
|
100 | //label text wrapping | |
100 | QString text = labelList.at(i); |
|
101 | QString text = labelList.at(i); | |
101 | QRectF boundingRect; |
|
102 | QRectF boundingRect; | |
102 | qreal size = axisRect.right() - axisRect.left() - labelPadding() - titleBoundingRect.height() - (titlePad * 2); |
|
103 | qreal size = axisRect.right() - axisRect.left() - labelPadding() - titleBoundingRect.height() - (titlePad * 2); | |
103 |
labelItem->set |
|
104 | labelItem->setHtml(ChartPresenter::truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(), | |
104 | size, Qt::Horizontal, boundingRect)); |
|
105 | size, Qt::Horizontal, boundingRect)); | |
105 |
|
106 | |||
106 | //label transformation origin point |
|
107 | //label transformation origin point | |
107 | const QRectF &rect = labelItem->boundingRect(); |
|
108 | const QRectF &rect = labelItem->boundingRect(); | |
108 | QPointF center = rect.center(); |
|
109 | QPointF center = rect.center(); | |
109 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
110 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
110 | int widthDiff = rect.width() - boundingRect.width(); |
|
111 | int widthDiff = rect.width() - boundingRect.width(); | |
111 |
|
112 | |||
112 | //ticks and label position |
|
113 | //ticks and label position | |
113 | if (axis()->alignment() == Qt::AlignLeft) { |
|
114 | if (axis()->alignment() == Qt::AlignLeft) { | |
114 | labelItem->setPos(axisRect.right() - rect.width() + (widthDiff / 2) - labelPadding(), layout[i] - center.y()); |
|
115 | labelItem->setPos(axisRect.right() - rect.width() + (widthDiff / 2) - labelPadding(), layout[i] - center.y()); | |
115 | tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]); |
|
116 | tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]); | |
116 | } else if (axis()->alignment() == Qt::AlignRight) { |
|
117 | } else if (axis()->alignment() == Qt::AlignRight) { | |
117 | labelItem->setPos(axisRect.left() + labelPadding() - (widthDiff / 2), layout[i] - center.y()); |
|
118 | labelItem->setPos(axisRect.left() + labelPadding() - (widthDiff / 2), layout[i] - center.y()); | |
118 | tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]); |
|
119 | tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]); | |
119 | } |
|
120 | } | |
120 |
|
121 | |||
121 | //label in between |
|
122 | //label in between | |
122 | bool forceHide = false; |
|
123 | bool forceHide = false; | |
123 | if (intervalAxis() && (i + 1) != layout.size()) { |
|
124 | if (intervalAxis() && (i + 1) != layout.size()) { | |
124 | qreal lowerBound = qMin(layout[i], gridRect.bottom()); |
|
125 | qreal lowerBound = qMin(layout[i], gridRect.bottom()); | |
125 | qreal upperBound = qMax(layout[i + 1], gridRect.top()); |
|
126 | qreal upperBound = qMax(layout[i + 1], gridRect.top()); | |
126 | const qreal delta = lowerBound - upperBound; |
|
127 | const qreal delta = lowerBound - upperBound; | |
127 | // Hide label in case visible part of the category at the grid edge is too narrow |
|
128 | // Hide label in case visible part of the category at the grid edge is too narrow | |
128 | if (delta < boundingRect.height() |
|
129 | if (delta < boundingRect.height() | |
129 | && (lowerBound == gridRect.bottom() || upperBound == gridRect.top())) { |
|
130 | && (lowerBound == gridRect.bottom() || upperBound == gridRect.top())) { | |
130 | forceHide = true; |
|
131 | forceHide = true; | |
131 | } else { |
|
132 | } else { | |
132 | labelItem->setPos(labelItem->pos().x() , lowerBound - (delta / 2.0) - center.y()); |
|
133 | labelItem->setPos(labelItem->pos().x() , lowerBound - (delta / 2.0) - center.y()); | |
133 | } |
|
134 | } | |
134 | } |
|
135 | } | |
135 |
|
136 | |||
136 | //label overlap detection - compensate one pixel for rounding errors |
|
137 | //label overlap detection - compensate one pixel for rounding errors | |
137 | if (labelItem->pos().y() + boundingRect.height() > height || forceHide || |
|
138 | if (labelItem->pos().y() + boundingRect.height() > height || forceHide || | |
138 | (labelItem->pos().y() + (boundingRect.height() / 2.0) - 1.0) > axisRect.bottom() || |
|
139 | (labelItem->pos().y() + (boundingRect.height() / 2.0) - 1.0) > axisRect.bottom() || | |
139 | labelItem->pos().y() + (boundingRect.height() / 2.0) < (axisRect.top() - 1.0)) { |
|
140 | labelItem->pos().y() + (boundingRect.height() / 2.0) < (axisRect.top() - 1.0)) { | |
140 | labelItem->setVisible(false); |
|
141 | labelItem->setVisible(false); | |
141 | } |
|
142 | } | |
142 | else { |
|
143 | else { | |
143 | labelItem->setVisible(true); |
|
144 | labelItem->setVisible(true); | |
144 | height=labelItem->pos().y(); |
|
145 | height=labelItem->pos().y(); | |
145 | } |
|
146 | } | |
146 |
|
147 | |||
147 | //shades |
|
148 | //shades | |
148 | if ((i + 1) % 2 && i > 1) { |
|
149 | if ((i + 1) % 2 && i > 1) { | |
149 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1)); |
|
150 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1)); | |
150 | qreal lowerBound = qMin(layout[i - 1], gridRect.bottom()); |
|
151 | qreal lowerBound = qMin(layout[i - 1], gridRect.bottom()); | |
151 | qreal upperBound = qMax(layout[i], gridRect.top()); |
|
152 | qreal upperBound = qMax(layout[i], gridRect.top()); | |
152 | rectItem->setRect(gridRect.left(), upperBound, gridRect.width(), lowerBound - upperBound); |
|
153 | rectItem->setRect(gridRect.left(), upperBound, gridRect.width(), lowerBound - upperBound); | |
153 | if (rectItem->rect().height() <= 0.0) |
|
154 | if (rectItem->rect().height() <= 0.0) | |
154 | rectItem->setVisible(false); |
|
155 | rectItem->setVisible(false); | |
155 | else |
|
156 | else | |
156 | rectItem->setVisible(true); |
|
157 | rectItem->setVisible(true); | |
157 | } |
|
158 | } | |
158 |
|
159 | |||
159 | // check if the grid line and the axis tick should be shown |
|
160 | // check if the grid line and the axis tick should be shown | |
160 | qreal y = gridItem->line().p1().y(); |
|
161 | qreal y = gridItem->line().p1().y(); | |
161 | if ((y < gridRect.top() || y > gridRect.bottom())) |
|
162 | if ((y < gridRect.top() || y > gridRect.bottom())) | |
162 | { |
|
163 | { | |
163 | gridItem->setVisible(false); |
|
164 | gridItem->setVisible(false); | |
164 | tickItem->setVisible(false); |
|
165 | tickItem->setVisible(false); | |
165 | }else{ |
|
166 | }else{ | |
166 | gridItem->setVisible(true); |
|
167 | gridItem->setVisible(true); | |
167 | tickItem->setVisible(true); |
|
168 | tickItem->setVisible(true); | |
168 | } |
|
169 | } | |
169 |
|
170 | |||
170 | } |
|
171 | } | |
171 | //begin/end grid line in case labels between |
|
172 | //begin/end grid line in case labels between | |
172 | if (intervalAxis()) { |
|
173 | if (intervalAxis()) { | |
173 | QGraphicsLineItem *gridLine; |
|
174 | QGraphicsLineItem *gridLine; | |
174 | gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size())); |
|
175 | gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size())); | |
175 | gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.right(), gridRect.top()); |
|
176 | gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.right(), gridRect.top()); | |
176 | gridLine->setVisible(true); |
|
177 | gridLine->setVisible(true); | |
177 | gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size() + 1)); |
|
178 | gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size() + 1)); | |
178 | gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom()); |
|
179 | gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom()); | |
179 | gridLine->setVisible(true); |
|
180 | gridLine->setVisible(true); | |
180 | } |
|
181 | } | |
181 | } |
|
182 | } | |
182 |
|
183 | |||
183 | QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
184 | QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
184 | { |
|
185 | { | |
185 | Q_UNUSED(constraint); |
|
186 | Q_UNUSED(constraint); | |
186 | QSizeF sh(0, 0); |
|
187 | QSizeF sh(0, 0); | |
187 |
|
188 | |||
188 | if (axis()->titleText().isEmpty() || !titleItem()->isVisible()) |
|
189 | if (axis()->titleText().isEmpty() || !titleItem()->isVisible()) | |
189 | return sh; |
|
190 | return sh; | |
190 |
|
191 | |||
191 | switch (which) { |
|
192 | switch (which) { | |
192 | case Qt::MinimumSize: { |
|
193 | case Qt::MinimumSize: { | |
193 | QRectF titleRect = textBoundingRect(axis()->titleFont(), "..."); |
|
194 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), "..."); | |
194 | sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width()); |
|
195 | sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width()); | |
195 | break; |
|
196 | break; | |
196 | } |
|
197 | } | |
197 | case Qt::MaximumSize: |
|
198 | case Qt::MaximumSize: | |
198 | case Qt::PreferredSize: { |
|
199 | case Qt::PreferredSize: { | |
199 | QRectF titleRect = textBoundingRect(axis()->titleFont(), axis()->titleText()); |
|
200 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText()); | |
200 | sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width()); |
|
201 | sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width()); | |
201 | break; |
|
202 | break; | |
202 | } |
|
203 | } | |
203 | default: |
|
204 | default: | |
204 | break; |
|
205 | break; | |
205 | } |
|
206 | } | |
206 |
|
207 | |||
207 | return sh; |
|
208 | return sh; | |
208 | } |
|
209 | } | |
209 |
|
210 | |||
210 | QTCOMMERCIALCHART_END_NAMESPACE |
|
211 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,221 +1,221 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "abstractbarchartitem_p.h" |
|
21 | #include "abstractbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "qabstractbarseries.h" |
|
25 | #include "qabstractbarseries.h" | |
26 | #include "qabstractbarseries_p.h" |
|
26 | #include "qabstractbarseries_p.h" | |
27 | #include "qchart.h" |
|
27 | #include "qchart.h" | |
28 | #include "chartpresenter_p.h" |
|
28 | #include "chartpresenter_p.h" | |
29 | #include "charttheme_p.h" |
|
29 | #include "charttheme_p.h" | |
30 | #include "baranimation_p.h" |
|
30 | #include "baranimation_p.h" | |
31 | #include "chartdataset_p.h" |
|
31 | #include "chartdataset_p.h" | |
32 | #include <QPainter> |
|
32 | #include <QPainter> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : |
|
36 | AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : | |
37 | ChartItem(series->d_func(),item), |
|
37 | ChartItem(series->d_func(),item), | |
38 | m_animation(0), |
|
38 | m_animation(0), | |
39 | m_series(series) |
|
39 | m_series(series) | |
40 | { |
|
40 | { | |
41 |
|
41 | |||
42 | setFlag(ItemClipsChildrenToShape); |
|
42 | setFlag(ItemClipsChildrenToShape); | |
43 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); |
|
43 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); | |
44 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); |
|
44 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); | |
45 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); |
|
45 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); | |
46 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); |
|
46 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); | |
47 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); |
|
47 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); | |
48 | connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged())); |
|
48 | connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged())); | |
49 | setZValue(ChartPresenter::BarSeriesZValue); |
|
49 | setZValue(ChartPresenter::BarSeriesZValue); | |
50 | handleDataStructureChanged(); |
|
50 | handleDataStructureChanged(); | |
51 | handleVisibleChanged(); |
|
51 | handleVisibleChanged(); | |
52 | handleUpdatedBars(); |
|
52 | handleUpdatedBars(); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | AbstractBarChartItem::~AbstractBarChartItem() |
|
55 | AbstractBarChartItem::~AbstractBarChartItem() | |
56 | { |
|
56 | { | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
59 | void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
60 | { |
|
60 | { | |
61 | Q_UNUSED(painter); |
|
61 | Q_UNUSED(painter); | |
62 | Q_UNUSED(option); |
|
62 | Q_UNUSED(option); | |
63 | Q_UNUSED(widget); |
|
63 | Q_UNUSED(widget); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QRectF AbstractBarChartItem::boundingRect() const |
|
66 | QRectF AbstractBarChartItem::boundingRect() const | |
67 | { |
|
67 | { | |
68 | return m_rect; |
|
68 | return m_rect; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
71 | void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout) | |
72 | { |
|
72 | { | |
73 | QSizeF size = geometry().size(); |
|
73 | QSizeF size = geometry().size(); | |
74 | if (geometry().size().isValid()) { |
|
74 | if (geometry().size().isValid()) { | |
75 | if (m_animation) { |
|
75 | if (m_animation) { | |
76 | if (m_layout.count() == 0 || m_oldSize != size) { |
|
76 | if (m_layout.count() == 0 || m_oldSize != size) { | |
77 | initializeLayout(); |
|
77 | initializeLayout(); | |
78 | m_oldSize = size; |
|
78 | m_oldSize = size; | |
79 | } |
|
79 | } | |
80 | m_animation->setup(m_layout, layout); |
|
80 | m_animation->setup(m_layout, layout); | |
81 | presenter()->startAnimation(m_animation); |
|
81 | presenter()->startAnimation(m_animation); | |
82 | } else { |
|
82 | } else { | |
83 | setLayout(layout); |
|
83 | setLayout(layout); | |
84 | update(); |
|
84 | update(); | |
85 | } |
|
85 | } | |
86 | } |
|
86 | } | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void AbstractBarChartItem::setAnimation(BarAnimation *animation) |
|
89 | void AbstractBarChartItem::setAnimation(BarAnimation *animation) | |
90 | { |
|
90 | { | |
91 | m_animation = animation; |
|
91 | m_animation = animation; | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout) |
|
94 | void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout) | |
95 | { |
|
95 | { | |
96 | if (layout.count() != m_bars.count()) |
|
96 | if (layout.count() != m_bars.count()) | |
97 | return; |
|
97 | return; | |
98 |
|
98 | |||
99 | m_layout = layout; |
|
99 | m_layout = layout; | |
100 |
|
100 | |||
101 | for (int i = 0; i < m_bars.count(); i++) { |
|
101 | for (int i = 0; i < m_bars.count(); i++) { | |
102 | m_bars.at(i)->setRect(layout.at(i)); |
|
102 | m_bars.at(i)->setRect(layout.at(i)); | |
103 |
QGraphics |
|
103 | QGraphicsTextItem *label = m_labels.at(i); | |
104 | label->setPos(layout.at(i).center() - label->boundingRect().center()); |
|
104 | label->setPos(layout.at(i).center() - label->boundingRect().center()); | |
105 |
|
105 | |||
106 | } |
|
106 | } | |
107 | } |
|
107 | } | |
108 | //handlers |
|
108 | //handlers | |
109 |
|
109 | |||
110 | void AbstractBarChartItem::handleDomainUpdated() |
|
110 | void AbstractBarChartItem::handleDomainUpdated() | |
111 | { |
|
111 | { | |
112 | m_domainMinX = domain()->minX(); |
|
112 | m_domainMinX = domain()->minX(); | |
113 | m_domainMaxX = domain()->maxX(); |
|
113 | m_domainMaxX = domain()->maxX(); | |
114 | m_domainMinY = domain()->minY(); |
|
114 | m_domainMinY = domain()->minY(); | |
115 | m_domainMaxY = domain()->maxY(); |
|
115 | m_domainMaxY = domain()->maxY(); | |
116 |
|
116 | |||
117 | QRectF rect(QPointF(0,0),domain()->size()); |
|
117 | QRectF rect(QPointF(0,0),domain()->size()); | |
118 |
|
118 | |||
119 | if(m_rect != rect){ |
|
119 | if(m_rect != rect){ | |
120 | prepareGeometryChange(); |
|
120 | prepareGeometryChange(); | |
121 | m_rect = rect; |
|
121 | m_rect = rect; | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | handleLayoutChanged(); |
|
124 | handleLayoutChanged(); | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | void AbstractBarChartItem::handleLayoutChanged() |
|
127 | void AbstractBarChartItem::handleLayoutChanged() | |
128 | { |
|
128 | { | |
129 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) |
|
129 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) | |
130 | return; // rect size zero. |
|
130 | return; // rect size zero. | |
131 | QVector<QRectF> layout = calculateLayout(); |
|
131 | QVector<QRectF> layout = calculateLayout(); | |
132 | applyLayout(layout); |
|
132 | applyLayout(layout); | |
133 | handleUpdatedBars(); |
|
133 | handleUpdatedBars(); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible) |
|
136 | void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible) | |
137 | { |
|
137 | { | |
138 |
foreach (QGraphics |
|
138 | foreach (QGraphicsTextItem *label, m_labels) | |
139 | label->setVisible(visible); |
|
139 | label->setVisible(visible); | |
140 | update(); |
|
140 | update(); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void AbstractBarChartItem::handleDataStructureChanged() |
|
143 | void AbstractBarChartItem::handleDataStructureChanged() | |
144 | { |
|
144 | { | |
145 | foreach (QGraphicsItem *item, childItems()) |
|
145 | foreach (QGraphicsItem *item, childItems()) | |
146 | delete item; |
|
146 | delete item; | |
147 |
|
147 | |||
148 | m_bars.clear(); |
|
148 | m_bars.clear(); | |
149 | m_labels.clear(); |
|
149 | m_labels.clear(); | |
150 | m_layout.clear(); |
|
150 | m_layout.clear(); | |
151 |
|
151 | |||
152 | // Create new graphic items for bars |
|
152 | // Create new graphic items for bars | |
153 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { |
|
153 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { | |
154 | for (int s = 0; s < m_series->count(); s++) { |
|
154 | for (int s = 0; s < m_series->count(); s++) { | |
155 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
155 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
156 |
|
156 | |||
157 | // Bars |
|
157 | // Bars | |
158 | Bar *bar = new Bar(set, c, this); |
|
158 | Bar *bar = new Bar(set, c, this); | |
159 | m_bars.append(bar); |
|
159 | m_bars.append(bar); | |
160 | connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*))); |
|
160 | connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*))); | |
161 | connect(bar, SIGNAL(hovered(bool,QBarSet*)), m_series, SIGNAL(hovered(bool,QBarSet*))); |
|
161 | connect(bar, SIGNAL(hovered(bool,QBarSet*)), m_series, SIGNAL(hovered(bool,QBarSet*))); | |
162 | connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int))); |
|
162 | connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int))); | |
163 | connect(bar, SIGNAL(hovered(bool,QBarSet*)), set, SIGNAL(hovered(bool))); |
|
163 | connect(bar, SIGNAL(hovered(bool,QBarSet*)), set, SIGNAL(hovered(bool))); | |
164 | // m_layout.append(QRectF(0, 0, 1, 1)); |
|
164 | // m_layout.append(QRectF(0, 0, 1, 1)); | |
165 |
|
165 | |||
166 | // Labels |
|
166 | // Labels | |
167 |
m_labels.append(new QGraphics |
|
167 | m_labels.append(new QGraphicsTextItem(this)); | |
168 | } |
|
168 | } | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | if(themeManager()) themeManager()->updateSeries(m_series); |
|
171 | if(themeManager()) themeManager()->updateSeries(m_series); | |
172 | handleLayoutChanged(); |
|
172 | handleLayoutChanged(); | |
173 | handleVisibleChanged(); |
|
173 | handleVisibleChanged(); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void AbstractBarChartItem::handleVisibleChanged() |
|
176 | void AbstractBarChartItem::handleVisibleChanged() | |
177 | { |
|
177 | { | |
178 | bool visible = m_series->isVisible(); |
|
178 | bool visible = m_series->isVisible(); | |
179 | if (visible) |
|
179 | if (visible) | |
180 | handleLabelsVisibleChanged(m_series->isLabelsVisible()); |
|
180 | handleLabelsVisibleChanged(m_series->isLabelsVisible()); | |
181 | else |
|
181 | else | |
182 | handleLabelsVisibleChanged(visible); |
|
182 | handleLabelsVisibleChanged(visible); | |
183 |
|
183 | |||
184 | foreach (QGraphicsItem *bar, m_bars) |
|
184 | foreach (QGraphicsItem *bar, m_bars) | |
185 | bar->setVisible(visible); |
|
185 | bar->setVisible(visible); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | void AbstractBarChartItem::handleOpacityChanged() |
|
188 | void AbstractBarChartItem::handleOpacityChanged() | |
189 | { |
|
189 | { | |
190 | foreach (QGraphicsItem *item, childItems()) |
|
190 | foreach (QGraphicsItem *item, childItems()) | |
191 | item->setOpacity(m_series->opacity()); |
|
191 | item->setOpacity(m_series->opacity()); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | void AbstractBarChartItem::handleUpdatedBars() |
|
194 | void AbstractBarChartItem::handleUpdatedBars() | |
195 | { |
|
195 | { | |
196 | // Handle changes in pen, brush, labels etc. |
|
196 | // Handle changes in pen, brush, labels etc. | |
197 | int categoryCount = m_series->d_func()->categoryCount(); |
|
197 | int categoryCount = m_series->d_func()->categoryCount(); | |
198 | int setCount = m_series->count(); |
|
198 | int setCount = m_series->count(); | |
199 | int itemIndex(0); |
|
199 | int itemIndex(0); | |
200 |
|
200 | |||
201 | for (int category = 0; category < categoryCount; category++) { |
|
201 | for (int category = 0; category < categoryCount; category++) { | |
202 | for (int set = 0; set < setCount; set++) { |
|
202 | for (int set = 0; set < setCount; set++) { | |
203 | QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
203 | QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
204 | Bar *bar = m_bars.at(itemIndex); |
|
204 | Bar *bar = m_bars.at(itemIndex); | |
205 | bar->setPen(barSet->m_pen); |
|
205 | bar->setPen(barSet->m_pen); | |
206 | bar->setBrush(barSet->m_brush); |
|
206 | bar->setBrush(barSet->m_brush); | |
207 | bar->update(); |
|
207 | bar->update(); | |
208 |
|
208 | |||
209 |
QGraphics |
|
209 | QGraphicsTextItem *label = m_labels.at(itemIndex); | |
210 |
label->set |
|
210 | label->setHtml(QString("%1").arg(barSet->value(category))); | |
211 | label->setFont(barSet->m_labelFont); |
|
211 | label->setFont(barSet->m_labelFont); | |
212 |
label->set |
|
212 | label->setDefaultTextColor(barSet->m_labelBrush.color()); | |
213 | label->update(); |
|
213 | label->update(); | |
214 | itemIndex++; |
|
214 | itemIndex++; | |
215 | } |
|
215 | } | |
216 | } |
|
216 | } | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | #include "moc_abstractbarchartitem_p.cpp" |
|
219 | #include "moc_abstractbarchartitem_p.cpp" | |
220 |
|
220 | |||
221 | QTCOMMERCIALCHART_END_NAMESPACE |
|
221 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,94 +1,94 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 |
|
30 | |||
31 | #ifndef ABSTRACTBARCHARTITEM_H |
|
31 | #ifndef ABSTRACTBARCHARTITEM_H | |
32 | #define ABSTRACTBARCHARTITEM_H |
|
32 | #define ABSTRACTBARCHARTITEM_H | |
33 |
|
33 | |||
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "qabstractbarseries.h" |
|
35 | #include "qabstractbarseries.h" | |
36 | #include <QPen> |
|
36 | #include <QPen> | |
37 | #include <QBrush> |
|
37 | #include <QBrush> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class Bar; |
|
41 | class Bar; | |
42 | class QAxisCategories; |
|
42 | class QAxisCategories; | |
43 | class QChart; |
|
43 | class QChart; | |
44 | class BarAnimation; |
|
44 | class BarAnimation; | |
45 |
|
45 | |||
46 | class AbstractBarChartItem : public ChartItem |
|
46 | class AbstractBarChartItem : public ChartItem | |
47 | { |
|
47 | { | |
48 | Q_OBJECT |
|
48 | Q_OBJECT | |
49 | public: |
|
49 | public: | |
50 | AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); |
|
50 | AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); | |
51 | virtual ~AbstractBarChartItem(); |
|
51 | virtual ~AbstractBarChartItem(); | |
52 |
|
52 | |||
53 | public: |
|
53 | public: | |
54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
55 | QRectF boundingRect() const; |
|
55 | QRectF boundingRect() const; | |
56 |
|
56 | |||
57 | virtual QVector<QRectF> calculateLayout() = 0; |
|
57 | virtual QVector<QRectF> calculateLayout() = 0; | |
58 | virtual void initializeLayout() = 0; |
|
58 | virtual void initializeLayout() = 0; | |
59 | virtual void applyLayout(const QVector<QRectF> &layout); |
|
59 | virtual void applyLayout(const QVector<QRectF> &layout); | |
60 | virtual void setAnimation(BarAnimation *animation); |
|
60 | virtual void setAnimation(BarAnimation *animation); | |
61 | void setLayout(const QVector<QRectF> &layout); |
|
61 | void setLayout(const QVector<QRectF> &layout); | |
62 | void updateLayout(const QVector<QRectF> &layout); |
|
62 | void updateLayout(const QVector<QRectF> &layout); | |
63 | QRectF geometry() const { return m_rect;} |
|
63 | QRectF geometry() const { return m_rect;} | |
64 |
|
64 | |||
65 | public Q_SLOTS: |
|
65 | public Q_SLOTS: | |
66 | void handleDomainUpdated(); |
|
66 | void handleDomainUpdated(); | |
67 | void handleLayoutChanged(); |
|
67 | void handleLayoutChanged(); | |
68 | void handleLabelsVisibleChanged(bool visible); |
|
68 | void handleLabelsVisibleChanged(bool visible); | |
69 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items |
|
69 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items | |
70 | void handleVisibleChanged(); |
|
70 | void handleVisibleChanged(); | |
71 | void handleOpacityChanged(); |
|
71 | void handleOpacityChanged(); | |
72 | virtual void handleUpdatedBars(); |
|
72 | virtual void handleUpdatedBars(); | |
73 |
|
73 | |||
74 | protected: |
|
74 | protected: | |
75 |
|
75 | |||
76 | qreal m_domainMinX; |
|
76 | qreal m_domainMinX; | |
77 | qreal m_domainMaxX; |
|
77 | qreal m_domainMaxX; | |
78 | qreal m_domainMinY; |
|
78 | qreal m_domainMinY; | |
79 | qreal m_domainMaxY; |
|
79 | qreal m_domainMaxY; | |
80 |
|
80 | |||
81 | QRectF m_rect; |
|
81 | QRectF m_rect; | |
82 | QVector<QRectF> m_layout; |
|
82 | QVector<QRectF> m_layout; | |
83 |
|
83 | |||
84 | BarAnimation *m_animation; |
|
84 | BarAnimation *m_animation; | |
85 |
|
85 | |||
86 | QAbstractBarSeries *m_series; // Not owned. |
|
86 | QAbstractBarSeries *m_series; // Not owned. | |
87 | QList<Bar *> m_bars; |
|
87 | QList<Bar *> m_bars; | |
88 |
QList<QGraphics |
|
88 | QList<QGraphicsTextItem *> m_labels; | |
89 | QSizeF m_oldSize; |
|
89 | QSizeF m_oldSize; | |
90 | }; |
|
90 | }; | |
91 |
|
91 | |||
92 | QTCOMMERCIALCHART_END_NAMESPACE |
|
92 | QTCOMMERCIALCHART_END_NAMESPACE | |
93 |
|
93 | |||
94 | #endif // ABSTRACTBARCHARTITEM_H |
|
94 | #endif // ABSTRACTBARCHARTITEM_H |
@@ -1,128 +1,128 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "horizontalpercentbarchartitem_p.h" |
|
21 | #include "horizontalpercentbarchartitem_p.h" | |
22 | #include "qabstractbarseries_p.h" |
|
22 | #include "qabstractbarseries_p.h" | |
23 | #include "qbarset_p.h" |
|
23 | #include "qbarset_p.h" | |
24 | #include "bar_p.h" |
|
24 | #include "bar_p.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) |
|
28 | HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) | |
29 | : AbstractBarChartItem(series, item) |
|
29 | : AbstractBarChartItem(series, item) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | void HorizontalPercentBarChartItem::initializeLayout() |
|
33 | void HorizontalPercentBarChartItem::initializeLayout() | |
34 | { |
|
34 | { | |
35 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
35 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
36 | qreal setCount = m_series->count(); |
|
36 | qreal setCount = m_series->count(); | |
37 | qreal barWidth = m_series->d_func()->barWidth(); |
|
37 | qreal barWidth = m_series->d_func()->barWidth(); | |
38 |
|
38 | |||
39 | m_layout.clear(); |
|
39 | m_layout.clear(); | |
40 | for(int category = 0; category < categoryCount; category++) { |
|
40 | for(int category = 0; category < categoryCount; category++) { | |
41 | for (int set = 0; set < setCount; set++) { |
|
41 | for (int set = 0; set < setCount; set++) { | |
42 | QRectF rect; |
|
42 | QRectF rect; | |
43 | QPointF topLeft; |
|
43 | QPointF topLeft; | |
44 | QPointF bottomRight; |
|
44 | QPointF bottomRight; | |
45 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { |
|
45 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { | |
46 | topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2), m_validData); |
|
46 | topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2), m_validData); | |
47 | bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2), m_validData); |
|
47 | bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2), m_validData); | |
48 | } else { |
|
48 | } else { | |
49 | topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2), m_validData); |
|
49 | topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2), m_validData); | |
50 | bottomRight = domain()->calculateGeometryPoint(QPointF(0, category + barWidth / 2), m_validData); |
|
50 | bottomRight = domain()->calculateGeometryPoint(QPointF(0, category + barWidth / 2), m_validData); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | if (!m_validData) |
|
53 | if (!m_validData) | |
54 | return; |
|
54 | return; | |
55 |
|
55 | |||
56 | rect.setTopLeft(topLeft); |
|
56 | rect.setTopLeft(topLeft); | |
57 | rect.setBottomRight(bottomRight); |
|
57 | rect.setBottomRight(bottomRight); | |
58 | m_layout.append(rect.normalized()); |
|
58 | m_layout.append(rect.normalized()); | |
59 | } |
|
59 | } | |
60 | } |
|
60 | } | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout() |
|
63 | QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout() | |
64 | { |
|
64 | { | |
65 | QVector<QRectF> layout; |
|
65 | QVector<QRectF> layout; | |
66 |
|
66 | |||
67 | // Use temporary qreals for accuracy |
|
67 | // Use temporary qreals for accuracy | |
68 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
68 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
69 | qreal setCount = m_series->count(); |
|
69 | qreal setCount = m_series->count(); | |
70 | qreal barWidth = m_series->d_func()->barWidth(); |
|
70 | qreal barWidth = m_series->d_func()->barWidth(); | |
71 |
|
71 | |||
72 | for(int category = 0; category < categoryCount; category++) { |
|
72 | for(int category = 0; category < categoryCount; category++) { | |
73 | qreal sum = 0; |
|
73 | qreal sum = 0; | |
74 | qreal categorySum = m_series->d_func()->categorySum(category); |
|
74 | qreal categorySum = m_series->d_func()->categorySum(category); | |
75 | for (int set = 0; set < setCount; set++) { |
|
75 | for (int set = 0; set < setCount; set++) { | |
76 | qreal value = m_series->barSets().at(set)->at(category); |
|
76 | qreal value = m_series->barSets().at(set)->at(category); | |
77 | QRectF rect; |
|
77 | QRectF rect; | |
78 | QPointF topLeft; |
|
78 | QPointF topLeft; | |
79 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
79 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
80 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : domain()->minX(), category - barWidth/2), m_validData); |
|
80 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : domain()->minX(), category - barWidth/2), m_validData); | |
81 | else |
|
81 | else | |
82 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : 0, category - barWidth/2), m_validData); |
|
82 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : 0, category - barWidth/2), m_validData); | |
83 | QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(100 * (value + sum)/categorySum, category + barWidth/2), m_validData); |
|
83 | QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(100 * (value + sum)/categorySum, category + barWidth/2), m_validData); | |
84 |
|
84 | |||
85 | if (!m_validData) |
|
85 | if (!m_validData) | |
86 | return QVector<QRectF>(); |
|
86 | return QVector<QRectF>(); | |
87 | rect.setTopLeft(topLeft); |
|
87 | rect.setTopLeft(topLeft); | |
88 | rect.setBottomRight(bottomRight); |
|
88 | rect.setBottomRight(bottomRight); | |
89 | layout.append(rect.normalized()); |
|
89 | layout.append(rect.normalized()); | |
90 | sum +=value; |
|
90 | sum +=value; | |
91 | } |
|
91 | } | |
92 | } |
|
92 | } | |
93 | return layout; |
|
93 | return layout; | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void HorizontalPercentBarChartItem::handleUpdatedBars() |
|
96 | void HorizontalPercentBarChartItem::handleUpdatedBars() | |
97 | { |
|
97 | { | |
98 | // Handle changes in pen, brush, labels etc. |
|
98 | // Handle changes in pen, brush, labels etc. | |
99 | int categoryCount = m_series->d_func()->categoryCount(); |
|
99 | int categoryCount = m_series->d_func()->categoryCount(); | |
100 | int setCount = m_series->count(); |
|
100 | int setCount = m_series->count(); | |
101 | int itemIndex(0); |
|
101 | int itemIndex(0); | |
102 |
|
102 | |||
103 | for (int category = 0; category < categoryCount; category++) { |
|
103 | for (int category = 0; category < categoryCount; category++) { | |
104 | for (int set = 0; set < setCount; set++) { |
|
104 | for (int set = 0; set < setCount; set++) { | |
105 | QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
105 | QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
106 | Bar *bar = m_bars.at(itemIndex); |
|
106 | Bar *bar = m_bars.at(itemIndex); | |
107 | bar->setPen(barSet->m_pen); |
|
107 | bar->setPen(barSet->m_pen); | |
108 | bar->setBrush(barSet->m_brush); |
|
108 | bar->setBrush(barSet->m_brush); | |
109 | bar->update(); |
|
109 | bar->update(); | |
110 |
|
110 | |||
111 |
QGraphics |
|
111 | QGraphicsTextItem *label = m_labels.at(itemIndex); | |
112 | int p = m_series->d_func()->percentageAt(set, category) * 100; |
|
112 | int p = m_series->d_func()->percentageAt(set, category) * 100; | |
113 | QString vString(QString::number(p)); |
|
113 | QString vString(QString::number(p)); | |
114 | vString.truncate(3); |
|
114 | vString.truncate(3); | |
115 | vString.append("%"); |
|
115 | vString.append("%"); | |
116 |
label->set |
|
116 | label->setHtml(vString); | |
117 | label->setFont(barSet->m_labelFont); |
|
117 | label->setFont(barSet->m_labelFont); | |
118 |
label->set |
|
118 | label->setDefaultTextColor(barSet->m_labelBrush.color()); | |
119 | label->update(); |
|
119 | label->update(); | |
120 | itemIndex++; |
|
120 | itemIndex++; | |
121 | } |
|
121 | } | |
122 | } |
|
122 | } | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | #include "moc_horizontalpercentbarchartitem_p.cpp" |
|
125 | #include "moc_horizontalpercentbarchartitem_p.cpp" | |
126 |
|
126 | |||
127 | QTCOMMERCIALCHART_END_NAMESPACE |
|
127 | QTCOMMERCIALCHART_END_NAMESPACE | |
128 |
|
128 |
@@ -1,129 +1,129 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "percentbarchartitem_p.h" |
|
21 | #include "percentbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qabstractbarseries_p.h" |
|
23 | #include "qabstractbarseries_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "qbarset_p.h" |
|
25 | #include "qbarset_p.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : |
|
29 | PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : | |
30 | AbstractBarChartItem(series, item) |
|
30 | AbstractBarChartItem(series, item) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | void PercentBarChartItem::initializeLayout() |
|
34 | void PercentBarChartItem::initializeLayout() | |
35 | { |
|
35 | { | |
36 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
36 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
37 | qreal setCount = m_series->count(); |
|
37 | qreal setCount = m_series->count(); | |
38 | qreal barWidth = m_series->d_func()->barWidth(); |
|
38 | qreal barWidth = m_series->d_func()->barWidth(); | |
39 |
|
39 | |||
40 | m_layout.clear(); |
|
40 | m_layout.clear(); | |
41 | for(int category = 0; category < categoryCount; category++) { |
|
41 | for(int category = 0; category < categoryCount; category++) { | |
42 | for (int set = 0; set < setCount; set++) { |
|
42 | for (int set = 0; set < setCount; set++) { | |
43 | QRectF rect; |
|
43 | QRectF rect; | |
44 | QPointF topLeft; |
|
44 | QPointF topLeft; | |
45 | QPointF bottomRight; |
|
45 | QPointF bottomRight; | |
46 |
|
46 | |||
47 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { |
|
47 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { | |
48 | topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, domain()->minY()), m_validData); |
|
48 | topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, domain()->minY()), m_validData); | |
49 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, domain()->minY()), m_validData); |
|
49 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, domain()->minY()), m_validData); | |
50 | } else { |
|
50 | } else { | |
51 | topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, 0), m_validData); |
|
51 | topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, 0), m_validData); | |
52 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, 0), m_validData); |
|
52 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, 0), m_validData); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | if (!m_validData) |
|
55 | if (!m_validData) | |
56 | return; |
|
56 | return; | |
57 |
|
57 | |||
58 | rect.setTopLeft(topLeft); |
|
58 | rect.setTopLeft(topLeft); | |
59 | rect.setBottomRight(bottomRight); |
|
59 | rect.setBottomRight(bottomRight); | |
60 | m_layout.append(rect.normalized()); |
|
60 | m_layout.append(rect.normalized()); | |
61 | } |
|
61 | } | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | QVector<QRectF> PercentBarChartItem::calculateLayout() |
|
65 | QVector<QRectF> PercentBarChartItem::calculateLayout() | |
66 | { |
|
66 | { | |
67 | QVector<QRectF> layout; |
|
67 | QVector<QRectF> layout; | |
68 |
|
68 | |||
69 | // Use temporary qreals for accuracy |
|
69 | // Use temporary qreals for accuracy | |
70 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
70 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
71 | qreal setCount = m_series->count(); |
|
71 | qreal setCount = m_series->count(); | |
72 | qreal barWidth = m_series->d_func()->barWidth(); |
|
72 | qreal barWidth = m_series->d_func()->barWidth(); | |
73 |
|
73 | |||
74 | for(int category = 0; category < categoryCount; category++) { |
|
74 | for(int category = 0; category < categoryCount; category++) { | |
75 | qreal sum = 0; |
|
75 | qreal sum = 0; | |
76 | qreal categorySum = m_series->d_func()->categorySum(category); |
|
76 | qreal categorySum = m_series->d_func()->categorySum(category); | |
77 | for (int set = 0; set < setCount; set++) { |
|
77 | for (int set = 0; set < setCount; set++) { | |
78 | qreal value = m_series->barSets().at(set)->at(category); |
|
78 | qreal value = m_series->barSets().at(set)->at(category); | |
79 | QRectF rect; |
|
79 | QRectF rect; | |
80 | QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth/2, 100 * (value + sum)/categorySum), m_validData); |
|
80 | QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth/2, 100 * (value + sum)/categorySum), m_validData); | |
81 | QPointF bottomRight; |
|
81 | QPointF bottomRight; | |
82 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
82 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
83 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : domain()->minY()), m_validData); |
|
83 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : domain()->minY()), m_validData); | |
84 | else |
|
84 | else | |
85 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : 0), m_validData); |
|
85 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : 0), m_validData); | |
86 |
|
86 | |||
87 | if (!m_validData) |
|
87 | if (!m_validData) | |
88 | return QVector<QRectF>(); |
|
88 | return QVector<QRectF>(); | |
89 | rect.setTopLeft(topLeft); |
|
89 | rect.setTopLeft(topLeft); | |
90 | rect.setBottomRight(bottomRight); |
|
90 | rect.setBottomRight(bottomRight); | |
91 | layout.append(rect.normalized()); |
|
91 | layout.append(rect.normalized()); | |
92 | sum +=value; |
|
92 | sum +=value; | |
93 | } |
|
93 | } | |
94 | } |
|
94 | } | |
95 | return layout; |
|
95 | return layout; | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void PercentBarChartItem::handleUpdatedBars() |
|
98 | void PercentBarChartItem::handleUpdatedBars() | |
99 | { |
|
99 | { | |
100 | // Handle changes in pen, brush, labels etc. |
|
100 | // Handle changes in pen, brush, labels etc. | |
101 | int categoryCount = m_series->d_func()->categoryCount(); |
|
101 | int categoryCount = m_series->d_func()->categoryCount(); | |
102 | int setCount = m_series->count(); |
|
102 | int setCount = m_series->count(); | |
103 | int itemIndex(0); |
|
103 | int itemIndex(0); | |
104 |
|
104 | |||
105 | for (int category = 0; category < categoryCount; category++) { |
|
105 | for (int category = 0; category < categoryCount; category++) { | |
106 | for (int set = 0; set < setCount; set++) { |
|
106 | for (int set = 0; set < setCount; set++) { | |
107 | QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
107 | QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
108 | Bar *bar = m_bars.at(itemIndex); |
|
108 | Bar *bar = m_bars.at(itemIndex); | |
109 | bar->setPen(barSet->m_pen); |
|
109 | bar->setPen(barSet->m_pen); | |
110 | bar->setBrush(barSet->m_brush); |
|
110 | bar->setBrush(barSet->m_brush); | |
111 | bar->update(); |
|
111 | bar->update(); | |
112 |
|
112 | |||
113 |
QGraphics |
|
113 | QGraphicsTextItem *label = m_labels.at(itemIndex); | |
114 | int p = m_series->d_func()->percentageAt(set, category) * 100; |
|
114 | int p = m_series->d_func()->percentageAt(set, category) * 100; | |
115 | QString vString(QString::number(p)); |
|
115 | QString vString(QString::number(p)); | |
116 | vString.truncate(3); |
|
116 | vString.truncate(3); | |
117 | vString.append("%"); |
|
117 | vString.append("%"); | |
118 |
label->set |
|
118 | label->setHtml(vString); | |
119 | label->setFont(barSet->m_labelFont); |
|
119 | label->setFont(barSet->m_labelFont); | |
120 |
label->set |
|
120 | label->setDefaultTextColor(barSet->m_labelBrush.color()); | |
121 | label->update(); |
|
121 | label->update(); | |
122 | itemIndex++; |
|
122 | itemIndex++; | |
123 | } |
|
123 | } | |
124 | } |
|
124 | } | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | #include "moc_percentbarchartitem_p.cpp" |
|
127 | #include "moc_percentbarchartitem_p.cpp" | |
128 |
|
128 | |||
129 | QTCOMMERCIALCHART_END_NAMESPACE |
|
129 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,383 +1,444 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 | #include "chartpresenter_p.h" |
|
20 | #include "chartpresenter_p.h" | |
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "chartitem_p.h" |
|
22 | #include "chartitem_p.h" | |
23 | #include "qchart_p.h" |
|
23 | #include "qchart_p.h" | |
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 | #include "qabstractaxis_p.h" |
|
25 | #include "qabstractaxis_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "chartanimation_p.h" |
|
27 | #include "chartanimation_p.h" | |
28 | #include "qabstractseries_p.h" |
|
28 | #include "qabstractseries_p.h" | |
29 | #include "qareaseries.h" |
|
29 | #include "qareaseries.h" | |
30 | #include "chartaxiselement_p.h" |
|
30 | #include "chartaxiselement_p.h" | |
31 | #include "chartbackground_p.h" |
|
31 | #include "chartbackground_p.h" | |
32 | #include "cartesianchartlayout_p.h" |
|
32 | #include "cartesianchartlayout_p.h" | |
33 | #include "polarchartlayout_p.h" |
|
33 | #include "polarchartlayout_p.h" | |
34 | #include "charttitle_p.h" |
|
34 | #include "charttitle_p.h" | |
35 | #include <QTimer> |
|
35 | #include <QTimer> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
|
39 | QGraphicsTextItem *dummyTextItem = 0; | |||
|
40 | class StaticDummyTextDeleter | |||
|
41 | { | |||
|
42 | public: | |||
|
43 | StaticDummyTextDeleter() {} | |||
|
44 | ~StaticDummyTextDeleter() { delete dummyTextItem; } | |||
|
45 | }; | |||
|
46 | StaticDummyTextDeleter staticDummyTextDeleter; | |||
|
47 | ||||
39 | ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type) |
|
48 | ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type) | |
40 | : QObject(chart), |
|
49 | : QObject(chart), | |
41 | m_chart(chart), |
|
50 | m_chart(chart), | |
42 | m_options(QChart::NoAnimation), |
|
51 | m_options(QChart::NoAnimation), | |
43 | m_state(ShowState), |
|
52 | m_state(ShowState), | |
44 | m_background(0), |
|
53 | m_background(0), | |
45 | m_plotAreaBackground(0), |
|
54 | m_plotAreaBackground(0), | |
46 | m_title(0) |
|
55 | m_title(0) | |
47 | { |
|
56 | { | |
48 | if (type == QChart::ChartTypeCartesian) |
|
57 | if (type == QChart::ChartTypeCartesian) | |
49 | m_layout = new CartesianChartLayout(this); |
|
58 | m_layout = new CartesianChartLayout(this); | |
50 | else if (type == QChart::ChartTypePolar) |
|
59 | else if (type == QChart::ChartTypePolar) | |
51 | m_layout = new PolarChartLayout(this); |
|
60 | m_layout = new PolarChartLayout(this); | |
52 | Q_ASSERT(m_layout); |
|
61 | Q_ASSERT(m_layout); | |
53 | } |
|
62 | } | |
54 |
|
63 | |||
55 | ChartPresenter::~ChartPresenter() |
|
64 | ChartPresenter::~ChartPresenter() | |
56 | { |
|
65 | { | |
57 |
|
66 | |||
58 | } |
|
67 | } | |
59 |
|
68 | |||
60 | void ChartPresenter::setGeometry(const QRectF rect) |
|
69 | void ChartPresenter::setGeometry(const QRectF rect) | |
61 | { |
|
70 | { | |
62 | if (m_rect != rect) { |
|
71 | if (m_rect != rect) { | |
63 | m_rect = rect; |
|
72 | m_rect = rect; | |
64 | foreach (ChartItem *chart, m_chartItems) { |
|
73 | foreach (ChartItem *chart, m_chartItems) { | |
65 | chart->domain()->setSize(rect.size()); |
|
74 | chart->domain()->setSize(rect.size()); | |
66 | chart->setPos(rect.topLeft()); |
|
75 | chart->setPos(rect.topLeft()); | |
67 | } |
|
76 | } | |
68 | } |
|
77 | } | |
69 | } |
|
78 | } | |
70 |
|
79 | |||
71 | QRectF ChartPresenter::geometry() const |
|
80 | QRectF ChartPresenter::geometry() const | |
72 | { |
|
81 | { | |
73 | return m_rect; |
|
82 | return m_rect; | |
74 | } |
|
83 | } | |
75 |
|
84 | |||
76 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) |
|
85 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) | |
77 | { |
|
86 | { | |
78 | axis->d_ptr->initializeGraphics(rootItem()); |
|
87 | axis->d_ptr->initializeGraphics(rootItem()); | |
79 | axis->d_ptr->initializeAnimations(m_options); |
|
88 | axis->d_ptr->initializeAnimations(m_options); | |
80 | ChartAxisElement *item = axis->d_ptr->axisItem(); |
|
89 | ChartAxisElement *item = axis->d_ptr->axisItem(); | |
81 | item->setPresenter(this); |
|
90 | item->setPresenter(this); | |
82 | item->setThemeManager(m_chart->d_ptr->m_themeManager); |
|
91 | item->setThemeManager(m_chart->d_ptr->m_themeManager); | |
83 | m_axisItems<<item; |
|
92 | m_axisItems<<item; | |
84 | m_axes<<axis; |
|
93 | m_axes<<axis; | |
85 | m_layout->invalidate(); |
|
94 | m_layout->invalidate(); | |
86 | } |
|
95 | } | |
87 |
|
96 | |||
88 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) |
|
97 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) | |
89 | { |
|
98 | { | |
90 | ChartAxisElement *item = axis->d_ptr->m_item.take(); |
|
99 | ChartAxisElement *item = axis->d_ptr->m_item.take(); | |
91 | item->hide(); |
|
100 | item->hide(); | |
92 | item->disconnect(); |
|
101 | item->disconnect(); | |
93 | item->deleteLater(); |
|
102 | item->deleteLater(); | |
94 | m_axisItems.removeAll(item); |
|
103 | m_axisItems.removeAll(item); | |
95 | m_axes.removeAll(axis); |
|
104 | m_axes.removeAll(axis); | |
96 | m_layout->invalidate(); |
|
105 | m_layout->invalidate(); | |
97 | } |
|
106 | } | |
98 |
|
107 | |||
99 |
|
108 | |||
100 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) |
|
109 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) | |
101 | { |
|
110 | { | |
102 | series->d_ptr->initializeGraphics(rootItem()); |
|
111 | series->d_ptr->initializeGraphics(rootItem()); | |
103 | series->d_ptr->initializeAnimations(m_options); |
|
112 | series->d_ptr->initializeAnimations(m_options); | |
104 | ChartItem *chart = series->d_ptr->chartItem(); |
|
113 | ChartItem *chart = series->d_ptr->chartItem(); | |
105 | chart->setPresenter(this); |
|
114 | chart->setPresenter(this); | |
106 | chart->setThemeManager(m_chart->d_ptr->m_themeManager); |
|
115 | chart->setThemeManager(m_chart->d_ptr->m_themeManager); | |
107 | chart->domain()->setSize(m_rect.size()); |
|
116 | chart->domain()->setSize(m_rect.size()); | |
108 | chart->setPos(m_rect.topLeft()); |
|
117 | chart->setPos(m_rect.topLeft()); | |
109 | chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored |
|
118 | chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored | |
110 | m_chartItems<<chart; |
|
119 | m_chartItems<<chart; | |
111 | m_series<<series; |
|
120 | m_series<<series; | |
112 | m_layout->invalidate(); |
|
121 | m_layout->invalidate(); | |
113 | } |
|
122 | } | |
114 |
|
123 | |||
115 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) |
|
124 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) | |
116 | { |
|
125 | { | |
117 | ChartItem *chart = series->d_ptr->m_item.take(); |
|
126 | ChartItem *chart = series->d_ptr->m_item.take(); | |
118 | chart->hide(); |
|
127 | chart->hide(); | |
119 | chart->disconnect(); |
|
128 | chart->disconnect(); | |
120 | chart->deleteLater(); |
|
129 | chart->deleteLater(); | |
121 | m_chartItems.removeAll(chart); |
|
130 | m_chartItems.removeAll(chart); | |
122 | m_series.removeAll(series); |
|
131 | m_series.removeAll(series); | |
123 | m_layout->invalidate(); |
|
132 | m_layout->invalidate(); | |
124 | } |
|
133 | } | |
125 |
|
134 | |||
126 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
135 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
127 | { |
|
136 | { | |
128 | if (m_options != options) { |
|
137 | if (m_options != options) { | |
129 | m_options = options; |
|
138 | m_options = options; | |
130 |
|
139 | |||
131 | foreach(QAbstractSeries* series, m_series){ |
|
140 | foreach(QAbstractSeries* series, m_series){ | |
132 | series->d_ptr->initializeAnimations(m_options); |
|
141 | series->d_ptr->initializeAnimations(m_options); | |
133 | } |
|
142 | } | |
134 | foreach(QAbstractAxis* axis, m_axes){ |
|
143 | foreach(QAbstractAxis* axis, m_axes){ | |
135 | axis->d_ptr->initializeAnimations(m_options); |
|
144 | axis->d_ptr->initializeAnimations(m_options); | |
136 | } |
|
145 | } | |
137 | } |
|
146 | } | |
138 | } |
|
147 | } | |
139 |
|
148 | |||
140 | void ChartPresenter::setState(State state,QPointF point) |
|
149 | void ChartPresenter::setState(State state,QPointF point) | |
141 | { |
|
150 | { | |
142 | m_state=state; |
|
151 | m_state=state; | |
143 | m_statePoint=point; |
|
152 | m_statePoint=point; | |
144 | } |
|
153 | } | |
145 |
|
154 | |||
146 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
155 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
147 | { |
|
156 | { | |
148 | return m_options; |
|
157 | return m_options; | |
149 | } |
|
158 | } | |
150 |
|
159 | |||
151 | void ChartPresenter::createBackgroundItem() |
|
160 | void ChartPresenter::createBackgroundItem() | |
152 | { |
|
161 | { | |
153 | if (!m_background) { |
|
162 | if (!m_background) { | |
154 | m_background = new ChartBackground(rootItem()); |
|
163 | m_background = new ChartBackground(rootItem()); | |
155 | m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default |
|
164 | m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default | |
156 | m_background->setBrush(QChartPrivate::defaultBrush()); |
|
165 | m_background->setBrush(QChartPrivate::defaultBrush()); | |
157 | m_background->setZValue(ChartPresenter::BackgroundZValue); |
|
166 | m_background->setZValue(ChartPresenter::BackgroundZValue); | |
158 | } |
|
167 | } | |
159 | } |
|
168 | } | |
160 |
|
169 | |||
161 | void ChartPresenter::createPlotAreaBackgroundItem() |
|
170 | void ChartPresenter::createPlotAreaBackgroundItem() | |
162 | { |
|
171 | { | |
163 | if (!m_plotAreaBackground) { |
|
172 | if (!m_plotAreaBackground) { | |
164 | if (m_chart->chartType() == QChart::ChartTypeCartesian) |
|
173 | if (m_chart->chartType() == QChart::ChartTypeCartesian) | |
165 | m_plotAreaBackground = new QGraphicsRectItem(rootItem()); |
|
174 | m_plotAreaBackground = new QGraphicsRectItem(rootItem()); | |
166 | else |
|
175 | else | |
167 | m_plotAreaBackground = new QGraphicsEllipseItem(rootItem()); |
|
176 | m_plotAreaBackground = new QGraphicsEllipseItem(rootItem()); | |
168 | // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes |
|
177 | // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes | |
169 | // antialising artifacts with axis lines for some reason. |
|
178 | // antialising artifacts with axis lines for some reason. | |
170 | m_plotAreaBackground->setPen(QPen(Qt::transparent)); |
|
179 | m_plotAreaBackground->setPen(QPen(Qt::transparent)); | |
171 | m_plotAreaBackground->setBrush(Qt::NoBrush); |
|
180 | m_plotAreaBackground->setBrush(Qt::NoBrush); | |
172 | m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue); |
|
181 | m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue); | |
173 | m_plotAreaBackground->setVisible(false); |
|
182 | m_plotAreaBackground->setVisible(false); | |
174 | } |
|
183 | } | |
175 | } |
|
184 | } | |
176 |
|
185 | |||
177 | void ChartPresenter::createTitleItem() |
|
186 | void ChartPresenter::createTitleItem() | |
178 | { |
|
187 | { | |
179 | if (!m_title) { |
|
188 | if (!m_title) { | |
180 | m_title = new ChartTitle(rootItem()); |
|
189 | m_title = new ChartTitle(rootItem()); | |
181 | m_title->setZValue(ChartPresenter::BackgroundZValue); |
|
190 | m_title->setZValue(ChartPresenter::BackgroundZValue); | |
182 | } |
|
191 | } | |
183 | } |
|
192 | } | |
184 |
|
193 | |||
185 |
|
194 | |||
186 | void ChartPresenter::handleAnimationFinished() |
|
195 | void ChartPresenter::handleAnimationFinished() | |
187 | { |
|
196 | { | |
188 | m_animations.removeAll(qobject_cast<ChartAnimation *>(sender())); |
|
197 | m_animations.removeAll(qobject_cast<ChartAnimation *>(sender())); | |
189 | if (m_animations.empty()) |
|
198 | if (m_animations.empty()) | |
190 | emit animationsFinished(); |
|
199 | emit animationsFinished(); | |
191 | } |
|
200 | } | |
192 |
|
201 | |||
193 | void ChartPresenter::startAnimation(ChartAnimation *animation) |
|
202 | void ChartPresenter::startAnimation(ChartAnimation *animation) | |
194 | { |
|
203 | { | |
195 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); |
|
204 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); | |
196 | QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection); |
|
205 | QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection); | |
197 | if (!m_animations.isEmpty()) |
|
206 | if (!m_animations.isEmpty()) | |
198 | m_animations.append(animation); |
|
207 | m_animations.append(animation); | |
199 | QTimer::singleShot(0, animation, SLOT(start())); |
|
208 | QTimer::singleShot(0, animation, SLOT(start())); | |
200 | } |
|
209 | } | |
201 |
|
210 | |||
202 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) |
|
211 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) | |
203 | { |
|
212 | { | |
204 | createBackgroundItem(); |
|
213 | createBackgroundItem(); | |
205 | m_background->setBrush(brush); |
|
214 | m_background->setBrush(brush); | |
206 | m_layout->invalidate(); |
|
215 | m_layout->invalidate(); | |
207 | } |
|
216 | } | |
208 |
|
217 | |||
209 | QBrush ChartPresenter::backgroundBrush() const |
|
218 | QBrush ChartPresenter::backgroundBrush() const | |
210 | { |
|
219 | { | |
211 | if (!m_background) |
|
220 | if (!m_background) | |
212 | return QBrush(); |
|
221 | return QBrush(); | |
213 | return m_background->brush(); |
|
222 | return m_background->brush(); | |
214 | } |
|
223 | } | |
215 |
|
224 | |||
216 | void ChartPresenter::setBackgroundPen(const QPen &pen) |
|
225 | void ChartPresenter::setBackgroundPen(const QPen &pen) | |
217 | { |
|
226 | { | |
218 | createBackgroundItem(); |
|
227 | createBackgroundItem(); | |
219 | m_background->setPen(pen); |
|
228 | m_background->setPen(pen); | |
220 | m_layout->invalidate(); |
|
229 | m_layout->invalidate(); | |
221 | } |
|
230 | } | |
222 |
|
231 | |||
223 | QPen ChartPresenter::backgroundPen() const |
|
232 | QPen ChartPresenter::backgroundPen() const | |
224 | { |
|
233 | { | |
225 | if (!m_background) |
|
234 | if (!m_background) | |
226 | return QPen(); |
|
235 | return QPen(); | |
227 | return m_background->pen(); |
|
236 | return m_background->pen(); | |
228 | } |
|
237 | } | |
229 |
|
238 | |||
230 | void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush) |
|
239 | void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush) | |
231 | { |
|
240 | { | |
232 | createPlotAreaBackgroundItem(); |
|
241 | createPlotAreaBackgroundItem(); | |
233 | m_plotAreaBackground->setBrush(brush); |
|
242 | m_plotAreaBackground->setBrush(brush); | |
234 | m_layout->invalidate(); |
|
243 | m_layout->invalidate(); | |
235 | } |
|
244 | } | |
236 |
|
245 | |||
237 | QBrush ChartPresenter::plotAreaBackgroundBrush() const |
|
246 | QBrush ChartPresenter::plotAreaBackgroundBrush() const | |
238 | { |
|
247 | { | |
239 | if (!m_plotAreaBackground) |
|
248 | if (!m_plotAreaBackground) | |
240 | return QBrush(); |
|
249 | return QBrush(); | |
241 | return m_plotAreaBackground->brush(); |
|
250 | return m_plotAreaBackground->brush(); | |
242 | } |
|
251 | } | |
243 |
|
252 | |||
244 | void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen) |
|
253 | void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen) | |
245 | { |
|
254 | { | |
246 | createPlotAreaBackgroundItem(); |
|
255 | createPlotAreaBackgroundItem(); | |
247 | m_plotAreaBackground->setPen(pen); |
|
256 | m_plotAreaBackground->setPen(pen); | |
248 | m_layout->invalidate(); |
|
257 | m_layout->invalidate(); | |
249 | } |
|
258 | } | |
250 |
|
259 | |||
251 | QPen ChartPresenter::plotAreaBackgroundPen() const |
|
260 | QPen ChartPresenter::plotAreaBackgroundPen() const | |
252 | { |
|
261 | { | |
253 | if (!m_plotAreaBackground) |
|
262 | if (!m_plotAreaBackground) | |
254 | return QPen(); |
|
263 | return QPen(); | |
255 | return m_plotAreaBackground->pen(); |
|
264 | return m_plotAreaBackground->pen(); | |
256 | } |
|
265 | } | |
257 |
|
266 | |||
258 | void ChartPresenter::setTitle(const QString &title) |
|
267 | void ChartPresenter::setTitle(const QString &title) | |
259 | { |
|
268 | { | |
260 | createTitleItem(); |
|
269 | createTitleItem(); | |
261 | m_title->setText(title); |
|
270 | m_title->setText(title); | |
262 | m_layout->invalidate(); |
|
271 | m_layout->invalidate(); | |
263 | } |
|
272 | } | |
264 |
|
273 | |||
265 | QString ChartPresenter::title() const |
|
274 | QString ChartPresenter::title() const | |
266 | { |
|
275 | { | |
267 | if (!m_title) |
|
276 | if (!m_title) | |
268 | return QString(); |
|
277 | return QString(); | |
269 | return m_title->text(); |
|
278 | return m_title->text(); | |
270 | } |
|
279 | } | |
271 |
|
280 | |||
272 | void ChartPresenter::setTitleFont(const QFont &font) |
|
281 | void ChartPresenter::setTitleFont(const QFont &font) | |
273 | { |
|
282 | { | |
274 | createTitleItem(); |
|
283 | createTitleItem(); | |
275 | m_title->setFont(font); |
|
284 | m_title->setFont(font); | |
276 | m_layout->invalidate(); |
|
285 | m_layout->invalidate(); | |
277 | } |
|
286 | } | |
278 |
|
287 | |||
279 | QFont ChartPresenter::titleFont() const |
|
288 | QFont ChartPresenter::titleFont() const | |
280 | { |
|
289 | { | |
281 | if (!m_title) |
|
290 | if (!m_title) | |
282 | return QFont(); |
|
291 | return QFont(); | |
283 | return m_title->font(); |
|
292 | return m_title->font(); | |
284 | } |
|
293 | } | |
285 |
|
294 | |||
286 | void ChartPresenter::setTitleBrush(const QBrush &brush) |
|
295 | void ChartPresenter::setTitleBrush(const QBrush &brush) | |
287 | { |
|
296 | { | |
288 | createTitleItem(); |
|
297 | createTitleItem(); | |
289 |
m_title->set |
|
298 | m_title->setDefaultTextColor(brush.color()); | |
290 | m_layout->invalidate(); |
|
299 | m_layout->invalidate(); | |
291 | } |
|
300 | } | |
292 |
|
301 | |||
293 | QBrush ChartPresenter::titleBrush() const |
|
302 | QBrush ChartPresenter::titleBrush() const | |
294 | { |
|
303 | { | |
295 | if (!m_title) |
|
304 | if (!m_title) | |
296 | return QBrush(); |
|
305 | return QBrush(); | |
297 |
return m_title-> |
|
306 | return QBrush(m_title->defaultTextColor()); | |
298 | } |
|
307 | } | |
299 |
|
308 | |||
300 | void ChartPresenter::setBackgroundVisible(bool visible) |
|
309 | void ChartPresenter::setBackgroundVisible(bool visible) | |
301 | { |
|
310 | { | |
302 | createBackgroundItem(); |
|
311 | createBackgroundItem(); | |
303 | m_background->setVisible(visible); |
|
312 | m_background->setVisible(visible); | |
304 | } |
|
313 | } | |
305 |
|
314 | |||
306 |
|
315 | |||
307 | bool ChartPresenter::isBackgroundVisible() const |
|
316 | bool ChartPresenter::isBackgroundVisible() const | |
308 | { |
|
317 | { | |
309 | if (!m_background) |
|
318 | if (!m_background) | |
310 | return false; |
|
319 | return false; | |
311 | return m_background->isVisible(); |
|
320 | return m_background->isVisible(); | |
312 | } |
|
321 | } | |
313 |
|
322 | |||
314 | void ChartPresenter::setPlotAreaBackgroundVisible(bool visible) |
|
323 | void ChartPresenter::setPlotAreaBackgroundVisible(bool visible) | |
315 | { |
|
324 | { | |
316 | createPlotAreaBackgroundItem(); |
|
325 | createPlotAreaBackgroundItem(); | |
317 | m_plotAreaBackground->setVisible(visible); |
|
326 | m_plotAreaBackground->setVisible(visible); | |
318 | } |
|
327 | } | |
319 |
|
328 | |||
320 | bool ChartPresenter::isPlotAreaBackgroundVisible() const |
|
329 | bool ChartPresenter::isPlotAreaBackgroundVisible() const | |
321 | { |
|
330 | { | |
322 | if (!m_plotAreaBackground) |
|
331 | if (!m_plotAreaBackground) | |
323 | return false; |
|
332 | return false; | |
324 | return m_plotAreaBackground->isVisible(); |
|
333 | return m_plotAreaBackground->isVisible(); | |
325 | } |
|
334 | } | |
326 |
|
335 | |||
327 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) |
|
336 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) | |
328 | { |
|
337 | { | |
329 | createBackgroundItem(); |
|
338 | createBackgroundItem(); | |
330 | m_background->setDropShadowEnabled(enabled); |
|
339 | m_background->setDropShadowEnabled(enabled); | |
331 | } |
|
340 | } | |
332 |
|
341 | |||
333 | bool ChartPresenter::isBackgroundDropShadowEnabled() const |
|
342 | bool ChartPresenter::isBackgroundDropShadowEnabled() const | |
334 | { |
|
343 | { | |
335 | if (!m_background) |
|
344 | if (!m_background) | |
336 | return false; |
|
345 | return false; | |
337 | return m_background->isDropShadowEnabled(); |
|
346 | return m_background->isDropShadowEnabled(); | |
338 | } |
|
347 | } | |
339 |
|
348 | |||
340 |
|
349 | |||
341 | AbstractChartLayout *ChartPresenter::layout() |
|
350 | AbstractChartLayout *ChartPresenter::layout() | |
342 | { |
|
351 | { | |
343 | return m_layout; |
|
352 | return m_layout; | |
344 | } |
|
353 | } | |
345 |
|
354 | |||
346 | QLegend *ChartPresenter::legend() |
|
355 | QLegend *ChartPresenter::legend() | |
347 | { |
|
356 | { | |
348 | return m_chart->legend(); |
|
357 | return m_chart->legend(); | |
349 | } |
|
358 | } | |
350 |
|
359 | |||
351 | void ChartPresenter::setVisible(bool visible) |
|
360 | void ChartPresenter::setVisible(bool visible) | |
352 | { |
|
361 | { | |
353 | m_chart->setVisible(visible); |
|
362 | m_chart->setVisible(visible); | |
354 | } |
|
363 | } | |
355 |
|
364 | |||
356 | ChartBackground *ChartPresenter::backgroundElement() |
|
365 | ChartBackground *ChartPresenter::backgroundElement() | |
357 | { |
|
366 | { | |
358 | return m_background; |
|
367 | return m_background; | |
359 | } |
|
368 | } | |
360 |
|
369 | |||
361 | QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement() |
|
370 | QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement() | |
362 | { |
|
371 | { | |
363 | return m_plotAreaBackground; |
|
372 | return m_plotAreaBackground; | |
364 | } |
|
373 | } | |
365 |
|
374 | |||
366 | QList<ChartAxisElement *> ChartPresenter::axisItems() const |
|
375 | QList<ChartAxisElement *> ChartPresenter::axisItems() const | |
367 | { |
|
376 | { | |
368 | return m_axisItems; |
|
377 | return m_axisItems; | |
369 | } |
|
378 | } | |
370 |
|
379 | |||
371 | QList<ChartItem *> ChartPresenter::chartItems() const |
|
380 | QList<ChartItem *> ChartPresenter::chartItems() const | |
372 | { |
|
381 | { | |
373 | return m_chartItems; |
|
382 | return m_chartItems; | |
374 | } |
|
383 | } | |
375 |
|
384 | |||
376 | ChartTitle *ChartPresenter::titleElement() |
|
385 | ChartTitle *ChartPresenter::titleElement() | |
377 | { |
|
386 | { | |
378 | return m_title; |
|
387 | return m_title; | |
379 | } |
|
388 | } | |
380 |
|
389 | |||
|
390 | QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle) | |||
|
391 | { | |||
|
392 | if (!dummyTextItem) | |||
|
393 | dummyTextItem = new QGraphicsTextItem; | |||
|
394 | ||||
|
395 | dummyTextItem->setFont(font); | |||
|
396 | dummyTextItem->setHtml(text); | |||
|
397 | QRectF boundingRect = dummyTextItem->boundingRect(); | |||
|
398 | ||||
|
399 | // Take rotation into account | |||
|
400 | if (angle) { | |||
|
401 | QTransform transform; | |||
|
402 | transform.rotate(angle); | |||
|
403 | boundingRect = transform.mapRect(boundingRect); | |||
|
404 | } | |||
|
405 | ||||
|
406 | return boundingRect; | |||
|
407 | } | |||
|
408 | ||||
|
409 | // boundingRect parameter returns the rotated bounding rect of the text | |||
|
410 | QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qreal angle, | |||
|
411 | qreal maxSize, Qt::Orientation constraintOrientation, | |||
|
412 | QRectF &boundingRect) | |||
|
413 | { | |||
|
414 | QString truncatedString(text); | |||
|
415 | boundingRect = textBoundingRect(font, truncatedString, angle); | |||
|
416 | qreal checkDimension = ((constraintOrientation == Qt::Horizontal) | |||
|
417 | ? boundingRect.width() : boundingRect.height()); | |||
|
418 | if (checkDimension > maxSize) { | |||
|
419 | truncatedString.append("..."); | |||
|
420 | while (checkDimension > maxSize && truncatedString.length() > 3) { | |||
|
421 | // Crude truncation logic - simply remove any html tag completely | |||
|
422 | int removeIndex(-1); | |||
|
423 | int removeCount(1); | |||
|
424 | if (truncatedString.at(truncatedString.length() - 4) == QLatin1Char('>')) { | |||
|
425 | removeIndex = truncatedString.lastIndexOf(QLatin1Char('<')); | |||
|
426 | if (removeIndex != -1) | |||
|
427 | removeCount = truncatedString.length() - 3 - removeIndex; | |||
|
428 | } | |||
|
429 | if (removeIndex == -1) | |||
|
430 | removeIndex = truncatedString.length() - 4; | |||
|
431 | ||||
|
432 | truncatedString.remove(removeIndex, removeCount); | |||
|
433 | boundingRect = textBoundingRect(font, truncatedString, angle); | |||
|
434 | checkDimension = ((constraintOrientation == Qt::Horizontal) | |||
|
435 | ? boundingRect.width() : boundingRect.height()); | |||
|
436 | } | |||
|
437 | } | |||
|
438 | ||||
|
439 | return truncatedString; | |||
|
440 | } | |||
|
441 | ||||
381 | #include "moc_chartpresenter_p.cpp" |
|
442 | #include "moc_chartpresenter_p.cpp" | |
382 |
|
443 | |||
383 | QTCOMMERCIALCHART_END_NAMESPACE |
|
444 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,180 +1,183 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 CHARTPRESENTER_H |
|
30 | #ifndef CHARTPRESENTER_H | |
31 | #define CHARTPRESENTER_H |
|
31 | #define CHARTPRESENTER_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "qchart.h" //because of QChart::ChartThemeId |
|
34 | #include "qchart.h" //because of QChart::ChartThemeId | |
35 | #include <QRectF> |
|
35 | #include <QRectF> | |
36 | #include <QMargins> |
|
36 | #include <QMargins> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class ChartItem; |
|
40 | class ChartItem; | |
41 | class AxisItem; |
|
41 | class AxisItem; | |
42 | class QAbstractSeries; |
|
42 | class QAbstractSeries; | |
43 | class ChartDataSet; |
|
43 | class ChartDataSet; | |
44 | class AbstractDomain; |
|
44 | class AbstractDomain; | |
45 | class ChartAxisElement; |
|
45 | class ChartAxisElement; | |
46 | class ChartAnimator; |
|
46 | class ChartAnimator; | |
47 | class ChartBackground; |
|
47 | class ChartBackground; | |
48 | class ChartTitle; |
|
48 | class ChartTitle; | |
49 | class ChartAnimation; |
|
49 | class ChartAnimation; | |
50 | class AbstractChartLayout; |
|
50 | class AbstractChartLayout; | |
51 |
|
51 | |||
52 | class ChartPresenter: public QObject |
|
52 | class ChartPresenter: public QObject | |
53 | { |
|
53 | { | |
54 | Q_OBJECT |
|
54 | Q_OBJECT | |
55 | public: |
|
55 | public: | |
56 | enum ZValues { |
|
56 | enum ZValues { | |
57 | BackgroundZValue = -1, |
|
57 | BackgroundZValue = -1, | |
58 | PlotAreaZValue, |
|
58 | PlotAreaZValue, | |
59 | ShadesZValue, |
|
59 | ShadesZValue, | |
60 | GridZValue, |
|
60 | GridZValue, | |
61 | AxisZValue, |
|
61 | AxisZValue, | |
62 | SeriesZValue, |
|
62 | SeriesZValue, | |
63 | LineChartZValue = SeriesZValue, |
|
63 | LineChartZValue = SeriesZValue, | |
64 | SplineChartZValue = SeriesZValue, |
|
64 | SplineChartZValue = SeriesZValue, | |
65 | BarSeriesZValue = SeriesZValue, |
|
65 | BarSeriesZValue = SeriesZValue, | |
66 | ScatterSeriesZValue = SeriesZValue, |
|
66 | ScatterSeriesZValue = SeriesZValue, | |
67 | PieSeriesZValue = SeriesZValue, |
|
67 | PieSeriesZValue = SeriesZValue, | |
68 | LegendZValue, |
|
68 | LegendZValue, | |
69 | TopMostZValue |
|
69 | TopMostZValue | |
70 | }; |
|
70 | }; | |
71 |
|
71 | |||
72 | enum State { |
|
72 | enum State { | |
73 | ShowState, |
|
73 | ShowState, | |
74 | ScrollUpState, |
|
74 | ScrollUpState, | |
75 | ScrollDownState, |
|
75 | ScrollDownState, | |
76 | ScrollLeftState, |
|
76 | ScrollLeftState, | |
77 | ScrollRightState, |
|
77 | ScrollRightState, | |
78 | ZoomInState, |
|
78 | ZoomInState, | |
79 | ZoomOutState |
|
79 | ZoomOutState | |
80 | }; |
|
80 | }; | |
81 |
|
81 | |||
82 | ChartPresenter(QChart *chart, QChart::ChartType type); |
|
82 | ChartPresenter(QChart *chart, QChart::ChartType type); | |
83 | virtual ~ChartPresenter(); |
|
83 | virtual ~ChartPresenter(); | |
84 |
|
84 | |||
85 |
|
85 | |||
86 | void setGeometry(QRectF rect); |
|
86 | void setGeometry(QRectF rect); | |
87 | QRectF geometry() const; |
|
87 | QRectF geometry() const; | |
88 |
|
88 | |||
89 | QGraphicsItem *rootItem(){ return m_chart; } |
|
89 | QGraphicsItem *rootItem(){ return m_chart; } | |
90 | ChartBackground *backgroundElement(); |
|
90 | ChartBackground *backgroundElement(); | |
91 | QAbstractGraphicsShapeItem *plotAreaElement(); |
|
91 | QAbstractGraphicsShapeItem *plotAreaElement(); | |
92 | ChartTitle *titleElement(); |
|
92 | ChartTitle *titleElement(); | |
93 | QList<ChartAxisElement *> axisItems() const; |
|
93 | QList<ChartAxisElement *> axisItems() const; | |
94 | QList<ChartItem *> chartItems() const; |
|
94 | QList<ChartItem *> chartItems() const; | |
95 |
|
95 | |||
96 | QLegend *legend(); |
|
96 | QLegend *legend(); | |
97 |
|
97 | |||
98 | void setBackgroundBrush(const QBrush &brush); |
|
98 | void setBackgroundBrush(const QBrush &brush); | |
99 | QBrush backgroundBrush() const; |
|
99 | QBrush backgroundBrush() const; | |
100 |
|
100 | |||
101 | void setBackgroundPen(const QPen &pen); |
|
101 | void setBackgroundPen(const QPen &pen); | |
102 | QPen backgroundPen() const; |
|
102 | QPen backgroundPen() const; | |
103 |
|
103 | |||
104 | void setPlotAreaBackgroundBrush(const QBrush &brush); |
|
104 | void setPlotAreaBackgroundBrush(const QBrush &brush); | |
105 | QBrush plotAreaBackgroundBrush() const; |
|
105 | QBrush plotAreaBackgroundBrush() const; | |
106 |
|
106 | |||
107 | void setPlotAreaBackgroundPen(const QPen &pen); |
|
107 | void setPlotAreaBackgroundPen(const QPen &pen); | |
108 | QPen plotAreaBackgroundPen() const; |
|
108 | QPen plotAreaBackgroundPen() const; | |
109 |
|
109 | |||
110 | void setTitle(const QString &title); |
|
110 | void setTitle(const QString &title); | |
111 | QString title() const; |
|
111 | QString title() const; | |
112 |
|
112 | |||
113 | void setTitleFont(const QFont &font); |
|
113 | void setTitleFont(const QFont &font); | |
114 | QFont titleFont() const; |
|
114 | QFont titleFont() const; | |
115 |
|
115 | |||
116 | void setTitleBrush(const QBrush &brush); |
|
116 | void setTitleBrush(const QBrush &brush); | |
117 | QBrush titleBrush() const; |
|
117 | QBrush titleBrush() const; | |
118 |
|
118 | |||
119 | void setBackgroundVisible(bool visible); |
|
119 | void setBackgroundVisible(bool visible); | |
120 | bool isBackgroundVisible() const; |
|
120 | bool isBackgroundVisible() const; | |
121 |
|
121 | |||
122 | void setPlotAreaBackgroundVisible(bool visible); |
|
122 | void setPlotAreaBackgroundVisible(bool visible); | |
123 | bool isPlotAreaBackgroundVisible() const; |
|
123 | bool isPlotAreaBackgroundVisible() const; | |
124 |
|
124 | |||
125 | void setBackgroundDropShadowEnabled(bool enabled); |
|
125 | void setBackgroundDropShadowEnabled(bool enabled); | |
126 | bool isBackgroundDropShadowEnabled() const; |
|
126 | bool isBackgroundDropShadowEnabled() const; | |
127 |
|
127 | |||
128 | void setVisible(bool visible); |
|
128 | void setVisible(bool visible); | |
129 |
|
129 | |||
130 | void setAnimationOptions(QChart::AnimationOptions options); |
|
130 | void setAnimationOptions(QChart::AnimationOptions options); | |
131 | QChart::AnimationOptions animationOptions() const; |
|
131 | QChart::AnimationOptions animationOptions() const; | |
132 |
|
132 | |||
133 | void startAnimation(ChartAnimation *animation); |
|
133 | void startAnimation(ChartAnimation *animation); | |
134 |
|
134 | |||
135 | //TODO refactor |
|
135 | //TODO refactor | |
136 | void setState(State state,QPointF point); |
|
136 | void setState(State state,QPointF point); | |
137 | State state() const { return m_state; } |
|
137 | State state() const { return m_state; } | |
138 | QPointF statePoint() const { return m_statePoint; } |
|
138 | QPointF statePoint() const { return m_statePoint; } | |
139 | AbstractChartLayout *layout(); |
|
139 | AbstractChartLayout *layout(); | |
140 |
|
140 | |||
141 | QChart::ChartType chartType() const { return m_chart->chartType(); } |
|
141 | QChart::ChartType chartType() const { return m_chart->chartType(); } | |
142 | QChart *chart() { return m_chart; } |
|
142 | QChart *chart() { return m_chart; } | |
143 |
|
143 | |||
|
144 | static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0); | |||
|
145 | static QString truncatedText(const QFont &font, const QString &text, qreal angle, qreal maxSize, | |||
|
146 | Qt::Orientation constraintOrientation, QRectF &boundingRect); | |||
144 | private: |
|
147 | private: | |
145 | void createBackgroundItem(); |
|
148 | void createBackgroundItem(); | |
146 | void createPlotAreaBackgroundItem(); |
|
149 | void createPlotAreaBackgroundItem(); | |
147 | void createTitleItem(); |
|
150 | void createTitleItem(); | |
148 |
|
151 | |||
149 | public Q_SLOTS: |
|
152 | public Q_SLOTS: | |
150 | void handleSeriesAdded(QAbstractSeries *series); |
|
153 | void handleSeriesAdded(QAbstractSeries *series); | |
151 | void handleSeriesRemoved(QAbstractSeries *series); |
|
154 | void handleSeriesRemoved(QAbstractSeries *series); | |
152 | void handleAxisAdded(QAbstractAxis *axis); |
|
155 | void handleAxisAdded(QAbstractAxis *axis); | |
153 | void handleAxisRemoved(QAbstractAxis *axis); |
|
156 | void handleAxisRemoved(QAbstractAxis *axis); | |
154 |
|
157 | |||
155 | private Q_SLOTS: |
|
158 | private Q_SLOTS: | |
156 | void handleAnimationFinished(); |
|
159 | void handleAnimationFinished(); | |
157 |
|
160 | |||
158 | Q_SIGNALS: |
|
161 | Q_SIGNALS: | |
159 | void animationsFinished(); |
|
162 | void animationsFinished(); | |
160 |
|
163 | |||
161 | private: |
|
164 | private: | |
162 | QChart *m_chart; |
|
165 | QChart *m_chart; | |
163 | QList<ChartItem *> m_chartItems; |
|
166 | QList<ChartItem *> m_chartItems; | |
164 | QList<ChartAxisElement *> m_axisItems; |
|
167 | QList<ChartAxisElement *> m_axisItems; | |
165 | QList<QAbstractSeries *> m_series; |
|
168 | QList<QAbstractSeries *> m_series; | |
166 | QList<QAbstractAxis *> m_axes; |
|
169 | QList<QAbstractAxis *> m_axes; | |
167 | QChart::AnimationOptions m_options; |
|
170 | QChart::AnimationOptions m_options; | |
168 | State m_state; |
|
171 | State m_state; | |
169 | QPointF m_statePoint; |
|
172 | QPointF m_statePoint; | |
170 | QList<ChartAnimation *> m_animations; |
|
173 | QList<ChartAnimation *> m_animations; | |
171 | AbstractChartLayout *m_layout; |
|
174 | AbstractChartLayout *m_layout; | |
172 | ChartBackground *m_background; |
|
175 | ChartBackground *m_background; | |
173 | QAbstractGraphicsShapeItem *m_plotAreaBackground; |
|
176 | QAbstractGraphicsShapeItem *m_plotAreaBackground; | |
174 | ChartTitle *m_title; |
|
177 | ChartTitle *m_title; | |
175 | QRectF m_rect; |
|
178 | QRectF m_rect; | |
176 | }; |
|
179 | }; | |
177 |
|
180 | |||
178 | QTCOMMERCIALCHART_END_NAMESPACE |
|
181 | QTCOMMERCIALCHART_END_NAMESPACE | |
179 |
|
182 | |||
180 | #endif /* CHARTPRESENTER_H */ |
|
183 | #endif /* CHARTPRESENTER_H */ |
@@ -1,94 +1,86 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "charttitle_p.h" |
|
21 | #include "charttitle_p.h" | |
|
22 | #include "chartpresenter_p.h" | |||
22 | #include <QFont> |
|
23 | #include <QFont> | |
23 | #include <QFontMetrics> |
|
24 | #include <QFontMetrics> | |
24 | #include <QDebug> |
|
25 | #include <QDebug> | |
25 |
|
26 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
28 | |||
28 | ChartTitle::ChartTitle(QGraphicsItem *parent) |
|
29 | ChartTitle::ChartTitle(QGraphicsItem *parent) | |
29 |
: QGraphics |
|
30 | : QGraphicsTextItem(parent) | |
30 | { |
|
31 | { | |
31 |
|
32 | |||
32 | } |
|
33 | } | |
33 |
|
34 | |||
34 | ChartTitle::~ChartTitle() |
|
35 | ChartTitle::~ChartTitle() | |
35 | { |
|
36 | { | |
36 |
|
37 | |||
37 | } |
|
38 | } | |
38 |
|
39 | |||
39 | void ChartTitle::setText(const QString &text) |
|
40 | void ChartTitle::setText(const QString &text) | |
40 | { |
|
41 | { | |
41 | m_text = text; |
|
42 | m_text = text; | |
42 | } |
|
43 | } | |
43 |
|
44 | |||
44 | QString ChartTitle::text() const |
|
45 | QString ChartTitle::text() const | |
45 | { |
|
46 | { | |
46 | return m_text; |
|
47 | return m_text; | |
47 | } |
|
48 | } | |
48 |
|
49 | |||
49 | void ChartTitle::setGeometry(const QRectF &rect) |
|
50 | void ChartTitle::setGeometry(const QRectF &rect) | |
50 | { |
|
51 | { | |
51 | QFontMetrics fn(font()); |
|
52 | QGraphicsTextItem::setHtml(ChartPresenter::truncatedText(font(), m_text, qreal(0.0), rect.width(), Qt::Horizontal, QRectF())); | |
52 |
|
||||
53 | int width = rect.width(); |
|
|||
54 |
|
||||
55 | if (fn.boundingRect(m_text).width() > width) { |
|
|||
56 | QString string = m_text + "..."; |
|
|||
57 | while (fn.boundingRect(string).width() > width && string.length() > 3) |
|
|||
58 | string.remove(string.length() - 4, 1); |
|
|||
59 | QGraphicsSimpleTextItem::setText(string); |
|
|||
60 | } else { |
|
|||
61 | QGraphicsSimpleTextItem::setText(m_text); |
|
|||
62 | } |
|
|||
63 |
|
||||
64 | setPos(rect.topLeft()); |
|
53 | setPos(rect.topLeft()); | |
65 | } |
|
54 | } | |
66 |
|
55 | |||
67 |
|
56 | |||
68 | QSizeF ChartTitle::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
57 | QSizeF ChartTitle::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
69 | { |
|
58 | { | |
70 | Q_UNUSED(constraint); |
|
59 | Q_UNUSED(constraint); | |
71 | QFontMetrics fn(font()); |
|
|||
72 | QSizeF sh; |
|
60 | QSizeF sh; | |
73 |
|
61 | |||
74 | switch (which) { |
|
62 | switch (which) { | |
75 | case Qt::MinimumSize: |
|
63 | case Qt::MinimumSize: { | |
76 | sh = QSizeF(fn.boundingRect("...").width(), fn.height()); |
|
64 | QRectF titleRect = ChartPresenter::textBoundingRect(font(), "..."); | |
|
65 | sh = QSizeF(titleRect.width(), titleRect.height()); | |||
77 | break; |
|
66 | break; | |
|
67 | } | |||
78 | case Qt::PreferredSize: |
|
68 | case Qt::PreferredSize: | |
79 | sh = fn.boundingRect(m_text).size(); |
|
69 | case Qt::MaximumSize: { | |
80 | break; |
|
70 | QRectF titleRect = ChartPresenter::textBoundingRect(font(), m_text); | |
81 | case Qt::MaximumSize: |
|
71 | sh = QSizeF(titleRect.width(), titleRect.height()); | |
82 | sh = fn.boundingRect(m_text).size(); |
|
|||
83 | break; |
|
72 | break; | |
84 | case Qt::MinimumDescent: |
|
73 | } | |
|
74 | case Qt::MinimumDescent: { | |||
|
75 | QFontMetrics fn(font()); | |||
85 | sh = QSizeF(0, fn.descent()); |
|
76 | sh = QSizeF(0, fn.descent()); | |
86 | break; |
|
77 | break; | |
|
78 | } | |||
87 | default: |
|
79 | default: | |
88 | break; |
|
80 | break; | |
89 | } |
|
81 | } | |
90 |
|
82 | |||
91 | return sh; |
|
83 | return sh; | |
92 | } |
|
84 | } | |
93 |
|
85 | |||
94 | QTCOMMERCIALCHART_END_NAMESPACE |
|
86 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,53 +1,53 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 CHARTTITLE_P_H_ |
|
30 | #ifndef CHARTTITLE_P_H_ | |
31 | #define CHARTTITLE_P_H_ |
|
31 | #define CHARTTITLE_P_H_ | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 |
#include <QGraphics |
|
34 | #include <QGraphicsTextItem> | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
class ChartTitle : public QGraphics |
|
38 | class ChartTitle : public QGraphicsTextItem | |
39 | { |
|
39 | { | |
40 | public: |
|
40 | public: | |
41 | ChartTitle(QGraphicsItem *parent = 0); |
|
41 | ChartTitle(QGraphicsItem *parent = 0); | |
42 | ~ChartTitle(); |
|
42 | ~ChartTitle(); | |
43 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; |
|
43 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; | |
44 | void setText(const QString &text); |
|
44 | void setText(const QString &text); | |
45 | QString text() const; |
|
45 | QString text() const; | |
46 | void setGeometry(const QRectF &rect); |
|
46 | void setGeometry(const QRectF &rect); | |
47 | private: |
|
47 | private: | |
48 | QString m_text; |
|
48 | QString m_text; | |
49 | }; |
|
49 | }; | |
50 |
|
50 | |||
51 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | QTCOMMERCIALCHART_END_NAMESPACE | |
52 |
|
52 | |||
53 | #endif /* CHARTTITLE_P_H_ */ |
|
53 | #endif /* CHARTTITLE_P_H_ */ |
@@ -1,82 +1,82 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "polarchartlayout_p.h" |
|
21 | #include "polarchartlayout_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "polarchartaxis_p.h" |
|
23 | #include "polarchartaxis_p.h" | |
24 | #include <QDebug> |
|
24 | #include <QDebug> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | static const qreal golden_ratio = 0.4; |
|
28 | static const qreal golden_ratio = 0.4; | |
29 |
|
29 | |||
30 | PolarChartLayout::PolarChartLayout(ChartPresenter *presenter) |
|
30 | PolarChartLayout::PolarChartLayout(ChartPresenter *presenter) | |
31 | : AbstractChartLayout(presenter) |
|
31 | : AbstractChartLayout(presenter) | |
32 | { |
|
32 | { | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | PolarChartLayout::~PolarChartLayout() |
|
35 | PolarChartLayout::~PolarChartLayout() | |
36 | { |
|
36 | { | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | QRectF PolarChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxisElement *> &axes) const |
|
39 | QRectF PolarChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxisElement *> &axes) const | |
40 | { |
|
40 | { | |
41 | // How to handle multiple angular/radial axes? |
|
41 | // How to handle multiple angular/radial axes? | |
42 | qreal axisRadius = geometry.height() / 2.0; |
|
42 | qreal axisRadius = geometry.height() / 2.0; | |
43 | if (geometry.width() < geometry.height()) |
|
43 | if (geometry.width() < geometry.height()) | |
44 | axisRadius = geometry.width() / 2.0; |
|
44 | axisRadius = geometry.width() / 2.0; | |
45 |
|
45 | |||
46 | int titleHeight = 0; |
|
46 | int titleHeight = 0; | |
47 | foreach (ChartAxisElement *chartAxis, axes) { |
|
47 | foreach (ChartAxisElement *chartAxis, axes) { | |
48 | if (!chartAxis->isVisible()) |
|
48 | if (!chartAxis->isVisible()) | |
49 | continue; |
|
49 | continue; | |
50 |
|
50 | |||
51 | PolarChartAxis *polarChartAxis = static_cast<PolarChartAxis *>(chartAxis); |
|
51 | PolarChartAxis *polarChartAxis = static_cast<PolarChartAxis *>(chartAxis); | |
52 | qreal radius = polarChartAxis->preferredAxisRadius(geometry.size()); |
|
52 | qreal radius = polarChartAxis->preferredAxisRadius(geometry.size()); | |
53 | if (radius < axisRadius) |
|
53 | if (radius < axisRadius) | |
54 | axisRadius = radius; |
|
54 | axisRadius = radius; | |
55 |
|
55 | |||
56 | if (chartAxis->axis()->orientation() == Qt::Horizontal |
|
56 | if (chartAxis->axis()->orientation() == Qt::Horizontal | |
57 | && chartAxis->axis()->isTitleVisible() |
|
57 | && chartAxis->axis()->isTitleVisible() | |
58 | && !chartAxis->axis()->titleText().isEmpty()) { |
|
58 | && !chartAxis->axis()->titleText().isEmpty()) { | |
59 | // If axis has angular title, adjust geometry down by the space title takes |
|
59 | // If axis has angular title, adjust geometry down by the space title takes | |
60 |
QRectF dummyRect = |
|
60 | QRectF dummyRect = ChartPresenter::textBoundingRect(chartAxis->axis()->titleFont(), chartAxis->axis()->titleText()); | |
61 | titleHeight = (dummyRect.height() / 2.0) + chartAxis->titlePadding(); |
|
61 | titleHeight = (dummyRect.height() / 2.0) + chartAxis->titlePadding(); | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | QRectF axisRect; |
|
65 | QRectF axisRect; | |
66 | axisRect.setSize(QSizeF(axisRadius * 2.0, axisRadius * 2.0)); |
|
66 | axisRect.setSize(QSizeF(axisRadius * 2.0, axisRadius * 2.0)); | |
67 | axisRect.moveCenter(geometry.center()); |
|
67 | axisRect.moveCenter(geometry.center()); | |
68 | axisRect.adjust(0, titleHeight, 0, titleHeight); |
|
68 | axisRect.adjust(0, titleHeight, 0, titleHeight); | |
69 |
|
69 | |||
70 | foreach (ChartAxisElement *chartAxis, axes) |
|
70 | foreach (ChartAxisElement *chartAxis, axes) | |
71 | chartAxis->setGeometry(axisRect, QRectF()); |
|
71 | chartAxis->setGeometry(axisRect, QRectF()); | |
72 |
|
72 | |||
73 | return axisRect; |
|
73 | return axisRect; | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | QRectF PolarChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxisElement *> &axes) const |
|
76 | QRectF PolarChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxisElement *> &axes) const | |
77 | { |
|
77 | { | |
78 | Q_UNUSED(axes); |
|
78 | Q_UNUSED(axes); | |
79 | return minimum; |
|
79 | return minimum; | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | QTCOMMERCIALCHART_END_NAMESPACE |
|
82 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,189 +1,181 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 <QPainter> |
|
21 | #include <QPainter> | |
22 | #include <QGraphicsSceneEvent> |
|
22 | #include <QGraphicsSceneEvent> | |
23 |
#include <QGraphics |
|
23 | #include <QGraphicsTextItem> | |
24 |
|
24 | |||
25 | #include "qlegend.h" |
|
25 | #include "qlegend.h" | |
26 | #include "qlegend_p.h" |
|
26 | #include "qlegend_p.h" | |
27 | #include "qlegendmarker.h" |
|
27 | #include "qlegendmarker.h" | |
28 | #include "qlegendmarker_p.h" |
|
28 | #include "qlegendmarker_p.h" | |
29 | #include "legendmarkeritem_p.h" |
|
29 | #include "legendmarkeritem_p.h" | |
|
30 | #include "chartpresenter_p.h" | |||
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
33 | |||
33 | LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) : |
|
34 | LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) : | |
34 | QGraphicsObject(parent), |
|
35 | QGraphicsObject(parent), | |
35 | m_marker(marker), |
|
36 | m_marker(marker), | |
36 | m_markerRect(0,0,10.0,10.0), |
|
37 | m_markerRect(0,0,10.0,10.0), | |
37 | m_boundingRect(0,0,0,0), |
|
38 | m_boundingRect(0,0,0,0), | |
38 |
m_textItem(new QGraphics |
|
39 | m_textItem(new QGraphicsTextItem(this)), | |
39 | m_rectItem(new QGraphicsRectItem(this)), |
|
40 | m_rectItem(new QGraphicsRectItem(this)), | |
40 | m_margin(4), |
|
41 | m_margin(4), | |
41 | m_space(4), |
|
42 | m_space(4), | |
42 | m_hovering(false), |
|
43 | m_hovering(false), | |
43 | m_pressPos(0, 0) |
|
44 | m_pressPos(0, 0) | |
44 | { |
|
45 | { | |
45 | m_rectItem->setRect(m_markerRect); |
|
46 | m_rectItem->setRect(m_markerRect); | |
46 | setAcceptHoverEvents(true); |
|
47 | setAcceptHoverEvents(true); | |
47 | } |
|
48 | } | |
48 |
|
49 | |||
49 | LegendMarkerItem::~LegendMarkerItem() |
|
50 | LegendMarkerItem::~LegendMarkerItem() | |
50 | { |
|
51 | { | |
51 | if (m_hovering) { |
|
52 | if (m_hovering) { | |
52 | emit m_marker->q_ptr->hovered(false); |
|
53 | emit m_marker->q_ptr->hovered(false); | |
53 | } |
|
54 | } | |
54 | } |
|
55 | } | |
55 |
|
56 | |||
56 | void LegendMarkerItem::setPen(const QPen &pen) |
|
57 | void LegendMarkerItem::setPen(const QPen &pen) | |
57 | { |
|
58 | { | |
58 | m_rectItem->setPen(pen); |
|
59 | m_rectItem->setPen(pen); | |
59 | } |
|
60 | } | |
60 |
|
61 | |||
61 | QPen LegendMarkerItem::pen() const |
|
62 | QPen LegendMarkerItem::pen() const | |
62 | { |
|
63 | { | |
63 | return m_rectItem->pen(); |
|
64 | return m_rectItem->pen(); | |
64 | } |
|
65 | } | |
65 |
|
66 | |||
66 | void LegendMarkerItem::setBrush(const QBrush &brush) |
|
67 | void LegendMarkerItem::setBrush(const QBrush &brush) | |
67 | { |
|
68 | { | |
68 | m_rectItem->setBrush(brush); |
|
69 | m_rectItem->setBrush(brush); | |
69 | } |
|
70 | } | |
70 |
|
71 | |||
71 | QBrush LegendMarkerItem::brush() const |
|
72 | QBrush LegendMarkerItem::brush() const | |
72 | { |
|
73 | { | |
73 | return m_rectItem->brush(); |
|
74 | return m_rectItem->brush(); | |
74 | } |
|
75 | } | |
75 |
|
76 | |||
76 | void LegendMarkerItem::setFont(const QFont &font) |
|
77 | void LegendMarkerItem::setFont(const QFont &font) | |
77 | { |
|
78 | { | |
78 | m_textItem->setFont(font); |
|
79 | m_textItem->setFont(font); | |
79 | QFontMetrics fn(font); |
|
80 | QFontMetrics fn(font); | |
80 | m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2); |
|
81 | m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2); | |
81 | updateGeometry(); |
|
82 | updateGeometry(); | |
82 | } |
|
83 | } | |
83 |
|
84 | |||
84 | QFont LegendMarkerItem::font() const |
|
85 | QFont LegendMarkerItem::font() const | |
85 | { |
|
86 | { | |
86 | return m_textItem->font(); |
|
87 | return m_textItem->font(); | |
87 | } |
|
88 | } | |
88 |
|
89 | |||
89 | void LegendMarkerItem::setLabel(const QString label) |
|
90 | void LegendMarkerItem::setLabel(const QString label) | |
90 | { |
|
91 | { | |
91 | m_label = label; |
|
92 | m_label = label; | |
92 | updateGeometry(); |
|
93 | updateGeometry(); | |
93 | } |
|
94 | } | |
94 |
|
95 | |||
95 | QString LegendMarkerItem::label() const |
|
96 | QString LegendMarkerItem::label() const | |
96 | { |
|
97 | { | |
97 | return m_label; |
|
98 | return m_label; | |
98 | } |
|
99 | } | |
99 |
|
100 | |||
100 | void LegendMarkerItem::setLabelBrush(const QBrush &brush) |
|
101 | void LegendMarkerItem::setLabelBrush(const QBrush &brush) | |
101 | { |
|
102 | { | |
102 |
m_textItem->set |
|
103 | m_textItem->setDefaultTextColor(brush.color()); | |
103 | } |
|
104 | } | |
104 |
|
105 | |||
105 | QBrush LegendMarkerItem::labelBrush() const |
|
106 | QBrush LegendMarkerItem::labelBrush() const | |
106 | { |
|
107 | { | |
107 |
return m_textItem-> |
|
108 | return QBrush(m_textItem->defaultTextColor()); | |
108 | } |
|
109 | } | |
109 |
|
110 | |||
110 | void LegendMarkerItem::setGeometry(const QRectF &rect) |
|
111 | void LegendMarkerItem::setGeometry(const QRectF &rect) | |
111 | { |
|
112 | { | |
112 | QFontMetrics fn (m_font); |
|
|||
113 |
|
||||
114 | int width = rect.width(); |
|
113 | int width = rect.width(); | |
115 |
qreal x = m_margin + m_markerRect.width() + |
|
114 | qreal x = m_margin + m_markerRect.width() + m_space + m_margin; | |
116 | qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin); |
|
115 | QRectF truncatedRect; | |
117 |
|
||||
118 | if (fn.boundingRect(m_label).width() + x > width) |
|
|||
119 | { |
|
|||
120 | QString string = m_label + "..."; |
|
|||
121 | while(fn.boundingRect(string).width() + x > width && string.length() > 3) |
|
|||
122 | string.remove(string.length() - 4, 1); |
|
|||
123 | m_textItem->setText(string); |
|
|||
124 | } |
|
|||
125 | else |
|
|||
126 | m_textItem->setText(m_label); |
|
|||
127 |
|
116 | |||
128 | const QRectF &textRect = m_textItem->boundingRect(); |
|
117 | m_textItem->setHtml(ChartPresenter::truncatedText(m_font, m_label, qreal(0.0), width - x, Qt::Horizontal, truncatedRect)); | |
129 |
|
118 | |||
|
119 | qreal y = qMax(m_markerRect.height() + 2 * m_margin, truncatedRect.height() + 2 * m_margin); | |||
|
120 | ||||
|
121 | const QRectF &textRect = m_textItem->boundingRect(); | |||
130 |
|
122 | |||
131 | m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2); |
|
123 | m_textItem->setPos(x - m_margin, y / 2 - textRect.height() / 2); | |
132 | m_rectItem->setRect(m_markerRect); |
|
124 | m_rectItem->setRect(m_markerRect); | |
133 | m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2); |
|
125 | m_rectItem->setPos(m_margin, y / 2 - m_markerRect.height() / 2); | |
134 |
|
126 | |||
135 | prepareGeometryChange(); |
|
127 | prepareGeometryChange(); | |
136 | m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y); |
|
128 | m_boundingRect = QRectF(0, 0, x + textRect.width() + m_margin, y); | |
137 | } |
|
129 | } | |
138 |
|
130 | |||
139 | QRectF LegendMarkerItem::boundingRect() const |
|
131 | QRectF LegendMarkerItem::boundingRect() const | |
140 | { |
|
132 | { | |
141 | return m_boundingRect; |
|
133 | return m_boundingRect; | |
142 | } |
|
134 | } | |
143 |
|
135 | |||
144 | void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
136 | void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
145 | { |
|
137 | { | |
146 | Q_UNUSED(option) |
|
138 | Q_UNUSED(option) | |
147 | Q_UNUSED(widget) |
|
139 | Q_UNUSED(widget) | |
148 | Q_UNUSED(painter) |
|
140 | Q_UNUSED(painter) | |
149 | } |
|
141 | } | |
150 |
|
142 | |||
151 | QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const |
|
143 | QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |
152 | { |
|
144 | { | |
153 | Q_UNUSED(constraint) |
|
145 | Q_UNUSED(constraint) | |
154 |
|
146 | |||
155 | QFontMetrics fn(m_textItem->font()); |
|
147 | QFontMetrics fn(m_textItem->font()); | |
156 | QSizeF sh; |
|
148 | QSizeF sh; | |
157 |
|
149 | |||
158 | switch (which) { |
|
150 | switch (which) { | |
159 | case Qt::MinimumSize: |
|
151 | case Qt::MinimumSize: | |
160 | sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); |
|
152 | sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); | |
161 | break; |
|
153 | break; | |
162 | case Qt::PreferredSize: |
|
154 | case Qt::PreferredSize: | |
163 | sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); |
|
155 | sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); | |
164 | break; |
|
156 | break; | |
165 | default: |
|
157 | default: | |
166 | break; |
|
158 | break; | |
167 | } |
|
159 | } | |
168 |
|
160 | |||
169 | return sh; |
|
161 | return sh; | |
170 | } |
|
162 | } | |
171 |
|
163 | |||
172 | void LegendMarkerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
164 | void LegendMarkerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
173 | { |
|
165 | { | |
174 | Q_UNUSED(event) |
|
166 | Q_UNUSED(event) | |
175 | m_hovering = true; |
|
167 | m_hovering = true; | |
176 | emit m_marker->q_ptr->hovered(true); |
|
168 | emit m_marker->q_ptr->hovered(true); | |
177 | } |
|
169 | } | |
178 |
|
170 | |||
179 | void LegendMarkerItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
171 | void LegendMarkerItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
180 | { |
|
172 | { | |
181 | Q_UNUSED(event) |
|
173 | Q_UNUSED(event) | |
182 | m_hovering = false; |
|
174 | m_hovering = false; | |
183 | emit m_marker->q_ptr->hovered(false); |
|
175 | emit m_marker->q_ptr->hovered(false); | |
184 | } |
|
176 | } | |
185 |
|
177 | |||
186 |
|
178 | |||
187 | #include "moc_legendmarkeritem_p.cpp" |
|
179 | #include "moc_legendmarkeritem_p.cpp" | |
188 |
|
180 | |||
189 | QTCOMMERCIALCHART_END_NAMESPACE |
|
181 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,102 +1,102 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 LEGENDMARKERITEM_P_H |
|
30 | #ifndef LEGENDMARKERITEM_P_H | |
31 | #define LEGENDMARKERITEM_P_H |
|
31 | #define LEGENDMARKERITEM_P_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include <QGraphicsObject> |
|
34 | #include <QGraphicsObject> | |
35 | #include <QFont> |
|
35 | #include <QFont> | |
36 | #include <QBrush> |
|
36 | #include <QBrush> | |
37 | #include <QPen> |
|
37 | #include <QPen> | |
38 |
#include <QGraphics |
|
38 | #include <QGraphicsTextItem> | |
39 | #include <QGraphicsLayoutItem> |
|
39 | #include <QGraphicsLayoutItem> | |
40 |
|
40 | |||
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
42 |
|
42 | |||
43 | class QLegendMarkerPrivate; |
|
43 | class QLegendMarkerPrivate; | |
44 |
|
44 | |||
45 | class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem |
|
45 | class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | Q_INTERFACES(QGraphicsLayoutItem) |
|
48 | Q_INTERFACES(QGraphicsLayoutItem) | |
49 | public: |
|
49 | public: | |
50 | explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0); |
|
50 | explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0); | |
51 | ~LegendMarkerItem(); |
|
51 | ~LegendMarkerItem(); | |
52 |
|
52 | |||
53 | void setPen(const QPen &pen); |
|
53 | void setPen(const QPen &pen); | |
54 | QPen pen() const; |
|
54 | QPen pen() const; | |
55 |
|
55 | |||
56 | void setBrush(const QBrush &brush); |
|
56 | void setBrush(const QBrush &brush); | |
57 | QBrush brush() const; |
|
57 | QBrush brush() const; | |
58 |
|
58 | |||
59 | void setFont(const QFont &font); |
|
59 | void setFont(const QFont &font); | |
60 | QFont font() const; |
|
60 | QFont font() const; | |
61 |
|
61 | |||
62 | void setLabel(const QString label); |
|
62 | void setLabel(const QString label); | |
63 | QString label() const; |
|
63 | QString label() const; | |
64 |
|
64 | |||
65 | void setLabelBrush(const QBrush &brush); |
|
65 | void setLabelBrush(const QBrush &brush); | |
66 | QBrush labelBrush() const; |
|
66 | QBrush labelBrush() const; | |
67 |
|
67 | |||
68 | void setGeometry(const QRectF &rect); |
|
68 | void setGeometry(const QRectF &rect); | |
69 | QRectF boundingRect() const; |
|
69 | QRectF boundingRect() const; | |
70 |
|
70 | |||
71 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
71 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
72 | QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint) const; |
|
72 | QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint) const; | |
73 |
|
73 | |||
74 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
|
74 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
75 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); |
|
75 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); | |
76 |
|
76 | |||
77 | protected: |
|
77 | protected: | |
78 | QLegendMarkerPrivate *m_marker; // Knows |
|
78 | QLegendMarkerPrivate *m_marker; // Knows | |
79 | QRectF m_markerRect; |
|
79 | QRectF m_markerRect; | |
80 | QRectF m_boundingRect; |
|
80 | QRectF m_boundingRect; | |
81 |
QGraphics |
|
81 | QGraphicsTextItem *m_textItem; | |
82 | QGraphicsRectItem *m_rectItem; |
|
82 | QGraphicsRectItem *m_rectItem; | |
83 | qreal m_margin; |
|
83 | qreal m_margin; | |
84 | qreal m_space; |
|
84 | qreal m_space; | |
85 | QString m_label; |
|
85 | QString m_label; | |
86 |
|
86 | |||
87 | QBrush m_labelBrush; |
|
87 | QBrush m_labelBrush; | |
88 | QFont m_font; |
|
88 | QFont m_font; | |
89 | QPen m_pen; |
|
89 | QPen m_pen; | |
90 | QBrush m_brush; |
|
90 | QBrush m_brush; | |
91 | bool m_hovering; |
|
91 | bool m_hovering; | |
92 |
|
92 | |||
93 | QPointF m_pressPos; |
|
93 | QPointF m_pressPos; | |
94 |
|
94 | |||
95 | friend class QLegendMarker; |
|
95 | friend class QLegendMarker; | |
96 | friend class QLegendMarkerPrivate; |
|
96 | friend class QLegendMarkerPrivate; | |
97 | friend class LegendLayout; |
|
97 | friend class LegendLayout; | |
98 | }; |
|
98 | }; | |
99 |
|
99 | |||
100 | QTCOMMERCIALCHART_END_NAMESPACE |
|
100 | QTCOMMERCIALCHART_END_NAMESPACE | |
101 |
|
101 | |||
102 | #endif // LEGENDMARKERITEM_P_H |
|
102 | #endif // LEGENDMARKERITEM_P_H |
@@ -1,90 +1,89 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 QLEGENDMARKERPRIVATE_H |
|
30 | #ifndef QLEGENDMARKERPRIVATE_H | |
31 | #define QLEGENDMARKERPRIVATE_H |
|
31 | #define QLEGENDMARKERPRIVATE_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include <QGraphicsObject> |
|
34 | #include <QGraphicsObject> | |
35 | #include <QBrush> |
|
35 | #include <QBrush> | |
36 | #include <QPen> |
|
36 | #include <QPen> | |
37 | #include <QGraphicsSimpleTextItem> |
|
|||
38 | #include <QGraphicsLayoutItem> |
|
37 | #include <QGraphicsLayoutItem> | |
39 |
|
38 | |||
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
41 |
|
40 | |||
42 | // TODO: check these |
|
41 | // TODO: check these | |
43 | class QAbstractSeries; |
|
42 | class QAbstractSeries; | |
44 | class QAreaSeries; |
|
43 | class QAreaSeries; | |
45 | class QXYSeries; |
|
44 | class QXYSeries; | |
46 | class QBarSet; |
|
45 | class QBarSet; | |
47 | class QAbstractBarSeries; |
|
46 | class QAbstractBarSeries; | |
48 | class QPieSlice; |
|
47 | class QPieSlice; | |
49 | class QLegend; |
|
48 | class QLegend; | |
50 | class QPieSeries; |
|
49 | class QPieSeries; | |
51 |
|
50 | |||
52 | class QLegendMarker; |
|
51 | class QLegendMarker; | |
53 | class LegendMarkerItem; |
|
52 | class LegendMarkerItem; | |
54 |
|
53 | |||
55 | class QLegendMarkerPrivate : public QObject |
|
54 | class QLegendMarkerPrivate : public QObject | |
56 | { |
|
55 | { | |
57 | Q_OBJECT |
|
56 | Q_OBJECT | |
58 | public: |
|
57 | public: | |
59 | explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend); |
|
58 | explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend); | |
60 | virtual ~QLegendMarkerPrivate(); |
|
59 | virtual ~QLegendMarkerPrivate(); | |
61 |
|
60 | |||
62 | // Helper for now. (or declare LegendLayout as friend) |
|
61 | // Helper for now. (or declare LegendLayout as friend) | |
63 | LegendMarkerItem* item() const { return m_item; } |
|
62 | LegendMarkerItem* item() const { return m_item; } | |
64 |
|
63 | |||
65 | virtual QAbstractSeries* series() = 0; |
|
64 | virtual QAbstractSeries* series() = 0; | |
66 | virtual QObject* relatedObject() = 0; |
|
65 | virtual QObject* relatedObject() = 0; | |
67 |
|
66 | |||
68 | void invalidateLegend(); |
|
67 | void invalidateLegend(); | |
69 |
|
68 | |||
70 | public Q_SLOTS: |
|
69 | public Q_SLOTS: | |
71 | virtual void updated() = 0; |
|
70 | virtual void updated() = 0; | |
72 |
|
71 | |||
73 | protected: |
|
72 | protected: | |
74 | LegendMarkerItem *m_item; |
|
73 | LegendMarkerItem *m_item; | |
75 | QLegend *m_legend; |
|
74 | QLegend *m_legend; | |
76 | bool m_customLabel; |
|
75 | bool m_customLabel; | |
77 | bool m_customBrush; |
|
76 | bool m_customBrush; | |
78 | bool m_customPen; |
|
77 | bool m_customPen; | |
79 |
|
78 | |||
80 | private: |
|
79 | private: | |
81 | QLegendMarker *q_ptr; |
|
80 | QLegendMarker *q_ptr; | |
82 |
|
81 | |||
83 | friend class QLegendPrivate; |
|
82 | friend class QLegendPrivate; | |
84 | friend class LegendMarkerItem; |
|
83 | friend class LegendMarkerItem; | |
85 | Q_DECLARE_PUBLIC(QLegendMarker) |
|
84 | Q_DECLARE_PUBLIC(QLegendMarker) | |
86 | }; |
|
85 | }; | |
87 |
|
86 | |||
88 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE | |
89 |
|
88 | |||
90 | #endif // QLEGENDMARKERPRIVATE_H |
|
89 | #endif // QLEGENDMARKERPRIVATE_H |
@@ -1,309 +1,309 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "qabstractseries.h" |
|
21 | #include "qabstractseries.h" | |
22 | #include "qabstractseries_p.h" |
|
22 | #include "qabstractseries_p.h" | |
23 | #include "chartdataset_p.h" |
|
23 | #include "chartdataset_p.h" | |
24 | #include "qchart.h" |
|
24 | #include "qchart.h" | |
25 | #include "qchart_p.h" |
|
25 | #include "qchart_p.h" | |
26 | #include "chartitem_p.h" |
|
26 | #include "chartitem_p.h" | |
27 | #include "xydomain_p.h" |
|
27 | #include "xydomain_p.h" | |
28 | #include "xlogydomain_p.h" |
|
28 | #include "xlogydomain_p.h" | |
29 | #include "logxydomain_p.h" |
|
29 | #include "logxydomain_p.h" | |
30 | #include "logxlogydomain_p.h" |
|
30 | #include "logxlogydomain_p.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QAbstractSeries |
|
35 | \class QAbstractSeries | |
36 | \brief Base class for all QtCommercial Chart series. |
|
36 | \brief Base class for all QtCommercial Chart series. | |
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | Usually you use the series type specific inherited classes instead of the base class. |
|
39 | Usually you use the series type specific inherited classes instead of the base class. | |
40 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, |
|
40 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, | |
41 | QPercentBarSeries, QPieSeries |
|
41 | QPercentBarSeries, QPieSeries | |
42 | */ |
|
42 | */ | |
43 | /*! |
|
43 | /*! | |
44 | \qmlclass AbstractSeries |
|
44 | \qmlclass AbstractSeries | |
45 | AbstractSeries is the base class for all series. |
|
45 | AbstractSeries is the base class for all series. | |
46 | The class cannot be instantiated by the user. |
|
46 | The class cannot be instantiated by the user. | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \enum QAbstractSeries::SeriesType |
|
50 | \enum QAbstractSeries::SeriesType | |
51 |
|
51 | |||
52 | The type of the series object. |
|
52 | The type of the series object. | |
53 |
|
53 | |||
54 | \value SeriesTypeLine |
|
54 | \value SeriesTypeLine | |
55 | \value SeriesTypeArea |
|
55 | \value SeriesTypeArea | |
56 | \value SeriesTypeBar |
|
56 | \value SeriesTypeBar | |
57 | \value SeriesTypeStackedBar |
|
57 | \value SeriesTypeStackedBar | |
58 | \value SeriesTypePercentBar |
|
58 | \value SeriesTypePercentBar | |
59 | \value SeriesTypePie |
|
59 | \value SeriesTypePie | |
60 | \value SeriesTypeScatter |
|
60 | \value SeriesTypeScatter | |
61 | \value SeriesTypeSpline |
|
61 | \value SeriesTypeSpline | |
62 | \value SeriesTypeHorizontalBar |
|
62 | \value SeriesTypeHorizontalBar | |
63 | \value SeriesTypeHorizontalStackedBar |
|
63 | \value SeriesTypeHorizontalStackedBar | |
64 | \value SeriesTypeHorizontalPercentBar |
|
64 | \value SeriesTypeHorizontalPercentBar | |
65 | */ |
|
65 | */ | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | \property QAbstractSeries::type |
|
68 | \property QAbstractSeries::type | |
69 | The type of the series. |
|
69 | The type of the series. | |
70 | */ |
|
70 | */ | |
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty ChartView.SeriesType AbstractSeries::type |
|
72 | \qmlproperty ChartView.SeriesType AbstractSeries::type | |
73 | The type of the series. |
|
73 | The type of the series. | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \property QAbstractSeries::name |
|
77 | \property QAbstractSeries::name | |
78 |
\brief name of the series property. The name is shown in legend for |
|
78 | \brief name of the series property. The name is shown in legend for series and supports html formatting. | |
79 | */ |
|
79 | */ | |
80 | /*! |
|
80 | /*! | |
81 | \qmlproperty string AbstractSeries::name |
|
81 | \qmlproperty string AbstractSeries::name | |
82 |
Name of the series. The name is shown in legend for |
|
82 | Name of the series. The name is shown in legend for series and supports html formatting. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \fn void QAbstractSeries::nameChanged() |
|
86 | \fn void QAbstractSeries::nameChanged() | |
87 | This signal is emitted when the series name changes. |
|
87 | This signal is emitted when the series name changes. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlsignal AbstractSeries::onNameChanged() |
|
90 | \qmlsignal AbstractSeries::onNameChanged() | |
91 | This signal is emitted when the series name changes. |
|
91 | This signal is emitted when the series name changes. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QAbstractSeries::visible |
|
95 | \property QAbstractSeries::visible | |
96 | \brief whether the series is visible or not; true by default. |
|
96 | \brief whether the series is visible or not; true by default. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty bool AbstractSeries::visible |
|
99 | \qmlproperty bool AbstractSeries::visible | |
100 | Visibility of the series. True by default. |
|
100 | Visibility of the series. True by default. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \fn void QAbstractSeries::visibleChanged() |
|
104 | \fn void QAbstractSeries::visibleChanged() | |
105 | Emitted when the series visibility changes. |
|
105 | Emitted when the series visibility changes. | |
106 | */ |
|
106 | */ | |
107 | /*! |
|
107 | /*! | |
108 | \qmlsignal AbstractSeries::onVisibleChanged() |
|
108 | \qmlsignal AbstractSeries::onVisibleChanged() | |
109 | Emitted when the series visibility changes. |
|
109 | Emitted when the series visibility changes. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \property QAbstractSeries::opacity |
|
113 | \property QAbstractSeries::opacity | |
114 | \brief The opacity of the series. |
|
114 | \brief The opacity of the series. | |
115 |
|
115 | |||
116 | By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque). |
|
116 | By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque). | |
117 | */ |
|
117 | */ | |
118 | /*! |
|
118 | /*! | |
119 | \qmlproperty real AbstractSeries::opacity |
|
119 | \qmlproperty real AbstractSeries::opacity | |
120 | The opacity of the series. By default the opacity is 1.0. |
|
120 | The opacity of the series. By default the opacity is 1.0. | |
121 | The valid values range from 0.0 (transparent) to 1.0 (opaque). |
|
121 | The valid values range from 0.0 (transparent) to 1.0 (opaque). | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \fn void QAbstractSeries::opacityChanged() |
|
125 | \fn void QAbstractSeries::opacityChanged() | |
126 | Emitted when the opacity of the series changes. |
|
126 | Emitted when the opacity of the series changes. | |
127 | */ |
|
127 | */ | |
128 | /*! |
|
128 | /*! | |
129 | \qmlsignal AbstractSeries::onOpacityChanged() |
|
129 | \qmlsignal AbstractSeries::onOpacityChanged() | |
130 | Emitted when the opacity of the series changes. |
|
130 | Emitted when the opacity of the series changes. | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \internal |
|
134 | \internal | |
135 | \brief Constructs QAbstractSeries object with \a parent. |
|
135 | \brief Constructs QAbstractSeries object with \a parent. | |
136 | */ |
|
136 | */ | |
137 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
137 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : | |
138 | QObject(parent), |
|
138 | QObject(parent), | |
139 | d_ptr(&d) |
|
139 | d_ptr(&d) | |
140 | { |
|
140 | { | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | \brief Virtual destructor for the chart series. |
|
144 | \brief Virtual destructor for the chart series. | |
145 | */ |
|
145 | */ | |
146 | QAbstractSeries::~QAbstractSeries() |
|
146 | QAbstractSeries::~QAbstractSeries() | |
147 | { |
|
147 | { | |
148 | if (d_ptr->m_chart) |
|
148 | if (d_ptr->m_chart) | |
149 | qFatal("Series still bound to a chart when destroyed!"); |
|
149 | qFatal("Series still bound to a chart when destroyed!"); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | void QAbstractSeries::setName(const QString &name) |
|
152 | void QAbstractSeries::setName(const QString &name) | |
153 | { |
|
153 | { | |
154 | if (name != d_ptr->m_name) { |
|
154 | if (name != d_ptr->m_name) { | |
155 | d_ptr->m_name = name; |
|
155 | d_ptr->m_name = name; | |
156 | emit nameChanged(); |
|
156 | emit nameChanged(); | |
157 | } |
|
157 | } | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | QString QAbstractSeries::name() const |
|
160 | QString QAbstractSeries::name() const | |
161 | { |
|
161 | { | |
162 | return d_ptr->m_name; |
|
162 | return d_ptr->m_name; | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | void QAbstractSeries::setVisible(bool visible) |
|
165 | void QAbstractSeries::setVisible(bool visible) | |
166 | { |
|
166 | { | |
167 | if (visible != d_ptr->m_visible) { |
|
167 | if (visible != d_ptr->m_visible) { | |
168 | d_ptr->m_visible = visible; |
|
168 | d_ptr->m_visible = visible; | |
169 | emit visibleChanged(); |
|
169 | emit visibleChanged(); | |
170 | } |
|
170 | } | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | bool QAbstractSeries::isVisible() const |
|
173 | bool QAbstractSeries::isVisible() const | |
174 | { |
|
174 | { | |
175 | return d_ptr->m_visible; |
|
175 | return d_ptr->m_visible; | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | qreal QAbstractSeries::opacity() const |
|
178 | qreal QAbstractSeries::opacity() const | |
179 | { |
|
179 | { | |
180 | return d_ptr->m_opacity; |
|
180 | return d_ptr->m_opacity; | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | void QAbstractSeries::setOpacity(qreal opacity) |
|
183 | void QAbstractSeries::setOpacity(qreal opacity) | |
184 | { |
|
184 | { | |
185 | if (opacity != d_ptr->m_opacity) { |
|
185 | if (opacity != d_ptr->m_opacity) { | |
186 | d_ptr->m_opacity = opacity; |
|
186 | d_ptr->m_opacity = opacity; | |
187 | emit opacityChanged(); |
|
187 | emit opacityChanged(); | |
188 | } |
|
188 | } | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | \brief Returns the chart where series belongs to. |
|
192 | \brief Returns the chart where series belongs to. | |
193 |
|
193 | |||
194 | Set automatically when the series is added to the chart |
|
194 | Set automatically when the series is added to the chart | |
195 | and unset when the series is removed from the chart. |
|
195 | and unset when the series is removed from the chart. | |
196 | */ |
|
196 | */ | |
197 | QChart *QAbstractSeries::chart() const |
|
197 | QChart *QAbstractSeries::chart() const | |
198 | { |
|
198 | { | |
199 | return d_ptr->m_chart; |
|
199 | return d_ptr->m_chart; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | /*! |
|
202 | /*! | |
203 | \brief Sets the visibility of the series to true. |
|
203 | \brief Sets the visibility of the series to true. | |
204 |
|
204 | |||
205 | \sa setVisible(), isVisible() |
|
205 | \sa setVisible(), isVisible() | |
206 | */ |
|
206 | */ | |
207 | void QAbstractSeries::show() |
|
207 | void QAbstractSeries::show() | |
208 | { |
|
208 | { | |
209 | setVisible(true); |
|
209 | setVisible(true); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | \brief Sets the visibility of the series to false. |
|
213 | \brief Sets the visibility of the series to false. | |
214 |
|
214 | |||
215 | \sa setVisible(), isVisible() |
|
215 | \sa setVisible(), isVisible() | |
216 | */ |
|
216 | */ | |
217 | void QAbstractSeries::hide() |
|
217 | void QAbstractSeries::hide() | |
218 | { |
|
218 | { | |
219 | setVisible(false); |
|
219 | setVisible(false); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | Attach \a axis to the series. |
|
223 | Attach \a axis to the series. | |
224 | \return true if the axis was attached successfully, false otherwise. |
|
224 | \return true if the axis was attached successfully, false otherwise. | |
225 | \sa QChart::addAxis(), QChart::createDefaultAxes() |
|
225 | \sa QChart::addAxis(), QChart::createDefaultAxes() | |
226 | */ |
|
226 | */ | |
227 | bool QAbstractSeries::attachAxis(QAbstractAxis* axis) |
|
227 | bool QAbstractSeries::attachAxis(QAbstractAxis* axis) | |
228 | { |
|
228 | { | |
229 | if(d_ptr->m_chart) { |
|
229 | if(d_ptr->m_chart) { | |
230 | return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis); |
|
230 | return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis); | |
231 | } else { |
|
231 | } else { | |
232 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; |
|
232 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; | |
233 | return false; |
|
233 | return false; | |
234 | } |
|
234 | } | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | /*! |
|
237 | /*! | |
238 | Detach \a axis from the series. |
|
238 | Detach \a axis from the series. | |
239 | \return true if the axis was detached successfully, false otherwise. |
|
239 | \return true if the axis was detached successfully, false otherwise. | |
240 | \sa QChart::removeAxis() |
|
240 | \sa QChart::removeAxis() | |
241 | */ |
|
241 | */ | |
242 | bool QAbstractSeries::detachAxis(QAbstractAxis* axis) |
|
242 | bool QAbstractSeries::detachAxis(QAbstractAxis* axis) | |
243 | { |
|
243 | { | |
244 | if(d_ptr->m_chart) { |
|
244 | if(d_ptr->m_chart) { | |
245 | return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis); |
|
245 | return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis); | |
246 | } |
|
246 | } | |
247 | else { |
|
247 | else { | |
248 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; |
|
248 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; | |
249 | return false; |
|
249 | return false; | |
250 | } |
|
250 | } | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | /*! |
|
253 | /*! | |
254 | Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except |
|
254 | Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except | |
255 | in case of a QPieSeries, which does not have any axes attached. |
|
255 | in case of a QPieSeries, which does not have any axes attached. | |
256 | \sa attachAxis(), detachAxis() |
|
256 | \sa attachAxis(), detachAxis() | |
257 | */ |
|
257 | */ | |
258 | QList<QAbstractAxis*> QAbstractSeries::attachedAxes() |
|
258 | QList<QAbstractAxis*> QAbstractSeries::attachedAxes() | |
259 | { |
|
259 | { | |
260 | return d_ptr->m_axes; |
|
260 | return d_ptr->m_axes; | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
263 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
264 |
|
264 | |||
265 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q) |
|
265 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q) | |
266 | : q_ptr(q), |
|
266 | : q_ptr(q), | |
267 | m_chart(0), |
|
267 | m_chart(0), | |
268 | m_item(0), |
|
268 | m_item(0), | |
269 | m_domain(new XYDomain()), |
|
269 | m_domain(new XYDomain()), | |
270 | m_visible(true), |
|
270 | m_visible(true), | |
271 | m_opacity(1.0) |
|
271 | m_opacity(1.0) | |
272 | { |
|
272 | { | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
275 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() | |
276 | { |
|
276 | { | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain) |
|
279 | void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain) | |
280 | { |
|
280 | { | |
281 | Q_ASSERT(domain); |
|
281 | Q_ASSERT(domain); | |
282 | if(m_domain.data()!=domain) { |
|
282 | if(m_domain.data()!=domain) { | |
283 | if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated())); |
|
283 | if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated())); | |
284 | m_domain.reset(domain); |
|
284 | m_domain.reset(domain); | |
285 | if(!m_item.isNull()) { |
|
285 | if(!m_item.isNull()) { | |
286 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); |
|
286 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); | |
287 | m_item->handleDomainUpdated(); |
|
287 | m_item->handleDomainUpdated(); | |
288 | } |
|
288 | } | |
289 | } |
|
289 | } | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
292 | void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
293 | { |
|
293 | { | |
294 | Q_ASSERT(!m_item.isNull()); |
|
294 | Q_ASSERT(!m_item.isNull()); | |
295 | Q_UNUSED(parent); |
|
295 | Q_UNUSED(parent); | |
296 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); |
|
296 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
299 | void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) | |
300 | { |
|
300 | { | |
301 | Q_UNUSED(options); |
|
301 | Q_UNUSED(options); | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | #include "moc_qabstractseries.cpp" |
|
304 | #include "moc_qabstractseries.cpp" | |
305 | #include "moc_qabstractseries_p.cpp" |
|
305 | #include "moc_qabstractseries_p.cpp" | |
306 |
|
306 | |||
307 | QTCOMMERCIALCHART_END_NAMESPACE |
|
307 | QTCOMMERCIALCHART_END_NAMESPACE | |
308 |
|
308 | |||
309 |
|
309 |
@@ -1,784 +1,784 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "legendscroller_p.h" |
|
23 | #include "legendscroller_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
25 | #include "chartbackground_p.h" |
|
25 | #include "chartbackground_p.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include "abstractchartlayout_p.h" |
|
27 | #include "abstractchartlayout_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "chartdataset_p.h" |
|
30 | #include "chartdataset_p.h" | |
31 | #include <QGraphicsScene> |
|
31 | #include <QGraphicsScene> | |
32 | #include <QGraphicsSceneResizeEvent> |
|
32 | #include <QGraphicsSceneResizeEvent> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \enum QChart::ChartTheme |
|
37 | \enum QChart::ChartTheme | |
38 |
|
38 | |||
39 | This enum describes the theme used by the chart. |
|
39 | This enum describes the theme used by the chart. | |
40 |
|
40 | |||
41 | \value ChartThemeLight The default theme |
|
41 | \value ChartThemeLight The default theme | |
42 | \value ChartThemeBlueCerulean |
|
42 | \value ChartThemeBlueCerulean | |
43 | \value ChartThemeDark |
|
43 | \value ChartThemeDark | |
44 | \value ChartThemeBrownSand |
|
44 | \value ChartThemeBrownSand | |
45 | \value ChartThemeBlueNcs |
|
45 | \value ChartThemeBlueNcs | |
46 | \value ChartThemeHighContrast |
|
46 | \value ChartThemeHighContrast | |
47 | \value ChartThemeBlueIcy |
|
47 | \value ChartThemeBlueIcy | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \enum QChart::AnimationOption |
|
51 | \enum QChart::AnimationOption | |
52 |
|
52 | |||
53 | For enabling/disabling animations. Defaults to NoAnimation. |
|
53 | For enabling/disabling animations. Defaults to NoAnimation. | |
54 |
|
54 | |||
55 | \value NoAnimation |
|
55 | \value NoAnimation | |
56 | \value GridAxisAnimations |
|
56 | \value GridAxisAnimations | |
57 | \value SeriesAnimations |
|
57 | \value SeriesAnimations | |
58 | \value AllAnimations |
|
58 | \value AllAnimations | |
59 | */ |
|
59 | */ | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | \enum QChart::ChartType |
|
62 | \enum QChart::ChartType | |
63 |
|
63 | |||
64 | This enum describes the chart type. |
|
64 | This enum describes the chart type. | |
65 |
|
65 | |||
66 | \value ChartTypeUndefined |
|
66 | \value ChartTypeUndefined | |
67 | \value ChartTypeCartesian |
|
67 | \value ChartTypeCartesian | |
68 | \value ChartTypePolar |
|
68 | \value ChartTypePolar | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \class QChart |
|
72 | \class QChart | |
73 | \brief QtCommercial chart API. |
|
73 | \brief QtCommercial chart API. | |
74 |
|
74 | |||
75 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
75 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
76 | representation of different types of series and other chart related objects like legend and |
|
76 | representation of different types of series and other chart related objects like legend and | |
77 | axes. If you simply want to show a chart in a layout, you can use the |
|
77 | axes. If you simply want to show a chart in a layout, you can use the | |
78 | convenience class QChartView instead of QChart. |
|
78 | convenience class QChartView instead of QChart. | |
79 | \sa QChartView, QPolarChart |
|
79 | \sa QChartView, QPolarChart | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | \property QChart::animationOptions |
|
83 | \property QChart::animationOptions | |
84 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
84 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QChart::backgroundVisible |
|
88 | \property QChart::backgroundVisible | |
89 | Specifies whether the chart background is visible or not. |
|
89 | Specifies whether the chart background is visible or not. | |
90 | \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible |
|
90 | \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible | |
91 | */ |
|
91 | */ | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | \property QChart::dropShadowEnabled |
|
94 | \property QChart::dropShadowEnabled | |
95 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
95 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop | |
96 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
96 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \property QChart::minimumMargins |
|
100 | \property QChart::minimumMargins | |
101 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
101 | Minimum margins between the plot area (axes) and the edge of the chart widget. | |
102 | This property is deprecated; use margins property instead. |
|
102 | This property is deprecated; use margins property instead. | |
103 |
|
103 | |||
104 | \sa margins |
|
104 | \sa margins | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \property QChart::margins |
|
108 | \property QChart::margins | |
109 | Margins between the plot area (axes) and the edge of the chart widget. |
|
109 | Margins between the plot area (axes) and the edge of the chart widget. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \property QChart::theme |
|
113 | \property QChart::theme | |
114 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
114 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, | |
115 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few |
|
115 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few | |
116 | different themes. |
|
116 | different themes. | |
117 | \note Changing the theme will overwrite all customizations previously applied to the series. |
|
117 | \note Changing the theme will overwrite all customizations previously applied to the series. | |
118 | */ |
|
118 | */ | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | \property QChart::title |
|
121 | \property QChart::title | |
122 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
122 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting. | |
123 | */ |
|
123 | */ | |
124 |
|
124 | |||
125 | /*! |
|
125 | /*! | |
126 | \property QChart::chartType |
|
126 | \property QChart::chartType | |
127 | Chart type indicates if the chart is a cartesian chart or a polar chart. |
|
127 | Chart type indicates if the chart is a cartesian chart or a polar chart. | |
128 | This property is set internally and it is read only. |
|
128 | This property is set internally and it is read only. | |
129 | \sa QPolarChart |
|
129 | \sa QPolarChart | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \property QChart::plotAreaBackgroundVisible |
|
133 | \property QChart::plotAreaBackgroundVisible | |
134 | Specifies whether the chart plot area background is visible or not. |
|
134 | Specifies whether the chart plot area background is visible or not. | |
135 | \note By default the plot area background is not visible and the plot area uses |
|
135 | \note By default the plot area background is not visible and the plot area uses | |
136 | the general chart background. |
|
136 | the general chart background. | |
137 | \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible |
|
137 | \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible | |
138 | */ |
|
138 | */ | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | \internal |
|
141 | \internal | |
142 | Constructs a chart object of \a type which is a child of a \a parent. |
|
142 | Constructs a chart object of \a type which is a child of a \a parent. | |
143 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
143 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
144 | This constructor is called only by subclasses. |
|
144 | This constructor is called only by subclasses. | |
145 | */ |
|
145 | */ | |
146 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
146 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
147 | : QGraphicsWidget(parent, wFlags), |
|
147 | : QGraphicsWidget(parent, wFlags), | |
148 | d_ptr(new QChartPrivate(this, type)) |
|
148 | d_ptr(new QChartPrivate(this, type)) | |
149 | { |
|
149 | { | |
150 | d_ptr->init(); |
|
150 | d_ptr->init(); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | Constructs a chart object which is a child of a \a parent. |
|
154 | Constructs a chart object which is a child of a \a parent. | |
155 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
155 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
156 | */ |
|
156 | */ | |
157 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
157 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
158 | : QGraphicsWidget(parent, wFlags), |
|
158 | : QGraphicsWidget(parent, wFlags), | |
159 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) |
|
159 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) | |
160 | { |
|
160 | { | |
161 | d_ptr->init(); |
|
161 | d_ptr->init(); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | Destroys the chart object and its children, like series and axis objects added to it. |
|
165 | Destroys the chart object and its children, like series and axis objects added to it. | |
166 | */ |
|
166 | */ | |
167 | QChart::~QChart() |
|
167 | QChart::~QChart() | |
168 | { |
|
168 | { | |
169 | //start by deleting dataset, it will remove all series and axes |
|
169 | //start by deleting dataset, it will remove all series and axes | |
170 | delete d_ptr->m_dataset; |
|
170 | delete d_ptr->m_dataset; | |
171 | d_ptr->m_dataset = 0; |
|
171 | d_ptr->m_dataset = 0; | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | Adds the \a series onto the chart and takes the ownership of it. |
|
175 | Adds the \a series onto the chart and takes the ownership of it. | |
176 |
|
176 | |||
177 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart |
|
177 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart | |
178 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to |
|
178 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to | |
179 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges |
|
179 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges | |
180 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other |
|
180 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other | |
181 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after |
|
181 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after | |
182 | a series has been added or explicitly attach axes for the series. |
|
182 | a series has been added or explicitly attach axes for the series. | |
183 |
|
183 | |||
184 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
184 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
185 | */ |
|
185 | */ | |
186 | void QChart::addSeries(QAbstractSeries *series) |
|
186 | void QChart::addSeries(QAbstractSeries *series) | |
187 | { |
|
187 | { | |
188 | Q_ASSERT(series); |
|
188 | Q_ASSERT(series); | |
189 | d_ptr->m_dataset->addSeries(series); |
|
189 | d_ptr->m_dataset->addSeries(series); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | Removes the \a series from the chart. |
|
193 | Removes the \a series from the chart. | |
194 | The chart releases its ownership of the specified \a series object. |
|
194 | The chart releases its ownership of the specified \a series object. | |
195 |
|
195 | |||
196 | \sa addSeries(), removeAllSeries() |
|
196 | \sa addSeries(), removeAllSeries() | |
197 | */ |
|
197 | */ | |
198 | void QChart::removeSeries(QAbstractSeries *series) |
|
198 | void QChart::removeSeries(QAbstractSeries *series) | |
199 | { |
|
199 | { | |
200 | Q_ASSERT(series); |
|
200 | Q_ASSERT(series); | |
201 | d_ptr->m_dataset->removeSeries(series); |
|
201 | d_ptr->m_dataset->removeSeries(series); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | /*! |
|
204 | /*! | |
205 | Removes and deletes all series objects that have been added to the chart. |
|
205 | Removes and deletes all series objects that have been added to the chart. | |
206 |
|
206 | |||
207 | \sa addSeries(), removeSeries() |
|
207 | \sa addSeries(), removeSeries() | |
208 | */ |
|
208 | */ | |
209 | void QChart::removeAllSeries() |
|
209 | void QChart::removeAllSeries() | |
210 | { |
|
210 | { | |
211 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
211 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ | |
212 | removeSeries(s); |
|
212 | removeSeries(s); | |
213 | delete s; |
|
213 | delete s; | |
214 | } |
|
214 | } | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | /*! |
|
217 | /*! | |
218 | Sets the \a brush that is used for painting the background of the chart area. |
|
218 | Sets the \a brush that is used for painting the background of the chart area. | |
219 | */ |
|
219 | */ | |
220 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
220 | void QChart::setBackgroundBrush(const QBrush &brush) | |
221 | { |
|
221 | { | |
222 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
222 | d_ptr->m_presenter->setBackgroundBrush(brush); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | /*! |
|
225 | /*! | |
226 | Gets the brush that is used for painting the background of the chart area. |
|
226 | Gets the brush that is used for painting the background of the chart area. | |
227 | */ |
|
227 | */ | |
228 | QBrush QChart::backgroundBrush() const |
|
228 | QBrush QChart::backgroundBrush() const | |
229 | { |
|
229 | { | |
230 | return d_ptr->m_presenter->backgroundBrush(); |
|
230 | return d_ptr->m_presenter->backgroundBrush(); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | /*! |
|
233 | /*! | |
234 | Sets the \a pen that is used for painting the background of the chart area. |
|
234 | Sets the \a pen that is used for painting the background of the chart area. | |
235 | */ |
|
235 | */ | |
236 | void QChart::setBackgroundPen(const QPen &pen) |
|
236 | void QChart::setBackgroundPen(const QPen &pen) | |
237 | { |
|
237 | { | |
238 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
238 | d_ptr->m_presenter->setBackgroundPen(pen); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | Gets the pen that is used for painting the background of the chart area. |
|
242 | Gets the pen that is used for painting the background of the chart area. | |
243 | */ |
|
243 | */ | |
244 | QPen QChart::backgroundPen() const |
|
244 | QPen QChart::backgroundPen() const | |
245 | { |
|
245 | { | |
246 | return d_ptr->m_presenter->backgroundPen(); |
|
246 | return d_ptr->m_presenter->backgroundPen(); | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | void QChart::setTitle(const QString &title) |
|
249 | void QChart::setTitle(const QString &title) | |
250 | { |
|
250 | { | |
251 | d_ptr->m_presenter->setTitle(title); |
|
251 | d_ptr->m_presenter->setTitle(title); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | QString QChart::title() const |
|
254 | QString QChart::title() const | |
255 | { |
|
255 | { | |
256 | return d_ptr->m_presenter->title(); |
|
256 | return d_ptr->m_presenter->title(); | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | /*! |
|
259 | /*! | |
260 | Sets the \a font that is used for drawing the chart title. |
|
260 | Sets the \a font that is used for drawing the chart title. | |
261 | */ |
|
261 | */ | |
262 | void QChart::setTitleFont(const QFont &font) |
|
262 | void QChart::setTitleFont(const QFont &font) | |
263 | { |
|
263 | { | |
264 | d_ptr->m_presenter->setTitleFont(font); |
|
264 | d_ptr->m_presenter->setTitleFont(font); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | /*! |
|
267 | /*! | |
268 | Gets the font that is used for drawing the chart title. |
|
268 | Gets the font that is used for drawing the chart title. | |
269 | */ |
|
269 | */ | |
270 | QFont QChart::titleFont() const |
|
270 | QFont QChart::titleFont() const | |
271 | { |
|
271 | { | |
272 | return d_ptr->m_presenter->titleFont(); |
|
272 | return d_ptr->m_presenter->titleFont(); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Sets the \a brush used for drawing the title text. |
|
276 | Sets the \a brush used for drawing the title text. | |
277 | */ |
|
277 | */ | |
278 | void QChart::setTitleBrush(const QBrush &brush) |
|
278 | void QChart::setTitleBrush(const QBrush &brush) | |
279 | { |
|
279 | { | |
280 | d_ptr->m_presenter->setTitleBrush(brush); |
|
280 | d_ptr->m_presenter->setTitleBrush(brush); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | /*! |
|
283 | /*! | |
284 | Returns the brush used for drawing the title text. |
|
284 | Returns the brush used for drawing the title text. | |
285 | */ |
|
285 | */ | |
286 | QBrush QChart::titleBrush() const |
|
286 | QBrush QChart::titleBrush() const | |
287 | { |
|
287 | { | |
288 | return d_ptr->m_presenter->titleBrush(); |
|
288 | return d_ptr->m_presenter->titleBrush(); | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | void QChart::setTheme(QChart::ChartTheme theme) |
|
291 | void QChart::setTheme(QChart::ChartTheme theme) | |
292 | { |
|
292 | { | |
293 | d_ptr->m_themeManager->setTheme(theme); |
|
293 | d_ptr->m_themeManager->setTheme(theme); | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | QChart::ChartTheme QChart::theme() const |
|
296 | QChart::ChartTheme QChart::theme() const | |
297 | { |
|
297 | { | |
298 | return d_ptr->m_themeManager->theme()->id(); |
|
298 | return d_ptr->m_themeManager->theme()->id(); | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | /*! |
|
301 | /*! | |
302 | Zooms in the view by a factor of two. |
|
302 | Zooms in the view by a factor of two. | |
303 | */ |
|
303 | */ | |
304 | void QChart::zoomIn() |
|
304 | void QChart::zoomIn() | |
305 | { |
|
305 | { | |
306 | d_ptr->zoomIn(2.0); |
|
306 | d_ptr->zoomIn(2.0); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | /*! |
|
309 | /*! | |
310 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
310 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
311 | \note This is not supported for polar charts. |
|
311 | \note This is not supported for polar charts. | |
312 | */ |
|
312 | */ | |
313 | void QChart::zoomIn(const QRectF &rect) |
|
313 | void QChart::zoomIn(const QRectF &rect) | |
314 | { |
|
314 | { | |
315 | if (d_ptr->m_type == QChart::ChartTypePolar) |
|
315 | if (d_ptr->m_type == QChart::ChartTypePolar) | |
316 | return; |
|
316 | return; | |
317 | d_ptr->zoomIn(rect); |
|
317 | d_ptr->zoomIn(rect); | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | /*! |
|
320 | /*! | |
321 | Zooms out the view by a factor of two. |
|
321 | Zooms out the view by a factor of two. | |
322 | */ |
|
322 | */ | |
323 | void QChart::zoomOut() |
|
323 | void QChart::zoomOut() | |
324 | { |
|
324 | { | |
325 | d_ptr->zoomOut(2.0); |
|
325 | d_ptr->zoomOut(2.0); | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | /*! |
|
328 | /*! | |
329 | Zooms in the view by a custom \a factor. |
|
329 | Zooms in the view by a custom \a factor. | |
330 |
|
330 | |||
331 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
331 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | |
332 | */ |
|
332 | */ | |
333 | void QChart::zoom(qreal factor) |
|
333 | void QChart::zoom(qreal factor) | |
334 | { |
|
334 | { | |
335 | if (qFuzzyCompare(factor, 0)) |
|
335 | if (qFuzzyCompare(factor, 0)) | |
336 | return; |
|
336 | return; | |
337 |
|
337 | |||
338 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
338 | if (qFuzzyCompare(factor, (qreal)1.0)) | |
339 | return; |
|
339 | return; | |
340 |
|
340 | |||
341 | if (factor < 0) |
|
341 | if (factor < 0) | |
342 | return; |
|
342 | return; | |
343 |
|
343 | |||
344 | if (factor > 1.0) |
|
344 | if (factor > 1.0) | |
345 | d_ptr->zoomIn(factor); |
|
345 | d_ptr->zoomIn(factor); | |
346 | else |
|
346 | else | |
347 | d_ptr->zoomOut(1.0 / factor); |
|
347 | d_ptr->zoomOut(1.0 / factor); | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | /*! |
|
350 | /*! | |
351 | Returns a pointer to the horizontal axis attached to the specified \a series. |
|
351 | Returns a pointer to the horizontal axis attached to the specified \a series. | |
352 | If no \a series is specified, the first horizontal axis added to the chart is returned. |
|
352 | If no \a series is specified, the first horizontal axis added to the chart is returned. | |
353 |
|
353 | |||
354 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
354 | \sa addAxis(), QAbstractSeries::attachAxis() | |
355 | */ |
|
355 | */ | |
356 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
356 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | |
357 | { |
|
357 | { | |
358 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); |
|
358 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); | |
359 | if (axisList.count()) |
|
359 | if (axisList.count()) | |
360 | return axisList[0]; |
|
360 | return axisList[0]; | |
361 | return 0; |
|
361 | return 0; | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | /*! |
|
364 | /*! | |
365 | Returns a pointer to the vertical axis attached to the specified \a series. |
|
365 | Returns a pointer to the vertical axis attached to the specified \a series. | |
366 | If no \a series is specified, the first vertical axis added to the chart is returned. |
|
366 | If no \a series is specified, the first vertical axis added to the chart is returned. | |
367 |
|
367 | |||
368 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
368 | \sa addAxis(), QAbstractSeries::attachAxis() | |
369 | */ |
|
369 | */ | |
370 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
370 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const | |
371 | { |
|
371 | { | |
372 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); |
|
372 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); | |
373 | if (axisList.count()) |
|
373 | if (axisList.count()) | |
374 | return axisList[0]; |
|
374 | return axisList[0]; | |
375 | return 0; |
|
375 | return 0; | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | /*! |
|
378 | /*! | |
379 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, |
|
379 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, | |
380 | then all axes added to the chart with the specified orientation are returned. |
|
380 | then all axes added to the chart with the specified orientation are returned. | |
381 | \sa addAxis(), createDefaultAxes() |
|
381 | \sa addAxis(), createDefaultAxes() | |
382 | */ |
|
382 | */ | |
383 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
383 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const | |
384 | { |
|
384 | { | |
385 | QList<QAbstractAxis *> result ; |
|
385 | QList<QAbstractAxis *> result ; | |
386 |
|
386 | |||
387 | if (series) { |
|
387 | if (series) { | |
388 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
388 | foreach (QAbstractAxis *axis, series->attachedAxes()){ | |
389 | if (orientation.testFlag(axis->orientation())) |
|
389 | if (orientation.testFlag(axis->orientation())) | |
390 | result << axis; |
|
390 | result << axis; | |
391 | } |
|
391 | } | |
392 | } else { |
|
392 | } else { | |
393 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ |
|
393 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ | |
394 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
394 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) | |
395 | result << axis; |
|
395 | result << axis; | |
396 | } |
|
396 | } | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | return result; |
|
399 | return result; | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 | /*! |
|
402 | /*! | |
403 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to |
|
403 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to | |
404 | the chart will be deleted. |
|
404 | the chart will be deleted. | |
405 |
|
405 | |||
406 | \note This function has to be called after all series have been added to the chart. The axes created by this function |
|
406 | \note This function has to be called after all series have been added to the chart. The axes created by this function | |
407 | will NOT get automatically attached to any series added to the chart after this function has been called. |
|
407 | will NOT get automatically attached to any series added to the chart after this function has been called. | |
408 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing |
|
408 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing | |
409 | if there are other series with properly attached axes also present. |
|
409 | if there are other series with properly attached axes also present. | |
410 |
|
410 | |||
411 | \table |
|
411 | \table | |
412 | \header |
|
412 | \header | |
413 | \o Series type |
|
413 | \o Series type | |
414 | \o X-axis |
|
414 | \o X-axis | |
415 | \o Y-axis |
|
415 | \o Y-axis | |
416 | \row |
|
416 | \row | |
417 | \o QXYSeries |
|
417 | \o QXYSeries | |
418 | \o QValueAxis |
|
418 | \o QValueAxis | |
419 | \o QValueAxis |
|
419 | \o QValueAxis | |
420 | \row |
|
420 | \row | |
421 | \o QBarSeries |
|
421 | \o QBarSeries | |
422 | \o QBarCategoryAxis |
|
422 | \o QBarCategoryAxis | |
423 | \o QValueAxis |
|
423 | \o QValueAxis | |
424 | \row |
|
424 | \row | |
425 | \o QPieSeries |
|
425 | \o QPieSeries | |
426 | \o None |
|
426 | \o None | |
427 | \o None |
|
427 | \o None | |
428 | \endtable |
|
428 | \endtable | |
429 |
|
429 | |||
430 | If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. |
|
430 | If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. | |
431 | If there are several series of different types added to the chart, then each series gets its own axes pair. |
|
431 | If there are several series of different types added to the chart, then each series gets its own axes pair. | |
432 |
|
432 | |||
433 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. |
|
433 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. | |
434 | QPieSeries does not create any axes. |
|
434 | QPieSeries does not create any axes. | |
435 |
|
435 | |||
436 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() |
|
436 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() | |
437 | */ |
|
437 | */ | |
438 | void QChart::createDefaultAxes() |
|
438 | void QChart::createDefaultAxes() | |
439 | { |
|
439 | { | |
440 | d_ptr->m_dataset->createDefaultAxes(); |
|
440 | d_ptr->m_dataset->createDefaultAxes(); | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
443 | /*! |
|
443 | /*! | |
444 | Returns the legend object of the chart. Ownership stays with the chart. |
|
444 | Returns the legend object of the chart. Ownership stays with the chart. | |
445 | */ |
|
445 | */ | |
446 | QLegend *QChart::legend() const |
|
446 | QLegend *QChart::legend() const | |
447 | { |
|
447 | { | |
448 | return d_ptr->m_legend; |
|
448 | return d_ptr->m_legend; | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | void QChart::setMinimumMargins(const QMargins &margins) |
|
451 | void QChart::setMinimumMargins(const QMargins &margins) | |
452 | { |
|
452 | { | |
453 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
453 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; | |
454 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
454 | d_ptr->m_presenter->layout()->setMargins(margins); | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
457 | QMargins QChart::minimumMargins() const |
|
457 | QMargins QChart::minimumMargins() const | |
458 | { |
|
458 | { | |
459 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
459 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; | |
460 | return d_ptr->m_presenter->layout()->margins(); |
|
460 | return d_ptr->m_presenter->layout()->margins(); | |
461 | } |
|
461 | } | |
462 |
|
462 | |||
463 | void QChart::setMargins(const QMargins &margins) |
|
463 | void QChart::setMargins(const QMargins &margins) | |
464 | { |
|
464 | { | |
465 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
465 | d_ptr->m_presenter->layout()->setMargins(margins); | |
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | QMargins QChart::margins() const |
|
468 | QMargins QChart::margins() const | |
469 | { |
|
469 | { | |
470 | return d_ptr->m_presenter->layout()->margins(); |
|
470 | return d_ptr->m_presenter->layout()->margins(); | |
471 | } |
|
471 | } | |
472 |
|
472 | |||
473 | QChart::ChartType QChart::chartType() const |
|
473 | QChart::ChartType QChart::chartType() const | |
474 | { |
|
474 | { | |
475 | return d_ptr->m_type; |
|
475 | return d_ptr->m_type; | |
476 | } |
|
476 | } | |
477 |
|
477 | |||
478 | /*! |
|
478 | /*! | |
479 | Returns the the rectangle within which the drawing of the chart is done. |
|
479 | Returns the the rectangle within which the drawing of the chart is done. | |
480 | It does not include the area defined by margins. |
|
480 | It does not include the area defined by margins. | |
481 | */ |
|
481 | */ | |
482 | QRectF QChart::plotArea() const |
|
482 | QRectF QChart::plotArea() const | |
483 | { |
|
483 | { | |
484 | return d_ptr->m_presenter->geometry(); |
|
484 | return d_ptr->m_presenter->geometry(); | |
485 | } |
|
485 | } | |
486 |
|
486 | |||
487 | /*! |
|
487 | /*! | |
488 | Sets the \a brush for the background of the plot area of the chart. |
|
488 | Sets the \a brush for the background of the plot area of the chart. | |
489 |
|
489 | |||
490 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() |
|
490 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() | |
491 | */ |
|
491 | */ | |
492 | void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) |
|
492 | void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) | |
493 | { |
|
493 | { | |
494 | d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); |
|
494 | d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); | |
495 | } |
|
495 | } | |
496 |
|
496 | |||
497 | /*! |
|
497 | /*! | |
498 | Returns the brush for the background of the plot area of the chart. |
|
498 | Returns the brush for the background of the plot area of the chart. | |
499 |
|
499 | |||
500 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() |
|
500 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() | |
501 | */ |
|
501 | */ | |
502 | QBrush QChart::plotAreaBackgroundBrush() const |
|
502 | QBrush QChart::plotAreaBackgroundBrush() const | |
503 | { |
|
503 | { | |
504 | return d_ptr->m_presenter->plotAreaBackgroundBrush(); |
|
504 | return d_ptr->m_presenter->plotAreaBackgroundBrush(); | |
505 | } |
|
505 | } | |
506 |
|
506 | |||
507 | /*! |
|
507 | /*! | |
508 | Sets the \a pen for the background of the plot area of the chart. |
|
508 | Sets the \a pen for the background of the plot area of the chart. | |
509 |
|
509 | |||
510 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() |
|
510 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() | |
511 | */ |
|
511 | */ | |
512 | void QChart::setPlotAreaBackgroundPen(const QPen &pen) |
|
512 | void QChart::setPlotAreaBackgroundPen(const QPen &pen) | |
513 | { |
|
513 | { | |
514 | d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); |
|
514 | d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); | |
515 | } |
|
515 | } | |
516 |
|
516 | |||
517 | /*! |
|
517 | /*! | |
518 | Returns the pen for the background of the plot area of the chart. |
|
518 | Returns the pen for the background of the plot area of the chart. | |
519 |
|
519 | |||
520 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() |
|
520 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() | |
521 | */ |
|
521 | */ | |
522 | QPen QChart::plotAreaBackgroundPen() const |
|
522 | QPen QChart::plotAreaBackgroundPen() const | |
523 | { |
|
523 | { | |
524 | return d_ptr->m_presenter->plotAreaBackgroundPen(); |
|
524 | return d_ptr->m_presenter->plotAreaBackgroundPen(); | |
525 | } |
|
525 | } | |
526 |
|
526 | |||
527 | void QChart::setPlotAreaBackgroundVisible(bool visible) |
|
527 | void QChart::setPlotAreaBackgroundVisible(bool visible) | |
528 | { |
|
528 | { | |
529 | d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); |
|
529 | d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); | |
530 | } |
|
530 | } | |
531 |
|
531 | |||
532 | bool QChart::isPlotAreaBackgroundVisible() const |
|
532 | bool QChart::isPlotAreaBackgroundVisible() const | |
533 | { |
|
533 | { | |
534 | return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); |
|
534 | return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); | |
535 | } |
|
535 | } | |
536 |
|
536 | |||
537 | void QChart::setAnimationOptions(AnimationOptions options) |
|
537 | void QChart::setAnimationOptions(AnimationOptions options) | |
538 | { |
|
538 | { | |
539 | d_ptr->m_presenter->setAnimationOptions(options); |
|
539 | d_ptr->m_presenter->setAnimationOptions(options); | |
540 | } |
|
540 | } | |
541 |
|
541 | |||
542 | QChart::AnimationOptions QChart::animationOptions() const |
|
542 | QChart::AnimationOptions QChart::animationOptions() const | |
543 | { |
|
543 | { | |
544 | return d_ptr->m_presenter->animationOptions(); |
|
544 | return d_ptr->m_presenter->animationOptions(); | |
545 | } |
|
545 | } | |
546 |
|
546 | |||
547 | /*! |
|
547 | /*! | |
548 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
548 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | |
549 |
|
549 | |||
550 | For polar charts, \a dx indicates the angle along angular axis instead of distance. |
|
550 | For polar charts, \a dx indicates the angle along angular axis instead of distance. | |
551 | */ |
|
551 | */ | |
552 | void QChart::scroll(qreal dx, qreal dy) |
|
552 | void QChart::scroll(qreal dx, qreal dy) | |
553 | { |
|
553 | { | |
554 | d_ptr->scroll(dx,dy); |
|
554 | d_ptr->scroll(dx,dy); | |
555 | } |
|
555 | } | |
556 |
|
556 | |||
557 | void QChart::setBackgroundVisible(bool visible) |
|
557 | void QChart::setBackgroundVisible(bool visible) | |
558 | { |
|
558 | { | |
559 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
559 | d_ptr->m_presenter->setBackgroundVisible(visible); | |
560 | } |
|
560 | } | |
561 |
|
561 | |||
562 | bool QChart::isBackgroundVisible() const |
|
562 | bool QChart::isBackgroundVisible() const | |
563 | { |
|
563 | { | |
564 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
564 | return d_ptr->m_presenter->isBackgroundVisible(); | |
565 | } |
|
565 | } | |
566 |
|
566 | |||
567 | void QChart::setDropShadowEnabled(bool enabled) |
|
567 | void QChart::setDropShadowEnabled(bool enabled) | |
568 | { |
|
568 | { | |
569 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
569 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); | |
570 | } |
|
570 | } | |
571 |
|
571 | |||
572 | bool QChart::isDropShadowEnabled() const |
|
572 | bool QChart::isDropShadowEnabled() const | |
573 | { |
|
573 | { | |
574 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
574 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); | |
575 | } |
|
575 | } | |
576 |
|
576 | |||
577 | /*! |
|
577 | /*! | |
578 | Returns all series that are added to the chart. |
|
578 | Returns all series that are added to the chart. | |
579 |
|
579 | |||
580 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
580 | \sa addSeries(), removeSeries(), removeAllSeries() | |
581 | */ |
|
581 | */ | |
582 | QList<QAbstractSeries *> QChart::series() const |
|
582 | QList<QAbstractSeries *> QChart::series() const | |
583 | { |
|
583 | { | |
584 | return d_ptr->m_dataset->series(); |
|
584 | return d_ptr->m_dataset->series(); | |
585 | } |
|
585 | } | |
586 |
|
586 | |||
587 | /*! |
|
587 | /*! | |
588 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. |
|
588 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. | |
589 | The chart takes ownership of both the \a axis and the \a series. |
|
589 | The chart takes ownership of both the \a axis and the \a series. | |
590 | Any horizontal axes previously attached to the \a series are deleted. |
|
590 | Any horizontal axes previously attached to the \a series are deleted. | |
591 |
|
591 | |||
592 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
592 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
593 | */ |
|
593 | */ | |
594 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) |
|
594 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) | |
595 | { |
|
595 | { | |
596 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); |
|
596 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); | |
597 |
|
597 | |||
598 | foreach (QAbstractAxis* a, list) { |
|
598 | foreach (QAbstractAxis* a, list) { | |
599 | d_ptr->m_dataset->removeAxis(a); |
|
599 | d_ptr->m_dataset->removeAxis(a); | |
600 | delete a; |
|
600 | delete a; | |
601 | } |
|
601 | } | |
602 |
|
602 | |||
603 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
603 | if (!d_ptr->m_dataset->axes().contains(axis)) | |
604 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); |
|
604 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); | |
605 | d_ptr->m_dataset->attachAxis(series, axis); |
|
605 | d_ptr->m_dataset->attachAxis(series, axis); | |
606 | } |
|
606 | } | |
607 |
|
607 | |||
608 | /*! |
|
608 | /*! | |
609 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. |
|
609 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. | |
610 | The chart takes ownership of both the \a axis and the \a series. |
|
610 | The chart takes ownership of both the \a axis and the \a series. | |
611 | Any vertical axes previously attached to the \a series are deleted. |
|
611 | Any vertical axes previously attached to the \a series are deleted. | |
612 |
|
612 | |||
613 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
613 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
614 | */ |
|
614 | */ | |
615 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) |
|
615 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) | |
616 | { |
|
616 | { | |
617 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); |
|
617 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); | |
618 |
|
618 | |||
619 | foreach (QAbstractAxis* a, list) { |
|
619 | foreach (QAbstractAxis* a, list) { | |
620 | d_ptr->m_dataset->removeAxis(a); |
|
620 | d_ptr->m_dataset->removeAxis(a); | |
621 | delete a; |
|
621 | delete a; | |
622 | } |
|
622 | } | |
623 |
|
623 | |||
624 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
624 | if (!d_ptr->m_dataset->axes().contains(axis)) | |
625 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); |
|
625 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); | |
626 | d_ptr->m_dataset->attachAxis(series, axis); |
|
626 | d_ptr->m_dataset->attachAxis(series, axis); | |
627 | } |
|
627 | } | |
628 |
|
628 | |||
629 | /*! |
|
629 | /*! | |
630 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
630 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. | |
631 |
|
631 | |||
632 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
632 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
633 | */ |
|
633 | */ | |
634 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
634 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) | |
635 | { |
|
635 | { | |
636 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
636 | d_ptr->m_dataset->addAxis(axis, alignment); | |
637 | } |
|
637 | } | |
638 |
|
638 | |||
639 | /*! |
|
639 | /*! | |
640 | Removes the \a axis from the chart. |
|
640 | Removes the \a axis from the chart. | |
641 | The chart releases its ownership of the specified \a axis object. |
|
641 | The chart releases its ownership of the specified \a axis object. | |
642 |
|
642 | |||
643 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
643 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() | |
644 | */ |
|
644 | */ | |
645 | void QChart::removeAxis(QAbstractAxis *axis) |
|
645 | void QChart::removeAxis(QAbstractAxis *axis) | |
646 | { |
|
646 | { | |
647 | d_ptr->m_dataset->removeAxis(axis); |
|
647 | d_ptr->m_dataset->removeAxis(axis); | |
648 | } |
|
648 | } | |
649 |
|
649 | |||
650 | /*! |
|
650 | /*! | |
651 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. |
|
651 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. | |
652 | */ |
|
652 | */ | |
653 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
653 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) | |
654 | { |
|
654 | { | |
655 | return d_ptr->m_dataset->mapToValue(position, series); |
|
655 | return d_ptr->m_dataset->mapToValue(position, series); | |
656 | } |
|
656 | } | |
657 |
|
657 | |||
658 | /*! |
|
658 | /*! | |
659 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. |
|
659 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. | |
660 | */ |
|
660 | */ | |
661 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
661 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) | |
662 | { |
|
662 | { | |
663 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
663 | return d_ptr->m_dataset->mapToPosition(value, series); | |
664 | } |
|
664 | } | |
665 |
|
665 | |||
666 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
666 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
667 |
|
667 | |||
668 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): |
|
668 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): | |
669 | q_ptr(q), |
|
669 | q_ptr(q), | |
670 | m_legend(0), |
|
670 | m_legend(0), | |
671 | m_dataset(new ChartDataSet(q)), |
|
671 | m_dataset(new ChartDataSet(q)), | |
672 | m_presenter(new ChartPresenter(q, type)), |
|
672 | m_presenter(new ChartPresenter(q, type)), | |
673 | m_themeManager(new ChartThemeManager(q)), |
|
673 | m_themeManager(new ChartThemeManager(q)), | |
674 | m_type(type) |
|
674 | m_type(type) | |
675 | { |
|
675 | { | |
676 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
676 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
677 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
677 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
678 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
678 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); | |
679 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
679 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
680 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
680 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
681 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
681 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
682 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
682 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); | |
683 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
683 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
684 | } |
|
684 | } | |
685 |
|
685 | |||
686 | QChartPrivate::~QChartPrivate() |
|
686 | QChartPrivate::~QChartPrivate() | |
687 | { |
|
687 | { | |
688 | } |
|
688 | } | |
689 |
|
689 | |||
690 | // Hackish solution to the problem of explicitly assigning the default pen/brush/font |
|
690 | // Hackish solution to the problem of explicitly assigning the default pen/brush/font | |
691 | // to a series or axis and having theme override it: |
|
691 | // to a series or axis and having theme override it: | |
692 | // Initialize pens, brushes, and fonts to something nobody is likely to ever use, |
|
692 | // Initialize pens, brushes, and fonts to something nobody is likely to ever use, | |
693 | // so that default theme initialization will always set these properly. |
|
693 | // so that default theme initialization will always set these properly. | |
694 | QPen &QChartPrivate::defaultPen() |
|
694 | QPen &QChartPrivate::defaultPen() | |
695 | { |
|
695 | { | |
696 | static QPen *defaultPen = 0; |
|
696 | static QPen *defaultPen = 0; | |
697 | if (!defaultPen) |
|
697 | if (!defaultPen) | |
698 | defaultPen = new QPen(QColor(1, 2, 0), 0.93247536); |
|
698 | defaultPen = new QPen(QColor(1, 2, 0), 0.93247536); | |
699 | return *defaultPen; |
|
699 | return *defaultPen; | |
700 | } |
|
700 | } | |
701 |
|
701 | |||
702 | QBrush &QChartPrivate::defaultBrush() |
|
702 | QBrush &QChartPrivate::defaultBrush() | |
703 | { |
|
703 | { | |
704 | static QBrush *defaultBrush = 0; |
|
704 | static QBrush *defaultBrush = 0; | |
705 | if (!defaultBrush) |
|
705 | if (!defaultBrush) | |
706 | defaultBrush = new QBrush(QColor(1, 2, 0), Qt::Dense7Pattern); |
|
706 | defaultBrush = new QBrush(QColor(1, 2, 0), Qt::Dense7Pattern); | |
707 | return *defaultBrush; |
|
707 | return *defaultBrush; | |
708 | } |
|
708 | } | |
709 |
|
709 | |||
710 | QFont &QChartPrivate::defaultFont() |
|
710 | QFont &QChartPrivate::defaultFont() | |
711 | { |
|
711 | { | |
712 | static QFont *defaultFont = 0; |
|
712 | static QFont *defaultFont = 0; | |
713 | if (!defaultFont) { |
|
713 | if (!defaultFont) { | |
714 | defaultFont = new QFont(); |
|
714 | defaultFont = new QFont(); | |
715 | defaultFont->setPointSizeF(8.34563465); |
|
715 | defaultFont->setPointSizeF(8.34563465); | |
716 | } |
|
716 | } | |
717 | return *defaultFont; |
|
717 | return *defaultFont; | |
718 | } |
|
718 | } | |
719 |
|
719 | |||
720 | void QChartPrivate::init() |
|
720 | void QChartPrivate::init() | |
721 | { |
|
721 | { | |
722 | m_legend = new LegendScroller(q_ptr); |
|
722 | m_legend = new LegendScroller(q_ptr); | |
723 | q_ptr->setTheme(QChart::ChartThemeLight); |
|
723 | q_ptr->setTheme(QChart::ChartThemeLight); | |
724 | q_ptr->setLayout(m_presenter->layout()); |
|
724 | q_ptr->setLayout(m_presenter->layout()); | |
725 | } |
|
725 | } | |
726 |
|
726 | |||
727 | void QChartPrivate::zoomIn(qreal factor) |
|
727 | void QChartPrivate::zoomIn(qreal factor) | |
728 | { |
|
728 | { | |
729 | QRectF rect = m_presenter->geometry(); |
|
729 | QRectF rect = m_presenter->geometry(); | |
730 | rect.setWidth(rect.width() / factor); |
|
730 | rect.setWidth(rect.width() / factor); | |
731 | rect.setHeight(rect.height() / factor); |
|
731 | rect.setHeight(rect.height() / factor); | |
732 | rect.moveCenter(m_presenter->geometry().center()); |
|
732 | rect.moveCenter(m_presenter->geometry().center()); | |
733 | zoomIn(rect); |
|
733 | zoomIn(rect); | |
734 | } |
|
734 | } | |
735 |
|
735 | |||
736 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
736 | void QChartPrivate::zoomIn(const QRectF &rect) | |
737 | { |
|
737 | { | |
738 | if (!rect.isValid()) |
|
738 | if (!rect.isValid()) | |
739 | return; |
|
739 | return; | |
740 |
|
740 | |||
741 | QRectF r = rect.normalized(); |
|
741 | QRectF r = rect.normalized(); | |
742 | const QRectF geometry = m_presenter->geometry(); |
|
742 | const QRectF geometry = m_presenter->geometry(); | |
743 | r.translate(-geometry.topLeft()); |
|
743 | r.translate(-geometry.topLeft()); | |
744 |
|
744 | |||
745 | if (!r.isValid()) |
|
745 | if (!r.isValid()) | |
746 | return; |
|
746 | return; | |
747 |
|
747 | |||
748 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
748 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
749 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
749 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); | |
750 | m_dataset->zoomInDomain(r); |
|
750 | m_dataset->zoomInDomain(r); | |
751 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
751 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
752 |
|
752 | |||
753 | } |
|
753 | } | |
754 |
|
754 | |||
755 | void QChartPrivate::zoomOut(qreal factor) |
|
755 | void QChartPrivate::zoomOut(qreal factor) | |
756 | { |
|
756 | { | |
757 | const QRectF geometry = m_presenter->geometry(); |
|
757 | const QRectF geometry = m_presenter->geometry(); | |
758 |
|
758 | |||
759 | QRectF r; |
|
759 | QRectF r; | |
760 | r.setSize(geometry.size() / factor); |
|
760 | r.setSize(geometry.size() / factor); | |
761 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
761 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); | |
762 | if (!r.isValid()) |
|
762 | if (!r.isValid()) | |
763 | return; |
|
763 | return; | |
764 |
|
764 | |||
765 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
765 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
766 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
766 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); | |
767 | m_dataset->zoomOutDomain(r); |
|
767 | m_dataset->zoomOutDomain(r); | |
768 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
768 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
769 | } |
|
769 | } | |
770 |
|
770 | |||
771 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
771 | void QChartPrivate::scroll(qreal dx, qreal dy) | |
772 | { |
|
772 | { | |
773 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
773 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); | |
774 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
774 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); | |
775 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
775 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); | |
776 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
776 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); | |
777 |
|
777 | |||
778 | m_dataset->scrollDomain(dx, dy); |
|
778 | m_dataset->scrollDomain(dx, dy); | |
779 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
779 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
780 | } |
|
780 | } | |
781 |
|
781 | |||
782 | #include "moc_qchart.cpp" |
|
782 | #include "moc_qchart.cpp" | |
783 |
|
783 | |||
784 | QTCOMMERCIALCHART_END_NAMESPACE |
|
784 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,961 +1,961 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qchartview.h> |
|
22 | #include <qchartview.h> | |
23 | #include <qlineseries.h> |
|
23 | #include <qlineseries.h> | |
24 | #include <qareaseries.h> |
|
24 | #include <qareaseries.h> | |
25 | #include <qscatterseries.h> |
|
25 | #include <qscatterseries.h> | |
26 | #include <qsplineseries.h> |
|
26 | #include <qsplineseries.h> | |
27 | #include <qpieseries.h> |
|
27 | #include <qpieseries.h> | |
28 | #include <qabstractbarseries.h> |
|
28 | #include <qabstractbarseries.h> | |
29 | #include <qbarseries.h> |
|
29 | #include <qbarseries.h> | |
30 | #include <qpercentbarseries.h> |
|
30 | #include <qpercentbarseries.h> | |
31 | #include <qstackedbarseries.h> |
|
31 | #include <qstackedbarseries.h> | |
32 | #include <qvalueaxis.h> |
|
32 | #include <qvalueaxis.h> | |
33 | #include <qbarcategoryaxis.h> |
|
33 | #include <qbarcategoryaxis.h> | |
34 | #include "tst_definitions.h" |
|
34 | #include "tst_definitions.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
36 | QTCOMMERCIALCHART_USE_NAMESPACE | |
37 |
|
37 | |||
38 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
38 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
39 | Q_DECLARE_METATYPE(QValueAxis *) |
|
39 | Q_DECLARE_METATYPE(QValueAxis *) | |
40 | Q_DECLARE_METATYPE(QBarCategoryAxis *) |
|
40 | Q_DECLARE_METATYPE(QBarCategoryAxis *) | |
41 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
41 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
42 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
42 | Q_DECLARE_METATYPE(QChart::AnimationOption) | |
43 | Q_DECLARE_METATYPE(QBrush) |
|
43 | Q_DECLARE_METATYPE(QBrush) | |
44 | Q_DECLARE_METATYPE(QPen) |
|
44 | Q_DECLARE_METATYPE(QPen) | |
45 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
45 | Q_DECLARE_METATYPE(QChart::ChartTheme) | |
46 |
|
46 | |||
47 | class tst_QChart : public QObject |
|
47 | class tst_QChart : public QObject | |
48 | { |
|
48 | { | |
49 | Q_OBJECT |
|
49 | Q_OBJECT | |
50 |
|
50 | |||
51 | public slots: |
|
51 | public slots: | |
52 | void initTestCase(); |
|
52 | void initTestCase(); | |
53 | void cleanupTestCase(); |
|
53 | void cleanupTestCase(); | |
54 | void init(); |
|
54 | void init(); | |
55 | void cleanup(); |
|
55 | void cleanup(); | |
56 |
|
56 | |||
57 | private slots: |
|
57 | private slots: | |
58 | void qchart_data(); |
|
58 | void qchart_data(); | |
59 | void qchart(); |
|
59 | void qchart(); | |
60 | void addSeries_data(); |
|
60 | void addSeries_data(); | |
61 | void addSeries(); |
|
61 | void addSeries(); | |
62 | void animationOptions_data(); |
|
62 | void animationOptions_data(); | |
63 | void animationOptions(); |
|
63 | void animationOptions(); | |
64 | void axisX_data(); |
|
64 | void axisX_data(); | |
65 | void axisX(); |
|
65 | void axisX(); | |
66 | void axisY_data(); |
|
66 | void axisY_data(); | |
67 | void axisY(); |
|
67 | void axisY(); | |
68 | void backgroundBrush_data(); |
|
68 | void backgroundBrush_data(); | |
69 | void backgroundBrush(); |
|
69 | void backgroundBrush(); | |
70 | void backgroundPen_data(); |
|
70 | void backgroundPen_data(); | |
71 | void backgroundPen(); |
|
71 | void backgroundPen(); | |
72 | void isBackgroundVisible_data(); |
|
72 | void isBackgroundVisible_data(); | |
73 | void isBackgroundVisible(); |
|
73 | void isBackgroundVisible(); | |
74 | void plotAreaBackgroundBrush_data(); |
|
74 | void plotAreaBackgroundBrush_data(); | |
75 | void plotAreaBackgroundBrush(); |
|
75 | void plotAreaBackgroundBrush(); | |
76 | void plotAreaBackgroundPen_data(); |
|
76 | void plotAreaBackgroundPen_data(); | |
77 | void plotAreaBackgroundPen(); |
|
77 | void plotAreaBackgroundPen(); | |
78 | void isPlotAreaBackgroundVisible_data(); |
|
78 | void isPlotAreaBackgroundVisible_data(); | |
79 | void isPlotAreaBackgroundVisible(); |
|
79 | void isPlotAreaBackgroundVisible(); | |
80 | void legend_data(); |
|
80 | void legend_data(); | |
81 | void legend(); |
|
81 | void legend(); | |
82 | void plotArea_data(); |
|
82 | void plotArea_data(); | |
83 | void plotArea(); |
|
83 | void plotArea(); | |
84 | void removeAllSeries_data(); |
|
84 | void removeAllSeries_data(); | |
85 | void removeAllSeries(); |
|
85 | void removeAllSeries(); | |
86 | void removeSeries_data(); |
|
86 | void removeSeries_data(); | |
87 | void removeSeries(); |
|
87 | void removeSeries(); | |
88 | void scroll_right_data(); |
|
88 | void scroll_right_data(); | |
89 | void scroll_right(); |
|
89 | void scroll_right(); | |
90 | void scroll_left_data(); |
|
90 | void scroll_left_data(); | |
91 | void scroll_left(); |
|
91 | void scroll_left(); | |
92 | void scroll_up_data(); |
|
92 | void scroll_up_data(); | |
93 | void scroll_up(); |
|
93 | void scroll_up(); | |
94 | void scroll_down_data(); |
|
94 | void scroll_down_data(); | |
95 | void scroll_down(); |
|
95 | void scroll_down(); | |
96 | void theme_data(); |
|
96 | void theme_data(); | |
97 | void theme(); |
|
97 | void theme(); | |
98 | void title_data(); |
|
98 | void title_data(); | |
99 | void title(); |
|
99 | void title(); | |
100 | void titleBrush_data(); |
|
100 | void titleBrush_data(); | |
101 | void titleBrush(); |
|
101 | void titleBrush(); | |
102 | void titleFont_data(); |
|
102 | void titleFont_data(); | |
103 | void titleFont(); |
|
103 | void titleFont(); | |
104 | void zoomIn_data(); |
|
104 | void zoomIn_data(); | |
105 | void zoomIn(); |
|
105 | void zoomIn(); | |
106 | void zoomOut_data(); |
|
106 | void zoomOut_data(); | |
107 | void zoomOut(); |
|
107 | void zoomOut(); | |
108 | void createDefaultAxesForLineSeries_data(); |
|
108 | void createDefaultAxesForLineSeries_data(); | |
109 | void createDefaultAxesForLineSeries(); |
|
109 | void createDefaultAxesForLineSeries(); | |
110 | void axisPolarOrientation(); |
|
110 | void axisPolarOrientation(); | |
111 | private: |
|
111 | private: | |
112 | void createTestData(); |
|
112 | void createTestData(); | |
113 |
|
113 | |||
114 | private: |
|
114 | private: | |
115 | QChartView* m_view; |
|
115 | QChartView* m_view; | |
116 | QChart* m_chart; |
|
116 | QChart* m_chart; | |
117 | }; |
|
117 | }; | |
118 |
|
118 | |||
119 | void tst_QChart::initTestCase() |
|
119 | void tst_QChart::initTestCase() | |
120 | { |
|
120 | { | |
121 |
|
121 | |||
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | void tst_QChart::cleanupTestCase() |
|
124 | void tst_QChart::cleanupTestCase() | |
125 | { |
|
125 | { | |
126 |
|
126 | |||
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | void tst_QChart::init() |
|
129 | void tst_QChart::init() | |
130 | { |
|
130 | { | |
131 | m_view = new QChartView(newQChartOrQPolarChart()); |
|
131 | m_view = new QChartView(newQChartOrQPolarChart()); | |
132 | m_chart = m_view->chart(); |
|
132 | m_chart = m_view->chart(); | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | void tst_QChart::cleanup() |
|
135 | void tst_QChart::cleanup() | |
136 | { |
|
136 | { | |
137 | delete m_view; |
|
137 | delete m_view; | |
138 | m_view = 0; |
|
138 | m_view = 0; | |
139 | m_chart = 0; |
|
139 | m_chart = 0; | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 |
|
142 | |||
143 | void tst_QChart::createTestData() |
|
143 | void tst_QChart::createTestData() | |
144 | { |
|
144 | { | |
145 | QLineSeries* series0 = new QLineSeries(this); |
|
145 | QLineSeries* series0 = new QLineSeries(this); | |
146 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
146 | *series0 << QPointF(0, 0) << QPointF(100, 100); | |
147 | m_chart->addSeries(series0); |
|
147 | m_chart->addSeries(series0); | |
148 | m_view->show(); |
|
148 | m_view->show(); | |
149 | QTest::qWaitForWindowShown(m_view); |
|
149 | QTest::qWaitForWindowShown(m_view); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | void tst_QChart::qchart_data() |
|
152 | void tst_QChart::qchart_data() | |
153 | { |
|
153 | { | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void tst_QChart::qchart() |
|
156 | void tst_QChart::qchart() | |
157 | { |
|
157 | { | |
158 | QVERIFY(m_chart); |
|
158 | QVERIFY(m_chart); | |
159 | QVERIFY(m_chart->legend()); |
|
159 | QVERIFY(m_chart->legend()); | |
160 | QVERIFY(m_chart->legend()->isVisible()); |
|
160 | QVERIFY(m_chart->legend()->isVisible()); | |
161 |
|
161 | |||
162 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
162 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); | |
163 | QVERIFY(!m_chart->axisX()); |
|
163 | QVERIFY(!m_chart->axisX()); | |
164 | QVERIFY(!m_chart->axisY()); |
|
164 | QVERIFY(!m_chart->axisY()); | |
165 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
165 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); | |
166 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
166 | QVERIFY(m_chart->backgroundPen()!=QPen()); | |
167 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
167 | QCOMPARE(m_chart->isBackgroundVisible(), true); | |
168 | QVERIFY(m_chart->plotArea().top()==0); |
|
168 | QVERIFY(m_chart->plotArea().top()==0); | |
169 | QVERIFY(m_chart->plotArea().left()==0); |
|
169 | QVERIFY(m_chart->plotArea().left()==0); | |
170 | QVERIFY(m_chart->plotArea().right()==0); |
|
170 | QVERIFY(m_chart->plotArea().right()==0); | |
171 | QVERIFY(m_chart->plotArea().bottom()==0); |
|
171 | QVERIFY(m_chart->plotArea().bottom()==0); | |
172 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
172 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); | |
173 | QCOMPARE(m_chart->title(), QString()); |
|
173 | QCOMPARE(m_chart->title(), QString()); | |
174 |
|
174 | |||
175 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
175 | //QCOMPARE(m_chart->titleBrush(),QBrush()); | |
176 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
176 | //QCOMPARE(m_chart->titleFont(),QFont()); | |
177 |
|
177 | |||
178 | m_chart->removeAllSeries(); |
|
178 | m_chart->removeAllSeries(); | |
179 | m_chart->scroll(0,0); |
|
179 | m_chart->scroll(0,0); | |
180 |
|
180 | |||
181 | m_chart->zoomIn(); |
|
181 | m_chart->zoomIn(); | |
182 | m_chart->zoomIn(QRectF()); |
|
182 | m_chart->zoomIn(QRectF()); | |
183 | m_chart->zoomOut(); |
|
183 | m_chart->zoomOut(); | |
184 |
|
184 | |||
185 | m_view->show(); |
|
185 | m_view->show(); | |
186 |
|
186 | |||
187 | QVERIFY(m_chart->plotArea().top()>0); |
|
187 | QVERIFY(m_chart->plotArea().top()>0); | |
188 | QVERIFY(m_chart->plotArea().left()>0); |
|
188 | QVERIFY(m_chart->plotArea().left()>0); | |
189 | QVERIFY(m_chart->plotArea().right()>0); |
|
189 | QVERIFY(m_chart->plotArea().right()>0); | |
190 | QVERIFY(m_chart->plotArea().bottom()>0); |
|
190 | QVERIFY(m_chart->plotArea().bottom()>0); | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | void tst_QChart::addSeries_data() |
|
193 | void tst_QChart::addSeries_data() | |
194 | { |
|
194 | { | |
195 | QTest::addColumn<QAbstractSeries *>("series"); |
|
195 | QTest::addColumn<QAbstractSeries *>("series"); | |
196 |
|
196 | |||
197 | QAbstractSeries* line = new QLineSeries(this); |
|
197 | QAbstractSeries* line = new QLineSeries(this); | |
198 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
198 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
199 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
199 | QAbstractSeries* scatter = new QScatterSeries(this); | |
200 | QAbstractSeries* spline = new QSplineSeries(this); |
|
200 | QAbstractSeries* spline = new QSplineSeries(this); | |
201 |
|
201 | |||
202 | QTest::newRow("lineSeries") << line; |
|
202 | QTest::newRow("lineSeries") << line; | |
203 | QTest::newRow("areaSeries") << area; |
|
203 | QTest::newRow("areaSeries") << area; | |
204 | QTest::newRow("scatterSeries") << scatter; |
|
204 | QTest::newRow("scatterSeries") << scatter; | |
205 | QTest::newRow("splineSeries") << spline; |
|
205 | QTest::newRow("splineSeries") << spline; | |
206 |
|
206 | |||
207 | if (!isPolarTest()) { |
|
207 | if (!isPolarTest()) { | |
208 | QAbstractSeries* pie = new QPieSeries(this); |
|
208 | QAbstractSeries* pie = new QPieSeries(this); | |
209 | QAbstractSeries* bar = new QBarSeries(this); |
|
209 | QAbstractSeries* bar = new QBarSeries(this); | |
210 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
210 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
211 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
211 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
212 | QTest::newRow("pieSeries") << pie; |
|
212 | QTest::newRow("pieSeries") << pie; | |
213 | QTest::newRow("barSeries") << bar; |
|
213 | QTest::newRow("barSeries") << bar; | |
214 | QTest::newRow("percentBarSeries") << percent; |
|
214 | QTest::newRow("percentBarSeries") << percent; | |
215 | QTest::newRow("stackedBarSeries") << stacked; |
|
215 | QTest::newRow("stackedBarSeries") << stacked; | |
216 | } |
|
216 | } | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | void tst_QChart::addSeries() |
|
219 | void tst_QChart::addSeries() | |
220 | { |
|
220 | { | |
221 | QFETCH(QAbstractSeries *, series); |
|
221 | QFETCH(QAbstractSeries *, series); | |
222 | m_view->show(); |
|
222 | m_view->show(); | |
223 | QTest::qWaitForWindowShown(m_view); |
|
223 | QTest::qWaitForWindowShown(m_view); | |
224 | QVERIFY(!series->chart()); |
|
224 | QVERIFY(!series->chart()); | |
225 | QCOMPARE(m_chart->series().count(), 0); |
|
225 | QCOMPARE(m_chart->series().count(), 0); | |
226 | m_chart->addSeries(series); |
|
226 | m_chart->addSeries(series); | |
227 | QCOMPARE(m_chart->series().count(), 1); |
|
227 | QCOMPARE(m_chart->series().count(), 1); | |
228 | QCOMPARE(m_chart->series().first(), series); |
|
228 | QCOMPARE(m_chart->series().first(), series); | |
229 | QVERIFY(series->chart() == m_chart); |
|
229 | QVERIFY(series->chart() == m_chart); | |
230 | m_chart->createDefaultAxes(); |
|
230 | m_chart->createDefaultAxes(); | |
231 | if(series->type()!=QAbstractSeries::SeriesTypePie){ |
|
231 | if(series->type()!=QAbstractSeries::SeriesTypePie){ | |
232 | QVERIFY(m_chart->axisY(series)); |
|
232 | QVERIFY(m_chart->axisY(series)); | |
233 | QVERIFY(m_chart->axisX(series)); |
|
233 | QVERIFY(m_chart->axisX(series)); | |
234 | }else{ |
|
234 | }else{ | |
235 | QVERIFY(!m_chart->axisY(series)); |
|
235 | QVERIFY(!m_chart->axisY(series)); | |
236 | QVERIFY(!m_chart->axisX(series)); |
|
236 | QVERIFY(!m_chart->axisX(series)); | |
237 | } |
|
237 | } | |
238 | m_chart->removeSeries(series); |
|
238 | m_chart->removeSeries(series); | |
239 | QVERIFY(!series->chart()); |
|
239 | QVERIFY(!series->chart()); | |
240 | QCOMPARE(m_chart->series().count(), 0); |
|
240 | QCOMPARE(m_chart->series().count(), 0); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | void tst_QChart::animationOptions_data() |
|
243 | void tst_QChart::animationOptions_data() | |
244 | { |
|
244 | { | |
245 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
245 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); | |
246 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
246 | QTest::newRow("AllAnimations") << QChart::AllAnimations; | |
247 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
247 | QTest::newRow("NoAnimation") << QChart::NoAnimation; | |
248 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
248 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; | |
249 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
249 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | void tst_QChart::animationOptions() |
|
252 | void tst_QChart::animationOptions() | |
253 | { |
|
253 | { | |
254 | createTestData(); |
|
254 | createTestData(); | |
255 | QFETCH(QChart::AnimationOption, animationOptions); |
|
255 | QFETCH(QChart::AnimationOption, animationOptions); | |
256 | m_chart->setAnimationOptions(animationOptions); |
|
256 | m_chart->setAnimationOptions(animationOptions); | |
257 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
257 | QCOMPARE(m_chart->animationOptions(), animationOptions); | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | void tst_QChart::axisX_data() |
|
260 | void tst_QChart::axisX_data() | |
261 | { |
|
261 | { | |
262 |
|
262 | |||
263 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
263 | QTest::addColumn<QAbstractAxis*>("axis"); | |
264 | QTest::addColumn<QAbstractSeries *>("series"); |
|
264 | QTest::addColumn<QAbstractSeries *>("series"); | |
265 |
|
265 | |||
266 | QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QLineSeries(this); |
|
266 | QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QLineSeries(this); | |
267 | QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); |
|
267 | QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); | |
268 | QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this); |
|
268 | QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this); | |
269 | QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this); |
|
269 | QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this); | |
270 | if (!isPolarTest()) { |
|
270 | if (!isPolarTest()) { | |
271 | QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this); |
|
271 | QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this); | |
272 | QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this); |
|
272 | QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this); | |
273 | QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this); |
|
273 | QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this); | |
274 | QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this); |
|
274 | QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this); | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this); |
|
277 | QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this); | |
278 | QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); |
|
278 | QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); | |
279 | QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this); |
|
279 | QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this); | |
280 | QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this); |
|
280 | QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this); | |
281 | if (!isPolarTest()) { |
|
281 | if (!isPolarTest()) { | |
282 | QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this); |
|
282 | QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this); | |
283 | QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this); |
|
283 | QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this); | |
284 | QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this); |
|
284 | QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this); | |
285 | QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this); |
|
285 | QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this); | |
286 | } |
|
286 | } | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | void tst_QChart::axisX() |
|
289 | void tst_QChart::axisX() | |
290 | { |
|
290 | { | |
291 | QFETCH(QAbstractAxis*, axis); |
|
291 | QFETCH(QAbstractAxis*, axis); | |
292 | QFETCH(QAbstractSeries*, series); |
|
292 | QFETCH(QAbstractSeries*, series); | |
293 | QVERIFY(!m_chart->axisX()); |
|
293 | QVERIFY(!m_chart->axisX()); | |
294 | m_view->show(); |
|
294 | m_view->show(); | |
295 | QTest::qWaitForWindowShown(m_view); |
|
295 | QTest::qWaitForWindowShown(m_view); | |
296 | m_chart->addSeries(series); |
|
296 | m_chart->addSeries(series); | |
297 | m_chart->setAxisX(axis,series); |
|
297 | m_chart->setAxisX(axis,series); | |
298 | QVERIFY(m_chart->axisX(series)==axis); |
|
298 | QVERIFY(m_chart->axisX(series)==axis); | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | void tst_QChart::axisY_data() |
|
301 | void tst_QChart::axisY_data() | |
302 | { |
|
302 | { | |
303 | axisX_data(); |
|
303 | axisX_data(); | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 |
|
306 | |||
307 | void tst_QChart::axisY() |
|
307 | void tst_QChart::axisY() | |
308 | { |
|
308 | { | |
309 | QFETCH(QAbstractAxis*, axis); |
|
309 | QFETCH(QAbstractAxis*, axis); | |
310 | QFETCH(QAbstractSeries*, series); |
|
310 | QFETCH(QAbstractSeries*, series); | |
311 | QVERIFY(!m_chart->axisY()); |
|
311 | QVERIFY(!m_chart->axisY()); | |
312 | m_view->show(); |
|
312 | m_view->show(); | |
313 | QTest::qWaitForWindowShown(m_view); |
|
313 | QTest::qWaitForWindowShown(m_view); | |
314 | m_chart->addSeries(series); |
|
314 | m_chart->addSeries(series); | |
315 | m_chart->setAxisY(axis,series); |
|
315 | m_chart->setAxisY(axis,series); | |
316 | QVERIFY(m_chart->axisY(series)==axis); |
|
316 | QVERIFY(m_chart->axisY(series)==axis); | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | void tst_QChart::backgroundBrush_data() |
|
319 | void tst_QChart::backgroundBrush_data() | |
320 | { |
|
320 | { | |
321 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
321 | QTest::addColumn<QBrush>("backgroundBrush"); | |
322 | QTest::newRow("null") << QBrush(); |
|
322 | QTest::newRow("null") << QBrush(); | |
323 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
323 | QTest::newRow("blue") << QBrush(Qt::blue); | |
324 | QTest::newRow("white") << QBrush(Qt::white); |
|
324 | QTest::newRow("white") << QBrush(Qt::white); | |
325 | QTest::newRow("black") << QBrush(Qt::black); |
|
325 | QTest::newRow("black") << QBrush(Qt::black); | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | void tst_QChart::backgroundBrush() |
|
328 | void tst_QChart::backgroundBrush() | |
329 | { |
|
329 | { | |
330 | QFETCH(QBrush, backgroundBrush); |
|
330 | QFETCH(QBrush, backgroundBrush); | |
331 | m_chart->setBackgroundBrush(backgroundBrush); |
|
331 | m_chart->setBackgroundBrush(backgroundBrush); | |
332 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
332 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | void tst_QChart::backgroundPen_data() |
|
335 | void tst_QChart::backgroundPen_data() | |
336 | { |
|
336 | { | |
337 | QTest::addColumn<QPen>("backgroundPen"); |
|
337 | QTest::addColumn<QPen>("backgroundPen"); | |
338 | QTest::newRow("null") << QPen(); |
|
338 | QTest::newRow("null") << QPen(); | |
339 | QTest::newRow("blue") << QPen(Qt::blue); |
|
339 | QTest::newRow("blue") << QPen(Qt::blue); | |
340 | QTest::newRow("white") << QPen(Qt::white); |
|
340 | QTest::newRow("white") << QPen(Qt::white); | |
341 | QTest::newRow("black") << QPen(Qt::black); |
|
341 | QTest::newRow("black") << QPen(Qt::black); | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 |
|
344 | |||
345 | void tst_QChart::backgroundPen() |
|
345 | void tst_QChart::backgroundPen() | |
346 | { |
|
346 | { | |
347 | QFETCH(QPen, backgroundPen); |
|
347 | QFETCH(QPen, backgroundPen); | |
348 | m_chart->setBackgroundPen(backgroundPen); |
|
348 | m_chart->setBackgroundPen(backgroundPen); | |
349 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
349 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | void tst_QChart::isBackgroundVisible_data() |
|
352 | void tst_QChart::isBackgroundVisible_data() | |
353 | { |
|
353 | { | |
354 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
354 | QTest::addColumn<bool>("isBackgroundVisible"); | |
355 | QTest::newRow("true") << true; |
|
355 | QTest::newRow("true") << true; | |
356 | QTest::newRow("false") << false; |
|
356 | QTest::newRow("false") << false; | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | void tst_QChart::isBackgroundVisible() |
|
359 | void tst_QChart::isBackgroundVisible() | |
360 | { |
|
360 | { | |
361 | QFETCH(bool, isBackgroundVisible); |
|
361 | QFETCH(bool, isBackgroundVisible); | |
362 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
362 | m_chart->setBackgroundVisible(isBackgroundVisible); | |
363 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
363 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | void tst_QChart::plotAreaBackgroundBrush_data() |
|
366 | void tst_QChart::plotAreaBackgroundBrush_data() | |
367 | { |
|
367 | { | |
368 | QTest::addColumn<QBrush>("plotAreaBackgroundBrush"); |
|
368 | QTest::addColumn<QBrush>("plotAreaBackgroundBrush"); | |
369 | QTest::newRow("null") << QBrush(); |
|
369 | QTest::newRow("null") << QBrush(); | |
370 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
370 | QTest::newRow("blue") << QBrush(Qt::blue); | |
371 | QTest::newRow("white") << QBrush(Qt::white); |
|
371 | QTest::newRow("white") << QBrush(Qt::white); | |
372 | QTest::newRow("black") << QBrush(Qt::black); |
|
372 | QTest::newRow("black") << QBrush(Qt::black); | |
373 | } |
|
373 | } | |
374 |
|
374 | |||
375 | void tst_QChart::plotAreaBackgroundBrush() |
|
375 | void tst_QChart::plotAreaBackgroundBrush() | |
376 | { |
|
376 | { | |
377 | QFETCH(QBrush, plotAreaBackgroundBrush); |
|
377 | QFETCH(QBrush, plotAreaBackgroundBrush); | |
378 | m_chart->setPlotAreaBackgroundBrush(plotAreaBackgroundBrush); |
|
378 | m_chart->setPlotAreaBackgroundBrush(plotAreaBackgroundBrush); | |
379 | QCOMPARE(m_chart->plotAreaBackgroundBrush(), plotAreaBackgroundBrush); |
|
379 | QCOMPARE(m_chart->plotAreaBackgroundBrush(), plotAreaBackgroundBrush); | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | void tst_QChart::plotAreaBackgroundPen_data() |
|
382 | void tst_QChart::plotAreaBackgroundPen_data() | |
383 | { |
|
383 | { | |
384 | QTest::addColumn<QPen>("plotAreaBackgroundPen"); |
|
384 | QTest::addColumn<QPen>("plotAreaBackgroundPen"); | |
385 | QTest::newRow("null") << QPen(); |
|
385 | QTest::newRow("null") << QPen(); | |
386 | QTest::newRow("blue") << QPen(Qt::blue); |
|
386 | QTest::newRow("blue") << QPen(Qt::blue); | |
387 | QTest::newRow("white") << QPen(Qt::white); |
|
387 | QTest::newRow("white") << QPen(Qt::white); | |
388 | QTest::newRow("black") << QPen(Qt::black); |
|
388 | QTest::newRow("black") << QPen(Qt::black); | |
389 | } |
|
389 | } | |
390 |
|
390 | |||
391 |
|
391 | |||
392 | void tst_QChart::plotAreaBackgroundPen() |
|
392 | void tst_QChart::plotAreaBackgroundPen() | |
393 | { |
|
393 | { | |
394 | QFETCH(QPen, plotAreaBackgroundPen); |
|
394 | QFETCH(QPen, plotAreaBackgroundPen); | |
395 | m_chart->setPlotAreaBackgroundPen(plotAreaBackgroundPen); |
|
395 | m_chart->setPlotAreaBackgroundPen(plotAreaBackgroundPen); | |
396 | QCOMPARE(m_chart->plotAreaBackgroundPen(), plotAreaBackgroundPen); |
|
396 | QCOMPARE(m_chart->plotAreaBackgroundPen(), plotAreaBackgroundPen); | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | void tst_QChart::isPlotAreaBackgroundVisible_data() |
|
399 | void tst_QChart::isPlotAreaBackgroundVisible_data() | |
400 | { |
|
400 | { | |
401 | QTest::addColumn<bool>("isPlotAreaBackgroundVisible"); |
|
401 | QTest::addColumn<bool>("isPlotAreaBackgroundVisible"); | |
402 | QTest::newRow("true") << true; |
|
402 | QTest::newRow("true") << true; | |
403 | QTest::newRow("false") << false; |
|
403 | QTest::newRow("false") << false; | |
404 | } |
|
404 | } | |
405 |
|
405 | |||
406 | void tst_QChart::isPlotAreaBackgroundVisible() |
|
406 | void tst_QChart::isPlotAreaBackgroundVisible() | |
407 | { |
|
407 | { | |
408 | QFETCH(bool, isPlotAreaBackgroundVisible); |
|
408 | QFETCH(bool, isPlotAreaBackgroundVisible); | |
409 | m_chart->setPlotAreaBackgroundVisible(isPlotAreaBackgroundVisible); |
|
409 | m_chart->setPlotAreaBackgroundVisible(isPlotAreaBackgroundVisible); | |
410 | QCOMPARE(m_chart->isPlotAreaBackgroundVisible(), isPlotAreaBackgroundVisible); |
|
410 | QCOMPARE(m_chart->isPlotAreaBackgroundVisible(), isPlotAreaBackgroundVisible); | |
411 | } |
|
411 | } | |
412 | void tst_QChart::legend_data() |
|
412 | void tst_QChart::legend_data() | |
413 | { |
|
413 | { | |
414 |
|
414 | |||
415 | } |
|
415 | } | |
416 |
|
416 | |||
417 | void tst_QChart::legend() |
|
417 | void tst_QChart::legend() | |
418 | { |
|
418 | { | |
419 | QLegend *legend = m_chart->legend(); |
|
419 | QLegend *legend = m_chart->legend(); | |
420 | QVERIFY(legend); |
|
420 | QVERIFY(legend); | |
421 |
|
421 | |||
422 | // Colors related signals |
|
422 | // Colors related signals | |
423 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); |
|
423 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); | |
424 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); |
|
424 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); | |
425 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); |
|
425 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); | |
426 |
|
426 | |||
427 | // colorChanged |
|
427 | // colorChanged | |
428 | legend->setColor(QColor("aliceblue")); |
|
428 | legend->setColor(QColor("aliceblue")); | |
429 | QCOMPARE(colorSpy.count(), 1); |
|
429 | QCOMPARE(colorSpy.count(), 1); | |
430 | QBrush b = legend->brush(); |
|
430 | QBrush b = legend->brush(); | |
431 | b.setColor(QColor("aqua")); |
|
431 | b.setColor(QColor("aqua")); | |
432 | legend->setBrush(b); |
|
432 | legend->setBrush(b); | |
433 | QCOMPARE(colorSpy.count(), 2); |
|
433 | QCOMPARE(colorSpy.count(), 2); | |
434 |
|
434 | |||
435 | // borderColorChanged |
|
435 | // borderColorChanged | |
436 | legend->setBorderColor(QColor("aliceblue")); |
|
436 | legend->setBorderColor(QColor("aliceblue")); | |
437 | QCOMPARE(borderColorSpy.count(), 1); |
|
437 | QCOMPARE(borderColorSpy.count(), 1); | |
438 | QPen p = legend->pen(); |
|
438 | QPen p = legend->pen(); | |
439 | p.setColor(QColor("aqua")); |
|
439 | p.setColor(QColor("aqua")); | |
440 | legend->setPen(p); |
|
440 | legend->setPen(p); | |
441 | QCOMPARE(borderColorSpy.count(), 2); |
|
441 | QCOMPARE(borderColorSpy.count(), 2); | |
442 |
|
442 | |||
443 | // labelColorChanged |
|
443 | // labelColorChanged | |
444 | legend->setLabelColor(QColor("lightsalmon")); |
|
444 | legend->setLabelColor(QColor("lightsalmon")); | |
445 | QCOMPARE(labelColorSpy.count(), 1); |
|
445 | QCOMPARE(labelColorSpy.count(), 1); | |
446 | b = legend->labelBrush(); |
|
446 | b = legend->labelBrush(); | |
447 | b.setColor(QColor("lightseagreen")); |
|
447 | b.setColor(QColor("lightseagreen")); | |
448 | legend->setLabelBrush(b); |
|
448 | legend->setLabelBrush(b); | |
449 | QCOMPARE(labelColorSpy.count(), 2); |
|
449 | QCOMPARE(labelColorSpy.count(), 2); | |
450 |
|
450 | |||
451 | // fontChanged |
|
451 | // fontChanged | |
452 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); |
|
452 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); | |
453 | QFont f = legend->font(); |
|
453 | QFont f = legend->font(); | |
454 | f.setBold(!f.bold()); |
|
454 | f.setBold(!f.bold()); | |
455 | legend->setFont(f); |
|
455 | legend->setFont(f); | |
456 | QCOMPARE(fontSpy.count(), 1); |
|
456 | QCOMPARE(fontSpy.count(), 1); | |
457 | } |
|
457 | } | |
458 |
|
458 | |||
459 | void tst_QChart::plotArea_data() |
|
459 | void tst_QChart::plotArea_data() | |
460 | { |
|
460 | { | |
461 |
|
461 | |||
462 | } |
|
462 | } | |
463 |
|
463 | |||
464 | void tst_QChart::plotArea() |
|
464 | void tst_QChart::plotArea() | |
465 | { |
|
465 | { | |
466 | createTestData(); |
|
466 | createTestData(); | |
467 | QRectF rect = m_chart->geometry(); |
|
467 | QRectF rect = m_chart->geometry(); | |
468 | QVERIFY(m_chart->plotArea().isValid()); |
|
468 | QVERIFY(m_chart->plotArea().isValid()); | |
469 | QVERIFY(m_chart->plotArea().height() < rect.height()); |
|
469 | QVERIFY(m_chart->plotArea().height() < rect.height()); | |
470 | QVERIFY(m_chart->plotArea().width() < rect.width()); |
|
470 | QVERIFY(m_chart->plotArea().width() < rect.width()); | |
471 | } |
|
471 | } | |
472 |
|
472 | |||
473 | void tst_QChart::removeAllSeries_data() |
|
473 | void tst_QChart::removeAllSeries_data() | |
474 | { |
|
474 | { | |
475 |
|
475 | |||
476 | } |
|
476 | } | |
477 |
|
477 | |||
478 | void tst_QChart::removeAllSeries() |
|
478 | void tst_QChart::removeAllSeries() | |
479 | { |
|
479 | { | |
480 | QLineSeries* series0 = new QLineSeries(this); |
|
480 | QLineSeries* series0 = new QLineSeries(this); | |
481 | QLineSeries* series1 = new QLineSeries(this); |
|
481 | QLineSeries* series1 = new QLineSeries(this); | |
482 | QLineSeries* series2 = new QLineSeries(this); |
|
482 | QLineSeries* series2 = new QLineSeries(this); | |
483 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
483 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); | |
484 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
484 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); | |
485 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
485 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); | |
486 |
|
486 | |||
487 | m_chart->addSeries(series0); |
|
487 | m_chart->addSeries(series0); | |
488 | m_chart->addSeries(series1); |
|
488 | m_chart->addSeries(series1); | |
489 | m_chart->addSeries(series2); |
|
489 | m_chart->addSeries(series2); | |
490 | m_view->show(); |
|
490 | m_view->show(); | |
491 | QTest::qWaitForWindowShown(m_view); |
|
491 | QTest::qWaitForWindowShown(m_view); | |
492 | m_chart->createDefaultAxes(); |
|
492 | m_chart->createDefaultAxes(); | |
493 | QCOMPARE(m_chart->axes().count(), 2); |
|
493 | QCOMPARE(m_chart->axes().count(), 2); | |
494 | QVERIFY(m_chart->axisY(series0)!=0); |
|
494 | QVERIFY(m_chart->axisY(series0)!=0); | |
495 | QVERIFY(m_chart->axisY(series1)!=0); |
|
495 | QVERIFY(m_chart->axisY(series1)!=0); | |
496 | QVERIFY(m_chart->axisY(series2)!=0); |
|
496 | QVERIFY(m_chart->axisY(series2)!=0); | |
497 |
|
497 | |||
498 | m_chart->removeAllSeries(); |
|
498 | m_chart->removeAllSeries(); | |
499 | QCOMPARE(m_chart->axes().count(), 2); |
|
499 | QCOMPARE(m_chart->axes().count(), 2); | |
500 | QVERIFY(m_chart->axisX() != 0); |
|
500 | QVERIFY(m_chart->axisX() != 0); | |
501 | QVERIFY(m_chart->axisY() != 0); |
|
501 | QVERIFY(m_chart->axisY() != 0); | |
502 | QCOMPARE(deleteSpy1.count(), 1); |
|
502 | QCOMPARE(deleteSpy1.count(), 1); | |
503 | QCOMPARE(deleteSpy2.count(), 1); |
|
503 | QCOMPARE(deleteSpy2.count(), 1); | |
504 | QCOMPARE(deleteSpy3.count(), 1); |
|
504 | QCOMPARE(deleteSpy3.count(), 1); | |
505 | } |
|
505 | } | |
506 |
|
506 | |||
507 | void tst_QChart::removeSeries_data() |
|
507 | void tst_QChart::removeSeries_data() | |
508 | { |
|
508 | { | |
509 | axisX_data(); |
|
509 | axisX_data(); | |
510 | } |
|
510 | } | |
511 |
|
511 | |||
512 | void tst_QChart::removeSeries() |
|
512 | void tst_QChart::removeSeries() | |
513 | { |
|
513 | { | |
514 | QFETCH(QAbstractAxis *, axis); |
|
514 | QFETCH(QAbstractAxis *, axis); | |
515 | QFETCH(QAbstractSeries *, series); |
|
515 | QFETCH(QAbstractSeries *, series); | |
516 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
516 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); | |
517 | m_view->show(); |
|
517 | m_view->show(); | |
518 | QTest::qWaitForWindowShown(m_view); |
|
518 | QTest::qWaitForWindowShown(m_view); | |
519 | if(!axis) axis = m_chart->axisY(); |
|
519 | if(!axis) axis = m_chart->axisY(); | |
520 | m_chart->addSeries(series); |
|
520 | m_chart->addSeries(series); | |
521 | m_chart->setAxisY(axis,series); |
|
521 | m_chart->setAxisY(axis,series); | |
522 | QCOMPARE(m_chart->axisY(series),axis); |
|
522 | QCOMPARE(m_chart->axisY(series),axis); | |
523 | m_chart->removeSeries(series); |
|
523 | m_chart->removeSeries(series); | |
524 | QCOMPARE(m_chart->axes().count(), 1); |
|
524 | QCOMPARE(m_chart->axes().count(), 1); | |
525 | QVERIFY(m_chart->axisY() != 0); |
|
525 | QVERIFY(m_chart->axisY() != 0); | |
526 | QVERIFY(m_chart->axisY(series)==0); |
|
526 | QVERIFY(m_chart->axisY(series)==0); | |
527 | QCOMPARE(deleteSpy.count(), 0); |
|
527 | QCOMPARE(deleteSpy.count(), 0); | |
528 | } |
|
528 | } | |
529 |
|
529 | |||
530 | void tst_QChart::scroll_right_data() |
|
530 | void tst_QChart::scroll_right_data() | |
531 | { |
|
531 | { | |
532 | QTest::addColumn<QAbstractSeries *>("series"); |
|
532 | QTest::addColumn<QAbstractSeries *>("series"); | |
533 |
|
533 | |||
534 | QLineSeries* series0 = new QLineSeries(this); |
|
534 | QLineSeries* series0 = new QLineSeries(this); | |
535 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
535 | *series0 << QPointF(0, 0) << QPointF(100, 100); | |
536 |
|
536 | |||
537 | QTest::newRow("lineSeries") << (QAbstractSeries*) series0; |
|
537 | QTest::newRow("lineSeries") << (QAbstractSeries*) series0; | |
538 |
|
538 | |||
539 |
|
539 | |||
540 | } |
|
540 | } | |
541 |
|
541 | |||
542 | void tst_QChart::scroll_right() |
|
542 | void tst_QChart::scroll_right() | |
543 | { |
|
543 | { | |
544 | QFETCH(QAbstractSeries *, series); |
|
544 | QFETCH(QAbstractSeries *, series); | |
545 | m_chart->addSeries(series); |
|
545 | m_chart->addSeries(series); | |
546 | m_chart->createDefaultAxes(); |
|
546 | m_chart->createDefaultAxes(); | |
547 | m_view->show(); |
|
547 | m_view->show(); | |
548 | QTest::qWaitForWindowShown(m_view); |
|
548 | QTest::qWaitForWindowShown(m_view); | |
549 | QAbstractAxis * axis = m_chart->axisX(); |
|
549 | QAbstractAxis * axis = m_chart->axisX(); | |
550 | QVERIFY(axis!=0); |
|
550 | QVERIFY(axis!=0); | |
551 |
|
551 | |||
552 | switch(axis->type()) |
|
552 | switch(axis->type()) | |
553 | { |
|
553 | { | |
554 | case QAbstractAxis::AxisTypeValue:{ |
|
554 | case QAbstractAxis::AxisTypeValue:{ | |
555 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
555 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | |
556 | QVERIFY(vaxis!=0); |
|
556 | QVERIFY(vaxis!=0); | |
557 | qreal min = vaxis->min(); |
|
557 | qreal min = vaxis->min(); | |
558 | qreal max = vaxis->max(); |
|
558 | qreal max = vaxis->max(); | |
559 | QVERIFY(max>min); |
|
559 | QVERIFY(max>min); | |
560 | m_chart->scroll(50, 0); |
|
560 | m_chart->scroll(50, 0); | |
561 | QVERIFY(min<vaxis->min()); |
|
561 | QVERIFY(min<vaxis->min()); | |
562 | QVERIFY(max<vaxis->max()); |
|
562 | QVERIFY(max<vaxis->max()); | |
563 | break; |
|
563 | break; | |
564 | } |
|
564 | } | |
565 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
565 | case QAbstractAxis::AxisTypeBarCategory:{ | |
566 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
566 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); | |
567 | QVERIFY(caxis!=0); |
|
567 | QVERIFY(caxis!=0); | |
568 | qreal min = caxis->min().toDouble(); |
|
568 | qreal min = caxis->min().toDouble(); | |
569 | qreal max = caxis->max().toDouble(); |
|
569 | qreal max = caxis->max().toDouble(); | |
570 | m_chart->scroll(50, 0); |
|
570 | m_chart->scroll(50, 0); | |
571 | QVERIFY(min<caxis->min().toDouble()); |
|
571 | QVERIFY(min<caxis->min().toDouble()); | |
572 | QVERIFY(max<caxis->max().toDouble()); |
|
572 | QVERIFY(max<caxis->max().toDouble()); | |
573 | break; |
|
573 | break; | |
574 | } |
|
574 | } | |
575 | default: |
|
575 | default: | |
576 | qFatal("Unsupported type"); |
|
576 | qFatal("Unsupported type"); | |
577 | break; |
|
577 | break; | |
578 | } |
|
578 | } | |
579 | } |
|
579 | } | |
580 |
|
580 | |||
581 | void tst_QChart::scroll_left_data() |
|
581 | void tst_QChart::scroll_left_data() | |
582 | { |
|
582 | { | |
583 | scroll_right_data(); |
|
583 | scroll_right_data(); | |
584 | } |
|
584 | } | |
585 |
|
585 | |||
586 | void tst_QChart::scroll_left() |
|
586 | void tst_QChart::scroll_left() | |
587 | { |
|
587 | { | |
588 | QFETCH(QAbstractSeries *, series); |
|
588 | QFETCH(QAbstractSeries *, series); | |
589 | m_chart->addSeries(series); |
|
589 | m_chart->addSeries(series); | |
590 | m_chart->createDefaultAxes(); |
|
590 | m_chart->createDefaultAxes(); | |
591 | m_view->show(); |
|
591 | m_view->show(); | |
592 | QTest::qWaitForWindowShown(m_view); |
|
592 | QTest::qWaitForWindowShown(m_view); | |
593 | QAbstractAxis * axis = m_chart->axisX(); |
|
593 | QAbstractAxis * axis = m_chart->axisX(); | |
594 | QVERIFY(axis!=0); |
|
594 | QVERIFY(axis!=0); | |
595 |
|
595 | |||
596 | switch(axis->type()) |
|
596 | switch(axis->type()) | |
597 | { |
|
597 | { | |
598 | case QAbstractAxis::AxisTypeValue:{ |
|
598 | case QAbstractAxis::AxisTypeValue:{ | |
599 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
599 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | |
600 | QVERIFY(vaxis!=0); |
|
600 | QVERIFY(vaxis!=0); | |
601 | qreal min = vaxis->min(); |
|
601 | qreal min = vaxis->min(); | |
602 | qreal max = vaxis->max(); |
|
602 | qreal max = vaxis->max(); | |
603 | m_chart->scroll(-50, 0); |
|
603 | m_chart->scroll(-50, 0); | |
604 | QVERIFY(min>vaxis->min()); |
|
604 | QVERIFY(min>vaxis->min()); | |
605 | QVERIFY(max>vaxis->max()); |
|
605 | QVERIFY(max>vaxis->max()); | |
606 | break; |
|
606 | break; | |
607 | } |
|
607 | } | |
608 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
608 | case QAbstractAxis::AxisTypeBarCategory:{ | |
609 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
609 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); | |
610 | QVERIFY(caxis!=0); |
|
610 | QVERIFY(caxis!=0); | |
611 | qreal min = caxis->min().toDouble(); |
|
611 | qreal min = caxis->min().toDouble(); | |
612 | qreal max = caxis->max().toDouble(); |
|
612 | qreal max = caxis->max().toDouble(); | |
613 | m_chart->scroll(-50, 0); |
|
613 | m_chart->scroll(-50, 0); | |
614 | QVERIFY(min>caxis->min().toDouble()); |
|
614 | QVERIFY(min>caxis->min().toDouble()); | |
615 | QVERIFY(max>caxis->max().toDouble()); |
|
615 | QVERIFY(max>caxis->max().toDouble()); | |
616 | break; |
|
616 | break; | |
617 | } |
|
617 | } | |
618 | default: |
|
618 | default: | |
619 | qFatal("Unsupported type"); |
|
619 | qFatal("Unsupported type"); | |
620 | break; |
|
620 | break; | |
621 | } |
|
621 | } | |
622 | } |
|
622 | } | |
623 |
|
623 | |||
624 | void tst_QChart::scroll_up_data() |
|
624 | void tst_QChart::scroll_up_data() | |
625 | { |
|
625 | { | |
626 | scroll_right_data(); |
|
626 | scroll_right_data(); | |
627 | } |
|
627 | } | |
628 |
|
628 | |||
629 | void tst_QChart::scroll_up() |
|
629 | void tst_QChart::scroll_up() | |
630 | { |
|
630 | { | |
631 | QFETCH(QAbstractSeries *, series); |
|
631 | QFETCH(QAbstractSeries *, series); | |
632 | m_chart->addSeries(series); |
|
632 | m_chart->addSeries(series); | |
633 | m_chart->createDefaultAxes(); |
|
633 | m_chart->createDefaultAxes(); | |
634 | m_view->show(); |
|
634 | m_view->show(); | |
635 | QTest::qWaitForWindowShown(m_view); |
|
635 | QTest::qWaitForWindowShown(m_view); | |
636 | QAbstractAxis * axis = m_chart->axisY(); |
|
636 | QAbstractAxis * axis = m_chart->axisY(); | |
637 | QVERIFY(axis!=0); |
|
637 | QVERIFY(axis!=0); | |
638 |
|
638 | |||
639 | switch(axis->type()) |
|
639 | switch(axis->type()) | |
640 | { |
|
640 | { | |
641 | case QAbstractAxis::AxisTypeValue:{ |
|
641 | case QAbstractAxis::AxisTypeValue:{ | |
642 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
642 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | |
643 | QVERIFY(vaxis!=0); |
|
643 | QVERIFY(vaxis!=0); | |
644 | qreal min = vaxis->min(); |
|
644 | qreal min = vaxis->min(); | |
645 | qreal max = vaxis->max(); |
|
645 | qreal max = vaxis->max(); | |
646 | m_chart->scroll(0, 50); |
|
646 | m_chart->scroll(0, 50); | |
647 | QVERIFY(min<vaxis->min()); |
|
647 | QVERIFY(min<vaxis->min()); | |
648 | QVERIFY(max<vaxis->max()); |
|
648 | QVERIFY(max<vaxis->max()); | |
649 | break; |
|
649 | break; | |
650 | } |
|
650 | } | |
651 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
651 | case QAbstractAxis::AxisTypeBarCategory:{ | |
652 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
652 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); | |
653 | QVERIFY(caxis!=0); |
|
653 | QVERIFY(caxis!=0); | |
654 | qreal min = caxis->min().toDouble(); |
|
654 | qreal min = caxis->min().toDouble(); | |
655 | qreal max = caxis->max().toDouble(); |
|
655 | qreal max = caxis->max().toDouble(); | |
656 | m_chart->scroll(0, 50); |
|
656 | m_chart->scroll(0, 50); | |
657 | QVERIFY(min<caxis->min().toDouble()); |
|
657 | QVERIFY(min<caxis->min().toDouble()); | |
658 | QVERIFY(max<caxis->max().toDouble()); |
|
658 | QVERIFY(max<caxis->max().toDouble()); | |
659 | break; |
|
659 | break; | |
660 | } |
|
660 | } | |
661 | default: |
|
661 | default: | |
662 | qFatal("Unsupported type"); |
|
662 | qFatal("Unsupported type"); | |
663 | break; |
|
663 | break; | |
664 | } |
|
664 | } | |
665 | } |
|
665 | } | |
666 |
|
666 | |||
667 | void tst_QChart::scroll_down_data() |
|
667 | void tst_QChart::scroll_down_data() | |
668 | { |
|
668 | { | |
669 | scroll_right_data(); |
|
669 | scroll_right_data(); | |
670 | } |
|
670 | } | |
671 |
|
671 | |||
672 | void tst_QChart::scroll_down() |
|
672 | void tst_QChart::scroll_down() | |
673 | { |
|
673 | { | |
674 | QFETCH(QAbstractSeries *, series); |
|
674 | QFETCH(QAbstractSeries *, series); | |
675 | m_chart->addSeries(series); |
|
675 | m_chart->addSeries(series); | |
676 | m_chart->createDefaultAxes(); |
|
676 | m_chart->createDefaultAxes(); | |
677 | m_view->show(); |
|
677 | m_view->show(); | |
678 | QTest::qWaitForWindowShown(m_view); |
|
678 | QTest::qWaitForWindowShown(m_view); | |
679 | QAbstractAxis * axis = m_chart->axisY(); |
|
679 | QAbstractAxis * axis = m_chart->axisY(); | |
680 | QVERIFY(axis!=0); |
|
680 | QVERIFY(axis!=0); | |
681 |
|
681 | |||
682 | switch(axis->type()) |
|
682 | switch(axis->type()) | |
683 | { |
|
683 | { | |
684 | case QAbstractAxis::AxisTypeValue:{ |
|
684 | case QAbstractAxis::AxisTypeValue:{ | |
685 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
685 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | |
686 | QVERIFY(vaxis!=0); |
|
686 | QVERIFY(vaxis!=0); | |
687 | qreal min = vaxis->min(); |
|
687 | qreal min = vaxis->min(); | |
688 | qreal max = vaxis->max(); |
|
688 | qreal max = vaxis->max(); | |
689 | m_chart->scroll(0, -50); |
|
689 | m_chart->scroll(0, -50); | |
690 | QVERIFY(min>vaxis->min()); |
|
690 | QVERIFY(min>vaxis->min()); | |
691 | QVERIFY(max>vaxis->max()); |
|
691 | QVERIFY(max>vaxis->max()); | |
692 | break; |
|
692 | break; | |
693 | } |
|
693 | } | |
694 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
694 | case QAbstractAxis::AxisTypeBarCategory:{ | |
695 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
695 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); | |
696 | QVERIFY(caxis!=0); |
|
696 | QVERIFY(caxis!=0); | |
697 | qreal min = caxis->min().toDouble(); |
|
697 | qreal min = caxis->min().toDouble(); | |
698 | qreal max = caxis->max().toDouble(); |
|
698 | qreal max = caxis->max().toDouble(); | |
699 | m_chart->scroll(0, -50); |
|
699 | m_chart->scroll(0, -50); | |
700 | QVERIFY(min>caxis->min().toDouble()); |
|
700 | QVERIFY(min>caxis->min().toDouble()); | |
701 | QVERIFY(max>caxis->max().toDouble()); |
|
701 | QVERIFY(max>caxis->max().toDouble()); | |
702 | break; |
|
702 | break; | |
703 | } |
|
703 | } | |
704 | default: |
|
704 | default: | |
705 | qFatal("Unsupported type"); |
|
705 | qFatal("Unsupported type"); | |
706 | break; |
|
706 | break; | |
707 | } |
|
707 | } | |
708 | } |
|
708 | } | |
709 |
|
709 | |||
710 | void tst_QChart::theme_data() |
|
710 | void tst_QChart::theme_data() | |
711 | { |
|
711 | { | |
712 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
712 | QTest::addColumn<QChart::ChartTheme>("theme"); | |
713 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
713 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; | |
714 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
714 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; | |
715 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
715 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; | |
716 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
716 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; | |
717 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
717 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; | |
718 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
718 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; | |
719 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
719 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; | |
720 | } |
|
720 | } | |
721 |
|
721 | |||
722 | void tst_QChart::theme() |
|
722 | void tst_QChart::theme() | |
723 | { |
|
723 | { | |
724 | QFETCH(QChart::ChartTheme, theme); |
|
724 | QFETCH(QChart::ChartTheme, theme); | |
725 | createTestData(); |
|
725 | createTestData(); | |
726 | m_chart->setTheme(theme); |
|
726 | m_chart->setTheme(theme); | |
727 | QVERIFY(m_chart->theme()==theme); |
|
727 | QVERIFY(m_chart->theme()==theme); | |
728 | } |
|
728 | } | |
729 |
|
729 | |||
730 | void tst_QChart::title_data() |
|
730 | void tst_QChart::title_data() | |
731 | { |
|
731 | { | |
732 | QTest::addColumn<QString>("title"); |
|
732 | QTest::addColumn<QString>("title"); | |
733 | QTest::newRow("null") << QString(); |
|
733 | QTest::newRow("null") << QString(); | |
734 | QTest::newRow("foo") << QString("foo"); |
|
734 | QTest::newRow("foo") << QString("foo"); | |
735 | } |
|
735 | } | |
736 |
|
736 | |||
737 | void tst_QChart::title() |
|
737 | void tst_QChart::title() | |
738 | { |
|
738 | { | |
739 | QFETCH(QString, title); |
|
739 | QFETCH(QString, title); | |
740 | m_chart->setTitle(title); |
|
740 | m_chart->setTitle(title); | |
741 | QCOMPARE(m_chart->title(), title); |
|
741 | QCOMPARE(m_chart->title(), title); | |
742 | } |
|
742 | } | |
743 |
|
743 | |||
744 | void tst_QChart::titleBrush_data() |
|
744 | void tst_QChart::titleBrush_data() | |
745 | { |
|
745 | { | |
746 | QTest::addColumn<QBrush>("titleBrush"); |
|
746 | QTest::addColumn<QBrush>("titleBrush"); | |
747 | QTest::newRow("null") << QBrush(); |
|
747 | QTest::newRow("null") << QBrush(); | |
748 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
748 | QTest::newRow("blue") << QBrush(Qt::blue); | |
749 | QTest::newRow("white") << QBrush(Qt::white); |
|
749 | QTest::newRow("white") << QBrush(Qt::white); | |
750 | QTest::newRow("black") << QBrush(Qt::black); |
|
750 | QTest::newRow("black") << QBrush(Qt::black); | |
751 | } |
|
751 | } | |
752 |
|
752 | |||
753 | void tst_QChart::titleBrush() |
|
753 | void tst_QChart::titleBrush() | |
754 | { |
|
754 | { | |
755 | QFETCH(QBrush, titleBrush); |
|
755 | QFETCH(QBrush, titleBrush); | |
756 | m_chart->setTitleBrush(titleBrush); |
|
756 | m_chart->setTitleBrush(titleBrush); | |
757 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
757 | QCOMPARE(m_chart->titleBrush().color(), titleBrush.color()); | |
758 | } |
|
758 | } | |
759 |
|
759 | |||
760 | void tst_QChart::titleFont_data() |
|
760 | void tst_QChart::titleFont_data() | |
761 | { |
|
761 | { | |
762 | QTest::addColumn<QFont>("titleFont"); |
|
762 | QTest::addColumn<QFont>("titleFont"); | |
763 | QTest::newRow("null") << QFont(); |
|
763 | QTest::newRow("null") << QFont(); | |
764 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
764 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); | |
765 | } |
|
765 | } | |
766 |
|
766 | |||
767 | void tst_QChart::titleFont() |
|
767 | void tst_QChart::titleFont() | |
768 | { |
|
768 | { | |
769 | QFETCH(QFont, titleFont); |
|
769 | QFETCH(QFont, titleFont); | |
770 | m_chart->setTitleFont(titleFont); |
|
770 | m_chart->setTitleFont(titleFont); | |
771 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
771 | QCOMPARE(m_chart->titleFont(), titleFont); | |
772 | } |
|
772 | } | |
773 |
|
773 | |||
774 | void tst_QChart::zoomIn_data() |
|
774 | void tst_QChart::zoomIn_data() | |
775 | { |
|
775 | { | |
776 | QTest::addColumn<QRectF>("rect"); |
|
776 | QTest::addColumn<QRectF>("rect"); | |
777 | QTest::newRow("null") << QRectF(); |
|
777 | QTest::newRow("null") << QRectF(); | |
778 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
778 | QTest::newRow("100x100") << QRectF(10,10,100,100); | |
779 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
779 | QTest::newRow("200x200") << QRectF(10,10,200,200); | |
780 | } |
|
780 | } | |
781 |
|
781 | |||
782 |
|
782 | |||
783 | void tst_QChart::zoomIn() |
|
783 | void tst_QChart::zoomIn() | |
784 | { |
|
784 | { | |
785 |
|
785 | |||
786 | QFETCH(QRectF, rect); |
|
786 | QFETCH(QRectF, rect); | |
787 | createTestData(); |
|
787 | createTestData(); | |
788 | m_chart->createDefaultAxes(); |
|
788 | m_chart->createDefaultAxes(); | |
789 | QRectF marigns = m_chart->plotArea(); |
|
789 | QRectF marigns = m_chart->plotArea(); | |
790 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
790 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); | |
791 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); |
|
791 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); | |
792 | QVERIFY(axisX!=0); |
|
792 | QVERIFY(axisX!=0); | |
793 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); |
|
793 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); | |
794 | QVERIFY(axisY!=0); |
|
794 | QVERIFY(axisY!=0); | |
795 | qreal minX = axisX->min(); |
|
795 | qreal minX = axisX->min(); | |
796 | qreal minY = axisY->min(); |
|
796 | qreal minY = axisY->min(); | |
797 | qreal maxX = axisX->max(); |
|
797 | qreal maxX = axisX->max(); | |
798 | qreal maxY = axisY->max(); |
|
798 | qreal maxY = axisY->max(); | |
799 | m_chart->zoomIn(rect); |
|
799 | m_chart->zoomIn(rect); | |
800 | if(rect.isValid()){ |
|
800 | if(rect.isValid()){ | |
801 | QVERIFY(minX<axisX->min()); |
|
801 | QVERIFY(minX<axisX->min()); | |
802 | QVERIFY(maxX>axisX->max()); |
|
802 | QVERIFY(maxX>axisX->max()); | |
803 | QVERIFY(minY<axisY->min()); |
|
803 | QVERIFY(minY<axisY->min()); | |
804 | QVERIFY(maxY>axisY->max()); |
|
804 | QVERIFY(maxY>axisY->max()); | |
805 | } |
|
805 | } | |
806 |
|
806 | |||
807 | } |
|
807 | } | |
808 |
|
808 | |||
809 | void tst_QChart::zoomOut_data() |
|
809 | void tst_QChart::zoomOut_data() | |
810 | { |
|
810 | { | |
811 |
|
811 | |||
812 | } |
|
812 | } | |
813 |
|
813 | |||
814 | void tst_QChart::zoomOut() |
|
814 | void tst_QChart::zoomOut() | |
815 | { |
|
815 | { | |
816 | createTestData(); |
|
816 | createTestData(); | |
817 | m_chart->createDefaultAxes(); |
|
817 | m_chart->createDefaultAxes(); | |
818 |
|
818 | |||
819 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); |
|
819 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); | |
820 | QVERIFY(axisX!=0); |
|
820 | QVERIFY(axisX!=0); | |
821 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); |
|
821 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); | |
822 | QVERIFY(axisY!=0); |
|
822 | QVERIFY(axisY!=0); | |
823 |
|
823 | |||
824 | qreal minX = axisX->min(); |
|
824 | qreal minX = axisX->min(); | |
825 | qreal minY = axisY->min(); |
|
825 | qreal minY = axisY->min(); | |
826 | qreal maxX = axisX->max(); |
|
826 | qreal maxX = axisX->max(); | |
827 | qreal maxY = axisY->max(); |
|
827 | qreal maxY = axisY->max(); | |
828 |
|
828 | |||
829 | m_chart->zoomIn(); |
|
829 | m_chart->zoomIn(); | |
830 |
|
830 | |||
831 | QVERIFY(minX < axisX->min()); |
|
831 | QVERIFY(minX < axisX->min()); | |
832 | QVERIFY(maxX > axisX->max()); |
|
832 | QVERIFY(maxX > axisX->max()); | |
833 | QVERIFY(minY < axisY->min()); |
|
833 | QVERIFY(minY < axisY->min()); | |
834 | QVERIFY(maxY > axisY->max()); |
|
834 | QVERIFY(maxY > axisY->max()); | |
835 |
|
835 | |||
836 | m_chart->zoomOut(); |
|
836 | m_chart->zoomOut(); | |
837 |
|
837 | |||
838 | // min x may be a zero value |
|
838 | // min x may be a zero value | |
839 | if (qFuzzyIsNull(minX)) |
|
839 | if (qFuzzyIsNull(minX)) | |
840 | QVERIFY(qFuzzyIsNull(axisX->min())); |
|
840 | QVERIFY(qFuzzyIsNull(axisX->min())); | |
841 | else |
|
841 | else | |
842 | QCOMPARE(minX, axisX->min()); |
|
842 | QCOMPARE(minX, axisX->min()); | |
843 |
|
843 | |||
844 | // min y may be a zero value |
|
844 | // min y may be a zero value | |
845 | if (qFuzzyIsNull(minY)) |
|
845 | if (qFuzzyIsNull(minY)) | |
846 | QVERIFY(qFuzzyIsNull(axisY->min())); |
|
846 | QVERIFY(qFuzzyIsNull(axisY->min())); | |
847 | else |
|
847 | else | |
848 | QCOMPARE(minY, axisY->min()); |
|
848 | QCOMPARE(minY, axisY->min()); | |
849 |
|
849 | |||
850 | QVERIFY(maxX == axisX->max()); |
|
850 | QVERIFY(maxX == axisX->max()); | |
851 | QVERIFY(maxY == axisY->max()); |
|
851 | QVERIFY(maxY == axisY->max()); | |
852 |
|
852 | |||
853 | } |
|
853 | } | |
854 |
|
854 | |||
855 | void tst_QChart::createDefaultAxesForLineSeries_data() |
|
855 | void tst_QChart::createDefaultAxesForLineSeries_data() | |
856 | { |
|
856 | { | |
857 | QTest::addColumn<qreal>("series1minX"); |
|
857 | QTest::addColumn<qreal>("series1minX"); | |
858 | QTest::addColumn<qreal>("series1midX"); |
|
858 | QTest::addColumn<qreal>("series1midX"); | |
859 | QTest::addColumn<qreal>("series1maxX"); |
|
859 | QTest::addColumn<qreal>("series1maxX"); | |
860 | QTest::addColumn<qreal>("series2minX"); |
|
860 | QTest::addColumn<qreal>("series2minX"); | |
861 | QTest::addColumn<qreal>("series2midX"); |
|
861 | QTest::addColumn<qreal>("series2midX"); | |
862 | QTest::addColumn<qreal>("series2maxX"); |
|
862 | QTest::addColumn<qreal>("series2maxX"); | |
863 | QTest::addColumn<qreal>("overallminX"); |
|
863 | QTest::addColumn<qreal>("overallminX"); | |
864 | QTest::addColumn<qreal>("overallmaxX"); |
|
864 | QTest::addColumn<qreal>("overallmaxX"); | |
865 | QTest::addColumn<qreal>("series1minY"); |
|
865 | QTest::addColumn<qreal>("series1minY"); | |
866 | QTest::addColumn<qreal>("series1midY"); |
|
866 | QTest::addColumn<qreal>("series1midY"); | |
867 | QTest::addColumn<qreal>("series1maxY"); |
|
867 | QTest::addColumn<qreal>("series1maxY"); | |
868 | QTest::addColumn<qreal>("series2minY"); |
|
868 | QTest::addColumn<qreal>("series2minY"); | |
869 | QTest::addColumn<qreal>("series2midY"); |
|
869 | QTest::addColumn<qreal>("series2midY"); | |
870 | QTest::addColumn<qreal>("series2maxY"); |
|
870 | QTest::addColumn<qreal>("series2maxY"); | |
871 | QTest::addColumn<qreal>("overallminY"); |
|
871 | QTest::addColumn<qreal>("overallminY"); | |
872 | QTest::addColumn<qreal>("overallmaxY"); |
|
872 | QTest::addColumn<qreal>("overallmaxY"); | |
873 | QTest::newRow("series1hasMinAndMax") << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0 |
|
873 | QTest::newRow("series1hasMinAndMax") << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0 | |
874 | << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0; |
|
874 | << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0; | |
875 | QTest::newRow("series2hasMinAndMax") << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 |
|
875 | QTest::newRow("series2hasMinAndMax") << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 | |
876 | << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; |
|
876 | << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; | |
877 | QTest::newRow("series1hasMinAndMaxX_series2hasMinAndMaxY") << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0 |
|
877 | QTest::newRow("series1hasMinAndMaxX_series2hasMinAndMaxY") << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0 | |
878 | << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; |
|
878 | << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; | |
879 | QTest::newRow("series1hasMin_series2hasMax") << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 |
|
879 | QTest::newRow("series1hasMin_series2hasMax") << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 | |
880 | << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; |
|
880 | << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; | |
881 | QTest::newRow("bothSeriesHaveSameMinAndMax") << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 |
|
881 | QTest::newRow("bothSeriesHaveSameMinAndMax") << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 | |
882 | << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)0.6 << (qreal)1.6; |
|
882 | << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)0.6 << (qreal)1.6; | |
883 | } |
|
883 | } | |
884 |
|
884 | |||
885 | void tst_QChart::createDefaultAxesForLineSeries() |
|
885 | void tst_QChart::createDefaultAxesForLineSeries() | |
886 | { |
|
886 | { | |
887 | QFETCH(qreal, series1minX); |
|
887 | QFETCH(qreal, series1minX); | |
888 | QFETCH(qreal, series1midX); |
|
888 | QFETCH(qreal, series1midX); | |
889 | QFETCH(qreal, series1maxX); |
|
889 | QFETCH(qreal, series1maxX); | |
890 | QFETCH(qreal, series2minX); |
|
890 | QFETCH(qreal, series2minX); | |
891 | QFETCH(qreal, series2midX); |
|
891 | QFETCH(qreal, series2midX); | |
892 | QFETCH(qreal, series2maxX); |
|
892 | QFETCH(qreal, series2maxX); | |
893 | QFETCH(qreal, series1minY); |
|
893 | QFETCH(qreal, series1minY); | |
894 | QFETCH(qreal, series1midY); |
|
894 | QFETCH(qreal, series1midY); | |
895 | QFETCH(qreal, series1maxY); |
|
895 | QFETCH(qreal, series1maxY); | |
896 | QFETCH(qreal, series2minY); |
|
896 | QFETCH(qreal, series2minY); | |
897 | QFETCH(qreal, series2midY); |
|
897 | QFETCH(qreal, series2midY); | |
898 | QFETCH(qreal, series2maxY); |
|
898 | QFETCH(qreal, series2maxY); | |
899 | QFETCH(qreal, overallminX); |
|
899 | QFETCH(qreal, overallminX); | |
900 | QFETCH(qreal, overallmaxX); |
|
900 | QFETCH(qreal, overallmaxX); | |
901 | QFETCH(qreal, overallminY); |
|
901 | QFETCH(qreal, overallminY); | |
902 | QFETCH(qreal, overallmaxY); |
|
902 | QFETCH(qreal, overallmaxY); | |
903 | QLineSeries* series1 = new QLineSeries(this); |
|
903 | QLineSeries* series1 = new QLineSeries(this); | |
904 | series1->append(series1minX, series1minY); |
|
904 | series1->append(series1minX, series1minY); | |
905 | series1->append(series1midX, series1midY); |
|
905 | series1->append(series1midX, series1midY); | |
906 | series1->append(series1maxX, series1maxY); |
|
906 | series1->append(series1maxX, series1maxY); | |
907 | QLineSeries* series2 = new QLineSeries(this); |
|
907 | QLineSeries* series2 = new QLineSeries(this); | |
908 | series2->append(series2minX, series2minY); |
|
908 | series2->append(series2minX, series2minY); | |
909 | series2->append(series2midX, series2midY); |
|
909 | series2->append(series2midX, series2midY); | |
910 | series2->append(series2maxX, series2maxY); |
|
910 | series2->append(series2maxX, series2maxY); | |
911 | QChart *chart = newQChartOrQPolarChart(); |
|
911 | QChart *chart = newQChartOrQPolarChart(); | |
912 | chart->addSeries(series1); |
|
912 | chart->addSeries(series1); | |
913 | chart->addSeries(series2); |
|
913 | chart->addSeries(series2); | |
914 | chart->createDefaultAxes(); |
|
914 | chart->createDefaultAxes(); | |
915 | QValueAxis *xAxis = (QValueAxis *)chart->axisX(); |
|
915 | QValueAxis *xAxis = (QValueAxis *)chart->axisX(); | |
916 | QCOMPARE(xAxis->min(), overallminX); |
|
916 | QCOMPARE(xAxis->min(), overallminX); | |
917 | QCOMPARE(xAxis->max(), overallmaxX); |
|
917 | QCOMPARE(xAxis->max(), overallmaxX); | |
918 | QValueAxis *yAxis = (QValueAxis *)chart->axisY(); |
|
918 | QValueAxis *yAxis = (QValueAxis *)chart->axisY(); | |
919 | QCOMPARE(yAxis->min(), overallminY); |
|
919 | QCOMPARE(yAxis->min(), overallminY); | |
920 | QCOMPARE(yAxis->max(), overallmaxY); |
|
920 | QCOMPARE(yAxis->max(), overallmaxY); | |
921 | QLineSeries *series3 = new QLineSeries(this); |
|
921 | QLineSeries *series3 = new QLineSeries(this); | |
922 | // Numbers clearly out of existing range |
|
922 | // Numbers clearly out of existing range | |
923 | series3->append(0, 0); |
|
923 | series3->append(0, 0); | |
924 | series3->append(100, 100); |
|
924 | series3->append(100, 100); | |
925 | // Adding a new series should not change the axes as they have not been told to update |
|
925 | // Adding a new series should not change the axes as they have not been told to update | |
926 | chart->addSeries(series3); |
|
926 | chart->addSeries(series3); | |
927 | QCOMPARE(xAxis->min(), overallminX); |
|
927 | QCOMPARE(xAxis->min(), overallminX); | |
928 | QCOMPARE(xAxis->max(), overallmaxX); |
|
928 | QCOMPARE(xAxis->max(), overallmaxX); | |
929 | QCOMPARE(yAxis->min(), overallminY); |
|
929 | QCOMPARE(yAxis->min(), overallminY); | |
930 | QCOMPARE(yAxis->max(), overallmaxY); |
|
930 | QCOMPARE(yAxis->max(), overallmaxY); | |
931 | } |
|
931 | } | |
932 |
|
932 | |||
933 | void tst_QChart::axisPolarOrientation() |
|
933 | void tst_QChart::axisPolarOrientation() | |
934 | { |
|
934 | { | |
935 | QLineSeries* series1 = new QLineSeries(this); |
|
935 | QLineSeries* series1 = new QLineSeries(this); | |
936 | series1->append(1, 2); |
|
936 | series1->append(1, 2); | |
937 | series1->append(2, 4); |
|
937 | series1->append(2, 4); | |
938 | series1->append(3, 8); |
|
938 | series1->append(3, 8); | |
939 | QPolarChart chart; |
|
939 | QPolarChart chart; | |
940 | chart.addSeries(series1); |
|
940 | chart.addSeries(series1); | |
941 |
|
941 | |||
942 | QValueAxis *xAxis = new QValueAxis(); |
|
942 | QValueAxis *xAxis = new QValueAxis(); | |
943 | QValueAxis *yAxis = new QValueAxis(); |
|
943 | QValueAxis *yAxis = new QValueAxis(); | |
944 | chart.addAxis(xAxis, QPolarChart::PolarOrientationAngular); |
|
944 | chart.addAxis(xAxis, QPolarChart::PolarOrientationAngular); | |
945 | chart.addAxis(yAxis, QPolarChart::PolarOrientationRadial); |
|
945 | chart.addAxis(yAxis, QPolarChart::PolarOrientationRadial); | |
946 |
|
946 | |||
947 | QList<QAbstractAxis *> xAxes = chart.axes(QPolarChart::PolarOrientationAngular); |
|
947 | QList<QAbstractAxis *> xAxes = chart.axes(QPolarChart::PolarOrientationAngular); | |
948 | QList<QAbstractAxis *> yAxes = chart.axes(QPolarChart::PolarOrientationRadial); |
|
948 | QList<QAbstractAxis *> yAxes = chart.axes(QPolarChart::PolarOrientationRadial); | |
949 |
|
949 | |||
950 | QCOMPARE(xAxes.size(), 1); |
|
950 | QCOMPARE(xAxes.size(), 1); | |
951 | QCOMPARE(yAxes.size(), 1); |
|
951 | QCOMPARE(yAxes.size(), 1); | |
952 | QCOMPARE(xAxes[0], xAxis); |
|
952 | QCOMPARE(xAxes[0], xAxis); | |
953 | QCOMPARE(yAxes[0], yAxis); |
|
953 | QCOMPARE(yAxes[0], yAxis); | |
954 |
|
954 | |||
955 | QCOMPARE(chart.axisPolarOrientation(xAxes[0]), QPolarChart::PolarOrientationAngular); |
|
955 | QCOMPARE(chart.axisPolarOrientation(xAxes[0]), QPolarChart::PolarOrientationAngular); | |
956 | QCOMPARE(chart.axisPolarOrientation(yAxes[0]), QPolarChart::PolarOrientationRadial); |
|
956 | QCOMPARE(chart.axisPolarOrientation(yAxes[0]), QPolarChart::PolarOrientationRadial); | |
957 | } |
|
957 | } | |
958 |
|
958 | |||
959 | QTEST_MAIN(tst_QChart) |
|
959 | QTEST_MAIN(tst_QChart) | |
960 | #include "tst_qchart.moc" |
|
960 | #include "tst_qchart.moc" | |
961 |
|
961 |
General Comments 0
You need to be logged in to leave comments.
Login now