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