@@ -1,140 +1,134 | |||||
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 "axisanimation_p.h" |
|
21 | #include "axisanimation_p.h" | |
22 | #include "chartaxis_p.h" |
|
22 | #include "chartaxis_p.h" | |
23 |
|
23 | |||
24 | Q_DECLARE_METATYPE(QVector<qreal>) |
|
24 | Q_DECLARE_METATYPE(QVector<qreal>) | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | AxisAnimation::AxisAnimation(ChartAxis *axis) |
|
29 | AxisAnimation::AxisAnimation(ChartAxis *axis) | |
30 | : ChartAnimation(axis), |
|
30 | : ChartAnimation(axis), | |
31 | m_axis(axis), |
|
31 | m_axis(axis), | |
32 | m_type(DefaultAnimation) |
|
32 | m_type(DefaultAnimation) | |
33 | { |
|
33 | { | |
34 | setDuration(ChartAnimationDuration); |
|
34 | setDuration(ChartAnimationDuration); | |
35 | setEasingCurve(QEasingCurve::OutQuart); |
|
35 | setEasingCurve(QEasingCurve::OutQuart); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | AxisAnimation::~AxisAnimation() |
|
38 | AxisAnimation::~AxisAnimation() | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | void AxisAnimation::setAnimationType(Animation type) |
|
42 | void AxisAnimation::setAnimationType(Animation type) | |
43 | { |
|
43 | { | |
44 | if (state() != QAbstractAnimation::Stopped) |
|
44 | if (state() != QAbstractAnimation::Stopped) | |
45 | stop(); |
|
45 | stop(); | |
46 | m_type = type; |
|
46 | m_type = type; | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | void AxisAnimation::setAnimationPoint(const QPointF &point) |
|
49 | void AxisAnimation::setAnimationPoint(const QPointF &point) | |
50 | { |
|
50 | { | |
51 | if (state() != QAbstractAnimation::Stopped) |
|
51 | if (state() != QAbstractAnimation::Stopped) | |
52 | stop(); |
|
52 | stop(); | |
53 | m_point = point; |
|
53 | m_point = point; | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout) |
|
56 | void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout) | |
57 | { |
|
57 | { | |
58 | if (state() != QAbstractAnimation::Stopped) stop(); |
|
58 | if (state() != QAbstractAnimation::Stopped) stop(); | |
59 |
|
59 | |||
60 | // TODO: cannot return even if layout is empty |
|
|||
61 | // New layout is not set properly without it (crash) |
|
|||
62 | // if (newLayout.count() == 0) |
|
|||
63 | // return; |
|
|||
64 |
|
||||
65 | switch (m_type) { |
|
60 | switch (m_type) { | |
66 | case ZoomOutAnimation: { |
|
61 | case ZoomOutAnimation: { | |
67 | QRectF rect = m_axis->gridGeometry(); |
|
62 | QRectF rect = m_axis->gridGeometry(); | |
68 | oldLayout.resize(newLayout.count()); |
|
63 | oldLayout.resize(newLayout.count()); | |
69 |
|
64 | |||
70 | for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) { |
|
65 | for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) { | |
71 | oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.bottom(); |
|
66 | oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.bottom(); | |
72 | oldLayout[j] = m_axis->orientation() == Qt::Horizontal ? rect.right() : rect.top(); |
|
67 | oldLayout[j] = m_axis->orientation() == Qt::Horizontal ? rect.right() : rect.top(); | |
73 | } |
|
68 | } | |
74 | } |
|
69 | } | |
75 | break; |
|
70 | break; | |
76 | case ZoomInAnimation: { |
|
71 | case ZoomInAnimation: { | |
77 | int index = qMin(oldLayout.count() * (m_axis->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0); |
|
72 | int index = qMin(oldLayout.count() * (m_axis->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0); | |
78 | oldLayout.resize(newLayout.count()); |
|
73 | oldLayout.resize(newLayout.count()); | |
79 |
|
74 | |||
80 | for (int i = 0; i < oldLayout.count(); i++) |
|
75 | for (int i = 0; i < oldLayout.count(); i++) | |
81 | oldLayout[i] = oldLayout[index]; |
|
76 | oldLayout[i] = oldLayout[index]; | |
82 | } |
|
77 | } | |
83 | break; |
|
78 | break; | |
84 | case MoveForwardAnimation: { |
|
79 | case MoveForwardAnimation: { | |
85 | oldLayout.resize(newLayout.count()); |
|
80 | oldLayout.resize(newLayout.count()); | |
86 |
|
81 | |||
87 | for (int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j) |
|
82 | for (int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j) | |
88 | oldLayout[i] = oldLayout[j]; |
|
83 | oldLayout[i] = oldLayout[j]; | |
89 | } |
|
84 | } | |
90 | break; |
|
85 | break; | |
91 | case MoveBackwordAnimation: { |
|
86 | case MoveBackwordAnimation: { | |
92 | oldLayout.resize(newLayout.count()); |
|
87 | oldLayout.resize(newLayout.count()); | |
93 |
|
88 | |||
94 | for (int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j) |
|
89 | for (int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j) | |
95 | oldLayout[i] = oldLayout[j]; |
|
90 | oldLayout[i] = oldLayout[j]; | |
96 | } |
|
91 | } | |
97 | break; |
|
92 | break; | |
98 | default: { |
|
93 | default: { | |
99 | oldLayout.resize(newLayout.count()); |
|
94 | oldLayout.resize(newLayout.count()); | |
100 | QRectF rect = m_axis->gridGeometry(); |
|
95 | QRectF rect = m_axis->gridGeometry(); | |
101 | for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j) |
|
96 | for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j) | |
102 | oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.top(); |
|
97 | oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.top(); | |
103 | } |
|
98 | } | |
104 | break; |
|
99 | break; | |
105 | } |
|
100 | } | |
106 |
|
101 | |||
107 | QVariantAnimation::KeyValues value; |
|
102 | QVariantAnimation::KeyValues value; | |
108 | setKeyValues(value); //workaround for wrong interpolation call |
|
103 | setKeyValues(value); //workaround for wrong interpolation call | |
109 | setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
104 | setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |
110 | setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
105 | setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |
111 | } |
|
106 | } | |
112 |
|
107 | |||
113 | QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const |
|
108 | QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const | |
114 | { |
|
109 | { | |
115 | QVector<qreal> startVector = qvariant_cast<QVector<qreal> >(start); |
|
110 | QVector<qreal> startVector = qvariant_cast<QVector<qreal> >(start); | |
116 | QVector<qreal> endVecotr = qvariant_cast<QVector<qreal> >(end); |
|
111 | QVector<qreal> endVecotr = qvariant_cast<QVector<qreal> >(end); | |
117 | QVector<qreal> result; |
|
112 | QVector<qreal> result; | |
118 |
|
113 | |||
119 | Q_ASSERT(startVector.count() == endVecotr.count()) ; |
|
114 | Q_ASSERT(startVector.count() == endVecotr.count()) ; | |
120 |
|
115 | |||
121 | for (int i = 0; i < startVector.count(); i++) { |
|
116 | for (int i = 0; i < startVector.count(); i++) { | |
122 | qreal value = startVector[i] + ((endVecotr[i] - startVector[i]) * progress); //qBound(0.0, progress, 1.0)); |
|
117 | qreal value = startVector[i] + ((endVecotr[i] - startVector[i]) * progress); //qBound(0.0, progress, 1.0)); | |
123 | result << value; |
|
118 | result << value; | |
124 | } |
|
119 | } | |
125 | return qVariantFromValue(result); |
|
120 | return qVariantFromValue(result); | |
126 | } |
|
121 | } | |
127 |
|
122 | |||
128 |
|
123 | |||
129 | void AxisAnimation::updateCurrentValue(const QVariant &value) |
|
124 | void AxisAnimation::updateCurrentValue(const QVariant &value) | |
130 | { |
|
125 | { | |
131 | if (state() != QAbstractAnimation::Stopped) { //workaround |
|
126 | if (state() != QAbstractAnimation::Stopped) { //workaround | |
132 | QVector<qreal> vector = qvariant_cast<QVector<qreal> >(value); |
|
127 | QVector<qreal> vector = qvariant_cast<QVector<qreal> >(value); | |
133 | // Q_ASSERT(vector.count() != 0); |
|
|||
134 | m_axis->setLayout(vector); |
|
128 | m_axis->setLayout(vector); | |
135 | m_axis->updateGeometry(); |
|
129 | m_axis->updateGeometry(); | |
136 | } |
|
130 | } | |
137 |
|
131 | |||
138 | } |
|
132 | } | |
139 |
|
133 | |||
140 | QTCOMMERCIALCHART_END_NAMESPACE |
|
134 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,173 +1,171 | |||||
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 "areachartitem_p.h" |
|
21 | #include "areachartitem_p.h" | |
22 | #include "qareaseries.h" |
|
22 | #include "qareaseries.h" | |
23 | #include "qareaseries_p.h" |
|
23 | #include "qareaseries_p.h" | |
24 | #include "qlineseries.h" |
|
24 | #include "qlineseries.h" | |
25 | #include "chartpresenter_p.h" |
|
25 | #include "chartpresenter_p.h" | |
26 | #include "abstractdomain_p.h" |
|
26 | #include "abstractdomain_p.h" | |
27 | #include <QPainter> |
|
27 | #include <QPainter> | |
28 | #include <QGraphicsSceneMouseEvent> |
|
28 | #include <QGraphicsSceneMouseEvent> | |
29 | #include <QDebug> |
|
29 | #include <QDebug> | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | //TODO: optimize : remove points which are not visible |
|
|||
35 |
|
||||
36 | AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item) |
|
34 | AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item) | |
37 | : ChartItem(areaSeries->d_func(),item), |
|
35 | : ChartItem(areaSeries->d_func(),item), | |
38 | m_series(areaSeries), |
|
36 | m_series(areaSeries), | |
39 | m_upper(0), |
|
37 | m_upper(0), | |
40 | m_lower(0), |
|
38 | m_lower(0), | |
41 | m_pointsVisible(false) |
|
39 | m_pointsVisible(false) | |
42 | { |
|
40 | { | |
43 | setAcceptHoverEvents(true); |
|
41 | setAcceptHoverEvents(true); | |
44 | setZValue(ChartPresenter::LineChartZValue); |
|
42 | setZValue(ChartPresenter::LineChartZValue); | |
45 | m_upper = new AreaBoundItem(this, m_series->upperSeries()); |
|
43 | m_upper = new AreaBoundItem(this, m_series->upperSeries()); | |
46 | if (m_series->lowerSeries()) |
|
44 | if (m_series->lowerSeries()) | |
47 | m_lower = new AreaBoundItem(this, m_series->lowerSeries()); |
|
45 | m_lower = new AreaBoundItem(this, m_series->lowerSeries()); | |
48 |
|
46 | |||
49 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated())); |
|
47 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated())); | |
50 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); |
|
48 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |
51 | QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); |
|
49 | QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); | |
52 | QObject::connect(this, SIGNAL(clicked(QPointF)), areaSeries, SIGNAL(clicked(QPointF))); |
|
50 | QObject::connect(this, SIGNAL(clicked(QPointF)), areaSeries, SIGNAL(clicked(QPointF))); | |
53 | QObject::connect(this, SIGNAL(hovered(QPointF,bool)), areaSeries, SIGNAL(hovered(QPointF,bool))); |
|
51 | QObject::connect(this, SIGNAL(hovered(QPointF,bool)), areaSeries, SIGNAL(hovered(QPointF,bool))); | |
54 |
|
52 | |||
55 | handleUpdated(); |
|
53 | handleUpdated(); | |
56 | } |
|
54 | } | |
57 |
|
55 | |||
58 | AreaChartItem::~AreaChartItem() |
|
56 | AreaChartItem::~AreaChartItem() | |
59 | { |
|
57 | { | |
60 | delete m_upper; |
|
58 | delete m_upper; | |
61 | delete m_lower; |
|
59 | delete m_lower; | |
62 | } |
|
60 | } | |
63 |
|
61 | |||
64 | void AreaChartItem::setPresenter(ChartPresenter *presenter) |
|
62 | void AreaChartItem::setPresenter(ChartPresenter *presenter) | |
65 | { |
|
63 | { | |
66 | m_upper->setPresenter(presenter); |
|
64 | m_upper->setPresenter(presenter); | |
67 | if (m_lower) { |
|
65 | if (m_lower) { | |
68 | m_lower->setPresenter(presenter); |
|
66 | m_lower->setPresenter(presenter); | |
69 | } |
|
67 | } | |
70 | ChartItem::setPresenter(presenter); |
|
68 | ChartItem::setPresenter(presenter); | |
71 | } |
|
69 | } | |
72 |
|
70 | |||
73 | QRectF AreaChartItem::boundingRect() const |
|
71 | QRectF AreaChartItem::boundingRect() const | |
74 | { |
|
72 | { | |
75 | return m_rect; |
|
73 | return m_rect; | |
76 | } |
|
74 | } | |
77 |
|
75 | |||
78 | QPainterPath AreaChartItem::shape() const |
|
76 | QPainterPath AreaChartItem::shape() const | |
79 | { |
|
77 | { | |
80 | return m_path; |
|
78 | return m_path; | |
81 | } |
|
79 | } | |
82 |
|
80 | |||
83 | void AreaChartItem::updatePath() |
|
81 | void AreaChartItem::updatePath() | |
84 | { |
|
82 | { | |
85 | QPainterPath path; |
|
83 | QPainterPath path; | |
86 | QRectF rect(QPointF(0,0),domain()->size()); |
|
84 | QRectF rect(QPointF(0,0),domain()->size()); | |
87 |
|
85 | |||
88 | path = m_upper->path(); |
|
86 | path = m_upper->path(); | |
89 |
|
87 | |||
90 | if (m_lower) { |
|
88 | if (m_lower) { | |
91 | path.connectPath(m_lower->path().toReversed()); |
|
89 | path.connectPath(m_lower->path().toReversed()); | |
92 | } else { |
|
90 | } else { | |
93 | QPointF first = path.pointAtPercent(0); |
|
91 | QPointF first = path.pointAtPercent(0); | |
94 | QPointF last = path.pointAtPercent(1); |
|
92 | QPointF last = path.pointAtPercent(1); | |
95 | path.lineTo(last.x(), rect.bottom()); |
|
93 | path.lineTo(last.x(), rect.bottom()); | |
96 | path.lineTo(first.x(), rect.bottom()); |
|
94 | path.lineTo(first.x(), rect.bottom()); | |
97 | } |
|
95 | } | |
98 | path.closeSubpath(); |
|
96 | path.closeSubpath(); | |
99 | prepareGeometryChange(); |
|
97 | prepareGeometryChange(); | |
100 | m_path = path; |
|
98 | m_path = path; | |
101 | m_rect = path.boundingRect(); |
|
99 | m_rect = path.boundingRect(); | |
102 | update(); |
|
100 | update(); | |
103 | } |
|
101 | } | |
104 |
|
102 | |||
105 | void AreaChartItem::handleUpdated() |
|
103 | void AreaChartItem::handleUpdated() | |
106 | { |
|
104 | { | |
107 | setVisible(m_series->isVisible()); |
|
105 | setVisible(m_series->isVisible()); | |
108 | m_pointsVisible = m_series->pointsVisible(); |
|
106 | m_pointsVisible = m_series->pointsVisible(); | |
109 | m_linePen = m_series->pen(); |
|
107 | m_linePen = m_series->pen(); | |
110 | m_brush = m_series->brush(); |
|
108 | m_brush = m_series->brush(); | |
111 | m_pointPen = m_series->pen(); |
|
109 | m_pointPen = m_series->pen(); | |
112 | m_pointPen.setWidthF(2 * m_pointPen.width()); |
|
110 | m_pointPen.setWidthF(2 * m_pointPen.width()); | |
113 | setOpacity(m_series->opacity()); |
|
111 | setOpacity(m_series->opacity()); | |
114 | update(); |
|
112 | update(); | |
115 | } |
|
113 | } | |
116 |
|
114 | |||
117 | void AreaChartItem::handleDomainUpdated() |
|
115 | void AreaChartItem::handleDomainUpdated() | |
118 | { |
|
116 | { | |
119 | AbstractDomain* d = m_upper->domain(); |
|
117 | AbstractDomain* d = m_upper->domain(); | |
120 |
|
118 | |||
121 | d->setSize(domain()->size()); |
|
119 | d->setSize(domain()->size()); | |
122 | d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY()); |
|
120 | d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY()); | |
123 | m_upper->handleDomainUpdated(); |
|
121 | m_upper->handleDomainUpdated(); | |
124 |
|
122 | |||
125 | if (m_lower) { |
|
123 | if (m_lower) { | |
126 | AbstractDomain* d = m_lower->domain(); |
|
124 | AbstractDomain* d = m_lower->domain(); | |
127 | d->setSize(domain()->size()); |
|
125 | d->setSize(domain()->size()); | |
128 | d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY()); |
|
126 | d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY()); | |
129 | m_lower->handleDomainUpdated(); |
|
127 | m_lower->handleDomainUpdated(); | |
130 | } |
|
128 | } | |
131 | } |
|
129 | } | |
132 |
|
130 | |||
133 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
131 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
134 | { |
|
132 | { | |
135 | Q_UNUSED(widget) |
|
133 | Q_UNUSED(widget) | |
136 | Q_UNUSED(option) |
|
134 | Q_UNUSED(option) | |
137 | painter->save(); |
|
135 | painter->save(); | |
138 | painter->setPen(m_linePen); |
|
136 | painter->setPen(m_linePen); | |
139 | painter->setBrush(m_brush); |
|
137 | painter->setBrush(m_brush); | |
140 | painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); |
|
138 | painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); | |
141 | painter->drawPath(m_path); |
|
139 | painter->drawPath(m_path); | |
142 | if (m_pointsVisible) { |
|
140 | if (m_pointsVisible) { | |
143 | painter->setPen(m_pointPen); |
|
141 | painter->setPen(m_pointPen); | |
144 | painter->drawPoints(m_upper->geometryPoints()); |
|
142 | painter->drawPoints(m_upper->geometryPoints()); | |
145 | if (m_lower) |
|
143 | if (m_lower) | |
146 | painter->drawPoints(m_lower->geometryPoints()); |
|
144 | painter->drawPoints(m_lower->geometryPoints()); | |
147 | } |
|
145 | } | |
148 | painter->restore(); |
|
146 | painter->restore(); | |
149 | } |
|
147 | } | |
150 |
|
148 | |||
151 | void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
149 | void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
152 | { |
|
150 | { | |
153 | emit clicked(m_upper->domain()->calculateDomainPoint(event->pos())); |
|
151 | emit clicked(m_upper->domain()->calculateDomainPoint(event->pos())); | |
154 | ChartItem::mousePressEvent(event); |
|
152 | ChartItem::mousePressEvent(event); | |
155 | } |
|
153 | } | |
156 |
|
154 | |||
157 | void AreaChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
155 | void AreaChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
158 | { |
|
156 | { | |
159 | emit hovered(domain()->calculateDomainPoint(event->pos()), true); |
|
157 | emit hovered(domain()->calculateDomainPoint(event->pos()), true); | |
160 | event->accept(); |
|
158 | event->accept(); | |
161 | // QGraphicsItem::hoverEnterEvent(event); |
|
159 | // QGraphicsItem::hoverEnterEvent(event); | |
162 | } |
|
160 | } | |
163 |
|
161 | |||
164 | void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
162 | void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
165 | { |
|
163 | { | |
166 | emit hovered(domain()->calculateDomainPoint(event->pos()), false); |
|
164 | emit hovered(domain()->calculateDomainPoint(event->pos()), false); | |
167 | event->accept(); |
|
165 | event->accept(); | |
168 | // QGraphicsItem::hoverEnterEvent(event); |
|
166 | // QGraphicsItem::hoverEnterEvent(event); | |
169 | } |
|
167 | } | |
170 |
|
168 | |||
171 | #include "moc_areachartitem_p.cpp" |
|
169 | #include "moc_areachartitem_p.cpp" | |
172 |
|
170 | |||
173 | QTCOMMERCIALCHART_END_NAMESPACE |
|
171 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,598 +1,594 | |||||
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 "qbarcategoryaxis.h" |
|
21 | #include "qbarcategoryaxis.h" | |
22 | #include "qbarcategoryaxis_p.h" |
|
22 | #include "qbarcategoryaxis_p.h" | |
23 | #include "chartbarcategoryaxisx_p.h" |
|
23 | #include "chartbarcategoryaxisx_p.h" | |
24 | #include "chartbarcategoryaxisy_p.h" |
|
24 | #include "chartbarcategoryaxisy_p.h" | |
25 | #include "abstractdomain_p.h" |
|
25 | #include "abstractdomain_p.h" | |
26 | #include "qchart.h" |
|
26 | #include "qchart.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | /*! |
|
30 | /*! | |
31 | \class QBarCategoryAxis |
|
31 | \class QBarCategoryAxis | |
32 | \brief The QBarCategoryAxis class is used for manipulating chart's axis. |
|
32 | \brief The QBarCategoryAxis class is used for manipulating chart's axis. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | BarCategoryAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | BarCategoryAxis can be setup to show axis line with tick marks, grid lines and shades. | |
36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. | |
37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. |
|
37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. | |
38 |
|
38 | |||
39 | Example code on how to use QBarCategoryAxis. |
|
39 | Example code on how to use QBarCategoryAxis. | |
40 | \code |
|
40 | \code | |
41 | QChartView *chartView = new QChartView; |
|
41 | QChartView *chartView = new QChartView; | |
42 | QBarSeries *series = new QBarSeries; |
|
42 | QBarSeries *series = new QBarSeries; | |
43 | // ... |
|
43 | // ... | |
44 | chartView->chart()->addSeries(series); |
|
44 | chartView->chart()->addSeries(series); | |
45 | chartView->chart()->createDefaultAxes(); |
|
45 | chartView->chart()->createDefaultAxes(); | |
46 |
|
46 | |||
47 | QBarCategoryAxis *axisX = new QBarCategoryAxis; |
|
47 | QBarCategoryAxis *axisX = new QBarCategoryAxis; | |
48 | QStringList categories; |
|
48 | QStringList categories; | |
49 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
49 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
50 | axisX->append(categories); |
|
50 | axisX->append(categories); | |
51 | axisX->setRange("Feb", "May"); |
|
51 | axisX->setRange("Feb", "May"); | |
52 | chartView->chart()->setAxisX(axisX, series); |
|
52 | chartView->chart()->setAxisX(axisX, series); | |
53 | \endcode |
|
53 | \endcode | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \qmlclass BarCategoryAxis QBarCategoryAxis |
|
57 | \qmlclass BarCategoryAxis QBarCategoryAxis | |
58 | \inherits AbstractAxis |
|
58 | \inherits AbstractAxis | |
59 | \brief The Axis element is used for manipulating chart's axes. |
|
59 | \brief The Axis element is used for manipulating chart's axes. | |
60 |
|
60 | |||
61 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
61 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
62 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
62 | Categories are drawn between ticks. Note that you can use this also with lineseries too. | |
63 |
|
63 | |||
64 | To access BarCategoryAxis you can use ChartView API. For example: |
|
64 | To access BarCategoryAxis you can use ChartView API. For example: | |
65 | \code |
|
65 | \code | |
66 | ChartView { |
|
66 | ChartView { | |
67 | BarCategoryAxis { |
|
67 | BarCategoryAxis { | |
68 | id: categoryAxis |
|
68 | id: categoryAxis | |
69 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] |
|
69 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] | |
70 | } |
|
70 | } | |
71 | // Add a few series... |
|
71 | // Add a few series... | |
72 | } |
|
72 | } | |
73 | \endcode |
|
73 | \endcode | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \property QBarCategoryAxis::categories |
|
77 | \property QBarCategoryAxis::categories | |
78 | Defines the categories of axis |
|
78 | Defines the categories of axis | |
79 | */ |
|
79 | */ | |
80 | /*! |
|
80 | /*! | |
81 | \qmlproperty QStringList BarCategoryAxis::categories |
|
81 | \qmlproperty QStringList BarCategoryAxis::categories | |
82 | Defines the categories of axis |
|
82 | Defines the categories of axis | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \property QBarCategoryAxis::min |
|
86 | \property QBarCategoryAxis::min | |
87 | Defines the minimum value on the axis. |
|
87 | Defines the minimum value on the axis. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty string BarCategoryAxis::min |
|
90 | \qmlproperty string BarCategoryAxis::min | |
91 | Defines the minimum value on the axis. |
|
91 | Defines the minimum value on the axis. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QBarCategoryAxis::max |
|
95 | \property QBarCategoryAxis::max | |
96 | Defines the maximum value on the axis. |
|
96 | Defines the maximum value on the axis. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty string BarCategoryAxis::max |
|
99 | \qmlproperty string BarCategoryAxis::max | |
100 | Defines the maximum value on the axis. |
|
100 | Defines the maximum value on the axis. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \property QBarCategoryAxis::count |
|
104 | \property QBarCategoryAxis::count | |
105 | The count of categories. |
|
105 | The count of categories. | |
106 | */ |
|
106 | */ | |
107 | /*! |
|
107 | /*! | |
108 | \qmlproperty int BarCategoryAxis::count |
|
108 | \qmlproperty int BarCategoryAxis::count | |
109 | The count of categories. |
|
109 | The count of categories. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \fn void QBarCategoryAxis::categoriesChanged() |
|
113 | \fn void QBarCategoryAxis::categoriesChanged() | |
114 | Axis emits signal when the categories of the axis has changed. |
|
114 | Axis emits signal when the categories of the axis has changed. | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \fn void QBarCategoryAxis::minChanged(const QString &min) |
|
118 | \fn void QBarCategoryAxis::minChanged(const QString &min) | |
119 | Axis emits signal when \a min of axis has changed. |
|
119 | Axis emits signal when \a min of axis has changed. | |
120 | */ |
|
120 | */ | |
121 | /*! |
|
121 | /*! | |
122 | \qmlsignal BarCategoryAxis::onMinChanged(const QString &min) |
|
122 | \qmlsignal BarCategoryAxis::onMinChanged(const QString &min) | |
123 | Axis emits signal when \a min of axis has changed. |
|
123 | Axis emits signal when \a min of axis has changed. | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \fn void QBarCategoryAxis::maxChanged(const QString &max) |
|
127 | \fn void QBarCategoryAxis::maxChanged(const QString &max) | |
128 | Axis emits signal when \a max of axis has changed. |
|
128 | Axis emits signal when \a max of axis has changed. | |
129 | */ |
|
129 | */ | |
130 | /*! |
|
130 | /*! | |
131 | \qmlsignal BarCategoryAxis::onMaxChanged(const QString &max) |
|
131 | \qmlsignal BarCategoryAxis::onMaxChanged(const QString &max) | |
132 | Axis emits signal when \a max of axis has changed. |
|
132 | Axis emits signal when \a max of axis has changed. | |
133 | */ |
|
133 | */ | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | \fn void QBarCategoryAxis::countChanged() |
|
136 | \fn void QBarCategoryAxis::countChanged() | |
137 | Axis emits signal when the count of categories has changed. |
|
137 | Axis emits signal when the count of categories has changed. | |
138 | */ |
|
138 | */ | |
139 | /*! |
|
139 | /*! | |
140 | \qmlsignal BarCategoryAxis::onCountChanged() |
|
140 | \qmlsignal BarCategoryAxis::onCountChanged() | |
141 | Axis emits signal when the count of categories has changed. |
|
141 | Axis emits signal when the count of categories has changed. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max) |
|
145 | \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max) | |
146 | Axis emits signal when \a min or \a max of axis has changed. |
|
146 | Axis emits signal when \a min or \a max of axis has changed. | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | Constructs an axis object which is a child of \a parent. |
|
150 | Constructs an axis object which is a child of \a parent. | |
151 | */ |
|
151 | */ | |
152 | QBarCategoryAxis::QBarCategoryAxis(QObject *parent): |
|
152 | QBarCategoryAxis::QBarCategoryAxis(QObject *parent): | |
153 | QAbstractAxis(*new QBarCategoryAxisPrivate(this), parent) |
|
153 | QAbstractAxis(*new QBarCategoryAxisPrivate(this), parent) | |
154 | { |
|
154 | { | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | Destroys the object |
|
158 | Destroys the object | |
159 | */ |
|
159 | */ | |
160 | QBarCategoryAxis::~QBarCategoryAxis() |
|
160 | QBarCategoryAxis::~QBarCategoryAxis() | |
161 | { |
|
161 | { | |
162 | Q_D(QBarCategoryAxis); |
|
162 | Q_D(QBarCategoryAxis); | |
163 | if (d->m_chart) |
|
163 | if (d->m_chart) | |
164 | d->m_chart->removeAxis(this); |
|
164 | d->m_chart->removeAxis(this); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | /*! |
|
167 | /*! | |
168 | \internal |
|
168 | \internal | |
169 | */ |
|
169 | */ | |
170 | QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent) |
|
170 | QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent) | |
171 | : QAbstractAxis(d, parent) |
|
171 | : QAbstractAxis(d, parent) | |
172 | { |
|
172 | { | |
173 |
|
173 | |||
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | Appends \a categories to axis. A maximum of the axis will be changed to last category in \a categories. |
|
177 | Appends \a categories to axis. A maximum of the axis will be changed to last category in \a categories. | |
178 | If there were no categories previously defined, minimum of axis will be also changed to first category in \a categories. |
|
178 | If there were no categories previously defined, minimum of axis will be also changed to first category in \a categories. | |
179 | A category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. |
|
179 | A category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. | |
180 | */ |
|
180 | */ | |
181 | void QBarCategoryAxis::append(const QStringList &categories) |
|
181 | void QBarCategoryAxis::append(const QStringList &categories) | |
182 | { |
|
182 | { | |
183 | if (categories.isEmpty()) |
|
183 | if (categories.isEmpty()) | |
184 | return; |
|
184 | return; | |
185 |
|
185 | |||
186 | Q_D(QBarCategoryAxis); |
|
186 | Q_D(QBarCategoryAxis); | |
187 |
|
187 | |||
188 | int count = d->m_categories.count(); |
|
188 | int count = d->m_categories.count(); | |
189 |
|
189 | |||
190 | foreach(QString category, categories) { |
|
190 | foreach(QString category, categories) { | |
191 | if (!d->m_categories.contains(category) && !category.isNull()) { |
|
191 | if (!d->m_categories.contains(category) && !category.isNull()) { | |
192 | d->m_categories.append(category); |
|
192 | d->m_categories.append(category); | |
193 | } |
|
193 | } | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | if (d->m_categories.count() == count) |
|
196 | if (d->m_categories.count() == count) | |
197 | return; |
|
197 | return; | |
198 |
|
198 | |||
199 | if (count == 0) |
|
199 | if (count == 0) | |
200 | setRange(d->m_categories.first(), d->m_categories.last()); |
|
200 | setRange(d->m_categories.first(), d->m_categories.last()); | |
201 | else |
|
201 | else | |
202 | setRange(d->m_minCategory, d->m_categories.last()); |
|
202 | setRange(d->m_minCategory, d->m_categories.last()); | |
203 |
|
203 | |||
204 | emit categoriesChanged(); |
|
204 | emit categoriesChanged(); | |
205 | emit countChanged(); |
|
205 | emit countChanged(); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | /*! |
|
208 | /*! | |
209 | Appends \a category to axis. A maximum of the axis will be changed to last \a category. |
|
209 | Appends \a category to axis. A maximum of the axis will be changed to last \a category. | |
210 | If there were no categories previously defined, minimum of axis will be also changed to \a category. |
|
210 | If there were no categories previously defined, minimum of axis will be also changed to \a category. | |
211 | A \a category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. |
|
211 | A \a category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. | |
212 | */ |
|
212 | */ | |
213 | void QBarCategoryAxis::append(const QString &category) |
|
213 | void QBarCategoryAxis::append(const QString &category) | |
214 | { |
|
214 | { | |
215 | Q_D(QBarCategoryAxis); |
|
215 | Q_D(QBarCategoryAxis); | |
216 |
|
216 | |||
217 | int count = d->m_categories.count(); |
|
217 | int count = d->m_categories.count(); | |
218 |
|
218 | |||
219 | if (!d->m_categories.contains(category) && !category.isNull()) |
|
219 | if (!d->m_categories.contains(category) && !category.isNull()) | |
220 | d->m_categories.append(category); |
|
220 | d->m_categories.append(category); | |
221 |
|
221 | |||
222 | if (d->m_categories.count() == count) |
|
222 | if (d->m_categories.count() == count) | |
223 | return; |
|
223 | return; | |
224 |
|
224 | |||
225 | if (count == 0) |
|
225 | if (count == 0) | |
226 | setRange(d->m_categories.last(), d->m_categories.last()); |
|
226 | setRange(d->m_categories.last(), d->m_categories.last()); | |
227 | else |
|
227 | else | |
228 | setRange(d->m_minCategory, d->m_categories.last()); |
|
228 | setRange(d->m_minCategory, d->m_categories.last()); | |
229 |
|
229 | |||
230 | emit categoriesChanged(); |
|
230 | emit categoriesChanged(); | |
231 | emit countChanged(); |
|
231 | emit countChanged(); | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | /*! |
|
234 | /*! | |
235 | Removes \a category from axis. Removing category which is currently maximum or minimum |
|
235 | Removes \a category from axis. Removing category which is currently maximum or minimum | |
236 | will affect the axis range. |
|
236 | will affect the axis range. | |
237 | */ |
|
237 | */ | |
238 | void QBarCategoryAxis::remove(const QString &category) |
|
238 | void QBarCategoryAxis::remove(const QString &category) | |
239 | { |
|
239 | { | |
240 | Q_D(QBarCategoryAxis); |
|
240 | Q_D(QBarCategoryAxis); | |
241 |
|
241 | |||
242 | if (d->m_categories.contains(category)) { |
|
242 | if (d->m_categories.contains(category)) { | |
243 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
243 | d->m_categories.removeAt(d->m_categories.indexOf(category)); | |
244 | if (!d->m_categories.isEmpty()) { |
|
244 | if (!d->m_categories.isEmpty()) { | |
245 | if (d->m_minCategory == category) { |
|
245 | if (d->m_minCategory == category) { | |
246 | setRange(d->m_categories.first(), d->m_maxCategory); |
|
246 | setRange(d->m_categories.first(), d->m_maxCategory); | |
247 | } else if (d->m_maxCategory == category) { |
|
247 | } else if (d->m_maxCategory == category) { | |
248 | setRange(d->m_minCategory, d->m_categories.last()); |
|
248 | setRange(d->m_minCategory, d->m_categories.last()); | |
249 | } else { |
|
249 | } else { | |
250 | d->updateCategoryDomain(); |
|
250 | d->updateCategoryDomain(); | |
251 | //TODO:: d->emitUpdated(); |
|
|||
252 | } |
|
251 | } | |
253 | } else { |
|
252 | } else { | |
254 | setRange(QString::null, QString::null); |
|
253 | setRange(QString::null, QString::null); | |
255 | } |
|
254 | } | |
256 | emit categoriesChanged(); |
|
255 | emit categoriesChanged(); | |
257 | emit countChanged(); |
|
256 | emit countChanged(); | |
258 | } |
|
257 | } | |
259 | } |
|
258 | } | |
260 |
|
259 | |||
261 | /*! |
|
260 | /*! | |
262 | Inserts \a category to axis at \a index. A \a category has to be valid QStrings and can not be duplicated. |
|
261 | Inserts \a category to axis at \a index. A \a category has to be valid QStrings and can not be duplicated. | |
263 | If \a category is prepended or appended to categories, minimum and maximum of axis is updated accordingly. |
|
262 | If \a category is prepended or appended to categories, minimum and maximum of axis is updated accordingly. | |
264 | */ |
|
263 | */ | |
265 | void QBarCategoryAxis::insert(int index, const QString &category) |
|
264 | void QBarCategoryAxis::insert(int index, const QString &category) | |
266 | { |
|
265 | { | |
267 | Q_D(QBarCategoryAxis); |
|
266 | Q_D(QBarCategoryAxis); | |
268 |
|
267 | |||
269 | int count = d->m_categories.count(); |
|
268 | int count = d->m_categories.count(); | |
270 |
|
269 | |||
271 | if (!d->m_categories.contains(category) && !category.isNull()) |
|
270 | if (!d->m_categories.contains(category) && !category.isNull()) | |
272 | d->m_categories.insert(index, category); |
|
271 | d->m_categories.insert(index, category); | |
273 |
|
272 | |||
274 | if (d->m_categories.count() == count) |
|
273 | if (d->m_categories.count() == count) | |
275 | return; |
|
274 | return; | |
276 |
|
275 | |||
277 | if (count == 0) { |
|
276 | if (count == 0) { | |
278 | setRange(d->m_categories.first(), d->m_categories.first()); |
|
277 | setRange(d->m_categories.first(), d->m_categories.first()); | |
279 | } else if (index == 0) { |
|
278 | } else if (index == 0) { | |
280 | setRange(d->m_categories.first(), d->m_maxCategory); |
|
279 | setRange(d->m_categories.first(), d->m_maxCategory); | |
281 | } else if (index == count) { |
|
280 | } else if (index == count) { | |
282 | setRange(d->m_minCategory, d->m_categories.last()); |
|
281 | setRange(d->m_minCategory, d->m_categories.last()); | |
283 | } else { |
|
282 | } else { | |
284 | d->updateCategoryDomain(); |
|
283 | d->updateCategoryDomain(); | |
285 | //TODO:: d->emitUpdated(); |
|
|||
286 | } |
|
284 | } | |
287 |
|
285 | |||
288 | emit categoriesChanged(); |
|
286 | emit categoriesChanged(); | |
289 | emit countChanged(); |
|
287 | emit countChanged(); | |
290 | } |
|
288 | } | |
291 |
|
289 | |||
292 | /*! |
|
290 | /*! | |
293 | Replaces \a oldCategory with \a newCategory. If \a oldCategory does not exits on the axis nothing is done. |
|
291 | Replaces \a oldCategory with \a newCategory. If \a oldCategory does not exits on the axis nothing is done. | |
294 | A \a newCategory has to be valid QStrings and can not be duplicated. In case of replacing minimum or maximum category, |
|
292 | A \a newCategory has to be valid QStrings and can not be duplicated. In case of replacing minimum or maximum category, | |
295 | minimum and maximum of axis is updated accordingly. |
|
293 | minimum and maximum of axis is updated accordingly. | |
296 | */ |
|
294 | */ | |
297 | void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory) |
|
295 | void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory) | |
298 | { |
|
296 | { | |
299 | Q_D(QBarCategoryAxis); |
|
297 | Q_D(QBarCategoryAxis); | |
300 |
|
298 | |||
301 | int pos = d->m_categories.indexOf(oldCategory); |
|
299 | int pos = d->m_categories.indexOf(oldCategory); | |
302 |
|
300 | |||
303 | if (pos != -1 && !d->m_categories.contains(newCategory) && !newCategory.isNull()) { |
|
301 | if (pos != -1 && !d->m_categories.contains(newCategory) && !newCategory.isNull()) { | |
304 | d->m_categories.replace(pos, newCategory); |
|
302 | d->m_categories.replace(pos, newCategory); | |
305 | if (d->m_minCategory == oldCategory) { |
|
303 | if (d->m_minCategory == oldCategory) { | |
306 | setRange(newCategory, d->m_maxCategory); |
|
304 | setRange(newCategory, d->m_maxCategory); | |
307 | } else if (d->m_maxCategory == oldCategory) { |
|
305 | } else if (d->m_maxCategory == oldCategory) { | |
308 | setRange(d->m_minCategory, newCategory); |
|
306 | setRange(d->m_minCategory, newCategory); | |
309 | } else { |
|
|||
310 | //TODO:: d->emitUpdated(); |
|
|||
311 | } |
|
307 | } | |
312 | emit categoriesChanged(); |
|
308 | emit categoriesChanged(); | |
313 | emit countChanged(); |
|
309 | emit countChanged(); | |
314 | } |
|
310 | } | |
315 | } |
|
311 | } | |
316 |
|
312 | |||
317 | /*! |
|
313 | /*! | |
318 | Removes all categories. Sets the maximum and minimum of the axis's range to QString::null. |
|
314 | Removes all categories. Sets the maximum and minimum of the axis's range to QString::null. | |
319 | */ |
|
315 | */ | |
320 | void QBarCategoryAxis::clear() |
|
316 | void QBarCategoryAxis::clear() | |
321 | { |
|
317 | { | |
322 | Q_D(QBarCategoryAxis); |
|
318 | Q_D(QBarCategoryAxis); | |
323 | d->m_categories.clear(); |
|
319 | d->m_categories.clear(); | |
324 | setRange(QString::null, QString::null); |
|
320 | setRange(QString::null, QString::null); | |
325 | emit categoriesChanged(); |
|
321 | emit categoriesChanged(); | |
326 | emit countChanged(); |
|
322 | emit countChanged(); | |
327 | } |
|
323 | } | |
328 |
|
324 | |||
329 | /*! |
|
325 | /*! | |
330 | Set \a categories and discards the old ones, range of axis is adjusted to match first and last category in \a categories. |
|
326 | Set \a categories and discards the old ones, range of axis is adjusted to match first and last category in \a categories. | |
331 | A category has to be valid QStrings and can not be duplicated. |
|
327 | A category has to be valid QStrings and can not be duplicated. | |
332 | */ |
|
328 | */ | |
333 | void QBarCategoryAxis::setCategories(const QStringList &categories) |
|
329 | void QBarCategoryAxis::setCategories(const QStringList &categories) | |
334 | { |
|
330 | { | |
335 | Q_D(QBarCategoryAxis); |
|
331 | Q_D(QBarCategoryAxis); | |
336 | d->m_categories.clear(); |
|
332 | d->m_categories.clear(); | |
337 | d->m_minCategory = QString::null; |
|
333 | d->m_minCategory = QString::null; | |
338 | d->m_maxCategory = QString::null; |
|
334 | d->m_maxCategory = QString::null; | |
339 | d->m_min = 0; |
|
335 | d->m_min = 0; | |
340 | d->m_max = 0; |
|
336 | d->m_max = 0; | |
341 | d->m_count = 0; |
|
337 | d->m_count = 0; | |
342 | append(categories); |
|
338 | append(categories); | |
343 | } |
|
339 | } | |
344 |
|
340 | |||
345 | /*! |
|
341 | /*! | |
346 | Returns categories |
|
342 | Returns categories | |
347 | */ |
|
343 | */ | |
348 | QStringList QBarCategoryAxis::categories() |
|
344 | QStringList QBarCategoryAxis::categories() | |
349 | { |
|
345 | { | |
350 | Q_D(QBarCategoryAxis); |
|
346 | Q_D(QBarCategoryAxis); | |
351 | return d->m_categories; |
|
347 | return d->m_categories; | |
352 | } |
|
348 | } | |
353 |
|
349 | |||
354 | /*! |
|
350 | /*! | |
355 | Returns number of categories. |
|
351 | Returns number of categories. | |
356 | */ |
|
352 | */ | |
357 | int QBarCategoryAxis::count() const |
|
353 | int QBarCategoryAxis::count() const | |
358 | { |
|
354 | { | |
359 | Q_D(const QBarCategoryAxis); |
|
355 | Q_D(const QBarCategoryAxis); | |
360 | return d->m_categories.count(); |
|
356 | return d->m_categories.count(); | |
361 | } |
|
357 | } | |
362 |
|
358 | |||
363 | /*! |
|
359 | /*! | |
364 | Returns category at \a index. Index must be valid. |
|
360 | Returns category at \a index. Index must be valid. | |
365 | */ |
|
361 | */ | |
366 | QString QBarCategoryAxis::at(int index) const |
|
362 | QString QBarCategoryAxis::at(int index) const | |
367 | { |
|
363 | { | |
368 | Q_D(const QBarCategoryAxis); |
|
364 | Q_D(const QBarCategoryAxis); | |
369 | return d->m_categories.at(index); |
|
365 | return d->m_categories.at(index); | |
370 | } |
|
366 | } | |
371 |
|
367 | |||
372 | /*! |
|
368 | /*! | |
373 | Sets minimum category to \a min. |
|
369 | Sets minimum category to \a min. | |
374 | */ |
|
370 | */ | |
375 | void QBarCategoryAxis::setMin(const QString &min) |
|
371 | void QBarCategoryAxis::setMin(const QString &min) | |
376 | { |
|
372 | { | |
377 | Q_D(QBarCategoryAxis); |
|
373 | Q_D(QBarCategoryAxis); | |
378 | d->setRange(min, d->m_maxCategory); |
|
374 | d->setRange(min, d->m_maxCategory); | |
379 | } |
|
375 | } | |
380 |
|
376 | |||
381 | /*! |
|
377 | /*! | |
382 | Returns minimum category. |
|
378 | Returns minimum category. | |
383 | */ |
|
379 | */ | |
384 | QString QBarCategoryAxis::min() const |
|
380 | QString QBarCategoryAxis::min() const | |
385 | { |
|
381 | { | |
386 | Q_D(const QBarCategoryAxis); |
|
382 | Q_D(const QBarCategoryAxis); | |
387 | return d->m_minCategory; |
|
383 | return d->m_minCategory; | |
388 | } |
|
384 | } | |
389 |
|
385 | |||
390 | /*! |
|
386 | /*! | |
391 | Sets maximum category to \a max. |
|
387 | Sets maximum category to \a max. | |
392 | */ |
|
388 | */ | |
393 | void QBarCategoryAxis::setMax(const QString &max) |
|
389 | void QBarCategoryAxis::setMax(const QString &max) | |
394 | { |
|
390 | { | |
395 | Q_D(QBarCategoryAxis); |
|
391 | Q_D(QBarCategoryAxis); | |
396 | d->setRange(d->m_minCategory, max); |
|
392 | d->setRange(d->m_minCategory, max); | |
397 | } |
|
393 | } | |
398 |
|
394 | |||
399 | /*! |
|
395 | /*! | |
400 | Returns maximum category |
|
396 | Returns maximum category | |
401 | */ |
|
397 | */ | |
402 | QString QBarCategoryAxis::max() const |
|
398 | QString QBarCategoryAxis::max() const | |
403 | { |
|
399 | { | |
404 | Q_D(const QBarCategoryAxis); |
|
400 | Q_D(const QBarCategoryAxis); | |
405 | return d->m_maxCategory; |
|
401 | return d->m_maxCategory; | |
406 | } |
|
402 | } | |
407 |
|
403 | |||
408 | /*! |
|
404 | /*! | |
409 | Sets range from \a minCategory to \a maxCategory |
|
405 | Sets range from \a minCategory to \a maxCategory | |
410 | */ |
|
406 | */ | |
411 | void QBarCategoryAxis::setRange(const QString &minCategory, const QString &maxCategory) |
|
407 | void QBarCategoryAxis::setRange(const QString &minCategory, const QString &maxCategory) | |
412 | { |
|
408 | { | |
413 | Q_D(QBarCategoryAxis); |
|
409 | Q_D(QBarCategoryAxis); | |
414 | d->setRange(minCategory,maxCategory); |
|
410 | d->setRange(minCategory,maxCategory); | |
415 | } |
|
411 | } | |
416 |
|
412 | |||
417 | /*! |
|
413 | /*! | |
418 | Returns the type of the axis |
|
414 | Returns the type of the axis | |
419 | */ |
|
415 | */ | |
420 | QAbstractAxis::AxisType QBarCategoryAxis::type() const |
|
416 | QAbstractAxis::AxisType QBarCategoryAxis::type() const | |
421 | { |
|
417 | { | |
422 | return AxisTypeBarCategory; |
|
418 | return AxisTypeBarCategory; | |
423 | } |
|
419 | } | |
424 |
|
420 | |||
425 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
421 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
426 |
|
422 | |||
427 | QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis *q) |
|
423 | QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis *q) | |
428 | : QAbstractAxisPrivate(q), |
|
424 | : QAbstractAxisPrivate(q), | |
429 | m_min(0.0), |
|
425 | m_min(0.0), | |
430 | m_max(0.0), |
|
426 | m_max(0.0), | |
431 | m_count(0) |
|
427 | m_count(0) | |
432 | { |
|
428 | { | |
433 |
|
429 | |||
434 | } |
|
430 | } | |
435 |
|
431 | |||
436 | QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate() |
|
432 | QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate() | |
437 | { |
|
433 | { | |
438 |
|
434 | |||
439 | } |
|
435 | } | |
440 |
|
436 | |||
441 | void QBarCategoryAxisPrivate::setMin(const QVariant &min) |
|
437 | void QBarCategoryAxisPrivate::setMin(const QVariant &min) | |
442 | { |
|
438 | { | |
443 | setRange(min, m_maxCategory); |
|
439 | setRange(min, m_maxCategory); | |
444 | } |
|
440 | } | |
445 |
|
441 | |||
446 | void QBarCategoryAxisPrivate::setMax(const QVariant &max) |
|
442 | void QBarCategoryAxisPrivate::setMax(const QVariant &max) | |
447 | { |
|
443 | { | |
448 | setRange(m_minCategory, max); |
|
444 | setRange(m_minCategory, max); | |
449 | } |
|
445 | } | |
450 |
|
446 | |||
451 | void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
447 | void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
452 | { |
|
448 | { | |
453 | QString value1 = min.toString(); |
|
449 | QString value1 = min.toString(); | |
454 | QString value2 = max.toString(); |
|
450 | QString value2 = max.toString(); | |
455 | setRange(value1, value2); |
|
451 | setRange(value1, value2); | |
456 | } |
|
452 | } | |
457 |
|
453 | |||
458 | void QBarCategoryAxisPrivate::setRange(qreal min, qreal max) |
|
454 | void QBarCategoryAxisPrivate::setRange(qreal min, qreal max) | |
459 | { |
|
455 | { | |
460 | Q_Q(QBarCategoryAxis); |
|
456 | Q_Q(QBarCategoryAxis); | |
461 |
|
457 | |||
462 | bool categoryChanged = false; |
|
458 | bool categoryChanged = false; | |
463 | bool changed = false; |
|
459 | bool changed = false; | |
464 |
|
460 | |||
465 | if (min > max) |
|
461 | if (min > max) | |
466 | return; |
|
462 | return; | |
467 |
|
463 | |||
468 | if (!qFuzzyIsNull(m_min - min)) { |
|
464 | if (!qFuzzyIsNull(m_min - min)) { | |
469 | m_min = min; |
|
465 | m_min = min; | |
470 | changed = true; |
|
466 | changed = true; | |
471 |
|
467 | |||
472 | int imin = m_min + 0.5; |
|
468 | int imin = m_min + 0.5; | |
473 | if (imin >= 0 && imin < m_categories.count()) { |
|
469 | if (imin >= 0 && imin < m_categories.count()) { | |
474 | QString minCategory = m_categories.at(imin); |
|
470 | QString minCategory = m_categories.at(imin); | |
475 | if (m_minCategory != minCategory && !minCategory.isEmpty()) { |
|
471 | if (m_minCategory != minCategory && !minCategory.isEmpty()) { | |
476 | m_minCategory = minCategory; |
|
472 | m_minCategory = minCategory; | |
477 | categoryChanged = true; |
|
473 | categoryChanged = true; | |
478 | emit q->minChanged(minCategory); |
|
474 | emit q->minChanged(minCategory); | |
479 | } |
|
475 | } | |
480 | } |
|
476 | } | |
481 |
|
477 | |||
482 | } |
|
478 | } | |
483 |
|
479 | |||
484 | if (!qFuzzyIsNull(m_max - max)) { |
|
480 | if (!qFuzzyIsNull(m_max - max)) { | |
485 | m_max = max; |
|
481 | m_max = max; | |
486 | changed = true; |
|
482 | changed = true; | |
487 |
|
483 | |||
488 | int imax = m_max - 0.5; |
|
484 | int imax = m_max - 0.5; | |
489 | if (imax >= 0 && imax < m_categories.count()) { |
|
485 | if (imax >= 0 && imax < m_categories.count()) { | |
490 | QString maxCategory = m_categories.at(imax); |
|
486 | QString maxCategory = m_categories.at(imax); | |
491 | if (m_maxCategory != maxCategory && !maxCategory.isEmpty()) { |
|
487 | if (m_maxCategory != maxCategory && !maxCategory.isEmpty()) { | |
492 | m_maxCategory = maxCategory; |
|
488 | m_maxCategory = maxCategory; | |
493 | categoryChanged = true; |
|
489 | categoryChanged = true; | |
494 | emit q->maxChanged(maxCategory); |
|
490 | emit q->maxChanged(maxCategory); | |
495 | } |
|
491 | } | |
496 | } |
|
492 | } | |
497 | } |
|
493 | } | |
498 |
|
494 | |||
499 | if (categoryChanged){ |
|
495 | if (categoryChanged){ | |
500 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
496 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |
501 | } |
|
497 | } | |
502 |
|
498 | |||
503 | if (changed) { |
|
499 | if (changed) { | |
504 | emit rangeChanged(m_min,m_max); |
|
500 | emit rangeChanged(m_min,m_max); | |
505 | } |
|
501 | } | |
506 | } |
|
502 | } | |
507 |
|
503 | |||
508 | void QBarCategoryAxisPrivate::setRange(const QString &minCategory, const QString &maxCategory) |
|
504 | void QBarCategoryAxisPrivate::setRange(const QString &minCategory, const QString &maxCategory) | |
509 | { |
|
505 | { | |
510 | Q_Q(QBarCategoryAxis); |
|
506 | Q_Q(QBarCategoryAxis); | |
511 | bool changed = false; |
|
507 | bool changed = false; | |
512 |
|
508 | |||
513 | //special case in case or clearing all categories |
|
509 | //special case in case or clearing all categories | |
514 | if (minCategory.isNull() && maxCategory.isNull()) { |
|
510 | if (minCategory.isNull() && maxCategory.isNull()) { | |
515 | m_minCategory = minCategory; |
|
511 | m_minCategory = minCategory; | |
516 | m_maxCategory = maxCategory; |
|
512 | m_maxCategory = maxCategory; | |
517 | m_min = 0; |
|
513 | m_min = 0; | |
518 | m_max = 0; |
|
514 | m_max = 0; | |
519 | m_count = 0; |
|
515 | m_count = 0; | |
520 | emit q->minChanged(minCategory); |
|
516 | emit q->minChanged(minCategory); | |
521 | emit q->maxChanged(maxCategory); |
|
517 | emit q->maxChanged(maxCategory); | |
522 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
518 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |
523 | emit rangeChanged(m_min,m_max); |
|
519 | emit rangeChanged(m_min,m_max); | |
524 | } |
|
520 | } | |
525 |
|
521 | |||
526 | if (m_categories.indexOf(maxCategory) < m_categories.indexOf(minCategory)) |
|
522 | if (m_categories.indexOf(maxCategory) < m_categories.indexOf(minCategory)) | |
527 | return; |
|
523 | return; | |
528 |
|
524 | |||
529 | if (!minCategory.isEmpty() && m_minCategory != minCategory && m_categories.contains(minCategory)) { |
|
525 | if (!minCategory.isEmpty() && m_minCategory != minCategory && m_categories.contains(minCategory)) { | |
530 | m_minCategory = minCategory; |
|
526 | m_minCategory = minCategory; | |
531 | m_min = m_categories.indexOf(m_minCategory) - 0.5; |
|
527 | m_min = m_categories.indexOf(m_minCategory) - 0.5; | |
532 | changed = true; |
|
528 | changed = true; | |
533 | emit q->minChanged(minCategory); |
|
529 | emit q->minChanged(minCategory); | |
534 | } |
|
530 | } | |
535 |
|
531 | |||
536 | if (!maxCategory.isEmpty() && m_maxCategory != maxCategory && m_categories.contains(maxCategory)) { |
|
532 | if (!maxCategory.isEmpty() && m_maxCategory != maxCategory && m_categories.contains(maxCategory)) { | |
537 | m_maxCategory = maxCategory; |
|
533 | m_maxCategory = maxCategory; | |
538 | m_max = m_categories.indexOf(m_maxCategory) + 0.5; |
|
534 | m_max = m_categories.indexOf(m_maxCategory) + 0.5; | |
539 | changed = true; |
|
535 | changed = true; | |
540 | emit q->maxChanged(maxCategory); |
|
536 | emit q->maxChanged(maxCategory); | |
541 | } |
|
537 | } | |
542 |
|
538 | |||
543 | if (changed) { |
|
539 | if (changed) { | |
544 | m_count = m_max - m_min; |
|
540 | m_count = m_max - m_min; | |
545 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
541 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |
546 | emit rangeChanged(m_min,m_max); |
|
542 | emit rangeChanged(m_min,m_max); | |
547 | } |
|
543 | } | |
548 | } |
|
544 | } | |
549 |
|
545 | |||
550 | void QBarCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
546 | void QBarCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
551 | { |
|
547 | { | |
552 | Q_Q(QBarCategoryAxis); |
|
548 | Q_Q(QBarCategoryAxis); | |
553 | ChartAxis* axis(0); |
|
549 | ChartAxis* axis(0); | |
554 | if (orientation() == Qt::Vertical) |
|
550 | if (orientation() == Qt::Vertical) | |
555 | axis = new ChartBarCategoryAxisY(q,parent); |
|
551 | axis = new ChartBarCategoryAxisY(q,parent); | |
556 | if (orientation() == Qt::Horizontal) |
|
552 | if (orientation() == Qt::Horizontal) | |
557 | axis = new ChartBarCategoryAxisX(q,parent); |
|
553 | axis = new ChartBarCategoryAxisX(q,parent); | |
558 |
|
554 | |||
559 | m_item.reset(axis); |
|
555 | m_item.reset(axis); | |
560 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
556 | QAbstractAxisPrivate::initializeGraphics(parent); | |
561 | } |
|
557 | } | |
562 |
|
558 | |||
563 | void QBarCategoryAxisPrivate::updateCategoryDomain() |
|
559 | void QBarCategoryAxisPrivate::updateCategoryDomain() | |
564 | { |
|
560 | { | |
565 | m_min = m_categories.indexOf(m_minCategory) - 0.5; |
|
561 | m_min = m_categories.indexOf(m_minCategory) - 0.5; | |
566 | m_max = m_categories.indexOf(m_maxCategory) + 0.5; |
|
562 | m_max = m_categories.indexOf(m_maxCategory) + 0.5; | |
567 | m_count = m_max - m_min; |
|
563 | m_count = m_max - m_min; | |
568 | } |
|
564 | } | |
569 |
|
565 | |||
570 |
|
566 | |||
571 | void QBarCategoryAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
567 | void QBarCategoryAxisPrivate::initializeDomain(AbstractDomain *domain) | |
572 | { |
|
568 | { | |
573 | Q_Q(QBarCategoryAxis); |
|
569 | Q_Q(QBarCategoryAxis); | |
574 | if (m_max == m_min) { |
|
570 | if (m_max == m_min) { | |
575 | int min; |
|
571 | int min; | |
576 | int max; |
|
572 | int max; | |
577 | if (orientation() == Qt::Vertical) { |
|
573 | if (orientation() == Qt::Vertical) { | |
578 | min = domain->minY() + 0.5; |
|
574 | min = domain->minY() + 0.5; | |
579 | max = domain->maxY() - 0.5; |
|
575 | max = domain->maxY() - 0.5; | |
580 | } else { |
|
576 | } else { | |
581 | min = domain->minX() + 0.5; |
|
577 | min = domain->minX() + 0.5; | |
582 | max = domain->maxX() - 0.5; |
|
578 | max = domain->maxX() - 0.5; | |
583 | } |
|
579 | } | |
584 |
|
580 | |||
585 | if (min > 0 && min < m_categories.count() && max > 0 && max < m_categories.count()) |
|
581 | if (min > 0 && min < m_categories.count() && max > 0 && max < m_categories.count()) | |
586 | q->setRange(m_categories.at(min), m_categories.at(max)); |
|
582 | q->setRange(m_categories.at(min), m_categories.at(max)); | |
587 | } else { |
|
583 | } else { | |
588 | if (orientation() == Qt::Vertical) |
|
584 | if (orientation() == Qt::Vertical) | |
589 | domain->setRangeY(m_min, m_max); |
|
585 | domain->setRangeY(m_min, m_max); | |
590 | else |
|
586 | else | |
591 | domain->setRangeX(m_min, m_max); |
|
587 | domain->setRangeX(m_min, m_max); | |
592 | } |
|
588 | } | |
593 | } |
|
589 | } | |
594 |
|
590 | |||
595 | #include "moc_qbarcategoryaxis.cpp" |
|
591 | #include "moc_qbarcategoryaxis.cpp" | |
596 | #include "moc_qbarcategoryaxis_p.cpp" |
|
592 | #include "moc_qbarcategoryaxis_p.cpp" | |
597 |
|
593 | |||
598 | QTCOMMERCIALCHART_END_NAMESPACE |
|
594 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,120 +1,119 | |||||
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 <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
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 | } |
|
35 | } | |
36 |
|
36 | |||
37 | ChartCategoryAxisX::~ChartCategoryAxisX() |
|
37 | ChartCategoryAxisX::~ChartCategoryAxisX() | |
38 | { |
|
38 | { | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QVector<qreal> ChartCategoryAxisX::calculateLayout() const |
|
41 | QVector<qreal> ChartCategoryAxisX::calculateLayout() const | |
42 | { |
|
42 | { | |
43 | int tickCount = m_axis->categoriesLabels().count() + 1; |
|
43 | int tickCount = m_axis->categoriesLabels().count() + 1; | |
44 | QVector<qreal> points; |
|
44 | QVector<qreal> points; | |
45 |
|
45 | |||
46 | if (tickCount < 2) |
|
46 | if (tickCount < 2) | |
47 | return points; |
|
47 | return points; | |
48 |
|
48 | |||
49 | const QRectF &gridRect = gridGeometry(); |
|
49 | const QRectF &gridRect = gridGeometry(); | |
50 | qreal range = max() - min(); |
|
50 | qreal range = max() - min(); | |
51 | if (range > 0) { |
|
51 | if (range > 0) { | |
52 | points.resize(tickCount); |
|
52 | points.resize(tickCount); | |
53 | qreal scale = gridRect.width() / range; |
|
53 | qreal scale = gridRect.width() / range; | |
54 | for (int i = 0; i < tickCount; ++i) { |
|
54 | for (int i = 0; i < tickCount; ++i) { | |
55 | if (i < tickCount - 1) { |
|
55 | if (i < tickCount - 1) { | |
56 | qreal x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left(); |
|
56 | qreal x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left(); | |
57 | points[i] = x; |
|
57 | points[i] = x; | |
58 | } else { |
|
58 | } else { | |
59 | qreal x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left(); |
|
59 | qreal x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left(); | |
60 | points[i] = x; |
|
60 | points[i] = x; | |
61 | } |
|
61 | } | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | return points; |
|
65 | return points; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void ChartCategoryAxisX::updateGeometry() |
|
68 | void ChartCategoryAxisX::updateGeometry() | |
69 | { |
|
69 | { | |
70 | //TODO: this is not optimal when many categories :( , create only visible lables |
|
|||
71 | setLabels(m_axis->categoriesLabels() << ""); |
|
70 | setLabels(m_axis->categoriesLabels() << ""); | |
72 | HorizontalAxis::updateGeometry(); |
|
71 | HorizontalAxis::updateGeometry(); | |
73 | } |
|
72 | } | |
74 |
|
73 | |||
75 | void ChartCategoryAxisX::handleAxisUpdated() |
|
74 | void ChartCategoryAxisX::handleAxisUpdated() | |
76 | { |
|
75 | { | |
77 | updateGeometry(); |
|
76 | updateGeometry(); | |
78 | } |
|
77 | } | |
79 |
|
78 | |||
80 | QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
79 | QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
81 | { |
|
80 | { | |
82 | Q_UNUSED(constraint) |
|
81 | Q_UNUSED(constraint) | |
83 |
|
82 | |||
84 | QFontMetrics fn(font()); |
|
83 | QFontMetrics fn(font()); | |
85 | QSizeF sh; |
|
84 | QSizeF sh; | |
86 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
85 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |
87 | QStringList ticksList = m_axis->categoriesLabels(); |
|
86 | QStringList ticksList = m_axis->categoriesLabels(); | |
88 | qreal width = 0; |
|
87 | qreal width = 0; | |
89 | qreal height = 0; |
|
88 | qreal height = 0; | |
90 |
|
89 | |||
91 | switch (which) { |
|
90 | switch (which) { | |
92 | case Qt::MinimumSize: { |
|
91 | case Qt::MinimumSize: { | |
93 | QRectF boundingRect = labelBoundingRect(fn, "..."); |
|
92 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
94 | width = qMax(boundingRect.width(), base.width()); |
|
93 | width = qMax(boundingRect.width(), base.width()); | |
95 | height = boundingRect.height() + labelPadding(); |
|
94 | height = boundingRect.height() + labelPadding(); | |
96 | height += base.height(); |
|
95 | height += base.height(); | |
97 | sh = QSizeF(width, height); |
|
96 | sh = QSizeF(width, height); | |
98 | break; |
|
97 | break; | |
99 | } |
|
98 | } | |
100 | case Qt::PreferredSize: { |
|
99 | case Qt::PreferredSize: { | |
101 | int labelHeight = 0; |
|
100 | int labelHeight = 0; | |
102 | foreach (const QString& s, ticksList) { |
|
101 | foreach (const QString& s, ticksList) { | |
103 | QRect rect = labelBoundingRect(fn, s); |
|
102 | QRect rect = labelBoundingRect(fn, s); | |
104 | labelHeight = qMax(rect.height(), labelHeight); |
|
103 | labelHeight = qMax(rect.height(), labelHeight); | |
105 | width += rect.width(); |
|
104 | width += rect.width(); | |
106 | } |
|
105 | } | |
107 | height = labelHeight + labelPadding(); |
|
106 | height = labelHeight + labelPadding(); | |
108 | height += base.height(); |
|
107 | height += base.height(); | |
109 | width = qMax(width, base.width()); |
|
108 | width = qMax(width, base.width()); | |
110 | sh = QSizeF(width, height); |
|
109 | sh = QSizeF(width, height); | |
111 | break; |
|
110 | break; | |
112 | } |
|
111 | } | |
113 | default: |
|
112 | default: | |
114 | break; |
|
113 | break; | |
115 | } |
|
114 | } | |
116 |
|
115 | |||
117 | return sh; |
|
116 | return sh; | |
118 | } |
|
117 | } | |
119 |
|
118 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
119 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,319 +1,317 | |||||
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 "qcategoryaxis.h" |
|
21 | #include "qcategoryaxis.h" | |
22 | #include "qcategoryaxis_p.h" |
|
22 | #include "qcategoryaxis_p.h" | |
23 | #include "chartcategoryaxisx_p.h" |
|
23 | #include "chartcategoryaxisx_p.h" | |
24 | #include "chartcategoryaxisy_p.h" |
|
24 | #include "chartcategoryaxisy_p.h" | |
25 | #include "qchart.h" |
|
25 | #include "qchart.h" | |
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 | \class QCategoryAxis |
|
31 | \class QCategoryAxis | |
32 | \brief The QCategoryAxis class allows putting a named ranges on the axis. |
|
32 | \brief The QCategoryAxis class allows putting a named ranges on the axis. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | This class can be used when the underlying data needs to be given extra meaning. |
|
35 | This class can be used when the underlying data needs to be given extra meaning. | |
36 | Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely. |
|
36 | Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely. | |
37 |
|
37 | |||
38 | Example code on how to use QCategoryAxis: |
|
38 | Example code on how to use QCategoryAxis: | |
39 | \table |
|
39 | \table | |
40 | \row |
|
40 | \row | |
41 | \o \br |
|
41 | \o \br | |
42 | \br |
|
42 | \br | |
43 | \code |
|
43 | \code | |
44 | QChartView *chartView = new QChartView; |
|
44 | QChartView *chartView = new QChartView; | |
45 | QLineSeries *series = new QLineSeries; |
|
45 | QLineSeries *series = new QLineSeries; | |
46 | // ... |
|
46 | // ... | |
47 | chartView->chart()->addSeries(series); |
|
47 | chartView->chart()->addSeries(series); | |
48 |
|
48 | |||
49 | QCategoryAxis *axisY = new QCategoryAxis; |
|
49 | QCategoryAxis *axisY = new QCategoryAxis; | |
50 | axisY->setMin(0); |
|
50 | axisY->setMin(0); | |
51 | axisY->setMax(52); |
|
51 | axisY->setMax(52); | |
52 | axisY->setStartValue(15); |
|
52 | axisY->setStartValue(15); | |
53 | axisY->append("First", 20); |
|
53 | axisY->append("First", 20); | |
54 | axisY->append("Second", 37); |
|
54 | axisY->append("Second", 37); | |
55 | axisY->append("Third", 52); |
|
55 | axisY->append("Third", 52); | |
56 | chartView->chart()->setAxisY(axisY, series); |
|
56 | chartView->chart()->setAxisY(axisY, series); | |
57 | \endcode |
|
57 | \endcode | |
58 | \o \br |
|
58 | \o \br | |
59 | \inlineimage api_category_axis.png |
|
59 | \inlineimage api_category_axis.png | |
60 | \endtable |
|
60 | \endtable | |
61 | */ |
|
61 | */ | |
62 | /*! |
|
62 | /*! | |
63 | \qmlclass CategoryAxis QCategoryAxis |
|
63 | \qmlclass CategoryAxis QCategoryAxis | |
64 | \inherits AbstractAxis |
|
64 | \inherits AbstractAxis | |
65 | \brief CategoryAxis allows putting a named ranges on the axis. |
|
65 | \brief CategoryAxis allows putting a named ranges on the axis. | |
66 |
|
66 | |||
67 | For example: |
|
67 | For example: | |
68 | \table |
|
68 | \table | |
69 | \row |
|
69 | \row | |
70 | \o \br |
|
70 | \o \br | |
71 | \br |
|
71 | \br | |
72 | \br |
|
72 | \br | |
73 | \snippet ../demos/qmlaxes/qml/qmlaxes/View3.qml 1 |
|
73 | \snippet ../demos/qmlaxes/qml/qmlaxes/View3.qml 1 | |
74 | \o \inlineimage demos_qmlaxes3.png |
|
74 | \o \inlineimage demos_qmlaxes3.png | |
75 | \endtable |
|
75 | \endtable | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \property QCategoryAxis::startValue |
|
79 | \property QCategoryAxis::startValue | |
80 | Defines the low end of the first category on the axis. |
|
80 | Defines the low end of the first category on the axis. | |
81 | */ |
|
81 | */ | |
82 | /*! |
|
82 | /*! | |
83 | \qmlproperty int CategoryAxis::startValue |
|
83 | \qmlproperty int CategoryAxis::startValue | |
84 | Defines the low end of the first category on the axis. |
|
84 | Defines the low end of the first category on the axis. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QCategoryAxis::count |
|
88 | \property QCategoryAxis::count | |
89 | The count of categories. |
|
89 | The count of categories. | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 | \qmlproperty int CategoryAxis::count |
|
92 | \qmlproperty int CategoryAxis::count | |
93 | The count of categories. |
|
93 | The count of categories. | |
94 | */ |
|
94 | */ | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | \property QCategoryAxis::categoriesLabels |
|
97 | \property QCategoryAxis::categoriesLabels | |
98 | The category labels as a string list. |
|
98 | The category labels as a string list. | |
99 | */ |
|
99 | */ | |
100 | /*! |
|
100 | /*! | |
101 | \qmlproperty StringList CategoryAxis::categoriesLabels |
|
101 | \qmlproperty StringList CategoryAxis::categoriesLabels | |
102 | The category labels as a list of strings. |
|
102 | The category labels as a list of strings. | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | Constructs an axis object which is a child of \a parent. |
|
106 | Constructs an axis object which is a child of \a parent. | |
107 | */ |
|
107 | */ | |
108 | QCategoryAxis::QCategoryAxis(QObject *parent): |
|
108 | QCategoryAxis::QCategoryAxis(QObject *parent): | |
109 | QValueAxis(*new QCategoryAxisPrivate(this), parent) |
|
109 | QValueAxis(*new QCategoryAxisPrivate(this), parent) | |
110 | { |
|
110 | { | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | /*! |
|
113 | /*! | |
114 | Destroys the object |
|
114 | Destroys the object | |
115 | */ |
|
115 | */ | |
116 | QCategoryAxis::~QCategoryAxis() |
|
116 | QCategoryAxis::~QCategoryAxis() | |
117 | { |
|
117 | { | |
118 | Q_D(QCategoryAxis); |
|
118 | Q_D(QCategoryAxis); | |
119 | if (d->m_chart) |
|
119 | if (d->m_chart) | |
120 | d->m_chart->removeAxis(this); |
|
120 | d->m_chart->removeAxis(this); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \internal |
|
124 | \internal | |
125 | */ |
|
125 | */ | |
126 | QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d, QObject *parent): QValueAxis(d, parent) |
|
126 | QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d, QObject *parent): QValueAxis(d, parent) | |
127 | { |
|
127 | { | |
128 |
|
128 | |||
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | \qmlmethod CategoryAxis::append(string label, real endValue) |
|
132 | \qmlmethod CategoryAxis::append(string label, real endValue) | |
133 | Appends new category to the axis with an \a label. Category label has to be unique. |
|
133 | Appends new category to the axis with an \a label. Category label has to be unique. | |
134 | Parameter \a endValue specifies the high end limit of the category. |
|
134 | Parameter \a endValue specifies the high end limit of the category. | |
135 | It has to be greater than the high end limit of the previous category. |
|
135 | It has to be greater than the high end limit of the previous category. | |
136 | Otherwise the method returns without adding a new category. |
|
136 | Otherwise the method returns without adding a new category. | |
137 | */ |
|
137 | */ | |
138 | /*! |
|
138 | /*! | |
139 | Appends new category to the axis with an \a categoryLabel. |
|
139 | Appends new category to the axis with an \a categoryLabel. | |
140 | Category label has to be unique. |
|
140 | Category label has to be unique. | |
141 | Parameter \a categoryEndValue specifies the high end limit of the category. |
|
141 | Parameter \a categoryEndValue specifies the high end limit of the category. | |
142 | It has to be greater than the high end limit of the previous category. |
|
142 | It has to be greater than the high end limit of the previous category. | |
143 | Otherwise the method returns without adding a new category. |
|
143 | Otherwise the method returns without adding a new category. | |
144 | */ |
|
144 | */ | |
145 | void QCategoryAxis::append(const QString &categoryLabel, qreal categoryEndValue) |
|
145 | void QCategoryAxis::append(const QString &categoryLabel, qreal categoryEndValue) | |
146 | { |
|
146 | { | |
147 | Q_D(QCategoryAxis); |
|
147 | Q_D(QCategoryAxis); | |
148 |
|
148 | |||
149 | if (!d->m_categories.contains(categoryLabel)) { |
|
149 | if (!d->m_categories.contains(categoryLabel)) { | |
150 | if (d->m_categories.isEmpty()) { |
|
150 | if (d->m_categories.isEmpty()) { | |
151 | Range range(d->m_categoryMinimum, categoryEndValue); |
|
151 | Range range(d->m_categoryMinimum, categoryEndValue); | |
152 | d->m_categoriesMap.insert(categoryLabel, range); |
|
152 | d->m_categoriesMap.insert(categoryLabel, range); | |
153 | d->m_categories.append(categoryLabel); |
|
153 | d->m_categories.append(categoryLabel); | |
154 | } else if (categoryEndValue > endValue(d->m_categories.last())) { |
|
154 | } else if (categoryEndValue > endValue(d->m_categories.last())) { | |
155 | Range previousRange = d->m_categoriesMap.value(d->m_categories.last()); |
|
155 | Range previousRange = d->m_categoriesMap.value(d->m_categories.last()); | |
156 | d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue)); |
|
156 | d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue)); | |
157 | d->m_categories.append(categoryLabel); |
|
157 | d->m_categories.append(categoryLabel); | |
158 | } |
|
158 | } | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | /*! |
|
162 | /*! | |
163 | Sets \a min to be the low end limit of the first category on the axis. |
|
163 | Sets \a min to be the low end limit of the first category on the axis. | |
164 | If there is already some categories added to the axis then passed value must be lower than the high end value of the already defined first category range. |
|
164 | If there is already some categories added to the axis then passed value must be lower than the high end value of the already defined first category range. | |
165 | Otherwise nothing is done. |
|
165 | Otherwise nothing is done. | |
166 | */ |
|
166 | */ | |
167 | void QCategoryAxis::setStartValue(qreal min) |
|
167 | void QCategoryAxis::setStartValue(qreal min) | |
168 | { |
|
168 | { | |
169 | Q_D(QCategoryAxis); |
|
169 | Q_D(QCategoryAxis); | |
170 | if (d->m_categories.isEmpty()) { |
|
170 | if (d->m_categories.isEmpty()) { | |
171 | d->m_categoryMinimum = min; |
|
171 | d->m_categoryMinimum = min; | |
172 | } else { |
|
172 | } else { | |
173 | Range range = d->m_categoriesMap.value(d->m_categories.first()); |
|
173 | Range range = d->m_categoriesMap.value(d->m_categories.first()); | |
174 | if (min < range.second) |
|
174 | if (min < range.second) | |
175 | d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second)); |
|
175 | d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second)); | |
176 | } |
|
176 | } | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | Returns the low end limit of the category specified by an \a categoryLabel |
|
180 | Returns the low end limit of the category specified by an \a categoryLabel | |
181 | */ |
|
181 | */ | |
182 | qreal QCategoryAxis::startValue(const QString &categoryLabel) const |
|
182 | qreal QCategoryAxis::startValue(const QString &categoryLabel) const | |
183 | { |
|
183 | { | |
184 | Q_D(const QCategoryAxis); |
|
184 | Q_D(const QCategoryAxis); | |
185 | if (categoryLabel.isEmpty()) |
|
185 | if (categoryLabel.isEmpty()) | |
186 | return d->m_categoryMinimum; |
|
186 | return d->m_categoryMinimum; | |
187 | return d->m_categoriesMap.value(categoryLabel).first; |
|
187 | return d->m_categoriesMap.value(categoryLabel).first; | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | Returns the high end limit of the interval specified by an \a categoryLabel |
|
191 | Returns the high end limit of the interval specified by an \a categoryLabel | |
192 | */ |
|
192 | */ | |
193 | qreal QCategoryAxis::endValue(const QString &categoryLabel) const |
|
193 | qreal QCategoryAxis::endValue(const QString &categoryLabel) const | |
194 | { |
|
194 | { | |
195 | Q_D(const QCategoryAxis); |
|
195 | Q_D(const QCategoryAxis); | |
196 | return d->m_categoriesMap.value(categoryLabel).second; |
|
196 | return d->m_categoriesMap.value(categoryLabel).second; | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | /*! |
|
199 | /*! | |
200 | \qmlmethod CategoryAxis::remove(string label) |
|
200 | \qmlmethod CategoryAxis::remove(string label) | |
201 | Removes a category specified by the \a label from the axis |
|
201 | Removes a category specified by the \a label from the axis | |
202 | */ |
|
202 | */ | |
203 | /*! |
|
203 | /*! | |
204 | Removes an interval specified by the \a categoryLabel from the axis |
|
204 | Removes an interval specified by the \a categoryLabel from the axis | |
205 | */ |
|
205 | */ | |
206 | void QCategoryAxis::remove(const QString &categoryLabel) |
|
206 | void QCategoryAxis::remove(const QString &categoryLabel) | |
207 | { |
|
207 | { | |
208 | Q_D(QCategoryAxis); |
|
208 | Q_D(QCategoryAxis); | |
209 | int labelIndex = d->m_categories.indexOf(categoryLabel); |
|
209 | int labelIndex = d->m_categories.indexOf(categoryLabel); | |
210 |
|
210 | |||
211 | // check if such label exists |
|
211 | // check if such label exists | |
212 | if (labelIndex != -1) { |
|
212 | if (labelIndex != -1) { | |
213 | d->m_categories.removeAt(labelIndex); |
|
213 | d->m_categories.removeAt(labelIndex); | |
214 | d->m_categoriesMap.remove(categoryLabel); |
|
214 | d->m_categoriesMap.remove(categoryLabel); | |
215 |
|
215 | |||
216 | // the range of the interval that follows (if exists) needs to be updated |
|
216 | // the range of the interval that follows (if exists) needs to be updated | |
217 | if (labelIndex < d->m_categories.count()) { |
|
217 | if (labelIndex < d->m_categories.count()) { | |
218 | QString label = d->m_categories.at(labelIndex); |
|
218 | QString label = d->m_categories.at(labelIndex); | |
219 | Range range = d->m_categoriesMap.value(label); |
|
219 | Range range = d->m_categoriesMap.value(label); | |
220 |
|
220 | |||
221 | // set the range |
|
221 | // set the range | |
222 | if (labelIndex == 0) { |
|
222 | if (labelIndex == 0) { | |
223 | range.first = d->m_categoryMinimum; |
|
223 | range.first = d->m_categoryMinimum; | |
224 | d->m_categoriesMap.insert(label, range); |
|
224 | d->m_categoriesMap.insert(label, range); | |
225 | } else { |
|
225 | } else { | |
226 | range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second; |
|
226 | range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second; | |
227 | d->m_categoriesMap.insert(label, range); |
|
227 | d->m_categoriesMap.insert(label, range); | |
228 | } |
|
228 | } | |
229 | } |
|
229 | } | |
230 | //TODO:: d->emitUpdated(); |
|
|||
231 | } |
|
230 | } | |
232 | } |
|
231 | } | |
233 |
|
232 | |||
234 | /*! |
|
233 | /*! | |
235 | \qmlmethod CategoryAxis::replace(string oldLabel, string newLabel) |
|
234 | \qmlmethod CategoryAxis::replace(string oldLabel, string newLabel) | |
236 | Replaces \a oldLabel of an existing category with a \a newLabel. |
|
235 | Replaces \a oldLabel of an existing category with a \a newLabel. | |
237 | If the old label does not exist the method returns without making any changes. |
|
236 | If the old label does not exist the method returns without making any changes. | |
238 | */ |
|
237 | */ | |
239 | /*! |
|
238 | /*! | |
240 | Replaces \a oldLabel of an existing category with a \a newLabel |
|
239 | Replaces \a oldLabel of an existing category with a \a newLabel | |
241 | If the old label does not exist the method returns without making any changes. |
|
240 | If the old label does not exist the method returns without making any changes. | |
242 | */ |
|
241 | */ | |
243 | void QCategoryAxis::replaceLabel(const QString &oldLabel, const QString &newLabel) |
|
242 | void QCategoryAxis::replaceLabel(const QString &oldLabel, const QString &newLabel) | |
244 | { |
|
243 | { | |
245 | Q_D(QCategoryAxis); |
|
244 | Q_D(QCategoryAxis); | |
246 | int labelIndex = d->m_categories.indexOf(oldLabel); |
|
245 | int labelIndex = d->m_categories.indexOf(oldLabel); | |
247 |
|
246 | |||
248 | // check if such label exists |
|
247 | // check if such label exists | |
249 | if (labelIndex != -1) { |
|
248 | if (labelIndex != -1) { | |
250 | d->m_categories.replace(labelIndex, newLabel); |
|
249 | d->m_categories.replace(labelIndex, newLabel); | |
251 | Range range = d->m_categoriesMap.value(oldLabel); |
|
250 | Range range = d->m_categoriesMap.value(oldLabel); | |
252 | d->m_categoriesMap.remove(oldLabel); |
|
251 | d->m_categoriesMap.remove(oldLabel); | |
253 | d->m_categoriesMap.insert(newLabel, range); |
|
252 | d->m_categoriesMap.insert(newLabel, range); | |
254 | //TODO:: d->emitUpdated(); |
|
|||
255 | } |
|
253 | } | |
256 | } |
|
254 | } | |
257 |
|
255 | |||
258 | /*! |
|
256 | /*! | |
259 | Returns the list of the intervals labels |
|
257 | Returns the list of the intervals labels | |
260 | */ |
|
258 | */ | |
261 | QStringList QCategoryAxis::categoriesLabels() |
|
259 | QStringList QCategoryAxis::categoriesLabels() | |
262 | { |
|
260 | { | |
263 | Q_D(QCategoryAxis); |
|
261 | Q_D(QCategoryAxis); | |
264 | return d->m_categories; |
|
262 | return d->m_categories; | |
265 | } |
|
263 | } | |
266 |
|
264 | |||
267 | /*! |
|
265 | /*! | |
268 | Returns number of intervals. |
|
266 | Returns number of intervals. | |
269 | */ |
|
267 | */ | |
270 | int QCategoryAxis::count() const |
|
268 | int QCategoryAxis::count() const | |
271 | { |
|
269 | { | |
272 | Q_D(const QCategoryAxis); |
|
270 | Q_D(const QCategoryAxis); | |
273 | return d->m_categories.count(); |
|
271 | return d->m_categories.count(); | |
274 | } |
|
272 | } | |
275 |
|
273 | |||
276 | /*! |
|
274 | /*! | |
277 | Returns the type of the axis |
|
275 | Returns the type of the axis | |
278 | */ |
|
276 | */ | |
279 | QAbstractAxis::AxisType QCategoryAxis::type() const |
|
277 | QAbstractAxis::AxisType QCategoryAxis::type() const | |
280 | { |
|
278 | { | |
281 | return QAbstractAxis::AxisTypeCategory; |
|
279 | return QAbstractAxis::AxisTypeCategory; | |
282 | } |
|
280 | } | |
283 |
|
281 | |||
284 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
282 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
285 |
|
283 | |||
286 | QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis *q) |
|
284 | QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis *q) | |
287 | : QValueAxisPrivate(q), |
|
285 | : QValueAxisPrivate(q), | |
288 | m_categoryMinimum(0) |
|
286 | m_categoryMinimum(0) | |
289 | { |
|
287 | { | |
290 |
|
288 | |||
291 | } |
|
289 | } | |
292 |
|
290 | |||
293 | QCategoryAxisPrivate::~QCategoryAxisPrivate() |
|
291 | QCategoryAxisPrivate::~QCategoryAxisPrivate() | |
294 | { |
|
292 | { | |
295 |
|
293 | |||
296 | } |
|
294 | } | |
297 |
|
295 | |||
298 | int QCategoryAxisPrivate::ticksCount() const |
|
296 | int QCategoryAxisPrivate::ticksCount() const | |
299 | { |
|
297 | { | |
300 | return m_categories.count() + 1; |
|
298 | return m_categories.count() + 1; | |
301 | } |
|
299 | } | |
302 |
|
300 | |||
303 | void QCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
301 | void QCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
304 | { |
|
302 | { | |
305 | Q_Q(QCategoryAxis); |
|
303 | Q_Q(QCategoryAxis); | |
306 | ChartAxis* axis(0); |
|
304 | ChartAxis* axis(0); | |
307 | if (orientation() == Qt::Vertical) |
|
305 | if (orientation() == Qt::Vertical) | |
308 | axis = new ChartCategoryAxisY(q,parent); |
|
306 | axis = new ChartCategoryAxisY(q,parent); | |
309 | else if(orientation() == Qt::Horizontal) |
|
307 | else if(orientation() == Qt::Horizontal) | |
310 | axis = new ChartCategoryAxisX(q,parent); |
|
308 | axis = new ChartCategoryAxisX(q,parent); | |
311 |
|
309 | |||
312 | m_item.reset(axis); |
|
310 | m_item.reset(axis); | |
313 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
311 | QAbstractAxisPrivate::initializeGraphics(parent); | |
314 | } |
|
312 | } | |
315 |
|
313 | |||
316 | #include "moc_qcategoryaxis.cpp" |
|
314 | #include "moc_qcategoryaxis.cpp" | |
317 | #include "moc_qcategoryaxis_p.cpp" |
|
315 | #include "moc_qcategoryaxis_p.cpp" | |
318 |
|
316 | |||
319 | QTCOMMERCIALCHART_END_NAMESPACE |
|
317 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,1007 +1,1002 | |||||
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 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \class QAbstractAxis |
|
29 | \class QAbstractAxis | |
30 | \brief The QAbstractAxis class is used for manipulating chart's axis. |
|
30 | \brief The QAbstractAxis class is used for manipulating chart's axis. | |
31 | \mainclass |
|
31 | \mainclass | |
32 |
|
32 | |||
33 | There is only one x Axis visible at the time, however there can be multiple y axes. |
|
33 | There is only one x Axis visible at the time, however there can be multiple y axes. | |
34 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
34 | Each chart series can be bound to exactly one Y axis and the shared common X axis. | |
35 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \qmlclass AbstractAxis QAbstractAxis |
|
39 | \qmlclass AbstractAxis QAbstractAxis | |
40 | \brief The Axis element is used for manipulating chart's axes |
|
40 | \brief The Axis element is used for manipulating chart's axes | |
41 |
|
41 | |||
42 | There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView. |
|
42 | There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView. | |
43 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
43 | Each chart series can be bound to exactly one Y axis and the shared common X axis. | |
44 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
44 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
45 |
|
45 | |||
46 | To access Axes you can use ChartView API. For example: |
|
46 | To access Axes you can use ChartView API. For example: | |
47 | \code |
|
47 | \code | |
48 | ChartView { |
|
48 | ChartView { | |
49 | axisX.min: 0 |
|
49 | axisX.min: 0 | |
50 | axisX.max: 3 |
|
50 | axisX.max: 3 | |
51 | axisX.ticksCount: 4 |
|
51 | axisX.ticksCount: 4 | |
52 | axisY.min: 0 |
|
52 | axisY.min: 0 | |
53 | axisY.max: 4 |
|
53 | axisY.max: 4 | |
54 | // Add a few series... |
|
54 | // Add a few series... | |
55 | } |
|
55 | } | |
56 | \endcode |
|
56 | \endcode | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \enum QAbstractAxis::AxisType |
|
60 | \enum QAbstractAxis::AxisType | |
61 |
|
61 | |||
62 | The type of the series object. |
|
62 | The type of the series object. | |
63 |
|
63 | |||
64 | \value AxisTypeNoAxis |
|
64 | \value AxisTypeNoAxis | |
65 | \value AxisTypeValue |
|
65 | \value AxisTypeValue | |
66 | \value AxisTypeBarCategory |
|
66 | \value AxisTypeBarCategory | |
67 | \value AxisTypeCategory |
|
67 | \value AxisTypeCategory | |
68 | \value AxisTypeDateTime |
|
68 | \value AxisTypeDateTime | |
69 | \value AxisTypeLogValue |
|
69 | \value AxisTypeLogValue | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | *\fn void QAbstractAxis::type() const |
|
73 | *\fn void QAbstractAxis::type() const | |
74 | Returns the type of the axis |
|
74 | Returns the type of the axis | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \property QAbstractAxis::lineVisible |
|
78 | \property QAbstractAxis::lineVisible | |
79 | The visibility of the axis line |
|
79 | The visibility of the axis line | |
80 | */ |
|
80 | */ | |
81 | /*! |
|
81 | /*! | |
82 | \qmlproperty bool AbstractAxis::lineVisible |
|
82 | \qmlproperty bool AbstractAxis::lineVisible | |
83 | The visibility of the axis line |
|
83 | The visibility of the axis line | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | \property QAbstractAxis::linePen |
|
87 | \property QAbstractAxis::linePen | |
88 | The pen of the line. |
|
88 | The pen of the line. | |
89 | */ |
|
89 | */ | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | \property QAbstractAxis::labelsVisible |
|
92 | \property QAbstractAxis::labelsVisible | |
93 | Defines if axis labels are visible. |
|
93 | Defines if axis labels are visible. | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlproperty bool AbstractAxis::labelsVisible |
|
96 | \qmlproperty bool AbstractAxis::labelsVisible | |
97 | Defines if axis labels are visible. |
|
97 | Defines if axis labels are visible. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \property QAbstractAxis::labelsPen |
|
101 | \property QAbstractAxis::labelsPen | |
102 | The pen of the labels. |
|
102 | The pen of the labels. | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \property QAbstractAxis::labelsBrush |
|
106 | \property QAbstractAxis::labelsBrush | |
107 | The brush of the labels. |
|
107 | The brush of the labels. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \property QAbstractAxis::visible |
|
111 | \property QAbstractAxis::visible | |
112 | The visibility of the axis. |
|
112 | The visibility of the axis. | |
113 | */ |
|
113 | */ | |
114 | /*! |
|
114 | /*! | |
115 | \qmlproperty bool AbstractAxis::visible |
|
115 | \qmlproperty bool AbstractAxis::visible | |
116 | The visibility of the axis. |
|
116 | The visibility of the axis. | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \property QAbstractAxis::gridVisible |
|
120 | \property QAbstractAxis::gridVisible | |
121 | The visibility of the grid lines. |
|
121 | The visibility of the grid lines. | |
122 | */ |
|
122 | */ | |
123 | /*! |
|
123 | /*! | |
124 | \qmlproperty bool AbstractAxis::gridVisible |
|
124 | \qmlproperty bool AbstractAxis::gridVisible | |
125 | The visibility of the grid lines. |
|
125 | The visibility of the grid lines. | |
126 | */ |
|
126 | */ | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | \property QAbstractAxis::color |
|
129 | \property QAbstractAxis::color | |
130 | The color of the axis and ticks. |
|
130 | The color of the axis and ticks. | |
131 | */ |
|
131 | */ | |
132 | /*! |
|
132 | /*! | |
133 | \qmlproperty color AbstractAxis::color |
|
133 | \qmlproperty color AbstractAxis::color | |
134 | The color of the axis and ticks. |
|
134 | The color of the axis and ticks. | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \property QAbstractAxis::gridLinePen |
|
138 | \property QAbstractAxis::gridLinePen | |
139 | The pen of the grid line. |
|
139 | The pen of the grid line. | |
140 | */ |
|
140 | */ | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | \property QAbstractAxis::labelsFont |
|
143 | \property QAbstractAxis::labelsFont | |
144 | The font of the axis labels. |
|
144 | The font of the axis labels. | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \qmlproperty Font AbstractAxis::labelsFont |
|
148 | \qmlproperty Font AbstractAxis::labelsFont | |
149 | The font of the axis labels. |
|
149 | The font of the axis labels. | |
150 |
|
150 | |||
151 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
151 | See the \l {Font} {QML Font Element} for detailed documentation. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \property QAbstractAxis::labelsColor |
|
155 | \property QAbstractAxis::labelsColor | |
156 | The color of the axis labels. |
|
156 | The color of the axis labels. | |
157 | */ |
|
157 | */ | |
158 | /*! |
|
158 | /*! | |
159 | \qmlproperty color AbstractAxis::labelsColor |
|
159 | \qmlproperty color AbstractAxis::labelsColor | |
160 | The color of the axis labels. |
|
160 | The color of the axis labels. | |
161 | */ |
|
161 | */ | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | \property QAbstractAxis::labelsAngle |
|
164 | \property QAbstractAxis::labelsAngle | |
165 | The angle of the axis labels in degrees. |
|
165 | The angle of the axis labels in degrees. | |
166 | */ |
|
166 | */ | |
167 | /*! |
|
167 | /*! | |
168 | \qmlproperty int AbstractAxis::labelsAngle |
|
168 | \qmlproperty int AbstractAxis::labelsAngle | |
169 | The angle of the axis labels in degrees. |
|
169 | The angle of the axis labels in degrees. | |
170 | */ |
|
170 | */ | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | \property QAbstractAxis::shadesVisible |
|
173 | \property QAbstractAxis::shadesVisible | |
174 | The visibility of the axis shades. |
|
174 | The visibility of the axis shades. | |
175 | */ |
|
175 | */ | |
176 | /*! |
|
176 | /*! | |
177 | \qmlproperty bool AbstractAxis::shadesVisible |
|
177 | \qmlproperty bool AbstractAxis::shadesVisible | |
178 | The visibility of the axis shades. |
|
178 | The visibility of the axis shades. | |
179 | */ |
|
179 | */ | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | \property QAbstractAxis::shadesColor |
|
182 | \property QAbstractAxis::shadesColor | |
183 | The fill (brush) color of the axis shades. |
|
183 | The fill (brush) color of the axis shades. | |
184 | */ |
|
184 | */ | |
185 | /*! |
|
185 | /*! | |
186 | \qmlproperty color AbstractAxis::shadesColor |
|
186 | \qmlproperty color AbstractAxis::shadesColor | |
187 | The fill (brush) color of the axis shades. |
|
187 | The fill (brush) color of the axis shades. | |
188 | */ |
|
188 | */ | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | \property QAbstractAxis::shadesBorderColor |
|
191 | \property QAbstractAxis::shadesBorderColor | |
192 | The border (pen) color of the axis shades. |
|
192 | The border (pen) color of the axis shades. | |
193 | */ |
|
193 | */ | |
194 | /*! |
|
194 | /*! | |
195 | \qmlproperty color AbstractAxis::shadesBorderColor |
|
195 | \qmlproperty color AbstractAxis::shadesBorderColor | |
196 | The border (pen) color of the axis shades. |
|
196 | The border (pen) color of the axis shades. | |
197 | */ |
|
197 | */ | |
198 |
|
198 | |||
199 | /*! |
|
199 | /*! | |
200 | \property QAbstractAxis::shadesPen |
|
200 | \property QAbstractAxis::shadesPen | |
201 | The pen of the axis shades (area between grid lines). |
|
201 | The pen of the axis shades (area between grid lines). | |
202 | */ |
|
202 | */ | |
203 |
|
203 | |||
204 | /*! |
|
204 | /*! | |
205 | \property QAbstractAxis::shadesBrush |
|
205 | \property QAbstractAxis::shadesBrush | |
206 | The brush of the axis shades (area between grid lines). |
|
206 | The brush of the axis shades (area between grid lines). | |
207 | */ |
|
207 | */ | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | \property QAbstractAxis::titleVisible |
|
210 | \property QAbstractAxis::titleVisible | |
211 | The visibility of the axis title. By default the value is true. |
|
211 | The visibility of the axis title. By default the value is true. | |
212 | */ |
|
212 | */ | |
213 | /*! |
|
213 | /*! | |
214 | \qmlproperty bool AbstractAxis::titleVisible |
|
214 | \qmlproperty bool AbstractAxis::titleVisible | |
215 | The visibility of the axis title. By default the value is true. |
|
215 | The visibility of the axis title. By default the value is true. | |
216 | */ |
|
216 | */ | |
217 |
|
217 | |||
218 | /*! |
|
218 | /*! | |
219 | \property QAbstractAxis::titleText |
|
219 | \property QAbstractAxis::titleText | |
220 | The title of the axis. Empty by default. |
|
220 | The title of the axis. Empty by default. | |
221 | */ |
|
221 | */ | |
222 | /*! |
|
222 | /*! | |
223 | \qmlproperty String AbstractAxis::titleText |
|
223 | \qmlproperty String AbstractAxis::titleText | |
224 | The title of the axis. Empty by default. |
|
224 | The title of the axis. Empty by default. | |
225 | */ |
|
225 | */ | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | \property QAbstractAxis::titlePen |
|
228 | \property QAbstractAxis::titlePen | |
229 | The pen of the title text. |
|
229 | The pen of the title text. | |
230 | */ |
|
230 | */ | |
231 |
|
231 | |||
232 | /*! |
|
232 | /*! | |
233 | \property QAbstractAxis::titleBrush |
|
233 | \property QAbstractAxis::titleBrush | |
234 | The brush of the title text. |
|
234 | The brush of the title text. | |
235 | */ |
|
235 | */ | |
236 |
|
236 | |||
237 | /*! |
|
237 | /*! | |
238 | \property QAbstractAxis::titleFont |
|
238 | \property QAbstractAxis::titleFont | |
239 | The font of the title of the axis. |
|
239 | The font of the title of the axis. | |
240 | */ |
|
240 | */ | |
241 | /*! |
|
241 | /*! | |
242 | \qmlproperty Font AbstractAxis::titleFont |
|
242 | \qmlproperty Font AbstractAxis::titleFont | |
243 | The font of the title of the axis. |
|
243 | The font of the title of the axis. | |
244 | */ |
|
244 | */ | |
245 |
|
245 | |||
246 | /*! |
|
246 | /*! | |
247 | \property QAbstractAxis::orientation |
|
247 | \property QAbstractAxis::orientation | |
248 | The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart. |
|
248 | The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart. | |
249 | */ |
|
249 | */ | |
250 | /*! |
|
250 | /*! | |
251 | \qmlproperty Qt.Orientation AbstractAxis::orientation |
|
251 | \qmlproperty Qt.Orientation AbstractAxis::orientation | |
252 | The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a Chart/Series. |
|
252 | The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a Chart/Series. | |
253 | */ |
|
253 | */ | |
254 |
|
254 | |||
255 | /*! |
|
255 | /*! | |
256 | \property QAbstractAxis::alignment |
|
256 | \property QAbstractAxis::alignment | |
257 | The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom. |
|
257 | The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom. | |
258 | */ |
|
258 | */ | |
259 | /*! |
|
259 | /*! | |
260 | \qmlproperty alignment AbstractAxis::alignment |
|
260 | \qmlproperty alignment AbstractAxis::alignment | |
261 | The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom. |
|
261 | The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom. | |
262 | */ |
|
262 | */ | |
263 |
|
263 | |||
264 | /*! |
|
264 | /*! | |
265 | \fn void QAbstractAxis::visibleChanged(bool visible) |
|
265 | \fn void QAbstractAxis::visibleChanged(bool visible) | |
266 | Visibility of the axis has changed to \a visible. |
|
266 | Visibility of the axis has changed to \a visible. | |
267 | */ |
|
267 | */ | |
268 | /*! |
|
268 | /*! | |
269 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) |
|
269 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) | |
270 | Visibility of the axis has changed to \a visible. |
|
270 | Visibility of the axis has changed to \a visible. | |
271 | */ |
|
271 | */ | |
272 |
|
272 | |||
273 | /*! |
|
273 | /*! | |
274 | \fn void QAbstractAxis::linePenChanged(const QPen& pen) |
|
274 | \fn void QAbstractAxis::linePenChanged(const QPen& pen) | |
275 | The pen of the line of the axis has changed to \a pen. |
|
275 | The pen of the line of the axis has changed to \a pen. | |
276 | */ |
|
276 | */ | |
277 |
|
277 | |||
278 | /*! |
|
278 | /*! | |
279 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) |
|
279 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) | |
280 | Visibility of the axis line has changed to \a visible. |
|
280 | Visibility of the axis line has changed to \a visible. | |
281 | */ |
|
281 | */ | |
282 | /*! |
|
282 | /*! | |
283 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) |
|
283 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) | |
284 | Visibility of the axis line has changed to \a visible. |
|
284 | Visibility of the axis line has changed to \a visible. | |
285 | */ |
|
285 | */ | |
286 |
|
286 | |||
287 | /*! |
|
287 | /*! | |
288 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) |
|
288 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) | |
289 | Visibility of the labels of the axis has changed to \a visible. |
|
289 | Visibility of the labels of the axis has changed to \a visible. | |
290 | */ |
|
290 | */ | |
291 | /*! |
|
291 | /*! | |
292 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) |
|
292 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) | |
293 | Visibility of the labels of the axis has changed to \a visible. |
|
293 | Visibility of the labels of the axis has changed to \a visible. | |
294 | */ |
|
294 | */ | |
295 |
|
295 | |||
296 | /*! |
|
296 | /*! | |
297 | \fn void QAbstractAxis::labelsFontChanged(const QFont& font) |
|
297 | \fn void QAbstractAxis::labelsFontChanged(const QFont& font) | |
298 | The font of the axis labels has changed to \a font. |
|
298 | The font of the axis labels has changed to \a font. | |
299 | */ |
|
299 | */ | |
300 | /*! |
|
300 | /*! | |
301 | \qmlsignal AbstractAxis::onLabelsFontChanged(Font font) |
|
301 | \qmlsignal AbstractAxis::onLabelsFontChanged(Font font) | |
302 | The font of the axis labels has changed to \a font. |
|
302 | The font of the axis labels has changed to \a font. | |
303 | */ |
|
303 | */ | |
304 |
|
304 | |||
305 | /*! |
|
305 | /*! | |
306 | \fn void QAbstractAxis::labelsPenChanged(const QPen& pen) |
|
306 | \fn void QAbstractAxis::labelsPenChanged(const QPen& pen) | |
307 | The pen of the axis labels has changed to \a pen. |
|
307 | The pen of the axis labels has changed to \a pen. | |
308 | */ |
|
308 | */ | |
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush) |
|
311 | \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush) | |
312 | The brush of the axis labels has changed to \a brush. |
|
312 | The brush of the axis labels has changed to \a brush. | |
313 | */ |
|
313 | */ | |
314 |
|
314 | |||
315 | /*! |
|
315 | /*! | |
316 | \fn void QAbstractAxis::labelsAngleChanged(int angle) |
|
316 | \fn void QAbstractAxis::labelsAngleChanged(int angle) | |
317 | The angle of the axis labels has changed to \a angle. |
|
317 | The angle of the axis labels has changed to \a angle. | |
318 | */ |
|
318 | */ | |
319 | /*! |
|
319 | /*! | |
320 | \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle) |
|
320 | \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle) | |
321 | The angle of the axis labels has changed to \a angle. |
|
321 | The angle of the axis labels has changed to \a angle. | |
322 | */ |
|
322 | */ | |
323 |
|
323 | |||
324 | /*! |
|
324 | /*! | |
325 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) |
|
325 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) | |
326 | 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. | |
327 | */ |
|
327 | */ | |
328 | /*! |
|
328 | /*! | |
329 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) |
|
329 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) | |
330 | Visibility of the grid lines of the axis has changed to \a visible. |
|
330 | Visibility of the grid lines of the axis has changed to \a visible. | |
331 | */ |
|
331 | */ | |
332 |
|
332 | |||
333 | /*! |
|
333 | /*! | |
334 | \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen) |
|
334 | \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen) | |
335 | The pen of the grid line has changed to \a pen. |
|
335 | The pen of the grid line has changed to \a pen. | |
336 | */ |
|
336 | */ | |
337 |
|
337 | |||
338 | /*! |
|
338 | /*! | |
339 | \fn void QAbstractAxis::colorChanged(QColor color) |
|
339 | \fn void QAbstractAxis::colorChanged(QColor color) | |
340 | Emitted if the \a color of the axis is changed. |
|
340 | Emitted if the \a color of the axis is changed. | |
341 | */ |
|
341 | */ | |
342 | /*! |
|
342 | /*! | |
343 | \qmlsignal AbstractAxis::onColorChanged(QColor color) |
|
343 | \qmlsignal AbstractAxis::onColorChanged(QColor color) | |
344 | Emitted if the \a color of the axis is changed. |
|
344 | Emitted if the \a color of the axis is changed. | |
345 | */ |
|
345 | */ | |
346 |
|
346 | |||
347 | /*! |
|
347 | /*! | |
348 | \fn void QAbstractAxis::labelsColorChanged(QColor color) |
|
348 | \fn void QAbstractAxis::labelsColorChanged(QColor color) | |
349 | Emitted if the \a color of the axis labels is changed. |
|
349 | Emitted if the \a color of the axis labels is changed. | |
350 | */ |
|
350 | */ | |
351 | /*! |
|
351 | /*! | |
352 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) |
|
352 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) | |
353 | Emitted if the \a color of the axis labels is changed. |
|
353 | Emitted if the \a color of the axis labels is changed. | |
354 | */ |
|
354 | */ | |
355 |
|
355 | |||
356 | /*! |
|
356 | /*! | |
357 | \fn void QAbstractAxis::titleVisibleChanged(bool visible) |
|
357 | \fn void QAbstractAxis::titleVisibleChanged(bool visible) | |
358 | 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. | |
359 | */ |
|
359 | */ | |
360 | /*! |
|
360 | /*! | |
361 | \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible) |
|
361 | \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible) | |
362 | Visibility of the title text of the axis has changed to \a visible. |
|
362 | Visibility of the title text of the axis has changed to \a visible. | |
363 | */ |
|
363 | */ | |
364 |
|
364 | |||
365 | /*! |
|
365 | /*! | |
366 | \fn void QAbstractAxis::titleTextChanged(const QString& text) |
|
366 | \fn void QAbstractAxis::titleTextChanged(const QString& text) | |
367 | The text of the axis title has changed to \a text. |
|
367 | The text of the axis title has changed to \a text. | |
368 | */ |
|
368 | */ | |
369 | /*! |
|
369 | /*! | |
370 | \qmlsignal AbstractAxis::onTitleTextChanged(String text) |
|
370 | \qmlsignal AbstractAxis::onTitleTextChanged(String text) | |
371 | The text of the axis title has changed to \a text. |
|
371 | The text of the axis title has changed to \a text. | |
372 | */ |
|
372 | */ | |
373 |
|
373 | |||
374 | /*! |
|
374 | /*! | |
375 | \fn void QAbstractAxis::titlePenChanged(const QPen& pen) |
|
375 | \fn void QAbstractAxis::titlePenChanged(const QPen& pen) | |
376 | The pen of the axis shades has changed to \a pen. |
|
376 | The pen of the axis shades has changed to \a pen. | |
377 | */ |
|
377 | */ | |
378 |
|
378 | |||
379 | /*! |
|
379 | /*! | |
380 | \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush) |
|
380 | \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush) | |
381 | The brush of the axis title has changed to \a brush. |
|
381 | The brush of the axis title has changed to \a brush. | |
382 | */ |
|
382 | */ | |
383 |
|
383 | |||
384 | /*! |
|
384 | /*! | |
385 | \fn void QAbstractAxis::titleFontChanged(const QFont& font) |
|
385 | \fn void QAbstractAxis::titleFontChanged(const QFont& font) | |
386 | The font of the axis title has changed to \a font. |
|
386 | The font of the axis title has changed to \a font. | |
387 | */ |
|
387 | */ | |
388 | /*! |
|
388 | /*! | |
389 | \qmlsignal AbstractAxis::onTitleFontChanged(Font font) |
|
389 | \qmlsignal AbstractAxis::onTitleFontChanged(Font font) | |
390 | The font of the axis title has changed to \a font. |
|
390 | The font of the axis title has changed to \a font. | |
391 | */ |
|
391 | */ | |
392 |
|
392 | |||
393 | /*! |
|
393 | /*! | |
394 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
394 | \fn void QAbstractAxis::shadesVisibleChanged(bool) | |
395 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
395 | Emitted if the visibility of the axis shades is changed to \a visible. | |
396 | */ |
|
396 | */ | |
397 | /*! |
|
397 | /*! | |
398 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) |
|
398 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) | |
399 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
399 | Emitted if the visibility of the axis shades is changed to \a visible. | |
400 | */ |
|
400 | */ | |
401 |
|
401 | |||
402 | /*! |
|
402 | /*! | |
403 | \fn void QAbstractAxis::shadesColorChanged(QColor color) |
|
403 | \fn void QAbstractAxis::shadesColorChanged(QColor color) | |
404 | Emitted if the \a color of the axis shades is changed. |
|
404 | Emitted if the \a color of the axis shades is changed. | |
405 | */ |
|
405 | */ | |
406 | /*! |
|
406 | /*! | |
407 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) |
|
407 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) | |
408 | Emitted if the \a color of the axis shades is changed. |
|
408 | Emitted if the \a color of the axis shades is changed. | |
409 | */ |
|
409 | */ | |
410 |
|
410 | |||
411 | /*! |
|
411 | /*! | |
412 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
412 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) | |
413 | Emitted if the border \a color of the axis shades is changed. |
|
413 | Emitted if the border \a color of the axis shades is changed. | |
414 | */ |
|
414 | */ | |
415 | /*! |
|
415 | /*! | |
416 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) |
|
416 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) | |
417 | Emitted if the border \a color of the axis shades is changed. |
|
417 | Emitted if the border \a color of the axis shades is changed. | |
418 | */ |
|
418 | */ | |
419 |
|
419 | |||
420 | /*! |
|
420 | /*! | |
421 | \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush) |
|
421 | \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush) | |
422 | The brush of the axis shades has changed to \a brush. |
|
422 | The brush of the axis shades has changed to \a brush. | |
423 | */ |
|
423 | */ | |
424 |
|
424 | |||
425 | /*! |
|
425 | /*! | |
426 | \fn void QAbstractAxis::shadesPenChanged(const QPen& pen) |
|
426 | \fn void QAbstractAxis::shadesPenChanged(const QPen& pen) | |
427 | The pen of the axis shades has changed to \a pen. |
|
427 | The pen of the axis shades has changed to \a pen. | |
428 | */ |
|
428 | */ | |
429 |
|
429 | |||
430 | /*! |
|
430 | /*! | |
431 | \internal |
|
431 | \internal | |
432 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
432 | Constructs new axis object which is a child of \a parent. Ownership is taken by | |
433 | QChart when axis added. |
|
433 | QChart when axis added. | |
434 | */ |
|
434 | */ | |
435 |
|
435 | |||
436 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) |
|
436 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) | |
437 | : QObject(parent), |
|
437 | : QObject(parent), | |
438 | d_ptr(&d) |
|
438 | d_ptr(&d) | |
439 | { |
|
439 | { | |
440 | } |
|
440 | } | |
441 |
|
441 | |||
442 | /*! |
|
442 | /*! | |
443 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
443 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. | |
444 | */ |
|
444 | */ | |
445 |
|
445 | |||
446 | QAbstractAxis::~QAbstractAxis() |
|
446 | QAbstractAxis::~QAbstractAxis() | |
447 | { |
|
447 | { | |
448 | if (d_ptr->m_chart) |
|
448 | if (d_ptr->m_chart) | |
449 | qFatal("Still binded axis detected !"); |
|
449 | qFatal("Still binded axis detected !"); | |
450 | } |
|
450 | } | |
451 |
|
451 | |||
452 | /*! |
|
452 | /*! | |
453 | Sets \a pen used to draw axis line and ticks. |
|
453 | Sets \a pen used to draw axis line and ticks. | |
454 | */ |
|
454 | */ | |
455 | void QAbstractAxis::setLinePen(const QPen &pen) |
|
455 | void QAbstractAxis::setLinePen(const QPen &pen) | |
456 | { |
|
456 | { | |
457 | if (d_ptr->m_axisPen != pen) { |
|
457 | if (d_ptr->m_axisPen != pen) { | |
458 | d_ptr->m_axisPen = pen; |
|
458 | d_ptr->m_axisPen = pen; | |
459 | emit linePenChanged(pen); |
|
459 | emit linePenChanged(pen); | |
460 | } |
|
460 | } | |
461 | } |
|
461 | } | |
462 |
|
462 | |||
463 | /*! |
|
463 | /*! | |
464 | Returns pen used to draw axis and ticks. |
|
464 | Returns pen used to draw axis and ticks. | |
465 | */ |
|
465 | */ | |
466 | QPen QAbstractAxis::linePen() const |
|
466 | QPen QAbstractAxis::linePen() const | |
467 | { |
|
467 | { | |
468 | return d_ptr->m_axisPen; |
|
468 | return d_ptr->m_axisPen; | |
469 | } |
|
469 | } | |
470 |
|
470 | |||
471 | //TODO: remove me 2.0 |
|
|||
472 | void QAbstractAxis::setLinePenColor(QColor color) |
|
471 | void QAbstractAxis::setLinePenColor(QColor color) | |
473 | { |
|
472 | { | |
474 | QPen p = d_ptr->m_axisPen; |
|
473 | QPen p = d_ptr->m_axisPen; | |
475 | if (p.color() != color) { |
|
474 | if (p.color() != color) { | |
476 | p.setColor(color); |
|
475 | p.setColor(color); | |
477 | setLinePen(p); |
|
476 | setLinePen(p); | |
478 | emit colorChanged(color); |
|
477 | emit colorChanged(color); | |
479 | } |
|
478 | } | |
480 | } |
|
479 | } | |
481 |
|
480 | |||
482 | QColor QAbstractAxis::linePenColor() const |
|
481 | QColor QAbstractAxis::linePenColor() const | |
483 | { |
|
482 | { | |
484 | return d_ptr->m_axisPen.color(); |
|
483 | return d_ptr->m_axisPen.color(); | |
485 | } |
|
484 | } | |
486 |
|
485 | |||
487 | /*! |
|
486 | /*! | |
488 | Sets if axis and ticks are \a visible. |
|
487 | Sets if axis and ticks are \a visible. | |
489 | */ |
|
488 | */ | |
490 | void QAbstractAxis::setLineVisible(bool visible) |
|
489 | void QAbstractAxis::setLineVisible(bool visible) | |
491 | { |
|
490 | { | |
492 | if (d_ptr->m_arrowVisible != visible) { |
|
491 | if (d_ptr->m_arrowVisible != visible) { | |
493 | d_ptr->m_arrowVisible = visible; |
|
492 | d_ptr->m_arrowVisible = visible; | |
494 | emit lineVisibleChanged(visible); |
|
493 | emit lineVisibleChanged(visible); | |
495 | } |
|
494 | } | |
496 | } |
|
495 | } | |
497 |
|
496 | |||
498 | bool QAbstractAxis::isLineVisible() const |
|
497 | bool QAbstractAxis::isLineVisible() const | |
499 | { |
|
498 | { | |
500 | return d_ptr->m_arrowVisible; |
|
499 | return d_ptr->m_arrowVisible; | |
501 | } |
|
500 | } | |
502 |
|
501 | |||
503 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
502 | void QAbstractAxis::setGridLineVisible(bool visible) | |
504 | { |
|
503 | { | |
505 | if (d_ptr->m_gridLineVisible != visible) { |
|
504 | if (d_ptr->m_gridLineVisible != visible) { | |
506 | d_ptr->m_gridLineVisible = visible; |
|
505 | d_ptr->m_gridLineVisible = visible; | |
507 | emit gridVisibleChanged(visible); |
|
506 | emit gridVisibleChanged(visible); | |
508 | } |
|
507 | } | |
509 | } |
|
508 | } | |
510 |
|
509 | |||
511 | bool QAbstractAxis::isGridLineVisible() const |
|
510 | bool QAbstractAxis::isGridLineVisible() const | |
512 | { |
|
511 | { | |
513 | return d_ptr->m_gridLineVisible; |
|
512 | return d_ptr->m_gridLineVisible; | |
514 | } |
|
513 | } | |
515 |
|
514 | |||
516 | /*! |
|
515 | /*! | |
517 | Sets \a pen used to draw grid line. |
|
516 | Sets \a pen used to draw grid line. | |
518 | */ |
|
517 | */ | |
519 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
518 | void QAbstractAxis::setGridLinePen(const QPen &pen) | |
520 | { |
|
519 | { | |
521 | if (d_ptr->m_gridLinePen != pen) { |
|
520 | if (d_ptr->m_gridLinePen != pen) { | |
522 | d_ptr->m_gridLinePen = pen; |
|
521 | d_ptr->m_gridLinePen = pen; | |
523 | emit gridLinePenChanged(pen); |
|
522 | emit gridLinePenChanged(pen); | |
524 | } |
|
523 | } | |
525 | } |
|
524 | } | |
526 |
|
525 | |||
527 | /*! |
|
526 | /*! | |
528 | Returns pen used to draw grid. |
|
527 | Returns pen used to draw grid. | |
529 | */ |
|
528 | */ | |
530 | QPen QAbstractAxis::gridLinePen() const |
|
529 | QPen QAbstractAxis::gridLinePen() const | |
531 | { |
|
530 | { | |
532 | return d_ptr->m_gridLinePen; |
|
531 | return d_ptr->m_gridLinePen; | |
533 | } |
|
532 | } | |
534 |
|
533 | |||
535 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
534 | void QAbstractAxis::setLabelsVisible(bool visible) | |
536 | { |
|
535 | { | |
537 | if (d_ptr->m_labelsVisible != visible) { |
|
536 | if (d_ptr->m_labelsVisible != visible) { | |
538 | d_ptr->m_labelsVisible = visible; |
|
537 | d_ptr->m_labelsVisible = visible; | |
539 | emit labelsVisibleChanged(visible); |
|
538 | emit labelsVisibleChanged(visible); | |
540 | } |
|
539 | } | |
541 | } |
|
540 | } | |
542 |
|
541 | |||
543 | bool QAbstractAxis::labelsVisible() const |
|
542 | bool QAbstractAxis::labelsVisible() const | |
544 | { |
|
543 | { | |
545 | return d_ptr->m_labelsVisible; |
|
544 | return d_ptr->m_labelsVisible; | |
546 | } |
|
545 | } | |
547 |
|
546 | |||
548 | /*! |
|
547 | /*! | |
549 | Sets \a pen used to draw labels. |
|
548 | Sets \a pen used to draw labels. | |
550 | */ |
|
549 | */ | |
551 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
550 | void QAbstractAxis::setLabelsPen(const QPen &pen) | |
552 | { |
|
551 | { | |
553 | if (d_ptr->m_labelsPen != pen) { |
|
552 | if (d_ptr->m_labelsPen != pen) { | |
554 | d_ptr->m_labelsPen = pen; |
|
553 | d_ptr->m_labelsPen = pen; | |
555 | emit labelsPenChanged(pen); |
|
554 | emit labelsPenChanged(pen); | |
556 | } |
|
555 | } | |
557 | } |
|
556 | } | |
558 |
|
557 | |||
559 | /*! |
|
558 | /*! | |
560 | Returns the pen used to labels. |
|
559 | Returns the pen used to labels. | |
561 | */ |
|
560 | */ | |
562 | QPen QAbstractAxis::labelsPen() const |
|
561 | QPen QAbstractAxis::labelsPen() const | |
563 | { |
|
562 | { | |
564 | return d_ptr->m_labelsPen; |
|
563 | return d_ptr->m_labelsPen; | |
565 | } |
|
564 | } | |
566 |
|
565 | |||
567 | /*! |
|
566 | /*! | |
568 | Sets \a brush used to draw labels. |
|
567 | Sets \a brush used to draw labels. | |
569 | */ |
|
568 | */ | |
570 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
569 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) | |
571 | { |
|
570 | { | |
572 | if (d_ptr->m_labelsBrush != brush) { |
|
571 | if (d_ptr->m_labelsBrush != brush) { | |
573 | d_ptr->m_labelsBrush = brush; |
|
572 | d_ptr->m_labelsBrush = brush; | |
574 | emit labelsBrushChanged(brush); |
|
573 | emit labelsBrushChanged(brush); | |
575 | } |
|
574 | } | |
576 | } |
|
575 | } | |
577 |
|
576 | |||
578 | /*! |
|
577 | /*! | |
579 | Returns brush used to draw labels. |
|
578 | Returns brush used to draw labels. | |
580 | */ |
|
579 | */ | |
581 | QBrush QAbstractAxis::labelsBrush() const |
|
580 | QBrush QAbstractAxis::labelsBrush() const | |
582 | { |
|
581 | { | |
583 | return d_ptr->m_labelsBrush; |
|
582 | return d_ptr->m_labelsBrush; | |
584 | } |
|
583 | } | |
585 |
|
584 | |||
586 | /*! |
|
585 | /*! | |
587 | Sets \a font used to draw labels. |
|
586 | Sets \a font used to draw labels. | |
588 | */ |
|
587 | */ | |
589 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
588 | void QAbstractAxis::setLabelsFont(const QFont &font) | |
590 | { |
|
589 | { | |
591 | if (d_ptr->m_labelsFont != font) { |
|
590 | if (d_ptr->m_labelsFont != font) { | |
592 | d_ptr->m_labelsFont = font; |
|
591 | d_ptr->m_labelsFont = font; | |
593 | emit labelsFontChanged(font); |
|
592 | emit labelsFontChanged(font); | |
594 | } |
|
593 | } | |
595 | } |
|
594 | } | |
596 |
|
595 | |||
597 | /*! |
|
596 | /*! | |
598 | Returns font used to draw labels. |
|
597 | Returns font used to draw labels. | |
599 | */ |
|
598 | */ | |
600 | QFont QAbstractAxis::labelsFont() const |
|
599 | QFont QAbstractAxis::labelsFont() const | |
601 | { |
|
600 | { | |
602 | return d_ptr->m_labelsFont; |
|
601 | return d_ptr->m_labelsFont; | |
603 | } |
|
602 | } | |
604 |
|
603 | |||
605 | void QAbstractAxis::setLabelsAngle(int angle) |
|
604 | void QAbstractAxis::setLabelsAngle(int angle) | |
606 | { |
|
605 | { | |
607 | if (d_ptr->m_labelsAngle != angle) { |
|
606 | if (d_ptr->m_labelsAngle != angle) { | |
608 | d_ptr->m_labelsAngle = angle; |
|
607 | d_ptr->m_labelsAngle = angle; | |
609 | emit labelsAngleChanged(angle); |
|
608 | emit labelsAngleChanged(angle); | |
610 | } |
|
609 | } | |
611 | } |
|
610 | } | |
612 |
|
611 | |||
613 | int QAbstractAxis::labelsAngle() const |
|
612 | int QAbstractAxis::labelsAngle() const | |
614 | { |
|
613 | { | |
615 | return d_ptr->m_labelsAngle; |
|
614 | return d_ptr->m_labelsAngle; | |
616 | } |
|
615 | } | |
617 | //TODO: remove me 2.0 |
|
|||
618 | void QAbstractAxis::setLabelsColor(QColor color) |
|
616 | void QAbstractAxis::setLabelsColor(QColor color) | |
619 | { |
|
617 | { | |
620 | QBrush b = d_ptr->m_labelsBrush; |
|
618 | QBrush b = d_ptr->m_labelsBrush; | |
621 | if (b.color() != color) { |
|
619 | if (b.color() != color) { | |
622 | b.setColor(color); |
|
620 | b.setColor(color); | |
623 | setLabelsBrush(b); |
|
621 | setLabelsBrush(b); | |
624 | emit labelsColorChanged(color); |
|
622 | emit labelsColorChanged(color); | |
625 | } |
|
623 | } | |
626 | } |
|
624 | } | |
627 |
|
625 | |||
628 | QColor QAbstractAxis::labelsColor() const |
|
626 | QColor QAbstractAxis::labelsColor() const | |
629 | { |
|
627 | { | |
630 | return d_ptr->m_labelsBrush.color(); |
|
628 | return d_ptr->m_labelsBrush.color(); | |
631 | } |
|
629 | } | |
632 |
|
630 | |||
633 | void QAbstractAxis::setTitleVisible(bool visible) |
|
631 | void QAbstractAxis::setTitleVisible(bool visible) | |
634 | { |
|
632 | { | |
635 | if (d_ptr->m_titleVisible != visible) { |
|
633 | if (d_ptr->m_titleVisible != visible) { | |
636 | d_ptr->m_titleVisible = visible; |
|
634 | d_ptr->m_titleVisible = visible; | |
637 | emit titleVisibleChanged(visible); |
|
635 | emit titleVisibleChanged(visible); | |
638 | } |
|
636 | } | |
639 | } |
|
637 | } | |
640 |
|
638 | |||
641 | bool QAbstractAxis::isTitleVisible() const |
|
639 | bool QAbstractAxis::isTitleVisible() const | |
642 | { |
|
640 | { | |
643 | return d_ptr->m_titleVisible; |
|
641 | return d_ptr->m_titleVisible; | |
644 | } |
|
642 | } | |
645 |
|
643 | |||
646 | /*! |
|
644 | /*! | |
647 | Sets \a pen used to draw title. |
|
645 | Sets \a pen used to draw title. | |
648 | */ |
|
646 | */ | |
649 | void QAbstractAxis::setTitlePen(const QPen &pen) |
|
647 | void QAbstractAxis::setTitlePen(const QPen &pen) | |
650 | { |
|
648 | { | |
651 | if (d_ptr->m_titlePen != pen) { |
|
649 | if (d_ptr->m_titlePen != pen) { | |
652 | d_ptr->m_titlePen = pen; |
|
650 | d_ptr->m_titlePen = pen; | |
653 | emit titlePenChanged(pen); |
|
651 | emit titlePenChanged(pen); | |
654 | } |
|
652 | } | |
655 | } |
|
653 | } | |
656 |
|
654 | |||
657 | /*! |
|
655 | /*! | |
658 | Returns the pen used to title. |
|
656 | Returns the pen used to title. | |
659 | */ |
|
657 | */ | |
660 | QPen QAbstractAxis::titlePen() const |
|
658 | QPen QAbstractAxis::titlePen() const | |
661 | { |
|
659 | { | |
662 | return d_ptr->m_titlePen; |
|
660 | return d_ptr->m_titlePen; | |
663 | } |
|
661 | } | |
664 |
|
662 | |||
665 | /*! |
|
663 | /*! | |
666 | Sets \a brush used to draw title. |
|
664 | Sets \a brush used to draw title. | |
667 | */ |
|
665 | */ | |
668 | void QAbstractAxis::setTitleBrush(const QBrush &brush) |
|
666 | void QAbstractAxis::setTitleBrush(const QBrush &brush) | |
669 | { |
|
667 | { | |
670 | if (d_ptr->m_titleBrush != brush) { |
|
668 | if (d_ptr->m_titleBrush != brush) { | |
671 | d_ptr->m_titleBrush = brush; |
|
669 | d_ptr->m_titleBrush = brush; | |
672 | emit titleBrushChanged(brush); |
|
670 | emit titleBrushChanged(brush); | |
673 | } |
|
671 | } | |
674 | } |
|
672 | } | |
675 |
|
673 | |||
676 | /*! |
|
674 | /*! | |
677 | Returns brush used to draw title. |
|
675 | Returns brush used to draw title. | |
678 | */ |
|
676 | */ | |
679 | QBrush QAbstractAxis::titleBrush() const |
|
677 | QBrush QAbstractAxis::titleBrush() const | |
680 | { |
|
678 | { | |
681 | return d_ptr->m_titleBrush; |
|
679 | return d_ptr->m_titleBrush; | |
682 | } |
|
680 | } | |
683 |
|
681 | |||
684 | /*! |
|
682 | /*! | |
685 | Sets \a font used to draw title. |
|
683 | Sets \a font used to draw title. | |
686 | */ |
|
684 | */ | |
687 | void QAbstractAxis::setTitleFont(const QFont &font) |
|
685 | void QAbstractAxis::setTitleFont(const QFont &font) | |
688 | { |
|
686 | { | |
689 | if (d_ptr->m_titleFont != font) { |
|
687 | if (d_ptr->m_titleFont != font) { | |
690 | d_ptr->m_titleFont = font; |
|
688 | d_ptr->m_titleFont = font; | |
691 | emit titleFontChanged(font); |
|
689 | emit titleFontChanged(font); | |
692 | } |
|
690 | } | |
693 | } |
|
691 | } | |
694 |
|
692 | |||
695 | /*! |
|
693 | /*! | |
696 | Returns font used to draw title. |
|
694 | Returns font used to draw title. | |
697 | */ |
|
695 | */ | |
698 | QFont QAbstractAxis::titleFont() const |
|
696 | QFont QAbstractAxis::titleFont() const | |
699 | { |
|
697 | { | |
700 | return d_ptr->m_titleFont; |
|
698 | return d_ptr->m_titleFont; | |
701 | } |
|
699 | } | |
702 |
|
700 | |||
703 | void QAbstractAxis::setTitleText(const QString &title) |
|
701 | void QAbstractAxis::setTitleText(const QString &title) | |
704 | { |
|
702 | { | |
705 | if (d_ptr->m_title != title) { |
|
703 | if (d_ptr->m_title != title) { | |
706 | d_ptr->m_title = title; |
|
704 | d_ptr->m_title = title; | |
707 | emit titleTextChanged(title); |
|
705 | emit titleTextChanged(title); | |
708 | } |
|
706 | } | |
709 | } |
|
707 | } | |
710 |
|
708 | |||
711 | QString QAbstractAxis::titleText() const |
|
709 | QString QAbstractAxis::titleText() const | |
712 | { |
|
710 | { | |
713 | return d_ptr->m_title; |
|
711 | return d_ptr->m_title; | |
714 | } |
|
712 | } | |
715 |
|
713 | |||
716 |
|
714 | |||
717 | void QAbstractAxis::setShadesVisible(bool visible) |
|
715 | void QAbstractAxis::setShadesVisible(bool visible) | |
718 | { |
|
716 | { | |
719 | if (d_ptr->m_shadesVisible != visible) { |
|
717 | if (d_ptr->m_shadesVisible != visible) { | |
720 | d_ptr->m_shadesVisible = visible; |
|
718 | d_ptr->m_shadesVisible = visible; | |
721 | emit shadesVisibleChanged(visible); |
|
719 | emit shadesVisibleChanged(visible); | |
722 | } |
|
720 | } | |
723 | } |
|
721 | } | |
724 |
|
722 | |||
725 | bool QAbstractAxis::shadesVisible() const |
|
723 | bool QAbstractAxis::shadesVisible() const | |
726 | { |
|
724 | { | |
727 | return d_ptr->m_shadesVisible; |
|
725 | return d_ptr->m_shadesVisible; | |
728 | } |
|
726 | } | |
729 |
|
727 | |||
730 | /*! |
|
728 | /*! | |
731 | Sets \a pen used to draw shades. |
|
729 | Sets \a pen used to draw shades. | |
732 | */ |
|
730 | */ | |
733 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
731 | void QAbstractAxis::setShadesPen(const QPen &pen) | |
734 | { |
|
732 | { | |
735 | if (d_ptr->m_shadesPen != pen) { |
|
733 | if (d_ptr->m_shadesPen != pen) { | |
736 | d_ptr->m_shadesPen = pen; |
|
734 | d_ptr->m_shadesPen = pen; | |
737 | emit shadesPenChanged(pen); |
|
735 | emit shadesPenChanged(pen); | |
738 | } |
|
736 | } | |
739 | } |
|
737 | } | |
740 |
|
738 | |||
741 | /*! |
|
739 | /*! | |
742 | Returns pen used to draw shades. |
|
740 | Returns pen used to draw shades. | |
743 | */ |
|
741 | */ | |
744 | QPen QAbstractAxis::shadesPen() const |
|
742 | QPen QAbstractAxis::shadesPen() const | |
745 | { |
|
743 | { | |
746 | return d_ptr->m_shadesPen; |
|
744 | return d_ptr->m_shadesPen; | |
747 | } |
|
745 | } | |
748 |
|
746 | |||
749 | /*! |
|
747 | /*! | |
750 | Sets \a brush used to draw shades. |
|
748 | Sets \a brush used to draw shades. | |
751 | */ |
|
749 | */ | |
752 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
750 | void QAbstractAxis::setShadesBrush(const QBrush &brush) | |
753 | { |
|
751 | { | |
754 | if (d_ptr->m_shadesBrush != brush) { |
|
752 | if (d_ptr->m_shadesBrush != brush) { | |
755 | d_ptr->m_shadesBrush = brush; |
|
753 | d_ptr->m_shadesBrush = brush; | |
756 | emit shadesBrushChanged(brush); |
|
754 | emit shadesBrushChanged(brush); | |
757 | } |
|
755 | } | |
758 | } |
|
756 | } | |
759 |
|
757 | |||
760 | /*! |
|
758 | /*! | |
761 | Returns brush used to draw shades. |
|
759 | Returns brush used to draw shades. | |
762 | */ |
|
760 | */ | |
763 | QBrush QAbstractAxis::shadesBrush() const |
|
761 | QBrush QAbstractAxis::shadesBrush() const | |
764 | { |
|
762 | { | |
765 | return d_ptr->m_shadesBrush; |
|
763 | return d_ptr->m_shadesBrush; | |
766 | } |
|
764 | } | |
767 |
|
765 | |||
768 | void QAbstractAxis::setShadesColor(QColor color) |
|
766 | void QAbstractAxis::setShadesColor(QColor color) | |
769 | { |
|
767 | { | |
770 | QBrush b = d_ptr->m_shadesBrush; |
|
768 | QBrush b = d_ptr->m_shadesBrush; | |
771 | if (b.color() != color) { |
|
769 | if (b.color() != color) { | |
772 | b.setColor(color); |
|
770 | b.setColor(color); | |
773 | setShadesBrush(b); |
|
771 | setShadesBrush(b); | |
774 | emit shadesColorChanged(color); |
|
772 | emit shadesColorChanged(color); | |
775 | } |
|
773 | } | |
776 | } |
|
774 | } | |
777 |
|
775 | |||
778 | QColor QAbstractAxis::shadesColor() const |
|
776 | QColor QAbstractAxis::shadesColor() const | |
779 | { |
|
777 | { | |
780 | return d_ptr->m_shadesBrush.color(); |
|
778 | return d_ptr->m_shadesBrush.color(); | |
781 | } |
|
779 | } | |
782 |
|
780 | |||
783 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
781 | void QAbstractAxis::setShadesBorderColor(QColor color) | |
784 | { |
|
782 | { | |
785 | QPen p = d_ptr->m_shadesPen; |
|
783 | QPen p = d_ptr->m_shadesPen; | |
786 | if (p.color() != color) { |
|
784 | if (p.color() != color) { | |
787 | p.setColor(color); |
|
785 | p.setColor(color); | |
788 | setShadesPen(p); |
|
786 | setShadesPen(p); | |
789 | emit shadesColorChanged(color); |
|
787 | emit shadesColorChanged(color); | |
790 | } |
|
788 | } | |
791 | } |
|
789 | } | |
792 |
|
790 | |||
793 | QColor QAbstractAxis::shadesBorderColor() const |
|
791 | QColor QAbstractAxis::shadesBorderColor() const | |
794 | { |
|
792 | { | |
795 | return d_ptr->m_shadesPen.color(); |
|
793 | return d_ptr->m_shadesPen.color(); | |
796 | } |
|
794 | } | |
797 |
|
795 | |||
798 |
|
796 | |||
799 | bool QAbstractAxis::isVisible() const |
|
797 | bool QAbstractAxis::isVisible() const | |
800 | { |
|
798 | { | |
801 | return d_ptr->m_visible; |
|
799 | return d_ptr->m_visible; | |
802 | } |
|
800 | } | |
803 |
|
801 | |||
804 | /*! |
|
802 | /*! | |
805 | Sets axis, shades, labels and grid lines to be visible. |
|
803 | Sets axis, shades, labels and grid lines to be visible. | |
806 | */ |
|
804 | */ | |
807 | void QAbstractAxis::setVisible(bool visible) |
|
805 | void QAbstractAxis::setVisible(bool visible) | |
808 | { |
|
806 | { | |
809 | if (d_ptr->m_visible != visible) { |
|
807 | if (d_ptr->m_visible != visible) { | |
810 | d_ptr->m_visible = visible; |
|
808 | d_ptr->m_visible = visible; | |
811 | emit visibleChanged(visible); |
|
809 | emit visibleChanged(visible); | |
812 | } |
|
810 | } | |
813 | } |
|
811 | } | |
814 |
|
812 | |||
815 |
|
813 | |||
816 | /*! |
|
814 | /*! | |
817 | Sets axis, shades, labels and grid lines to be visible. |
|
815 | Sets axis, shades, labels and grid lines to be visible. | |
818 | */ |
|
816 | */ | |
819 | void QAbstractAxis::show() |
|
817 | void QAbstractAxis::show() | |
820 | { |
|
818 | { | |
821 | setVisible(true); |
|
819 | setVisible(true); | |
822 | } |
|
820 | } | |
823 |
|
821 | |||
824 | /*! |
|
822 | /*! | |
825 | Sets axis, shades, labels and grid lines to not be visible. |
|
823 | Sets axis, shades, labels and grid lines to not be visible. | |
826 | */ |
|
824 | */ | |
827 | void QAbstractAxis::hide() |
|
825 | void QAbstractAxis::hide() | |
828 | { |
|
826 | { | |
829 | setVisible(false); |
|
827 | setVisible(false); | |
830 | } |
|
828 | } | |
831 |
|
829 | |||
832 | /*! |
|
830 | /*! | |
833 | Sets the minimum value shown on the axis. |
|
831 | Sets the minimum value shown on the axis. | |
834 | Depending on the actual axis type the \a min parameter is converted to appropriate type. |
|
832 | Depending on the actual axis type the \a min parameter is converted to appropriate type. | |
835 | If the conversion is impossible then the function call does nothing |
|
833 | If the conversion is impossible then the function call does nothing | |
836 | */ |
|
834 | */ | |
837 | void QAbstractAxis::setMin(const QVariant &min) |
|
835 | void QAbstractAxis::setMin(const QVariant &min) | |
838 | { |
|
836 | { | |
839 | d_ptr->setMin(min); |
|
837 | d_ptr->setMin(min); | |
840 | } |
|
838 | } | |
841 |
|
839 | |||
842 | /*! |
|
840 | /*! | |
843 | Sets the maximum value shown on the axis. |
|
841 | Sets the maximum value shown on the axis. | |
844 | Depending on the actual axis type the \a max parameter is converted to appropriate type. |
|
842 | Depending on the actual axis type the \a max parameter is converted to appropriate type. | |
845 | If the conversion is impossible then the function call does nothing |
|
843 | If the conversion is impossible then the function call does nothing | |
846 | */ |
|
844 | */ | |
847 | void QAbstractAxis::setMax(const QVariant &max) |
|
845 | void QAbstractAxis::setMax(const QVariant &max) | |
848 | { |
|
846 | { | |
849 | d_ptr->setMax(max); |
|
847 | d_ptr->setMax(max); | |
850 | } |
|
848 | } | |
851 |
|
849 | |||
852 | /*! |
|
850 | /*! | |
853 | Sets the range shown on the axis. |
|
851 | Sets the range shown on the axis. | |
854 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. |
|
852 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. | |
855 | If the conversion is impossible then the function call does nothing. |
|
853 | If the conversion is impossible then the function call does nothing. | |
856 | */ |
|
854 | */ | |
857 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
855 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) | |
858 | { |
|
856 | { | |
859 | d_ptr->setRange(min, max); |
|
857 | d_ptr->setRange(min, max); | |
860 | } |
|
858 | } | |
861 |
|
859 | |||
862 |
|
860 | |||
863 | /*! |
|
861 | /*! | |
864 | Returns the orientation in which the axis is being used (Vertical or Horizontal) |
|
862 | Returns the orientation in which the axis is being used (Vertical or Horizontal) | |
865 | */ |
|
863 | */ | |
866 | // NOTE: should have const but it breaks BC: |
|
|||
867 | // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function |
|
|||
868 | Qt::Orientation QAbstractAxis::orientation() |
|
864 | Qt::Orientation QAbstractAxis::orientation() | |
869 | { |
|
865 | { | |
870 | return d_ptr->orientation(); |
|
866 | return d_ptr->orientation(); | |
871 | } |
|
867 | } | |
872 |
|
868 | |||
873 | Qt::Alignment QAbstractAxis::alignment() const |
|
869 | Qt::Alignment QAbstractAxis::alignment() const | |
874 | { |
|
870 | { | |
875 | return d_ptr->alignment(); |
|
871 | return d_ptr->alignment(); | |
876 | } |
|
872 | } | |
877 |
|
873 | |||
878 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
874 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
879 |
|
875 | |||
880 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) |
|
876 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) | |
881 | : q_ptr(q), |
|
877 | : q_ptr(q), | |
882 | m_chart(0), |
|
878 | m_chart(0), | |
883 | m_alignment(0), |
|
879 | m_alignment(0), | |
884 | m_orientation(Qt::Orientation(0)), |
|
880 | m_orientation(Qt::Orientation(0)), | |
885 | m_visible(true), |
|
881 | m_visible(true), | |
886 | m_arrowVisible(true), |
|
882 | m_arrowVisible(true), | |
887 | m_gridLineVisible(true), |
|
883 | m_gridLineVisible(true), | |
888 | m_labelsVisible(true), |
|
884 | m_labelsVisible(true), | |
889 | m_labelsAngle(0), |
|
885 | m_labelsAngle(0), | |
890 | m_titleVisible(true), |
|
886 | m_titleVisible(true), | |
891 | m_shadesVisible(false), |
|
887 | m_shadesVisible(false), | |
892 | m_shadesBrush(Qt::SolidPattern), |
|
888 | m_shadesBrush(Qt::SolidPattern), | |
893 | m_shadesOpacity(1.0), |
|
889 | m_shadesOpacity(1.0), | |
894 | m_dirty(false) |
|
890 | m_dirty(false) | |
895 | { |
|
891 | { | |
896 |
|
892 | |||
897 | } |
|
893 | } | |
898 |
|
894 | |||
899 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
895 | QAbstractAxisPrivate::~QAbstractAxisPrivate() | |
900 | { |
|
896 | { | |
901 | } |
|
897 | } | |
902 |
|
898 | |||
903 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) |
|
899 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) | |
904 | { |
|
900 | { | |
905 | switch(alignment) { |
|
901 | switch(alignment) { | |
906 | case Qt::AlignTop: |
|
902 | case Qt::AlignTop: | |
907 | case Qt::AlignBottom: |
|
903 | case Qt::AlignBottom: | |
908 | m_orientation = Qt::Horizontal; |
|
904 | m_orientation = Qt::Horizontal; | |
909 | break; |
|
905 | break; | |
910 | case Qt::AlignLeft: |
|
906 | case Qt::AlignLeft: | |
911 | case Qt::AlignRight: |
|
907 | case Qt::AlignRight: | |
912 | m_orientation = Qt::Vertical; |
|
908 | m_orientation = Qt::Vertical; | |
913 | break; |
|
909 | break; | |
914 | default: |
|
910 | default: | |
915 | qWarning()<<"No alignment specified !"; |
|
911 | qWarning()<<"No alignment specified !"; | |
916 | break; |
|
912 | break; | |
917 | }; |
|
913 | }; | |
918 | m_alignment=alignment; |
|
914 | m_alignment=alignment; | |
919 | } |
|
915 | } | |
920 |
|
916 | |||
921 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) |
|
917 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) | |
922 | { |
|
918 | { | |
923 | QPen pen; |
|
919 | QPen pen; | |
924 | QBrush brush; |
|
920 | QBrush brush; | |
925 | QFont font; |
|
921 | QFont font; | |
926 |
|
922 | |||
927 | bool axisX = m_orientation == Qt::Horizontal; |
|
923 | bool axisX = m_orientation == Qt::Horizontal; | |
928 |
|
924 | |||
929 | //TODO: introduce axis brush |
|
|||
930 | if (m_visible) { |
|
925 | if (m_visible) { | |
931 | if (m_arrowVisible) { |
|
926 | if (m_arrowVisible) { | |
932 | if (forced || pen == m_axisPen) { |
|
927 | if (forced || pen == m_axisPen) { | |
933 | q_ptr->setLinePen(theme->axisLinePen()); |
|
928 | q_ptr->setLinePen(theme->axisLinePen()); | |
934 | } |
|
929 | } | |
935 | } |
|
930 | } | |
936 | if (m_gridLineVisible) { |
|
931 | if (m_gridLineVisible) { | |
937 | if (forced || pen == m_gridLinePen) { |
|
932 | if (forced || pen == m_gridLinePen) { | |
938 | q_ptr->setGridLinePen(theme->girdLinePen()); |
|
933 | q_ptr->setGridLinePen(theme->girdLinePen()); | |
939 | } |
|
934 | } | |
940 | } |
|
935 | } | |
941 | if (m_labelsVisible) { |
|
936 | if (m_labelsVisible) { | |
942 | if (forced || brush == m_labelsBrush){ |
|
937 | if (forced || brush == m_labelsBrush){ | |
943 | q_ptr->setLabelsBrush(theme->labelBrush()); |
|
938 | q_ptr->setLabelsBrush(theme->labelBrush()); | |
944 | } |
|
939 | } | |
945 | if (forced || pen == m_labelsPen){ |
|
940 | if (forced || pen == m_labelsPen){ | |
946 | q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons |
|
941 | q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons | |
947 | } |
|
942 | } | |
948 | if (forced || font == m_labelsFont){ |
|
943 | if (forced || font == m_labelsFont){ | |
949 | q_ptr->setLabelsFont(theme->labelFont()); |
|
944 | q_ptr->setLabelsFont(theme->labelFont()); | |
950 | } |
|
945 | } | |
951 | } |
|
946 | } | |
952 | if (m_titleVisible) { |
|
947 | if (m_titleVisible) { | |
953 | if (forced || brush == m_titleBrush){ |
|
948 | if (forced || brush == m_titleBrush){ | |
954 | q_ptr->setTitleBrush(theme->labelBrush()); |
|
949 | q_ptr->setTitleBrush(theme->labelBrush()); | |
955 | } |
|
950 | } | |
956 | if (forced || pen == m_titlePen){ |
|
951 | if (forced || pen == m_titlePen){ | |
957 | q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons |
|
952 | q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons | |
958 | } |
|
953 | } | |
959 | if (forced || font == m_titleFont){ |
|
954 | if (forced || font == m_titleFont){ | |
960 | QFont font(m_labelsFont); |
|
955 | QFont font(m_labelsFont); | |
961 | font.setBold(true); |
|
956 | font.setBold(true); | |
962 | q_ptr->setTitleFont(font); |
|
957 | q_ptr->setTitleFont(font); | |
963 | } |
|
958 | } | |
964 | } |
|
959 | } | |
965 | if (forced || m_shadesVisible) { |
|
960 | if (forced || m_shadesVisible) { | |
966 | if (forced || brush == m_shadesBrush){ |
|
961 | if (forced || brush == m_shadesBrush){ | |
967 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); |
|
962 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); | |
968 | } |
|
963 | } | |
969 | if (forced || pen == m_shadesPen){ |
|
964 | if (forced || pen == m_shadesPen){ | |
970 | q_ptr->setShadesPen(theme->backgroundShadesPen()); |
|
965 | q_ptr->setShadesPen(theme->backgroundShadesPen()); | |
971 | } |
|
966 | } | |
972 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth |
|
967 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth | |
973 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) |
|
968 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) | |
974 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { |
|
969 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { | |
975 | q_ptr->setShadesVisible(true); |
|
970 | q_ptr->setShadesVisible(true); | |
976 | } |
|
971 | } | |
977 | } |
|
972 | } | |
978 | } |
|
973 | } | |
979 | } |
|
974 | } | |
980 |
|
975 | |||
981 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) |
|
976 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) | |
982 | { |
|
977 | { | |
983 | setRange(min,max); |
|
978 | setRange(min,max); | |
984 | } |
|
979 | } | |
985 |
|
980 | |||
986 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
981 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
987 | { |
|
982 | { | |
988 | Q_UNUSED(parent); |
|
983 | Q_UNUSED(parent); | |
989 | } |
|
984 | } | |
990 |
|
985 | |||
991 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
986 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) | |
992 | { |
|
987 | { | |
993 | ChartAxis* axis = m_item.data(); |
|
988 | ChartAxis* axis = m_item.data(); | |
994 | Q_ASSERT(axis); |
|
989 | Q_ASSERT(axis); | |
995 | if(options.testFlag(QChart::GridAxisAnimations)) { |
|
990 | if(options.testFlag(QChart::GridAxisAnimations)) { | |
996 | axis->setAnimation(new AxisAnimation(axis)); |
|
991 | axis->setAnimation(new AxisAnimation(axis)); | |
997 | }else{ |
|
992 | }else{ | |
998 | axis->setAnimation(0); |
|
993 | axis->setAnimation(0); | |
999 | } |
|
994 | } | |
1000 | } |
|
995 | } | |
1001 |
|
996 | |||
1002 |
|
997 | |||
1003 |
|
998 | |||
1004 | #include "moc_qabstractaxis.cpp" |
|
999 | #include "moc_qabstractaxis.cpp" | |
1005 | #include "moc_qabstractaxis_p.cpp" |
|
1000 | #include "moc_qabstractaxis_p.cpp" | |
1006 |
|
1001 | |||
1007 | QTCOMMERCIALCHART_END_NAMESPACE |
|
1002 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,192 +1,192 | |||||
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 | #ifndef QABSTRACTAXIS_H |
|
21 | #ifndef QABSTRACTAXIS_H | |
22 | #define QABSTRACTAXIS_H |
|
22 | #define QABSTRACTAXIS_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QPen> |
|
25 | #include <QPen> | |
26 | #include <QFont> |
|
26 | #include <QFont> | |
27 | #include <QVariant> |
|
27 | #include <QVariant> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QAbstractAxisPrivate; |
|
31 | class QAbstractAxisPrivate; | |
32 |
|
32 | |||
33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject |
|
33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | //visibility |
|
36 | //visibility | |
37 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
37 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) | |
38 | //arrow |
|
38 | //arrow | |
39 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) |
|
39 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) | |
40 | Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged) |
|
40 | Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged) | |
41 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) |
|
41 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) | |
42 | //labels |
|
42 | //labels | |
43 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
43 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) | |
44 | Q_PROPERTY(QPen labelsPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged) |
|
44 | Q_PROPERTY(QPen labelsPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged) | |
45 | Q_PROPERTY(QBrush labelsBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged) |
|
45 | Q_PROPERTY(QBrush labelsBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged) | |
46 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged) |
|
46 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged) | |
47 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged) |
|
47 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged) | |
48 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
48 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) | |
49 | //grid |
|
49 | //grid | |
50 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
50 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) | |
51 | Q_PROPERTY(QPen gridLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged) |
|
51 | Q_PROPERTY(QPen gridLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged) | |
52 | //shades |
|
52 | //shades | |
53 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
53 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) | |
54 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
54 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) | |
55 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
55 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) | |
56 | Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged) |
|
56 | Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged) | |
57 | Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged) |
|
57 | Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged) | |
58 | //title |
|
58 | //title | |
59 | Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged) |
|
59 | Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged) | |
60 | Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged) |
|
60 | Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged) | |
61 | Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged) |
|
61 | Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged) | |
62 | Q_PROPERTY(bool titleVisible READ isTitleVisible WRITE setTitleVisible NOTIFY titleVisibleChanged) |
|
62 | Q_PROPERTY(bool titleVisible READ isTitleVisible WRITE setTitleVisible NOTIFY titleVisibleChanged) | |
63 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont NOTIFY titleFontChanged) |
|
63 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont NOTIFY titleFontChanged) | |
64 | //orientation |
|
64 | //orientation | |
65 | Q_PROPERTY(Qt::Orientation orientation READ orientation) |
|
65 | Q_PROPERTY(Qt::Orientation orientation READ orientation) | |
66 | //aligment |
|
66 | //aligment | |
67 | Q_PROPERTY(Qt::Alignment alignment READ alignment) |
|
67 | Q_PROPERTY(Qt::Alignment alignment READ alignment) | |
68 |
|
68 | |||
69 | public: |
|
69 | public: | |
70 |
|
70 | |||
71 | enum AxisType { |
|
71 | enum AxisType { | |
72 | AxisTypeNoAxis = 0x0, |
|
72 | AxisTypeNoAxis = 0x0, | |
73 | AxisTypeValue = 0x1, |
|
73 | AxisTypeValue = 0x1, | |
74 | AxisTypeBarCategory = 0x2, |
|
74 | AxisTypeBarCategory = 0x2, | |
75 | AxisTypeCategory = 0x3, |
|
75 | AxisTypeCategory = 0x3, | |
76 | AxisTypeDateTime = 0x4, |
|
76 | AxisTypeDateTime = 0x4, | |
77 | AxisTypeLogValue = 0x5 |
|
77 | AxisTypeLogValue = 0x5 | |
78 | }; |
|
78 | }; | |
79 |
|
79 | |||
80 | Q_DECLARE_FLAGS(AxisTypes, AxisType) |
|
80 | Q_DECLARE_FLAGS(AxisTypes, AxisType) | |
81 |
|
81 | |||
82 | protected: |
|
82 | protected: | |
83 | explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0); |
|
83 | explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0); | |
84 |
|
84 | |||
85 | public: |
|
85 | public: | |
86 | ~QAbstractAxis(); |
|
86 | ~QAbstractAxis(); | |
87 |
|
87 | |||
88 | virtual AxisType type() const = 0; |
|
88 | virtual AxisType type() const = 0; | |
89 |
|
89 | |||
90 | //visibility handling |
|
90 | //visibility handling | |
91 | bool isVisible() const; |
|
91 | bool isVisible() const; | |
92 | void setVisible(bool visible = true); |
|
92 | void setVisible(bool visible = true); | |
93 | void show(); |
|
93 | void show(); | |
94 | void hide(); |
|
94 | void hide(); | |
95 |
|
95 | |||
96 | //arrow handling |
|
96 | //arrow handling | |
97 | bool isLineVisible() const; |
|
97 | bool isLineVisible() const; | |
98 | void setLineVisible(bool visible = true); |
|
98 | void setLineVisible(bool visible = true); | |
99 | void setLinePen(const QPen &pen); |
|
99 | void setLinePen(const QPen &pen); | |
100 | QPen linePen() const; |
|
100 | QPen linePen() const; | |
101 | void setLinePenColor(QColor color); |
|
101 | void setLinePenColor(QColor color); | |
102 | QColor linePenColor() const; |
|
102 | QColor linePenColor() const; | |
103 |
|
103 | |||
104 | //grid handling |
|
104 | //grid handling | |
105 | bool isGridLineVisible() const; |
|
105 | bool isGridLineVisible() const; | |
106 | void setGridLineVisible(bool visible = true); |
|
106 | void setGridLineVisible(bool visible = true); | |
107 | void setGridLinePen(const QPen &pen); |
|
107 | void setGridLinePen(const QPen &pen); | |
108 | QPen gridLinePen() const; |
|
108 | QPen gridLinePen() const; | |
109 |
|
109 | |||
110 | //labels handling |
|
110 | //labels handling | |
111 | bool labelsVisible() const; |
|
111 | bool labelsVisible() const; | |
112 | void setLabelsVisible(bool visible = true); |
|
112 | void setLabelsVisible(bool visible = true); | |
113 | void setLabelsPen(const QPen &pen); |
|
113 | void setLabelsPen(const QPen &pen); | |
114 | QPen labelsPen() const; |
|
114 | QPen labelsPen() const; | |
115 | void setLabelsBrush(const QBrush &brush); |
|
115 | void setLabelsBrush(const QBrush &brush); | |
116 | QBrush labelsBrush() const; |
|
116 | QBrush labelsBrush() const; | |
117 | void setLabelsFont(const QFont &font); |
|
117 | void setLabelsFont(const QFont &font); | |
118 | QFont labelsFont() const; |
|
118 | QFont labelsFont() const; | |
119 | void setLabelsAngle(int angle); |
|
119 | void setLabelsAngle(int angle); | |
120 | int labelsAngle() const; |
|
120 | int labelsAngle() const; | |
121 | void setLabelsColor(QColor color); |
|
121 | void setLabelsColor(QColor color); | |
122 | QColor labelsColor() const; |
|
122 | QColor labelsColor() const; | |
123 |
|
123 | |||
124 | //title handling |
|
124 | //title handling | |
125 | bool isTitleVisible() const; |
|
125 | bool isTitleVisible() const; | |
126 | void setTitleVisible(bool visible = true); |
|
126 | void setTitleVisible(bool visible = true); | |
127 | void setTitlePen(const QPen &pen); |
|
127 | void setTitlePen(const QPen &pen); | |
128 | QPen titlePen() const; |
|
128 | QPen titlePen() const; | |
129 | void setTitleBrush(const QBrush &brush); |
|
129 | void setTitleBrush(const QBrush &brush); | |
130 | QBrush titleBrush() const; |
|
130 | QBrush titleBrush() const; | |
131 | void setTitleFont(const QFont &font); |
|
131 | void setTitleFont(const QFont &font); | |
132 | QFont titleFont() const; |
|
132 | QFont titleFont() const; | |
133 | void setTitleText(const QString &title); |
|
133 | void setTitleText(const QString &title); | |
134 | QString titleText() const; |
|
134 | QString titleText() const; | |
135 |
|
135 | |||
136 | //shades handling |
|
136 | //shades handling | |
137 | bool shadesVisible() const; |
|
137 | bool shadesVisible() const; | |
138 | void setShadesVisible(bool visible = true); |
|
138 | void setShadesVisible(bool visible = true); | |
139 | void setShadesPen(const QPen &pen); |
|
139 | void setShadesPen(const QPen &pen); | |
140 | QPen shadesPen() const; |
|
140 | QPen shadesPen() const; | |
141 | void setShadesBrush(const QBrush &brush); |
|
141 | void setShadesBrush(const QBrush &brush); | |
142 | QBrush shadesBrush() const; |
|
142 | QBrush shadesBrush() const; | |
143 | void setShadesColor(QColor color); |
|
143 | void setShadesColor(QColor color); | |
144 | QColor shadesColor() const; |
|
144 | QColor shadesColor() const; | |
145 | void setShadesBorderColor(QColor color); |
|
145 | void setShadesBorderColor(QColor color); | |
146 | QColor shadesBorderColor() const; |
|
146 | QColor shadesBorderColor() const; | |
147 |
|
147 | |||
148 |
Qt::Orientation orientation(); |
|
148 | Qt::Orientation orientation(); | |
149 | Qt::Alignment alignment() const; |
|
149 | Qt::Alignment alignment() const; | |
150 |
|
150 | |||
151 | //range handling |
|
151 | //range handling | |
152 | void setMin(const QVariant &min); |
|
152 | void setMin(const QVariant &min); | |
153 | void setMax(const QVariant &max); |
|
153 | void setMax(const QVariant &max); | |
154 | void setRange(const QVariant &min, const QVariant &max); |
|
154 | void setRange(const QVariant &min, const QVariant &max); | |
155 |
|
155 | |||
156 | Q_SIGNALS: |
|
156 | Q_SIGNALS: | |
157 | void visibleChanged(bool visible); |
|
157 | void visibleChanged(bool visible); | |
158 | void linePenChanged(const QPen& pen); |
|
158 | void linePenChanged(const QPen& pen); | |
159 | void lineVisibleChanged(bool visible); |
|
159 | void lineVisibleChanged(bool visible); | |
160 | void labelsVisibleChanged(bool visible); |
|
160 | void labelsVisibleChanged(bool visible); | |
161 | void labelsPenChanged(const QPen& pen); |
|
161 | void labelsPenChanged(const QPen& pen); | |
162 | void labelsBrushChanged(const QBrush& brush); |
|
162 | void labelsBrushChanged(const QBrush& brush); | |
163 | void labelsFontChanged(const QFont& pen); |
|
163 | void labelsFontChanged(const QFont& pen); | |
164 | void labelsAngleChanged(int angle); |
|
164 | void labelsAngleChanged(int angle); | |
165 | void gridLinePenChanged(const QPen& pen); |
|
165 | void gridLinePenChanged(const QPen& pen); | |
166 | void gridVisibleChanged(bool visible); |
|
166 | void gridVisibleChanged(bool visible); | |
167 | void colorChanged(QColor color); |
|
167 | void colorChanged(QColor color); | |
168 | void labelsColorChanged(QColor color); |
|
168 | void labelsColorChanged(QColor color); | |
169 | void titleTextChanged(const QString& title); |
|
169 | void titleTextChanged(const QString& title); | |
170 | void titlePenChanged(const QPen& pen); |
|
170 | void titlePenChanged(const QPen& pen); | |
171 | void titleBrushChanged(const QBrush& brush); |
|
171 | void titleBrushChanged(const QBrush& brush); | |
172 | void titleVisibleChanged(bool visible); |
|
172 | void titleVisibleChanged(bool visible); | |
173 | void titleFontChanged(const QFont& font); |
|
173 | void titleFontChanged(const QFont& font); | |
174 | void shadesVisibleChanged(bool visible); |
|
174 | void shadesVisibleChanged(bool visible); | |
175 | void shadesColorChanged(QColor color); |
|
175 | void shadesColorChanged(QColor color); | |
176 | void shadesBorderColorChanged(QColor color); |
|
176 | void shadesBorderColorChanged(QColor color); | |
177 | void shadesPenChanged(const QPen& pen); |
|
177 | void shadesPenChanged(const QPen& pen); | |
178 | void shadesBrushChanged(const QBrush& brush); |
|
178 | void shadesBrushChanged(const QBrush& brush); | |
179 |
|
179 | |||
180 | protected: |
|
180 | protected: | |
181 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
181 | QScopedPointer<QAbstractAxisPrivate> d_ptr; | |
182 | Q_DISABLE_COPY(QAbstractAxis) |
|
182 | Q_DISABLE_COPY(QAbstractAxis) | |
183 | friend class ChartDataSet; |
|
183 | friend class ChartDataSet; | |
184 | friend class ChartAxis; |
|
184 | friend class ChartAxis; | |
185 | friend class ChartPresenter; |
|
185 | friend class ChartPresenter; | |
186 | friend class ChartThemeManager; |
|
186 | friend class ChartThemeManager; | |
187 | friend class AbstractDomain; |
|
187 | friend class AbstractDomain; | |
188 | }; |
|
188 | }; | |
189 |
|
189 | |||
190 | QTCOMMERCIALCHART_END_NAMESPACE |
|
190 | QTCOMMERCIALCHART_END_NAMESPACE | |
191 |
|
191 | |||
192 | #endif // QABSTRACTAXIS_H |
|
192 | #endif // QABSTRACTAXIS_H |
@@ -1,84 +1,83 | |||||
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 | #ifndef QVALUEAXIS_H |
|
21 | #ifndef QVALUEAXIS_H | |
22 | #define QVALUEAXIS_H |
|
22 | #define QVALUEAXIS_H | |
23 |
|
23 | |||
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QValueAxisPrivate; |
|
28 | class QValueAxisPrivate; | |
29 |
|
29 | |||
30 | class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis |
|
30 | class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged) |
|
33 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged) | |
34 | Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled) |
|
34 | Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled) | |
35 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) |
|
35 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) | |
36 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) |
|
36 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) | |
37 | Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged) |
|
37 | Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged) | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
40 | explicit QValueAxis(QObject *parent = 0); |
|
40 | explicit QValueAxis(QObject *parent = 0); | |
41 | ~QValueAxis(); |
|
41 | ~QValueAxis(); | |
42 |
|
42 | |||
43 | protected: |
|
43 | protected: | |
44 | QValueAxis(QValueAxisPrivate &d, QObject *parent = 0); |
|
44 | QValueAxis(QValueAxisPrivate &d, QObject *parent = 0); | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | AxisType type() const; |
|
47 | AxisType type() const; | |
48 |
|
48 | |||
49 | //range handling |
|
49 | //range handling | |
50 | void setMin(qreal min); |
|
50 | void setMin(qreal min); | |
51 | qreal min() const; |
|
51 | qreal min() const; | |
52 | void setMax(qreal max); |
|
52 | void setMax(qreal max); | |
53 | qreal max() const; |
|
53 | qreal max() const; | |
54 | void setRange(qreal min, qreal max); |
|
54 | void setRange(qreal min, qreal max); | |
55 |
|
55 | |||
56 | //ticks handling |
|
56 | //ticks handling | |
57 | void setTickCount(int count); |
|
57 | void setTickCount(int count); | |
58 | int tickCount() const; |
|
58 | int tickCount() const; | |
59 |
|
59 | |||
60 | void setLabelFormat(const QString &format); |
|
60 | void setLabelFormat(const QString &format); | |
61 | QString labelFormat() const; |
|
61 | QString labelFormat() const; | |
62 |
|
62 | |||
63 | //TODO: deprecated! (2.0) |
|
|||
64 | void setNiceNumbersEnabled(bool enable = true); |
|
63 | void setNiceNumbersEnabled(bool enable = true); | |
65 | bool niceNumbersEnabled() const; |
|
64 | bool niceNumbersEnabled() const; | |
66 |
|
65 | |||
67 | public Q_SLOTS: |
|
66 | public Q_SLOTS: | |
68 | void applyNiceNumbers(); |
|
67 | void applyNiceNumbers(); | |
69 |
|
68 | |||
70 | Q_SIGNALS: |
|
69 | Q_SIGNALS: | |
71 | void minChanged(qreal min); |
|
70 | void minChanged(qreal min); | |
72 | void maxChanged(qreal max); |
|
71 | void maxChanged(qreal max); | |
73 | void rangeChanged(qreal min, qreal max); |
|
72 | void rangeChanged(qreal min, qreal max); | |
74 | void tickCountChanged(int tickCount); |
|
73 | void tickCountChanged(int tickCount); | |
75 | void labelFormatChanged(const QString &format); |
|
74 | void labelFormatChanged(const QString &format); | |
76 |
|
75 | |||
77 | private: |
|
76 | private: | |
78 | Q_DECLARE_PRIVATE(QValueAxis) |
|
77 | Q_DECLARE_PRIVATE(QValueAxis) | |
79 | Q_DISABLE_COPY(QValueAxis) |
|
78 | Q_DISABLE_COPY(QValueAxis) | |
80 | }; |
|
79 | }; | |
81 |
|
80 | |||
82 | QTCOMMERCIALCHART_END_NAMESPACE |
|
81 | QTCOMMERCIALCHART_END_NAMESPACE | |
83 |
|
82 | |||
84 | #endif // QVALUEAXIS_H |
|
83 | #endif // QVALUEAXIS_H |
@@ -1,70 +1,70 | |||||
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 QVALUEAXIS_P_H |
|
30 | #ifndef QVALUEAXIS_P_H | |
31 | #define QVALUEAXIS_P_H |
|
31 | #define QVALUEAXIS_P_H | |
32 |
|
32 | |||
33 | #include "qvalueaxis.h" |
|
33 | #include "qvalueaxis.h" | |
34 | #include "qabstractaxis_p.h" |
|
34 | #include "qabstractaxis_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | class QValueAxisPrivate : public QAbstractAxisPrivate |
|
38 | class QValueAxisPrivate : public QAbstractAxisPrivate | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 | QValueAxisPrivate(QValueAxis *q); |
|
42 | QValueAxisPrivate(QValueAxis *q); | |
43 | ~QValueAxisPrivate(); |
|
43 | ~QValueAxisPrivate(); | |
44 |
|
44 | |||
45 | public: |
|
45 | public: | |
46 | void initializeGraphics(QGraphicsItem* parent); |
|
46 | void initializeGraphics(QGraphicsItem* parent); | |
47 | void initializeDomain(AbstractDomain *domain); |
|
47 | void initializeDomain(AbstractDomain *domain); | |
48 |
|
48 | |||
49 | qreal min() { return m_min; }; |
|
49 | qreal min() { return m_min; }; | |
50 | qreal max() { return m_max; }; |
|
50 | qreal max() { return m_max; }; | |
51 | void setRange(qreal min,qreal max); |
|
51 | void setRange(qreal min,qreal max); | |
52 |
|
52 | |||
53 | protected: |
|
53 | protected: | |
54 | void setMin(const QVariant &min); |
|
54 | void setMin(const QVariant &min); | |
55 | void setMax(const QVariant &max); |
|
55 | void setMax(const QVariant &max); | |
56 | void setRange(const QVariant &min, const QVariant &max); |
|
56 | void setRange(const QVariant &min, const QVariant &max); | |
57 |
|
57 | |||
58 | private: |
|
58 | private: | |
59 | qreal m_min; |
|
59 | qreal m_min; | |
60 | qreal m_max; |
|
60 | qreal m_max; | |
61 | int m_tickCount; |
|
61 | int m_tickCount; | |
62 | QString m_format; |
|
62 | QString m_format; | |
63 | bool m_applying; |
|
63 | bool m_applying; | |
64 |
bool m_niceNumbersEnabled; |
|
64 | bool m_niceNumbersEnabled; | |
65 | Q_DECLARE_PUBLIC(QValueAxis) |
|
65 | Q_DECLARE_PUBLIC(QValueAxis) | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
69 | |||
70 | #endif // QVALUEAXIS_P_H |
|
70 | #endif // QVALUEAXIS_P_H |
@@ -1,167 +1,166 | |||||
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 ChartAxis; |
|
45 | class ChartAxis; | |
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 ChartLayout; |
|
50 | class ChartLayout; | |
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 | ShadesZValue , |
|
58 | ShadesZValue , | |
59 | GridZValue, |
|
59 | GridZValue, | |
60 | AxisZValue, |
|
60 | AxisZValue, | |
61 | SeriesZValue, |
|
61 | SeriesZValue, | |
62 | LineChartZValue = SeriesZValue, |
|
62 | LineChartZValue = SeriesZValue, | |
63 | SplineChartZValue = SeriesZValue, |
|
63 | SplineChartZValue = SeriesZValue, | |
64 | BarSeriesZValue = SeriesZValue, |
|
64 | BarSeriesZValue = SeriesZValue, | |
65 | ScatterSeriesZValue = SeriesZValue, |
|
65 | ScatterSeriesZValue = SeriesZValue, | |
66 | PieSeriesZValue = SeriesZValue, |
|
66 | PieSeriesZValue = SeriesZValue, | |
67 | LegendZValue, |
|
67 | LegendZValue, | |
68 | TopMostZValue |
|
68 | TopMostZValue | |
69 | }; |
|
69 | }; | |
70 |
|
70 | |||
71 | enum State { |
|
71 | enum State { | |
72 | ShowState, |
|
72 | ShowState, | |
73 | ScrollUpState, |
|
73 | ScrollUpState, | |
74 | ScrollDownState, |
|
74 | ScrollDownState, | |
75 | ScrollLeftState, |
|
75 | ScrollLeftState, | |
76 | ScrollRightState, |
|
76 | ScrollRightState, | |
77 | ZoomInState, |
|
77 | ZoomInState, | |
78 | ZoomOutState |
|
78 | ZoomOutState | |
79 | }; |
|
79 | }; | |
80 |
|
80 | |||
81 | ChartPresenter(QChart *chart); |
|
81 | ChartPresenter(QChart *chart); | |
82 | virtual ~ChartPresenter(); |
|
82 | virtual ~ChartPresenter(); | |
83 |
|
83 | |||
84 |
|
84 | |||
85 | void setGeometry(QRectF rect); |
|
85 | void setGeometry(QRectF rect); | |
86 | QRectF geometry() const; |
|
86 | QRectF geometry() const; | |
87 |
|
87 | |||
88 | QGraphicsItem *rootItem(){ return m_chart; } |
|
88 | QGraphicsItem *rootItem(){ return m_chart; } | |
89 | ChartBackground *backgroundElement(); |
|
89 | ChartBackground *backgroundElement(); | |
90 | ChartTitle *titleElement(); |
|
90 | ChartTitle *titleElement(); | |
91 | QList<ChartAxis *> axisItems() const; |
|
91 | QList<ChartAxis *> axisItems() const; | |
92 | QList<ChartItem *> chartItems() const; |
|
92 | QList<ChartItem *> chartItems() const; | |
93 |
|
93 | |||
94 | ChartItem* chartElement(QAbstractSeries* series) const; |
|
94 | ChartItem* chartElement(QAbstractSeries* series) const; | |
95 | ChartAxis* chartElement(QAbstractAxis* axis) const; |
|
95 | ChartAxis* chartElement(QAbstractAxis* axis) const; | |
96 |
|
96 | |||
97 | QLegend *legend(); |
|
97 | QLegend *legend(); | |
98 |
|
98 | |||
99 | void setBackgroundBrush(const QBrush &brush); |
|
99 | void setBackgroundBrush(const QBrush &brush); | |
100 | QBrush backgroundBrush() const; |
|
100 | QBrush backgroundBrush() const; | |
101 |
|
101 | |||
102 | void setBackgroundPen(const QPen &pen); |
|
102 | void setBackgroundPen(const QPen &pen); | |
103 | QPen backgroundPen() const; |
|
103 | QPen backgroundPen() const; | |
104 |
|
104 | |||
105 | void setTitle(const QString &title); |
|
105 | void setTitle(const QString &title); | |
106 | QString title() const; |
|
106 | QString title() const; | |
107 |
|
107 | |||
108 | void setTitleFont(const QFont &font); |
|
108 | void setTitleFont(const QFont &font); | |
109 | QFont titleFont() const; |
|
109 | QFont titleFont() const; | |
110 |
|
110 | |||
111 | void setTitleBrush(const QBrush &brush); |
|
111 | void setTitleBrush(const QBrush &brush); | |
112 | QBrush titleBrush() const; |
|
112 | QBrush titleBrush() const; | |
113 |
|
113 | |||
114 | void setBackgroundVisible(bool visible); |
|
114 | void setBackgroundVisible(bool visible); | |
115 | bool isBackgroundVisible() const; |
|
115 | bool isBackgroundVisible() const; | |
116 |
|
116 | |||
117 | void setBackgroundDropShadowEnabled(bool enabled); |
|
117 | void setBackgroundDropShadowEnabled(bool enabled); | |
118 | bool isBackgroundDropShadowEnabled() const; |
|
118 | bool isBackgroundDropShadowEnabled() const; | |
119 |
|
119 | |||
120 | void setVisible(bool visible); |
|
120 | void setVisible(bool visible); | |
121 |
|
121 | |||
122 | void setAnimationOptions(QChart::AnimationOptions options); |
|
122 | void setAnimationOptions(QChart::AnimationOptions options); | |
123 | QChart::AnimationOptions animationOptions() const; |
|
123 | QChart::AnimationOptions animationOptions() const; | |
124 |
|
124 | |||
125 | void startAnimation(ChartAnimation *animation); |
|
125 | void startAnimation(ChartAnimation *animation); | |
126 |
|
126 | |||
127 | //TODO refactor |
|
|||
128 | void setState(State state,QPointF point); |
|
127 | void setState(State state,QPointF point); | |
129 | State state() const { return m_state; } |
|
128 | State state() const { return m_state; } | |
130 | QPointF statePoint() const { return m_statePoint; } |
|
129 | QPointF statePoint() const { return m_statePoint; } | |
131 | ChartLayout *layout(); |
|
130 | ChartLayout *layout(); | |
132 |
|
131 | |||
133 | private: |
|
132 | private: | |
134 | void createBackgroundItem(); |
|
133 | void createBackgroundItem(); | |
135 | void createTitleItem(); |
|
134 | void createTitleItem(); | |
136 |
|
135 | |||
137 | public Q_SLOTS: |
|
136 | public Q_SLOTS: | |
138 | void handleSeriesAdded(QAbstractSeries *series); |
|
137 | void handleSeriesAdded(QAbstractSeries *series); | |
139 | void handleSeriesRemoved(QAbstractSeries *series); |
|
138 | void handleSeriesRemoved(QAbstractSeries *series); | |
140 | void handleAxisAdded(QAbstractAxis *axis); |
|
139 | void handleAxisAdded(QAbstractAxis *axis); | |
141 | void handleAxisRemoved(QAbstractAxis *axis); |
|
140 | void handleAxisRemoved(QAbstractAxis *axis); | |
142 |
|
141 | |||
143 | private Q_SLOTS: |
|
142 | private Q_SLOTS: | |
144 | void handleAnimationFinished(); |
|
143 | void handleAnimationFinished(); | |
145 |
|
144 | |||
146 | Q_SIGNALS: |
|
145 | Q_SIGNALS: | |
147 | void animationsFinished(); |
|
146 | void animationsFinished(); | |
148 |
|
147 | |||
149 | private: |
|
148 | private: | |
150 | QChart *m_chart; |
|
149 | QChart *m_chart; | |
151 | QList<ChartItem *> m_chartItems; |
|
150 | QList<ChartItem *> m_chartItems; | |
152 | QList<ChartAxis *> m_axisItems; |
|
151 | QList<ChartAxis *> m_axisItems; | |
153 | QList<QAbstractSeries *> m_series; |
|
152 | QList<QAbstractSeries *> m_series; | |
154 | QList<QAbstractAxis *> m_axes; |
|
153 | QList<QAbstractAxis *> m_axes; | |
155 | QChart::AnimationOptions m_options; |
|
154 | QChart::AnimationOptions m_options; | |
156 | State m_state; |
|
155 | State m_state; | |
157 | QPointF m_statePoint; |
|
156 | QPointF m_statePoint; | |
158 | QList<ChartAnimation *> m_animations; |
|
157 | QList<ChartAnimation *> m_animations; | |
159 | ChartLayout *m_layout; |
|
158 | ChartLayout *m_layout; | |
160 | ChartBackground *m_background; |
|
159 | ChartBackground *m_background; | |
161 | ChartTitle *m_title; |
|
160 | ChartTitle *m_title; | |
162 | QRectF m_rect; |
|
161 | QRectF m_rect; | |
163 | }; |
|
162 | }; | |
164 |
|
163 | |||
165 | QTCOMMERCIALCHART_END_NAMESPACE |
|
164 | QTCOMMERCIALCHART_END_NAMESPACE | |
166 |
|
165 | |||
167 | #endif /* CHARTPRESENTER_H */ |
|
166 | #endif /* CHARTPRESENTER_H */ |
@@ -1,259 +1,256 | |||||
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 "qabstractseries_p.h" |
|
20 | #include "qabstractseries_p.h" | |
21 | #include "qabstractaxis_p.h" |
|
21 | #include "qabstractaxis_p.h" | |
22 | #include <QTime> |
|
22 | #include <QTime> | |
23 | //themes |
|
23 | //themes | |
24 | #include "chartthemesystem_p.h" |
|
24 | #include "chartthemesystem_p.h" | |
25 | #include "chartthemelight_p.h" |
|
25 | #include "chartthemelight_p.h" | |
26 | #include "chartthemebluecerulean_p.h" |
|
26 | #include "chartthemebluecerulean_p.h" | |
27 | #include "chartthemedark_p.h" |
|
27 | #include "chartthemedark_p.h" | |
28 | #include "chartthemebrownsand_p.h" |
|
28 | #include "chartthemebrownsand_p.h" | |
29 | #include "chartthemebluencs_p.h" |
|
29 | #include "chartthemebluencs_p.h" | |
30 | #include "chartthemehighcontrast_p.h" |
|
30 | #include "chartthemehighcontrast_p.h" | |
31 | #include "chartthemeblueicy_p.h" |
|
31 | #include "chartthemeblueicy_p.h" | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | ChartThemeManager::ChartThemeManager(QChart* chart) : |
|
35 | ChartThemeManager::ChartThemeManager(QChart* chart) : | |
36 | m_chart(chart) |
|
36 | m_chart(chart) | |
37 | { |
|
37 | { | |
38 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
38 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 |
|
41 | |||
42 | void ChartThemeManager::setTheme(QChart::ChartTheme theme) |
|
42 | void ChartThemeManager::setTheme(QChart::ChartTheme theme) | |
43 | { |
|
43 | { | |
44 | if(m_theme.isNull() || theme != m_theme->id()) |
|
44 | if(m_theme.isNull() || theme != m_theme->id()) | |
45 | { |
|
45 | { | |
46 | switch (theme) { |
|
46 | switch (theme) { | |
47 | case QChart::ChartThemeLight: |
|
47 | case QChart::ChartThemeLight: | |
48 | m_theme.reset(new ChartThemeLight()); |
|
48 | m_theme.reset(new ChartThemeLight()); | |
49 | break; |
|
49 | break; | |
50 | case QChart::ChartThemeBlueCerulean: |
|
50 | case QChart::ChartThemeBlueCerulean: | |
51 | m_theme.reset(new ChartThemeBlueCerulean()); |
|
51 | m_theme.reset(new ChartThemeBlueCerulean()); | |
52 | break; |
|
52 | break; | |
53 | case QChart::ChartThemeDark: |
|
53 | case QChart::ChartThemeDark: | |
54 | m_theme.reset(new ChartThemeDark()); |
|
54 | m_theme.reset(new ChartThemeDark()); | |
55 | break; |
|
55 | break; | |
56 | case QChart::ChartThemeBrownSand: |
|
56 | case QChart::ChartThemeBrownSand: | |
57 | m_theme.reset(new ChartThemeBrownSand()); |
|
57 | m_theme.reset(new ChartThemeBrownSand()); | |
58 | break; |
|
58 | break; | |
59 | case QChart::ChartThemeBlueNcs: |
|
59 | case QChart::ChartThemeBlueNcs: | |
60 | m_theme.reset(new ChartThemeBlueNcs()); |
|
60 | m_theme.reset(new ChartThemeBlueNcs()); | |
61 | break; |
|
61 | break; | |
62 | case QChart::ChartThemeHighContrast: |
|
62 | case QChart::ChartThemeHighContrast: | |
63 | m_theme.reset(new ChartThemeHighContrast()); |
|
63 | m_theme.reset(new ChartThemeHighContrast()); | |
64 | break; |
|
64 | break; | |
65 | case QChart::ChartThemeBlueIcy: |
|
65 | case QChart::ChartThemeBlueIcy: | |
66 | m_theme.reset(new ChartThemeBlueIcy()); |
|
66 | m_theme.reset(new ChartThemeBlueIcy()); | |
67 | break; |
|
67 | break; | |
68 | default: |
|
68 | default: | |
69 | m_theme.reset(new ChartThemeSystem()); |
|
69 | m_theme.reset(new ChartThemeSystem()); | |
70 | break; |
|
70 | break; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | if(!m_theme.isNull()) |
|
73 | if(!m_theme.isNull()) | |
74 | { |
|
74 | { | |
75 | decorateChart(m_chart,m_theme.data(),true); |
|
75 | decorateChart(m_chart,m_theme.data(),true); | |
76 | decorateLegend(m_chart->legend(),m_theme.data(),true); |
|
76 | decorateLegend(m_chart->legend(),m_theme.data(),true); | |
77 | foreach(QAbstractAxis* axis, m_axisList) { |
|
77 | foreach(QAbstractAxis* axis, m_axisList) { | |
78 | axis->d_ptr->initializeTheme(m_theme.data(),true); |
|
78 | axis->d_ptr->initializeTheme(m_theme.data(),true); | |
79 | } |
|
79 | } | |
80 | foreach(QAbstractSeries* series, m_seriesMap.keys()) { |
|
80 | foreach(QAbstractSeries* series, m_seriesMap.keys()) { | |
81 | series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),true); |
|
81 | series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),true); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | } |
|
84 | } | |
85 | } |
|
85 | } | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void ChartThemeManager::decorateChart(QChart *chart,ChartTheme* theme,bool force) const |
|
88 | void ChartThemeManager::decorateChart(QChart *chart,ChartTheme* theme,bool force) const | |
89 | { |
|
89 | { | |
90 | QBrush brush; |
|
90 | QBrush brush; | |
91 |
|
91 | |||
92 | if (force || brush == chart->backgroundBrush()) |
|
92 | if (force || brush == chart->backgroundBrush()) | |
93 | chart->setBackgroundBrush(theme->chartBackgroundGradient()); |
|
93 | chart->setBackgroundBrush(theme->chartBackgroundGradient()); | |
94 |
|
94 | |||
95 | chart->setTitleFont(theme->masterFont()); |
|
95 | chart->setTitleFont(theme->masterFont()); | |
96 | chart->setTitleBrush(theme->labelBrush()); |
|
96 | chart->setTitleBrush(theme->labelBrush()); | |
97 | chart->setDropShadowEnabled(theme->isBackgroundDropShadowEnabled()); |
|
97 | chart->setDropShadowEnabled(theme->isBackgroundDropShadowEnabled()); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void ChartThemeManager::decorateLegend(QLegend *legend, ChartTheme* theme, bool force) const |
|
100 | void ChartThemeManager::decorateLegend(QLegend *legend, ChartTheme* theme, bool force) const | |
101 | { |
|
101 | { | |
102 | QPen pen; |
|
102 | QPen pen; | |
103 | QBrush brush; |
|
103 | QBrush brush; | |
104 | QFont font; |
|
104 | QFont font; | |
105 |
|
105 | |||
106 | if (force || pen == legend->pen()) |
|
106 | if (force || pen == legend->pen()) | |
107 | legend->setPen(theme->axisLinePen()); |
|
107 | legend->setPen(theme->axisLinePen()); | |
108 |
|
108 | |||
109 | if (force || brush == legend->brush()) |
|
109 | if (force || brush == legend->brush()) | |
110 | legend->setBrush(theme->chartBackgroundGradient()); |
|
110 | legend->setBrush(theme->chartBackgroundGradient()); | |
111 |
|
111 | |||
112 | if (force || font == legend->font()) |
|
112 | if (force || font == legend->font()) | |
113 | legend->setFont(theme->labelFont()); |
|
113 | legend->setFont(theme->labelFont()); | |
114 |
|
114 | |||
115 | if (force || brush == legend->labelBrush()) |
|
115 | if (force || brush == legend->labelBrush()) | |
116 | legend->setLabelBrush(theme->labelBrush()); |
|
116 | legend->setLabelBrush(theme->labelBrush()); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | int ChartThemeManager::createIndexKey(QList<int> keys) const |
|
119 | int ChartThemeManager::createIndexKey(QList<int> keys) const | |
120 | { |
|
120 | { | |
121 | qSort(keys); |
|
121 | qSort(keys); | |
122 |
|
122 | |||
123 | int key = 0; |
|
123 | int key = 0; | |
124 | QList<int>::iterator i; |
|
124 | QList<int>::iterator i; | |
125 | i = keys.begin(); |
|
125 | i = keys.begin(); | |
126 |
|
126 | |||
127 | while (i != keys.end()) { |
|
127 | while (i != keys.end()) { | |
128 | if (*i != key) |
|
128 | if (*i != key) | |
129 | break; |
|
129 | break; | |
130 | key++; |
|
130 | key++; | |
131 | i++; |
|
131 | i++; | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | return key; |
|
134 | return key; | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | int ChartThemeManager::seriesCount(QAbstractSeries::SeriesType type) const |
|
137 | int ChartThemeManager::seriesCount(QAbstractSeries::SeriesType type) const | |
138 | { |
|
138 | { | |
139 | int count = 0; |
|
139 | int count = 0; | |
140 | QList<QAbstractSeries *> series = m_seriesMap.keys(); |
|
140 | QList<QAbstractSeries *> series = m_seriesMap.keys(); | |
141 | foreach(QAbstractSeries *s, series) { |
|
141 | foreach(QAbstractSeries *s, series) { | |
142 | if (s->type() == type) |
|
142 | if (s->type() == type) | |
143 | count++; |
|
143 | count++; | |
144 | } |
|
144 | } | |
145 | return count; |
|
145 | return count; | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | void ChartThemeManager::handleSeriesAdded(QAbstractSeries *series) |
|
148 | void ChartThemeManager::handleSeriesAdded(QAbstractSeries *series) | |
149 | { |
|
149 | { | |
150 | int key = createIndexKey(m_seriesMap.values()); |
|
150 | int key = createIndexKey(m_seriesMap.values()); | |
151 | m_seriesMap.insert(series,key); |
|
151 | m_seriesMap.insert(series,key); | |
152 | series->d_ptr->initializeTheme(key,m_theme.data(),false); |
|
152 | series->d_ptr->initializeTheme(key,m_theme.data(),false); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void ChartThemeManager::handleSeriesRemoved(QAbstractSeries *series) |
|
155 | void ChartThemeManager::handleSeriesRemoved(QAbstractSeries *series) | |
156 | { |
|
156 | { | |
157 | m_seriesMap.remove(series); |
|
157 | m_seriesMap.remove(series); | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | void ChartThemeManager::handleAxisAdded(QAbstractAxis *axis) |
|
160 | void ChartThemeManager::handleAxisAdded(QAbstractAxis *axis) | |
161 | { |
|
161 | { | |
162 | m_axisList.append(axis); |
|
162 | m_axisList.append(axis); | |
163 | axis->d_ptr->initializeTheme(m_theme.data(),false); |
|
163 | axis->d_ptr->initializeTheme(m_theme.data(),false); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | void ChartThemeManager::handleAxisRemoved(QAbstractAxis *axis) |
|
166 | void ChartThemeManager::handleAxisRemoved(QAbstractAxis *axis) | |
167 | { |
|
167 | { | |
168 | m_axisList.removeAll(axis); |
|
168 | m_axisList.removeAll(axis); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | void ChartThemeManager::updateSeries(QAbstractSeries *series) |
|
171 | void ChartThemeManager::updateSeries(QAbstractSeries *series) | |
172 | { |
|
172 | { | |
173 | if(m_seriesMap.contains(series)){ |
|
173 | if(m_seriesMap.contains(series)){ | |
174 | series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),false); |
|
174 | series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),false); | |
175 | } |
|
175 | } | |
176 | } |
|
176 | } | |
177 | QList<QGradient> ChartThemeManager::generateSeriesGradients(const QList<QColor>& colors) |
|
177 | QList<QGradient> ChartThemeManager::generateSeriesGradients(const QList<QColor>& colors) | |
178 | { |
|
178 | { | |
179 | QList<QGradient> result; |
|
179 | QList<QGradient> result; | |
180 | // Generate gradients in HSV color space |
|
180 | // Generate gradients in HSV color space | |
181 | foreach (const QColor &color, colors) { |
|
181 | foreach (const QColor &color, colors) { | |
182 | QLinearGradient g; |
|
182 | QLinearGradient g; | |
183 | qreal h = color.hsvHueF(); |
|
183 | qreal h = color.hsvHueF(); | |
184 | qreal s = color.hsvSaturationF(); |
|
184 | qreal s = color.hsvSaturationF(); | |
185 |
|
185 | |||
186 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
|||
187 | // most themes. The rest of the gradients we can define manually in theme specific |
|
|||
188 | // implementation. |
|
|||
189 | QColor start = color; |
|
186 | QColor start = color; | |
190 | start.setHsvF(h, 0.0, 1.0); |
|
187 | start.setHsvF(h, 0.0, 1.0); | |
191 | g.setColorAt(0.0, start); |
|
188 | g.setColorAt(0.0, start); | |
192 |
|
189 | |||
193 | g.setColorAt(0.5, color); |
|
190 | g.setColorAt(0.5, color); | |
194 |
|
191 | |||
195 | QColor end = color; |
|
192 | QColor end = color; | |
196 | end.setHsvF(h, s, 0.25); |
|
193 | end.setHsvF(h, s, 0.25); | |
197 | g.setColorAt(1.0, end); |
|
194 | g.setColorAt(1.0, end); | |
198 |
|
195 | |||
199 | result << g; |
|
196 | result << g; | |
200 | } |
|
197 | } | |
201 |
|
198 | |||
202 | return result; |
|
199 | return result; | |
203 | } |
|
200 | } | |
204 |
|
201 | |||
205 |
|
202 | |||
206 | QColor ChartThemeManager::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
203 | QColor ChartThemeManager::colorAt(const QColor &start, const QColor &end, qreal pos) | |
207 | { |
|
204 | { | |
208 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); |
|
205 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); | |
209 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
206 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
210 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
207 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
211 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
208 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
212 | QColor c; |
|
209 | QColor c; | |
213 | c.setRgbF(r, g, b); |
|
210 | c.setRgbF(r, g, b); | |
214 | return c; |
|
211 | return c; | |
215 | } |
|
212 | } | |
216 |
|
213 | |||
217 | QColor ChartThemeManager::colorAt(const QGradient &gradient, qreal pos) |
|
214 | QColor ChartThemeManager::colorAt(const QGradient &gradient, qreal pos) | |
218 | { |
|
215 | { | |
219 | Q_ASSERT(pos >= 0 && pos <= 1.0); |
|
216 | Q_ASSERT(pos >= 0 && pos <= 1.0); | |
220 |
|
217 | |||
221 | QGradientStops stops = gradient.stops(); |
|
218 | QGradientStops stops = gradient.stops(); | |
222 | int count = stops.count(); |
|
219 | int count = stops.count(); | |
223 |
|
220 | |||
224 | // find previous stop relative to position |
|
221 | // find previous stop relative to position | |
225 | QGradientStop prev = stops.first(); |
|
222 | QGradientStop prev = stops.first(); | |
226 | for (int i = 0; i < count; i++) { |
|
223 | for (int i = 0; i < count; i++) { | |
227 | QGradientStop stop = stops.at(i); |
|
224 | QGradientStop stop = stops.at(i); | |
228 | if (pos > stop.first) |
|
225 | if (pos > stop.first) | |
229 | prev = stop; |
|
226 | prev = stop; | |
230 |
|
227 | |||
231 | // given position is actually a stop position? |
|
228 | // given position is actually a stop position? | |
232 | if (pos == stop.first) { |
|
229 | if (pos == stop.first) { | |
233 | //qDebug() << "stop color" << pos; |
|
230 | //qDebug() << "stop color" << pos; | |
234 | return stop.second; |
|
231 | return stop.second; | |
235 | } |
|
232 | } | |
236 | } |
|
233 | } | |
237 |
|
234 | |||
238 | // find next stop relative to position |
|
235 | // find next stop relative to position | |
239 | QGradientStop next = stops.last(); |
|
236 | QGradientStop next = stops.last(); | |
240 | for (int i = count - 1; i >= 0; i--) { |
|
237 | for (int i = count - 1; i >= 0; i--) { | |
241 | QGradientStop stop = stops.at(i); |
|
238 | QGradientStop stop = stops.at(i); | |
242 | if (pos < stop.first) |
|
239 | if (pos < stop.first) | |
243 | next = stop; |
|
240 | next = stop; | |
244 | } |
|
241 | } | |
245 |
|
242 | |||
246 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
243 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
247 |
|
244 | |||
248 | qreal range = next.first - prev.first; |
|
245 | qreal range = next.first - prev.first; | |
249 | qreal posDelta = pos - prev.first; |
|
246 | qreal posDelta = pos - prev.first; | |
250 | qreal relativePos = posDelta / range; |
|
247 | qreal relativePos = posDelta / range; | |
251 |
|
248 | |||
252 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
249 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
253 |
|
250 | |||
254 | return colorAt(prev.second, next.second, relativePos); |
|
251 | return colorAt(prev.second, next.second, relativePos); | |
255 | } |
|
252 | } | |
256 |
|
253 | |||
257 | #include "moc_chartthememanager_p.cpp" |
|
254 | #include "moc_chartthememanager_p.cpp" | |
258 |
|
255 | |||
259 | QTCOMMERCIALCHART_END_NAMESPACE |
|
256 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -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> |
|
37 | #include <QGraphicsSimpleTextItem> | |
38 | #include <QGraphicsLayoutItem> |
|
38 | #include <QGraphicsLayoutItem> | |
39 |
|
39 | |||
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
41 |
|
41 | |||
42 | // 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,663 +1,654 | |||||
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 "chartlayout_p.h" |
|
27 | #include "chartlayout_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 | \class QChart |
|
62 | \class QChart | |
63 | \brief QtCommercial chart API. |
|
63 | \brief QtCommercial chart API. | |
64 |
|
64 | |||
65 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
65 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
66 | representation of different types of series and other chart related objects like |
|
66 | representation of different types of series and other chart related objects like | |
67 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
67 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the | |
68 | convenience class QChartView instead of QChart. |
|
68 | convenience class QChartView instead of QChart. | |
69 | \sa QChartView |
|
69 | \sa QChartView | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \property QChart::animationOptions |
|
73 | \property QChart::animationOptions | |
74 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
74 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \property QChart::backgroundVisible |
|
78 | \property QChart::backgroundVisible | |
79 | Whether the chart background is visible or not. |
|
79 | Whether the chart background is visible or not. | |
80 | \sa setBackgroundBrush(), setBackgroundPen() |
|
80 | \sa setBackgroundBrush(), setBackgroundPen() | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QChart::dropShadowEnabled |
|
84 | \property QChart::dropShadowEnabled | |
85 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
85 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop | |
86 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
86 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \property QChart::minimumMargins |
|
90 | \property QChart::minimumMargins | |
91 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
91 | Minimum margins between the plot area (axes) and the edge of the chart widget. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QChart::margins |
|
95 | \property QChart::margins | |
96 | Minimum between the plot area (axes) and the edge of the chart widget. |
|
96 | Minimum between the plot area (axes) and the edge of the chart widget. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \property QChart::theme |
|
100 | \property QChart::theme | |
101 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
101 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, | |
102 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
102 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few | |
103 | different themes. |
|
103 | different themes. | |
104 | Note: changing the theme will overwrite all customizations previously applied to the series. |
|
104 | Note: changing the theme will overwrite all customizations previously applied to the series. | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \property QChart::title |
|
108 | \property QChart::title | |
109 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
109 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
113 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
114 | */ |
|
114 | */ | |
115 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
115 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
116 | : QGraphicsWidget(parent, wFlags), |
|
116 | : QGraphicsWidget(parent, wFlags), | |
117 | d_ptr(new QChartPrivate(this)) |
|
117 | d_ptr(new QChartPrivate(this)) | |
118 | { |
|
118 | { | |
119 | d_ptr->m_legend = new LegendScroller(this); |
|
119 | d_ptr->m_legend = new LegendScroller(this); | |
120 | setTheme(QChart::ChartThemeLight); |
|
120 | setTheme(QChart::ChartThemeLight); | |
121 | setLayout(d_ptr->m_presenter->layout()); |
|
121 | setLayout(d_ptr->m_presenter->layout()); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | Destroys the object and it's children, like series and axis objects added to it. |
|
125 | Destroys the object and it's children, like series and axis objects added to it. | |
126 | */ |
|
126 | */ | |
127 | QChart::~QChart() |
|
127 | QChart::~QChart() | |
128 | { |
|
128 | { | |
129 | //start by deleting dataset, it will remove all series and axes |
|
129 | //start by deleting dataset, it will remove all series and axes | |
130 | delete d_ptr->m_dataset; |
|
130 | delete d_ptr->m_dataset; | |
131 | d_ptr->m_dataset = 0; |
|
131 | d_ptr->m_dataset = 0; | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | Adds the \a series onto the chart and takes the ownership of the object. |
|
135 | Adds the \a series onto the chart and takes the ownership of the object. | |
136 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
136 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
137 | the y axis). |
|
137 | the y axis). | |
138 |
|
138 | |||
139 | \sa removeSeries(), removeAllSeries() |
|
139 | \sa removeSeries(), removeAllSeries() | |
140 | */ |
|
140 | */ | |
141 | void QChart::addSeries(QAbstractSeries *series) |
|
141 | void QChart::addSeries(QAbstractSeries *series) | |
142 | { |
|
142 | { | |
143 | Q_ASSERT(series); |
|
143 | Q_ASSERT(series); | |
144 | d_ptr->m_dataset->addSeries(series); |
|
144 | d_ptr->m_dataset->addSeries(series); | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | Removes the \a series specified in a perameter from the QChartView. |
|
148 | Removes the \a series specified in a perameter from the QChartView. | |
149 | It releses its ownership of the specified QChartSeries object. |
|
149 | It releses its ownership of the specified QChartSeries object. | |
150 | It does not delete the pointed QChartSeries data object |
|
150 | It does not delete the pointed QChartSeries data object | |
151 | \sa addSeries(), removeAllSeries() |
|
151 | \sa addSeries(), removeAllSeries() | |
152 | */ |
|
152 | */ | |
153 | void QChart::removeSeries(QAbstractSeries *series) |
|
153 | void QChart::removeSeries(QAbstractSeries *series) | |
154 | { |
|
154 | { | |
155 | Q_ASSERT(series); |
|
155 | Q_ASSERT(series); | |
156 | d_ptr->m_dataset->removeSeries(series); |
|
156 | d_ptr->m_dataset->removeSeries(series); | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | Removes all the QChartSeries that have been added to the QChartView |
|
160 | Removes all the QChartSeries that have been added to the QChartView | |
161 | It also deletes the pointed QChartSeries data objects |
|
161 | It also deletes the pointed QChartSeries data objects | |
162 | \sa addSeries(), removeSeries() |
|
162 | \sa addSeries(), removeSeries() | |
163 | */ |
|
163 | */ | |
164 | void QChart::removeAllSeries() |
|
164 | void QChart::removeAllSeries() | |
165 | { |
|
165 | { | |
166 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
166 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ | |
167 | removeSeries(s); |
|
167 | removeSeries(s); | |
168 | delete s; |
|
168 | delete s; | |
169 | } |
|
169 | } | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | Sets the \a brush that is used for painting the background of the chart area. |
|
173 | Sets the \a brush that is used for painting the background of the chart area. | |
174 | */ |
|
174 | */ | |
175 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
175 | void QChart::setBackgroundBrush(const QBrush &brush) | |
176 | { |
|
176 | { | |
177 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
177 | d_ptr->m_presenter->setBackgroundBrush(brush); | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | Gets the brush that is used for painting the background of the chart area. |
|
181 | Gets the brush that is used for painting the background of the chart area. | |
182 | */ |
|
182 | */ | |
183 | QBrush QChart::backgroundBrush() const |
|
183 | QBrush QChart::backgroundBrush() const | |
184 | { |
|
184 | { | |
185 | return d_ptr->m_presenter->backgroundBrush(); |
|
185 | return d_ptr->m_presenter->backgroundBrush(); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | Sets the \a pen that is used for painting the background of the chart area. |
|
189 | Sets the \a pen that is used for painting the background of the chart area. | |
190 | */ |
|
190 | */ | |
191 | void QChart::setBackgroundPen(const QPen &pen) |
|
191 | void QChart::setBackgroundPen(const QPen &pen) | |
192 | { |
|
192 | { | |
193 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
193 | d_ptr->m_presenter->setBackgroundPen(pen); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | /*! |
|
196 | /*! | |
197 | Gets the pen that is used for painting the background of the chart area. |
|
197 | Gets the pen that is used for painting the background of the chart area. | |
198 | */ |
|
198 | */ | |
199 | QPen QChart::backgroundPen() const |
|
199 | QPen QChart::backgroundPen() const | |
200 | { |
|
200 | { | |
201 | return d_ptr->m_presenter->backgroundPen(); |
|
201 | return d_ptr->m_presenter->backgroundPen(); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | /*! |
|
204 | /*! | |
205 | Sets the chart \a title. The description text that is drawn above the chart. |
|
205 | Sets the chart \a title. The description text that is drawn above the chart. | |
206 | */ |
|
206 | */ | |
207 | void QChart::setTitle(const QString &title) |
|
207 | void QChart::setTitle(const QString &title) | |
208 | { |
|
208 | { | |
209 | d_ptr->m_presenter->setTitle(title); |
|
209 | d_ptr->m_presenter->setTitle(title); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | Returns the chart title. The description text that is drawn above the chart. |
|
213 | Returns the chart title. The description text that is drawn above the chart. | |
214 | */ |
|
214 | */ | |
215 | QString QChart::title() const |
|
215 | QString QChart::title() const | |
216 | { |
|
216 | { | |
217 | return d_ptr->m_presenter->title(); |
|
217 | return d_ptr->m_presenter->title(); | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | /*! |
|
220 | /*! | |
221 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
221 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | |
222 | */ |
|
222 | */ | |
223 | void QChart::setTitleFont(const QFont &font) |
|
223 | void QChart::setTitleFont(const QFont &font) | |
224 | { |
|
224 | { | |
225 | d_ptr->m_presenter->setTitleFont(font); |
|
225 | d_ptr->m_presenter->setTitleFont(font); | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | /*! |
|
228 | /*! | |
229 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
229 | Gets the font that is used for drawing the chart description text that is rendered above the chart. | |
230 | */ |
|
230 | */ | |
231 | QFont QChart::titleFont() const |
|
231 | QFont QChart::titleFont() const | |
232 | { |
|
232 | { | |
233 | return d_ptr->m_presenter->titleFont(); |
|
233 | return d_ptr->m_presenter->titleFont(); | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | /*! |
|
236 | /*! | |
237 | Sets the \a brush used for rendering the title text. |
|
237 | Sets the \a brush used for rendering the title text. | |
238 | */ |
|
238 | */ | |
239 | void QChart::setTitleBrush(const QBrush &brush) |
|
239 | void QChart::setTitleBrush(const QBrush &brush) | |
240 | { |
|
240 | { | |
241 | d_ptr->m_presenter->setTitleBrush(brush); |
|
241 | d_ptr->m_presenter->setTitleBrush(brush); | |
242 | } |
|
242 | } | |
243 |
|
243 | |||
244 | /*! |
|
244 | /*! | |
245 | Returns the brush used for rendering the title text. |
|
245 | Returns the brush used for rendering the title text. | |
246 | */ |
|
246 | */ | |
247 | QBrush QChart::titleBrush() const |
|
247 | QBrush QChart::titleBrush() const | |
248 | { |
|
248 | { | |
249 | return d_ptr->m_presenter->titleBrush(); |
|
249 | return d_ptr->m_presenter->titleBrush(); | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | void QChart::setTheme(QChart::ChartTheme theme) |
|
252 | void QChart::setTheme(QChart::ChartTheme theme) | |
253 | { |
|
253 | { | |
254 | d_ptr->m_themeManager->setTheme(theme); |
|
254 | d_ptr->m_themeManager->setTheme(theme); | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | QChart::ChartTheme QChart::theme() const |
|
257 | QChart::ChartTheme QChart::theme() const | |
258 | { |
|
258 | { | |
259 | return d_ptr->m_themeManager->theme()->id(); |
|
259 | return d_ptr->m_themeManager->theme()->id(); | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | /*! |
|
262 | /*! | |
263 | Zooms in the view by a factor of 2 |
|
263 | Zooms in the view by a factor of 2 | |
264 | */ |
|
264 | */ | |
265 | void QChart::zoomIn() |
|
265 | void QChart::zoomIn() | |
266 | { |
|
266 | { | |
267 | d_ptr->zoomIn(2.0); |
|
267 | d_ptr->zoomIn(2.0); | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | /*! |
|
270 | /*! | |
271 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
271 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
272 | */ |
|
272 | */ | |
273 | void QChart::zoomIn(const QRectF &rect) |
|
273 | void QChart::zoomIn(const QRectF &rect) | |
274 | { |
|
274 | { | |
275 | d_ptr->zoomIn(rect); |
|
275 | d_ptr->zoomIn(rect); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | /*! |
|
278 | /*! | |
279 | Restores the view zoom level to the previous one. |
|
279 | Restores the view zoom level to the previous one. | |
280 | */ |
|
280 | */ | |
281 | void QChart::zoomOut() |
|
281 | void QChart::zoomOut() | |
282 | { |
|
282 | { | |
283 | d_ptr->zoomOut(2.0); |
|
283 | d_ptr->zoomOut(2.0); | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 | /*! |
|
286 | /*! | |
287 | Zooms in the view by a \a factor. |
|
287 | Zooms in the view by a \a factor. | |
288 |
|
288 | |||
289 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
289 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | |
290 | */ |
|
290 | */ | |
291 | void QChart::zoom(qreal factor) |
|
291 | void QChart::zoom(qreal factor) | |
292 | { |
|
292 | { | |
293 | if (qFuzzyCompare(factor, 0)) |
|
293 | if (qFuzzyCompare(factor, 0)) | |
294 | return; |
|
294 | return; | |
295 |
|
295 | |||
296 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
296 | if (qFuzzyCompare(factor, (qreal)1.0)) | |
297 | return; |
|
297 | return; | |
298 |
|
298 | |||
299 | if (factor < 0) |
|
299 | if (factor < 0) | |
300 | return; |
|
300 | return; | |
301 |
|
301 | |||
302 | if (factor > 1.0) |
|
302 | if (factor > 1.0) | |
303 | d_ptr->zoomIn(factor); |
|
303 | d_ptr->zoomIn(factor); | |
304 | else |
|
304 | else | |
305 | d_ptr->zoomOut(1.0 / factor); |
|
305 | d_ptr->zoomOut(1.0 / factor); | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | /*! |
|
308 | /*! | |
309 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
309 | Returns the pointer to the x axis object of the chart asociated with the specified \a series | |
310 | If no series is provided then pointer to currently visible axis is provided |
|
310 | If no series is provided then pointer to currently visible axis is provided | |
311 | */ |
|
311 | */ | |
312 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
312 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | |
313 | { |
|
313 | { | |
314 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); |
|
314 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); | |
315 | if (axisList.count()) |
|
315 | if (axisList.count()) | |
316 | return axisList[0]; |
|
316 | return axisList[0]; | |
317 | return 0; |
|
317 | return 0; | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | /*! |
|
320 | /*! | |
321 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
321 | Returns the pointer to the y axis object of the chart asociated with the specified \a series | |
322 | If no series is provided then pointer to currently visible axis is provided |
|
322 | If no series is provided then pointer to currently visible axis is provided | |
323 | */ |
|
323 | */ | |
324 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
324 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const | |
325 | { |
|
325 | { | |
326 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); |
|
326 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); | |
327 | if (axisList.count()) |
|
327 | if (axisList.count()) | |
328 | return axisList[0]; |
|
328 | return axisList[0]; | |
329 | return 0; |
|
329 | return 0; | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | /*! |
|
332 | /*! | |
333 | Returns the axes added for the \a series with \a orientation. If no series is provided, then all axes with the |
|
333 | Returns the axes added for the \a series with \a orientation. If no series is provided, then all axes with the | |
334 | specified orientation are returned. |
|
334 | specified orientation are returned. | |
335 | \sa addAxis(), createDefaultAxes() |
|
335 | \sa addAxis(), createDefaultAxes() | |
336 | */ |
|
336 | */ | |
337 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
337 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const | |
338 | { |
|
338 | { | |
339 | QList<QAbstractAxis *> result ; |
|
339 | QList<QAbstractAxis *> result ; | |
340 |
|
340 | |||
341 | if (series) { |
|
341 | if (series) { | |
342 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
342 | foreach (QAbstractAxis *axis, series->attachedAxes()){ | |
343 | if (orientation.testFlag(axis->orientation())) |
|
343 | if (orientation.testFlag(axis->orientation())) | |
344 | result << axis; |
|
344 | result << axis; | |
345 | } |
|
345 | } | |
346 | } else { |
|
346 | } else { | |
347 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ |
|
347 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ | |
348 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
348 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) | |
349 | result << axis; |
|
349 | result << axis; | |
350 | } |
|
350 | } | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | return result; |
|
353 | return result; | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | /*! |
|
356 | /*! | |
357 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. |
|
357 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. | |
358 |
|
358 | |||
359 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
359 | Creates the axes for the chart based on the series that has already been added to the chart. | |
360 |
|
360 | |||
361 | \table |
|
361 | \table | |
362 | \header |
|
362 | \header | |
363 | \o Series type |
|
363 | \o Series type | |
364 | \o X-axis |
|
364 | \o X-axis | |
365 | \o Y-axis |
|
365 | \o Y-axis | |
366 | \row |
|
366 | \row | |
367 | \o QXYSeries |
|
367 | \o QXYSeries | |
368 | \o QValueAxis |
|
368 | \o QValueAxis | |
369 | \o QValueAxis |
|
369 | \o QValueAxis | |
370 | \row |
|
370 | \row | |
371 | \o QBarSeries |
|
371 | \o QBarSeries | |
372 | \o QBarCategoryAxis |
|
372 | \o QBarCategoryAxis | |
373 | \o QValueAxis |
|
373 | \o QValueAxis | |
374 | \row |
|
374 | \row | |
375 | \o QPieSeries |
|
375 | \o QPieSeries | |
376 | \o None |
|
376 | \o None | |
377 | \o None |
|
377 | \o None | |
378 | \endtable |
|
378 | \endtable | |
379 |
|
379 | |||
380 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. |
|
380 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. | |
381 | If there are sevaral series added of different types then each series gets its own axes pair. |
|
381 | If there are sevaral series added of different types then each series gets its own axes pair. | |
382 |
|
382 | |||
383 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. |
|
383 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. | |
384 |
|
384 | |||
385 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
385 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. | |
386 | QPieSeries does not create any axes. |
|
386 | QPieSeries does not create any axes. | |
387 |
|
387 | |||
388 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
388 | \sa axisX(), axisY(), setAxisX(), setAxisY() | |
389 | */ |
|
389 | */ | |
390 | void QChart::createDefaultAxes() |
|
390 | void QChart::createDefaultAxes() | |
391 | { |
|
391 | { | |
392 | d_ptr->m_dataset->createDefaultAxes(); |
|
392 | d_ptr->m_dataset->createDefaultAxes(); | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | /*! |
|
395 | /*! | |
396 | Returns the legend object of the chart. Ownership stays in chart. |
|
396 | Returns the legend object of the chart. Ownership stays in chart. | |
397 | */ |
|
397 | */ | |
398 | QLegend *QChart::legend() const |
|
398 | QLegend *QChart::legend() const | |
399 | { |
|
399 | { | |
400 | return d_ptr->m_legend; |
|
400 | return d_ptr->m_legend; | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | /*! |
|
403 | /*! | |
404 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
404 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
405 | Deprecated. Use setMargins(). |
|
405 | Deprecated. Use setMargins(). | |
406 | */ |
|
406 | */ | |
407 | void QChart::setMinimumMargins(const QMargins &margins) |
|
407 | void QChart::setMinimumMargins(const QMargins &margins) | |
408 | { |
|
408 | { | |
409 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
409 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; | |
410 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
410 | d_ptr->m_presenter->layout()->setMargins(margins); | |
411 | } |
|
411 | } | |
412 |
|
412 | |||
413 | /*! |
|
413 | /*! | |
414 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
414 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
415 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
415 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
416 | Deprecated. Use margins(). |
|
416 | Deprecated. Use margins(). | |
417 | */ |
|
417 | */ | |
418 | QMargins QChart::minimumMargins() const |
|
418 | QMargins QChart::minimumMargins() const | |
419 | { |
|
419 | { | |
420 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
420 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; | |
421 | return d_ptr->m_presenter->layout()->margins(); |
|
421 | return d_ptr->m_presenter->layout()->margins(); | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | /*! |
|
424 | /*! | |
425 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
425 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
426 | */ |
|
426 | */ | |
427 | void QChart::setMargins(const QMargins &margins) |
|
427 | void QChart::setMargins(const QMargins &margins) | |
428 | { |
|
428 | { | |
429 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
429 | d_ptr->m_presenter->layout()->setMargins(margins); | |
430 | } |
|
430 | } | |
431 |
|
431 | |||
432 | /*! |
|
432 | /*! | |
433 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
433 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
434 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
434 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
435 | */ |
|
435 | */ | |
436 | QMargins QChart::margins() const |
|
436 | QMargins QChart::margins() const | |
437 | { |
|
437 | { | |
438 | return d_ptr->m_presenter->layout()->margins(); |
|
438 | return d_ptr->m_presenter->layout()->margins(); | |
439 | } |
|
439 | } | |
440 |
|
440 | |||
441 | /*! |
|
441 | /*! | |
442 | Returns the the rect within which the drawing of the chart is done. |
|
442 | Returns the the rect within which the drawing of the chart is done. | |
443 | It does not include the area defines by margins. |
|
443 | It does not include the area defines by margins. | |
444 | */ |
|
444 | */ | |
445 | QRectF QChart::plotArea() const |
|
445 | QRectF QChart::plotArea() const | |
446 | { |
|
446 | { | |
447 | return d_ptr->m_presenter->geometry(); |
|
447 | return d_ptr->m_presenter->geometry(); | |
448 | } |
|
448 | } | |
449 |
|
449 | |||
450 | ///*! |
|
|||
451 | // TODO: Dummy. |
|
|||
452 | // Adjust the ranges of the axes so that all the data of the specified \a series is visible |
|
|||
453 | // */ |
|
|||
454 | //void QChart::adjustViewToSeries(QAbstractSeries* series) |
|
|||
455 | //{ |
|
|||
456 | // // |
|
|||
457 | //} |
|
|||
458 |
|
||||
459 | /*! |
|
450 | /*! | |
460 | Sets animation \a options for the chart |
|
451 | Sets animation \a options for the chart | |
461 | */ |
|
452 | */ | |
462 | void QChart::setAnimationOptions(AnimationOptions options) |
|
453 | void QChart::setAnimationOptions(AnimationOptions options) | |
463 | { |
|
454 | { | |
464 | d_ptr->m_presenter->setAnimationOptions(options); |
|
455 | d_ptr->m_presenter->setAnimationOptions(options); | |
465 | } |
|
456 | } | |
466 |
|
457 | |||
467 | QChart::AnimationOptions QChart::animationOptions() const |
|
458 | QChart::AnimationOptions QChart::animationOptions() const | |
468 | { |
|
459 | { | |
469 | return d_ptr->m_presenter->animationOptions(); |
|
460 | return d_ptr->m_presenter->animationOptions(); | |
470 | } |
|
461 | } | |
471 |
|
462 | |||
472 | /*! |
|
463 | /*! | |
473 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
464 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | |
474 | */ |
|
465 | */ | |
475 | void QChart::scroll(qreal dx, qreal dy) |
|
466 | void QChart::scroll(qreal dx, qreal dy) | |
476 | { |
|
467 | { | |
477 | d_ptr->scroll(dx,dy); |
|
468 | d_ptr->scroll(dx,dy); | |
478 | } |
|
469 | } | |
479 |
|
470 | |||
480 | void QChart::setBackgroundVisible(bool visible) |
|
471 | void QChart::setBackgroundVisible(bool visible) | |
481 | { |
|
472 | { | |
482 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
473 | d_ptr->m_presenter->setBackgroundVisible(visible); | |
483 | } |
|
474 | } | |
484 |
|
475 | |||
485 | bool QChart::isBackgroundVisible() const |
|
476 | bool QChart::isBackgroundVisible() const | |
486 | { |
|
477 | { | |
487 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
478 | return d_ptr->m_presenter->isBackgroundVisible(); | |
488 | } |
|
479 | } | |
489 |
|
480 | |||
490 | void QChart::setDropShadowEnabled(bool enabled) |
|
481 | void QChart::setDropShadowEnabled(bool enabled) | |
491 | { |
|
482 | { | |
492 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
483 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); | |
493 | } |
|
484 | } | |
494 |
|
485 | |||
495 | bool QChart::isDropShadowEnabled() const |
|
486 | bool QChart::isDropShadowEnabled() const | |
496 | { |
|
487 | { | |
497 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
488 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); | |
498 | } |
|
489 | } | |
499 |
|
490 | |||
500 | /*! |
|
491 | /*! | |
501 | Returns all the series that are added to the chart. |
|
492 | Returns all the series that are added to the chart. | |
502 |
|
493 | |||
503 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
494 | \sa addSeries(), removeSeries(), removeAllSeries() | |
504 | */ |
|
495 | */ | |
505 | QList<QAbstractSeries *> QChart::series() const |
|
496 | QList<QAbstractSeries *> QChart::series() const | |
506 | { |
|
497 | { | |
507 | return d_ptr->m_dataset->series(); |
|
498 | return d_ptr->m_dataset->series(); | |
508 | } |
|
499 | } | |
509 |
|
500 | |||
510 | /*! |
|
501 | /*! | |
511 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
502 | Sets \a axis to the chart, which will control the presentation of the \a series | |
512 |
|
503 | |||
513 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
504 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() | |
514 | */ |
|
505 | */ | |
515 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) |
|
506 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) | |
516 | { |
|
507 | { | |
517 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); |
|
508 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); | |
518 |
|
509 | |||
519 | foreach(QAbstractAxis* a, list){ |
|
510 | foreach(QAbstractAxis* a, list){ | |
520 | d_ptr->m_dataset->removeAxis(a); |
|
511 | d_ptr->m_dataset->removeAxis(a); | |
521 | delete a; |
|
512 | delete a; | |
522 | } |
|
513 | } | |
523 |
|
514 | |||
524 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
515 | if(!d_ptr->m_dataset->axes().contains(axis)) | |
525 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); |
|
516 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); | |
526 | d_ptr->m_dataset->attachAxis(series,axis); |
|
517 | d_ptr->m_dataset->attachAxis(series,axis); | |
527 | } |
|
518 | } | |
528 |
|
519 | |||
529 | /*! |
|
520 | /*! | |
530 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
521 | Sets \a axis to the chart, which will control the presentation of the \a series | |
531 |
|
522 | |||
532 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
523 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() | |
533 | */ |
|
524 | */ | |
534 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) |
|
525 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) | |
535 | { |
|
526 | { | |
536 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); |
|
527 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); | |
537 |
|
528 | |||
538 | foreach(QAbstractAxis* a, list) { |
|
529 | foreach(QAbstractAxis* a, list) { | |
539 | d_ptr->m_dataset->removeAxis(a); |
|
530 | d_ptr->m_dataset->removeAxis(a); | |
540 | delete a; |
|
531 | delete a; | |
541 | } |
|
532 | } | |
542 |
|
533 | |||
543 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
534 | if(!d_ptr->m_dataset->axes().contains(axis)) | |
544 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); |
|
535 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); | |
545 | d_ptr->m_dataset->attachAxis(series,axis); |
|
536 | d_ptr->m_dataset->attachAxis(series,axis); | |
546 | } |
|
537 | } | |
547 |
|
538 | |||
548 | /*! |
|
539 | /*! | |
549 | Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
540 | Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis. | |
550 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
541 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
551 | */ |
|
542 | */ | |
552 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
543 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) | |
553 | { |
|
544 | { | |
554 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
545 | d_ptr->m_dataset->addAxis(axis, alignment); | |
555 | } |
|
546 | } | |
556 |
|
547 | |||
557 | /*! |
|
548 | /*! | |
558 | Removes \a axis from the chart. The ownership is returned to the caller. |
|
549 | Removes \a axis from the chart. The ownership is returned to the caller. | |
559 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
550 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() | |
560 | */ |
|
551 | */ | |
561 | void QChart::removeAxis(QAbstractAxis *axis) |
|
552 | void QChart::removeAxis(QAbstractAxis *axis) | |
562 | { |
|
553 | { | |
563 | d_ptr->m_dataset->removeAxis(axis); |
|
554 | d_ptr->m_dataset->removeAxis(axis); | |
564 | } |
|
555 | } | |
565 |
|
556 | |||
566 | /*! |
|
557 | /*! | |
567 | Returns the value in the \a series domain that coresponds to the charts widget point defines by \a position. |
|
558 | Returns the value in the \a series domain that coresponds to the charts widget point defines by \a position. | |
568 | */ |
|
559 | */ | |
569 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
560 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) | |
570 | { |
|
561 | { | |
571 | return d_ptr->m_dataset->mapToValue(position, series); |
|
562 | return d_ptr->m_dataset->mapToValue(position, series); | |
572 | } |
|
563 | } | |
573 |
|
564 | |||
574 | /*! |
|
565 | /*! | |
575 | Returns the position on the charts widget that coresponds to the \a value in the \a series domain. |
|
566 | Returns the position on the charts widget that coresponds to the \a value in the \a series domain. | |
576 | */ |
|
567 | */ | |
577 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
568 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) | |
578 | { |
|
569 | { | |
579 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
570 | return d_ptr->m_dataset->mapToPosition(value, series); | |
580 | } |
|
571 | } | |
581 |
|
572 | |||
582 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
573 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
583 |
|
574 | |||
584 | QChartPrivate::QChartPrivate(QChart *q): |
|
575 | QChartPrivate::QChartPrivate(QChart *q): | |
585 | q_ptr(q), |
|
576 | q_ptr(q), | |
586 | m_legend(0), |
|
577 | m_legend(0), | |
587 | m_dataset(new ChartDataSet(q)), |
|
578 | m_dataset(new ChartDataSet(q)), | |
588 | m_presenter(new ChartPresenter(q)), |
|
579 | m_presenter(new ChartPresenter(q)), | |
589 | m_themeManager(new ChartThemeManager(q)) |
|
580 | m_themeManager(new ChartThemeManager(q)) | |
590 | { |
|
581 | { | |
591 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
582 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
592 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
583 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
593 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
584 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); | |
594 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
585 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
595 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
586 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
596 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
587 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
597 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
588 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); | |
598 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
589 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
599 | } |
|
590 | } | |
600 |
|
591 | |||
601 | QChartPrivate::~QChartPrivate() |
|
592 | QChartPrivate::~QChartPrivate() | |
602 | { |
|
593 | { | |
603 |
|
594 | |||
604 | } |
|
595 | } | |
605 |
|
596 | |||
606 | void QChartPrivate::zoomIn(qreal factor) |
|
597 | void QChartPrivate::zoomIn(qreal factor) | |
607 | { |
|
598 | { | |
608 | QRectF rect = m_presenter->geometry(); |
|
599 | QRectF rect = m_presenter->geometry(); | |
609 | rect.setWidth(rect.width() / factor); |
|
600 | rect.setWidth(rect.width() / factor); | |
610 | rect.setHeight(rect.height() / factor); |
|
601 | rect.setHeight(rect.height() / factor); | |
611 | rect.moveCenter(m_presenter->geometry().center()); |
|
602 | rect.moveCenter(m_presenter->geometry().center()); | |
612 | zoomIn(rect); |
|
603 | zoomIn(rect); | |
613 | } |
|
604 | } | |
614 |
|
605 | |||
615 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
606 | void QChartPrivate::zoomIn(const QRectF &rect) | |
616 | { |
|
607 | { | |
617 | if (!rect.isValid()) |
|
608 | if (!rect.isValid()) | |
618 | return; |
|
609 | return; | |
619 |
|
610 | |||
620 | QRectF r = rect.normalized(); |
|
611 | QRectF r = rect.normalized(); | |
621 | const QRectF geometry = m_presenter->geometry(); |
|
612 | const QRectF geometry = m_presenter->geometry(); | |
622 | r.translate(-geometry.topLeft()); |
|
613 | r.translate(-geometry.topLeft()); | |
623 |
|
614 | |||
624 | if (!r.isValid()) |
|
615 | if (!r.isValid()) | |
625 | return; |
|
616 | return; | |
626 |
|
617 | |||
627 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
618 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
628 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
619 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); | |
629 | m_dataset->zoomInDomain(r); |
|
620 | m_dataset->zoomInDomain(r); | |
630 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
621 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
631 |
|
622 | |||
632 | } |
|
623 | } | |
633 |
|
624 | |||
634 | void QChartPrivate::zoomOut(qreal factor) |
|
625 | void QChartPrivate::zoomOut(qreal factor) | |
635 | { |
|
626 | { | |
636 | const QRectF geometry = m_presenter->geometry(); |
|
627 | const QRectF geometry = m_presenter->geometry(); | |
637 |
|
628 | |||
638 | QRectF r; |
|
629 | QRectF r; | |
639 | r.setSize(geometry.size() / factor); |
|
630 | r.setSize(geometry.size() / factor); | |
640 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
631 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); | |
641 | if (!r.isValid()) |
|
632 | if (!r.isValid()) | |
642 | return; |
|
633 | return; | |
643 |
|
634 | |||
644 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
635 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
645 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
636 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); | |
646 | m_dataset->zoomOutDomain(r); |
|
637 | m_dataset->zoomOutDomain(r); | |
647 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
638 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
648 | } |
|
639 | } | |
649 |
|
640 | |||
650 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
641 | void QChartPrivate::scroll(qreal dx, qreal dy) | |
651 | { |
|
642 | { | |
652 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
643 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); | |
653 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
644 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); | |
654 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
645 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); | |
655 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
646 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); | |
656 |
|
647 | |||
657 | m_dataset->scrollDomain(dx, dy); |
|
648 | m_dataset->scrollDomain(dx, dy); | |
658 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
649 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
659 | } |
|
650 | } | |
660 |
|
651 | |||
661 | #include "moc_qchart.cpp" |
|
652 | #include "moc_qchart.cpp" | |
662 |
|
653 | |||
663 | QTCOMMERCIALCHART_END_NAMESPACE |
|
654 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,195 +1,194 | |||||
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 "scatterchartitem_p.h" |
|
21 | #include "scatterchartitem_p.h" | |
22 | #include "qscatterseries.h" |
|
22 | #include "qscatterseries.h" | |
23 | #include "qscatterseries_p.h" |
|
23 | #include "qscatterseries_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "abstractdomain_p.h" |
|
25 | #include "abstractdomain_p.h" | |
26 | #include <QPainter> |
|
26 | #include <QPainter> | |
27 | #include <QGraphicsScene> |
|
27 | #include <QGraphicsScene> | |
28 | #include <QDebug> |
|
28 | #include <QDebug> | |
29 | #include <QGraphicsSceneMouseEvent> |
|
29 | #include <QGraphicsSceneMouseEvent> | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem* item) |
|
33 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem* item) | |
34 | : XYChart(series,item), |
|
34 | : XYChart(series,item), | |
35 | m_series(series), |
|
35 | m_series(series), | |
36 | m_items(this), |
|
36 | m_items(this), | |
37 | m_visible(true), |
|
37 | m_visible(true), | |
38 | m_shape(QScatterSeries::MarkerShapeRectangle), |
|
38 | m_shape(QScatterSeries::MarkerShapeRectangle), | |
39 | m_size(15) |
|
39 | m_size(15) | |
40 | { |
|
40 | { | |
41 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated())); |
|
41 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated())); | |
42 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); |
|
42 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |
43 | QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); |
|
43 | QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); | |
44 |
|
44 | |||
45 | setZValue(ChartPresenter::ScatterSeriesZValue); |
|
45 | setZValue(ChartPresenter::ScatterSeriesZValue); | |
46 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
46 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
47 |
|
47 | |||
48 | handleUpdated(); |
|
48 | handleUpdated(); | |
49 |
|
49 | |||
50 | m_items.setHandlesChildEvents(false); |
|
50 | m_items.setHandlesChildEvents(false); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | QRectF ScatterChartItem::boundingRect() const |
|
53 | QRectF ScatterChartItem::boundingRect() const | |
54 | { |
|
54 | { | |
55 | return m_rect; |
|
55 | return m_rect; | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | void ScatterChartItem::createPoints(int count) |
|
58 | void ScatterChartItem::createPoints(int count) | |
59 | { |
|
59 | { | |
60 | for (int i = 0; i < count; ++i) { |
|
60 | for (int i = 0; i < count; ++i) { | |
61 |
|
61 | |||
62 | QGraphicsItem *item = 0; |
|
62 | QGraphicsItem *item = 0; | |
63 |
|
63 | |||
64 | switch (m_shape) { |
|
64 | switch (m_shape) { | |
65 | case QScatterSeries::MarkerShapeCircle: { |
|
65 | case QScatterSeries::MarkerShapeCircle: { | |
66 | item = new CircleMarker(0, 0, m_size, m_size, this); |
|
66 | item = new CircleMarker(0, 0, m_size, m_size, this); | |
67 | const QRectF &rect = item->boundingRect(); |
|
67 | const QRectF &rect = item->boundingRect(); | |
68 | item->setPos(-rect.width() / 2, -rect.height() / 2); |
|
68 | item->setPos(-rect.width() / 2, -rect.height() / 2); | |
69 | break; |
|
69 | break; | |
70 | } |
|
70 | } | |
71 | case QScatterSeries::MarkerShapeRectangle: |
|
71 | case QScatterSeries::MarkerShapeRectangle: | |
72 | item = new RectangleMarker(0, 0, m_size, m_size, this); |
|
72 | item = new RectangleMarker(0, 0, m_size, m_size, this); | |
73 | item->setPos(-m_size / 2, -m_size / 2); |
|
73 | item->setPos(-m_size / 2, -m_size / 2); | |
74 | break; |
|
74 | break; | |
75 | default: |
|
75 | default: | |
76 | qWarning() << "Unsupported marker type"; |
|
76 | qWarning() << "Unsupported marker type"; | |
77 | break; |
|
77 | break; | |
78 | } |
|
78 | } | |
79 | m_items.addToGroup(item); |
|
79 | m_items.addToGroup(item); | |
80 | } |
|
80 | } | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | void ScatterChartItem::deletePoints(int count) |
|
83 | void ScatterChartItem::deletePoints(int count) | |
84 | { |
|
84 | { | |
85 | QList<QGraphicsItem *> items = m_items.childItems(); |
|
85 | QList<QGraphicsItem *> items = m_items.childItems(); | |
86 |
|
86 | |||
87 | for (int i = 0; i < count; ++i) { |
|
87 | for (int i = 0; i < count; ++i) { | |
88 | QGraphicsItem *item = items.takeLast(); |
|
88 | QGraphicsItem *item = items.takeLast(); | |
89 | m_markerMap.remove(item); |
|
89 | m_markerMap.remove(item); | |
90 | delete(item); |
|
90 | delete(item); | |
91 | } |
|
91 | } | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | void ScatterChartItem::markerSelected(QGraphicsItem *marker) |
|
94 | void ScatterChartItem::markerSelected(QGraphicsItem *marker) | |
95 | { |
|
95 | { | |
96 | emit XYChart::clicked(domain()->calculateDomainPoint(m_markerMap[marker])); |
|
96 | emit XYChart::clicked(domain()->calculateDomainPoint(m_markerMap[marker])); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void ScatterChartItem::markerHovered(QGraphicsItem *marker, bool state) |
|
99 | void ScatterChartItem::markerHovered(QGraphicsItem *marker, bool state) | |
100 | { |
|
100 | { | |
101 | emit XYChart::hovered(domain()->calculateDomainPoint(m_markerMap[marker]), state); |
|
101 | emit XYChart::hovered(domain()->calculateDomainPoint(m_markerMap[marker]), state); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void ScatterChartItem::updateGeometry() |
|
104 | void ScatterChartItem::updateGeometry() | |
105 | { |
|
105 | { | |
106 |
|
106 | |||
107 | const QVector<QPointF>& points = geometryPoints(); |
|
107 | const QVector<QPointF>& points = geometryPoints(); | |
108 |
|
108 | |||
109 | if (points.size() == 0) { |
|
109 | if (points.size() == 0) { | |
110 | deletePoints(m_items.childItems().count()); |
|
110 | deletePoints(m_items.childItems().count()); | |
111 | return; |
|
111 | return; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | int diff = m_items.childItems().size() - points.size(); |
|
114 | int diff = m_items.childItems().size() - points.size(); | |
115 |
|
115 | |||
116 | if (diff > 0) |
|
116 | if (diff > 0) | |
117 | deletePoints(diff); |
|
117 | deletePoints(diff); | |
118 | else if (diff < 0) |
|
118 | else if (diff < 0) | |
119 | createPoints(-diff); |
|
119 | createPoints(-diff); | |
120 |
|
120 | |||
121 | if (diff != 0) |
|
121 | if (diff != 0) | |
122 | handleUpdated(); |
|
122 | handleUpdated(); | |
123 |
|
123 | |||
124 | QList<QGraphicsItem *> items = m_items.childItems(); |
|
124 | QList<QGraphicsItem *> items = m_items.childItems(); | |
125 |
|
125 | |||
126 | QRectF clipRect(QPointF(0,0),domain()->size()); |
|
126 | QRectF clipRect(QPointF(0,0),domain()->size()); | |
127 |
|
127 | |||
128 | for (int i = 0; i < points.size(); i++) { |
|
128 | for (int i = 0; i < points.size(); i++) { | |
129 | QGraphicsItem *item = items.at(i); |
|
129 | QGraphicsItem *item = items.at(i); | |
130 | const QPointF &point = points.at(i); |
|
130 | const QPointF &point = points.at(i); | |
131 | const QRectF &rect = item->boundingRect(); |
|
131 | const QRectF &rect = item->boundingRect(); | |
132 | m_markerMap[item] = point; |
|
132 | m_markerMap[item] = point; | |
133 | item->setPos(point.x() - rect.width() / 2, point.y() - rect.height() / 2); |
|
133 | item->setPos(point.x() - rect.width() / 2, point.y() - rect.height() / 2); | |
134 | if (!m_visible || !clipRect.contains(point)) |
|
134 | if (!m_visible || !clipRect.contains(point)) | |
135 | item->setVisible(false); |
|
135 | item->setVisible(false); | |
136 | else |
|
136 | else | |
137 | item->setVisible(true); |
|
137 | item->setVisible(true); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | prepareGeometryChange(); |
|
140 | prepareGeometryChange(); | |
141 | m_rect = clipRect; |
|
141 | m_rect = clipRect; | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
144 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
145 | { |
|
145 | { | |
146 | Q_UNUSED(painter) |
|
146 | Q_UNUSED(painter) | |
147 | Q_UNUSED(option) |
|
147 | Q_UNUSED(option) | |
148 | Q_UNUSED(widget) |
|
148 | Q_UNUSED(widget) | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void ScatterChartItem::setPen(const QPen &pen) |
|
151 | void ScatterChartItem::setPen(const QPen &pen) | |
152 | { |
|
152 | { | |
153 | foreach (QGraphicsItem *item , m_items.childItems()) |
|
153 | foreach (QGraphicsItem *item , m_items.childItems()) | |
154 | static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen); |
|
154 | static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void ScatterChartItem::setBrush(const QBrush &brush) |
|
157 | void ScatterChartItem::setBrush(const QBrush &brush) | |
158 | { |
|
158 | { | |
159 | foreach (QGraphicsItem *item , m_items.childItems()) |
|
159 | foreach (QGraphicsItem *item , m_items.childItems()) | |
160 | static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush); |
|
160 | static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | void ScatterChartItem::handleUpdated() |
|
163 | void ScatterChartItem::handleUpdated() | |
164 | { |
|
164 | { | |
165 | int count = m_items.childItems().count(); |
|
165 | int count = m_items.childItems().count(); | |
166 |
|
166 | |||
167 | if (count == 0) |
|
167 | if (count == 0) | |
168 | return; |
|
168 | return; | |
169 |
|
169 | |||
170 | bool recreate = m_visible != m_series->isVisible() |
|
170 | bool recreate = m_visible != m_series->isVisible() | |
171 | || m_size != m_series->markerSize() |
|
171 | || m_size != m_series->markerSize() | |
172 | || m_shape != m_series->markerShape(); |
|
172 | || m_shape != m_series->markerShape(); | |
173 |
|
173 | |||
174 | m_visible = m_series->isVisible(); |
|
174 | m_visible = m_series->isVisible(); | |
175 | m_size = m_series->markerSize(); |
|
175 | m_size = m_series->markerSize(); | |
176 | m_shape = m_series->markerShape(); |
|
176 | m_shape = m_series->markerShape(); | |
177 | setOpacity(m_series->opacity()); |
|
177 | setOpacity(m_series->opacity()); | |
178 |
|
178 | |||
179 | if (recreate) { |
|
179 | if (recreate) { | |
180 | // TODO: optimize handleUpdate to recreate points only in case shape changed |
|
|||
181 | deletePoints(count); |
|
180 | deletePoints(count); | |
182 | createPoints(count); |
|
181 | createPoints(count); | |
183 |
|
182 | |||
184 | // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points |
|
183 | // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points | |
185 | updateGeometry(); |
|
184 | updateGeometry(); | |
186 | } |
|
185 | } | |
187 |
|
186 | |||
188 | setPen(m_series->pen()); |
|
187 | setPen(m_series->pen()); | |
189 | setBrush(m_series->brush()); |
|
188 | setBrush(m_series->brush()); | |
190 | update(); |
|
189 | update(); | |
191 | } |
|
190 | } | |
192 |
|
191 | |||
193 | #include "moc_scatterchartitem_p.cpp" |
|
192 | #include "moc_scatterchartitem_p.cpp" | |
194 |
|
193 | |||
195 | QTCOMMERCIALCHART_END_NAMESPACE |
|
194 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,160 +1,158 | |||||
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 "xychart_p.h" |
|
21 | #include "xychart_p.h" | |
22 | #include "qxyseries.h" |
|
22 | #include "qxyseries.h" | |
23 | #include "qxyseries_p.h" |
|
23 | #include "qxyseries_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "abstractdomain_p.h" |
|
25 | #include "abstractdomain_p.h" | |
26 | #include "qxymodelmapper.h" |
|
26 | #include "qxymodelmapper.h" | |
27 | #include <QPainter> |
|
27 | #include <QPainter> | |
28 | #include <QAbstractItemModel> |
|
28 | #include <QAbstractItemModel> | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | //TODO: optimize : remove points which are not visible |
|
|||
34 |
|
||||
35 | XYChart::XYChart(QXYSeries *series,QGraphicsItem* item): |
|
33 | XYChart::XYChart(QXYSeries *series,QGraphicsItem* item): | |
36 | ChartItem(series->d_func(),item), |
|
34 | ChartItem(series->d_func(),item), | |
37 | m_series(series), |
|
35 | m_series(series), | |
38 | m_animation(0), |
|
36 | m_animation(0), | |
39 | m_dirty(true) |
|
37 | m_dirty(true) | |
40 | { |
|
38 | { | |
41 | QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int))); |
|
39 | QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int))); | |
42 | QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced())); |
|
40 | QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced())); | |
43 | QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int))); |
|
41 | QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int))); | |
44 | QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int))); |
|
42 | QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int))); | |
45 | QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF))); |
|
43 | QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF))); | |
46 | QObject::connect(this, SIGNAL(hovered(QPointF,bool)), series, SIGNAL(hovered(QPointF,bool))); |
|
44 | QObject::connect(this, SIGNAL(hovered(QPointF,bool)), series, SIGNAL(hovered(QPointF,bool))); | |
47 | } |
|
45 | } | |
48 |
|
46 | |||
49 | void XYChart::setGeometryPoints(const QVector<QPointF>& points) |
|
47 | void XYChart::setGeometryPoints(const QVector<QPointF>& points) | |
50 | { |
|
48 | { | |
51 | m_points = points; |
|
49 | m_points = points; | |
52 | } |
|
50 | } | |
53 |
|
51 | |||
54 | void XYChart::setAnimation(XYAnimation *animation) |
|
52 | void XYChart::setAnimation(XYAnimation *animation) | |
55 | { |
|
53 | { | |
56 | m_animation = animation; |
|
54 | m_animation = animation; | |
57 | } |
|
55 | } | |
58 |
|
56 | |||
59 | void XYChart::setDirty(bool dirty) |
|
57 | void XYChart::setDirty(bool dirty) | |
60 | { |
|
58 | { | |
61 | m_dirty = dirty; |
|
59 | m_dirty = dirty; | |
62 | } |
|
60 | } | |
63 |
|
61 | |||
64 | void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index) |
|
62 | void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index) | |
65 | { |
|
63 | { | |
66 |
|
64 | |||
67 | if (m_animation) { |
|
65 | if (m_animation) { | |
68 | m_animation->setup(oldPoints, newPoints, index); |
|
66 | m_animation->setup(oldPoints, newPoints, index); | |
69 | m_points = newPoints; |
|
67 | m_points = newPoints; | |
70 | setDirty(false); |
|
68 | setDirty(false); | |
71 | presenter()->startAnimation(m_animation); |
|
69 | presenter()->startAnimation(m_animation); | |
72 | } else { |
|
70 | } else { | |
73 | m_points = newPoints; |
|
71 | m_points = newPoints; | |
74 | updateGeometry(); |
|
72 | updateGeometry(); | |
75 | } |
|
73 | } | |
76 | } |
|
74 | } | |
77 |
|
75 | |||
78 | //handlers |
|
76 | //handlers | |
79 |
|
77 | |||
80 | void XYChart::handlePointAdded(int index) |
|
78 | void XYChart::handlePointAdded(int index) | |
81 | { |
|
79 | { | |
82 | Q_ASSERT(index < m_series->count()); |
|
80 | Q_ASSERT(index < m_series->count()); | |
83 | Q_ASSERT(index >= 0); |
|
81 | Q_ASSERT(index >= 0); | |
84 |
|
82 | |||
85 | QVector<QPointF> points; |
|
83 | QVector<QPointF> points; | |
86 |
|
84 | |||
87 | if (m_dirty || m_points.isEmpty()) { |
|
85 | if (m_dirty || m_points.isEmpty()) { | |
88 | points = domain()->calculateGeometryPoints(m_series->points()); |
|
86 | points = domain()->calculateGeometryPoints(m_series->points()); | |
89 | } else { |
|
87 | } else { | |
90 | points = m_points; |
|
88 | points = m_points; | |
91 | QPointF point = domain()->calculateGeometryPoint(m_series->points()[index], m_validData); |
|
89 | QPointF point = domain()->calculateGeometryPoint(m_series->points()[index], m_validData); | |
92 | if (!m_validData) |
|
90 | if (!m_validData) | |
93 | m_points.clear(); |
|
91 | m_points.clear(); | |
94 | else |
|
92 | else | |
95 | points.insert(index, point); |
|
93 | points.insert(index, point); | |
96 | } |
|
94 | } | |
97 |
|
95 | |||
98 | updateChart(m_points, points, index); |
|
96 | updateChart(m_points, points, index); | |
99 | } |
|
97 | } | |
100 |
|
98 | |||
101 | void XYChart::handlePointRemoved(int index) |
|
99 | void XYChart::handlePointRemoved(int index) | |
102 | { |
|
100 | { | |
103 | Q_ASSERT(index <= m_series->count()); |
|
101 | Q_ASSERT(index <= m_series->count()); | |
104 | Q_ASSERT(index >= 0); |
|
102 | Q_ASSERT(index >= 0); | |
105 |
|
103 | |||
106 | QVector<QPointF> points; |
|
104 | QVector<QPointF> points; | |
107 |
|
105 | |||
108 | if (m_dirty || m_points.isEmpty()) { |
|
106 | if (m_dirty || m_points.isEmpty()) { | |
109 | points = domain()->calculateGeometryPoints(m_series->points()); |
|
107 | points = domain()->calculateGeometryPoints(m_series->points()); | |
110 | } else { |
|
108 | } else { | |
111 | points = m_points; |
|
109 | points = m_points; | |
112 | points.remove(index); |
|
110 | points.remove(index); | |
113 | } |
|
111 | } | |
114 |
|
112 | |||
115 | updateChart(m_points, points, index); |
|
113 | updateChart(m_points, points, index); | |
116 | } |
|
114 | } | |
117 |
|
115 | |||
118 | void XYChart::handlePointReplaced(int index) |
|
116 | void XYChart::handlePointReplaced(int index) | |
119 | { |
|
117 | { | |
120 | Q_ASSERT(index < m_series->count()); |
|
118 | Q_ASSERT(index < m_series->count()); | |
121 | Q_ASSERT(index >= 0); |
|
119 | Q_ASSERT(index >= 0); | |
122 |
|
120 | |||
123 | QVector<QPointF> points; |
|
121 | QVector<QPointF> points; | |
124 |
|
122 | |||
125 | if (m_dirty || m_points.isEmpty()) { |
|
123 | if (m_dirty || m_points.isEmpty()) { | |
126 | points = domain()->calculateGeometryPoints(m_series->points()); |
|
124 | points = domain()->calculateGeometryPoints(m_series->points()); | |
127 | } else { |
|
125 | } else { | |
128 | QPointF point = domain()->calculateGeometryPoint(m_series->points()[index], m_validData); |
|
126 | QPointF point = domain()->calculateGeometryPoint(m_series->points()[index], m_validData); | |
129 | if (!m_validData) |
|
127 | if (!m_validData) | |
130 | m_points.clear(); |
|
128 | m_points.clear(); | |
131 | points = m_points; |
|
129 | points = m_points; | |
132 | if (m_validData) |
|
130 | if (m_validData) | |
133 | points.replace(index, point); |
|
131 | points.replace(index, point); | |
134 | } |
|
132 | } | |
135 |
|
133 | |||
136 | updateChart(m_points, points, index); |
|
134 | updateChart(m_points, points, index); | |
137 | } |
|
135 | } | |
138 |
|
136 | |||
139 | void XYChart::handlePointsReplaced() |
|
137 | void XYChart::handlePointsReplaced() | |
140 | { |
|
138 | { | |
141 | // All the points were replaced -> recalculate |
|
139 | // All the points were replaced -> recalculate | |
142 | QVector<QPointF> points = domain()->calculateGeometryPoints(m_series->points()); |
|
140 | QVector<QPointF> points = domain()->calculateGeometryPoints(m_series->points()); | |
143 | updateChart(m_points, points, -1); |
|
141 | updateChart(m_points, points, -1); | |
144 | } |
|
142 | } | |
145 |
|
143 | |||
146 | void XYChart::handleDomainUpdated() |
|
144 | void XYChart::handleDomainUpdated() | |
147 | { |
|
145 | { | |
148 | if (isEmpty()) return; |
|
146 | if (isEmpty()) return; | |
149 | QVector<QPointF> points = domain()->calculateGeometryPoints(m_series->points()); |
|
147 | QVector<QPointF> points = domain()->calculateGeometryPoints(m_series->points()); | |
150 | updateChart(m_points, points); |
|
148 | updateChart(m_points, points); | |
151 | } |
|
149 | } | |
152 |
|
150 | |||
153 | bool XYChart::isEmpty() |
|
151 | bool XYChart::isEmpty() | |
154 | { |
|
152 | { | |
155 | return domain()->isEmpty() || m_series->points().isEmpty(); |
|
153 | return domain()->isEmpty() || m_series->points().isEmpty(); | |
156 | } |
|
154 | } | |
157 |
|
155 | |||
158 | #include "moc_xychart_p.cpp" |
|
156 | #include "moc_xychart_p.cpp" | |
159 |
|
157 | |||
160 | QTCOMMERCIALCHART_END_NAMESPACE |
|
158 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now