@@ -1,352 +1,352 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartaxiselement_p.h" |
|
21 | #include "chartaxiselement_p.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "abstractchartlayout_p.h" |
|
24 | #include "abstractchartlayout_p.h" | |
25 | #include <qmath.h> |
|
25 | #include <qmath.h> | |
26 | #include <QDateTime> |
|
26 | #include <QDateTime> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | static const char *labelFormatMatchString = "%[\\-\\+#\\s\\d\\.lhjztL]*([dicuoxfegXFEG])"; |
|
30 | static const char *labelFormatMatchString = "%[\\-\\+#\\s\\d\\.lhjztL]*([dicuoxfegXFEG])"; | |
31 | static QRegExp *labelFormatMatcher = 0; |
|
31 | static QRegExp *labelFormatMatcher = 0; | |
32 | class StaticLabelFormatMatcherDeleter |
|
32 | class StaticLabelFormatMatcherDeleter | |
33 | { |
|
33 | { | |
34 | public: |
|
34 | public: | |
35 | StaticLabelFormatMatcherDeleter() {} |
|
35 | StaticLabelFormatMatcherDeleter() {} | |
36 | ~StaticLabelFormatMatcherDeleter() { delete labelFormatMatcher; } |
|
36 | ~StaticLabelFormatMatcherDeleter() { delete labelFormatMatcher; } | |
37 | }; |
|
37 | }; | |
38 | StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter; |
|
38 | static StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter; | |
39 |
|
39 | |||
40 | ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) |
|
40 | ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) | |
41 | : ChartElement(item), |
|
41 | : ChartElement(item), | |
42 | m_axis(axis), |
|
42 | m_axis(axis), | |
43 | m_animation(0), |
|
43 | m_animation(0), | |
44 | m_grid(new QGraphicsItemGroup(item)), |
|
44 | m_grid(new QGraphicsItemGroup(item)), | |
45 | m_arrow(new QGraphicsItemGroup(item)), |
|
45 | m_arrow(new QGraphicsItemGroup(item)), | |
46 | m_shades(new QGraphicsItemGroup(item)), |
|
46 | m_shades(new QGraphicsItemGroup(item)), | |
47 | m_labels(new QGraphicsItemGroup(item)), |
|
47 | m_labels(new QGraphicsItemGroup(item)), | |
48 | m_title(new QGraphicsTextItem(item)), |
|
48 | m_title(new QGraphicsTextItem(item)), | |
49 | m_intervalAxis(intervalAxis) |
|
49 | m_intervalAxis(intervalAxis) | |
50 |
|
50 | |||
51 | { |
|
51 | { | |
52 | //initial initialization |
|
52 | //initial initialization | |
53 | m_arrow->setHandlesChildEvents(false); |
|
53 | m_arrow->setHandlesChildEvents(false); | |
54 | m_arrow->setZValue(ChartPresenter::AxisZValue); |
|
54 | m_arrow->setZValue(ChartPresenter::AxisZValue); | |
55 | m_labels->setZValue(ChartPresenter::AxisZValue); |
|
55 | m_labels->setZValue(ChartPresenter::AxisZValue); | |
56 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
56 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
57 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
57 | m_grid->setZValue(ChartPresenter::GridZValue); | |
58 | m_title->setZValue(ChartPresenter::GridZValue); |
|
58 | m_title->setZValue(ChartPresenter::GridZValue); | |
59 | handleVisibleChanged(axis->isVisible()); |
|
59 | handleVisibleChanged(axis->isVisible()); | |
60 | connectSlots(); |
|
60 | connectSlots(); | |
61 |
|
61 | |||
62 | setFlag(QGraphicsItem::ItemHasNoContents, true); |
|
62 | setFlag(QGraphicsItem::ItemHasNoContents, true); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | ChartAxisElement::~ChartAxisElement() |
|
65 | ChartAxisElement::~ChartAxisElement() | |
66 | { |
|
66 | { | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void ChartAxisElement::connectSlots() |
|
69 | void ChartAxisElement::connectSlots() | |
70 | { |
|
70 | { | |
71 | QObject::connect(axis(), SIGNAL(visibleChanged(bool)), this, SLOT(handleVisibleChanged(bool))); |
|
71 | QObject::connect(axis(), SIGNAL(visibleChanged(bool)), this, SLOT(handleVisibleChanged(bool))); | |
72 | QObject::connect(axis(), SIGNAL(lineVisibleChanged(bool)), this, SLOT(handleArrowVisibleChanged(bool))); |
|
72 | QObject::connect(axis(), SIGNAL(lineVisibleChanged(bool)), this, SLOT(handleArrowVisibleChanged(bool))); | |
73 | QObject::connect(axis(), SIGNAL(gridVisibleChanged(bool)), this, SLOT(handleGridVisibleChanged(bool))); |
|
73 | QObject::connect(axis(), SIGNAL(gridVisibleChanged(bool)), this, SLOT(handleGridVisibleChanged(bool))); | |
74 | QObject::connect(axis(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); |
|
74 | QObject::connect(axis(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); | |
75 | QObject::connect(axis(), SIGNAL(shadesVisibleChanged(bool)), this, SLOT(handleShadesVisibleChanged(bool))); |
|
75 | QObject::connect(axis(), SIGNAL(shadesVisibleChanged(bool)), this, SLOT(handleShadesVisibleChanged(bool))); | |
76 | QObject::connect(axis(), SIGNAL(labelsAngleChanged(int)), this, SLOT(handleLabelsAngleChanged(int))); |
|
76 | QObject::connect(axis(), SIGNAL(labelsAngleChanged(int)), this, SLOT(handleLabelsAngleChanged(int))); | |
77 | QObject::connect(axis(), SIGNAL(linePenChanged(const QPen&)), this, SLOT(handleArrowPenChanged(const QPen&))); |
|
77 | QObject::connect(axis(), SIGNAL(linePenChanged(const QPen&)), this, SLOT(handleArrowPenChanged(const QPen&))); | |
78 | QObject::connect(axis(), SIGNAL(labelsPenChanged(const QPen&)), this, SLOT(handleLabelsPenChanged(const QPen&))); |
|
78 | QObject::connect(axis(), SIGNAL(labelsPenChanged(const QPen&)), this, SLOT(handleLabelsPenChanged(const QPen&))); | |
79 | QObject::connect(axis(), SIGNAL(labelsBrushChanged(const QBrush&)), this, SLOT(handleLabelsBrushChanged(const QBrush&))); |
|
79 | QObject::connect(axis(), SIGNAL(labelsBrushChanged(const QBrush&)), this, SLOT(handleLabelsBrushChanged(const QBrush&))); | |
80 | QObject::connect(axis(), SIGNAL(labelsFontChanged(const QFont&)), this, SLOT(handleLabelsFontChanged(const QFont&))); |
|
80 | QObject::connect(axis(), SIGNAL(labelsFontChanged(const QFont&)), this, SLOT(handleLabelsFontChanged(const QFont&))); | |
81 | QObject::connect(axis(), SIGNAL(gridLinePenChanged(const QPen&)), this, SLOT(handleGridPenChanged(const QPen&))); |
|
81 | QObject::connect(axis(), SIGNAL(gridLinePenChanged(const QPen&)), this, SLOT(handleGridPenChanged(const QPen&))); | |
82 | QObject::connect(axis(), SIGNAL(shadesPenChanged(const QPen&)), this, SLOT(handleShadesPenChanged(const QPen&))); |
|
82 | QObject::connect(axis(), SIGNAL(shadesPenChanged(const QPen&)), this, SLOT(handleShadesPenChanged(const QPen&))); | |
83 | QObject::connect(axis(), SIGNAL(shadesBrushChanged(const QBrush&)), this, SLOT(handleShadesBrushChanged(const QBrush&))); |
|
83 | QObject::connect(axis(), SIGNAL(shadesBrushChanged(const QBrush&)), this, SLOT(handleShadesBrushChanged(const QBrush&))); | |
84 | QObject::connect(axis(), SIGNAL(titleTextChanged(const QString&)), this, SLOT(handleTitleTextChanged(const QString&))); |
|
84 | QObject::connect(axis(), SIGNAL(titleTextChanged(const QString&)), this, SLOT(handleTitleTextChanged(const QString&))); | |
85 | QObject::connect(axis(), SIGNAL(titleFontChanged(const QFont&)), this, SLOT(handleTitleFontChanged(const QFont&))); |
|
85 | QObject::connect(axis(), SIGNAL(titleFontChanged(const QFont&)), this, SLOT(handleTitleFontChanged(const QFont&))); | |
86 | QObject::connect(axis(), SIGNAL(titlePenChanged(const QPen&)), this, SLOT(handleTitlePenChanged(const QPen&))); |
|
86 | QObject::connect(axis(), SIGNAL(titlePenChanged(const QPen&)), this, SLOT(handleTitlePenChanged(const QPen&))); | |
87 | QObject::connect(axis(), SIGNAL(titleBrushChanged(const QBrush&)), this, SLOT(handleTitleBrushChanged(const QBrush&))); |
|
87 | QObject::connect(axis(), SIGNAL(titleBrushChanged(const QBrush&)), this, SLOT(handleTitleBrushChanged(const QBrush&))); | |
88 | QObject::connect(axis(), SIGNAL(titleVisibleChanged(bool)), this, SLOT(handleTitleVisibleChanged(bool))); |
|
88 | QObject::connect(axis(), SIGNAL(titleVisibleChanged(bool)), this, SLOT(handleTitleVisibleChanged(bool))); | |
89 | QObject::connect(axis()->d_ptr.data(), SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(handleRangeChanged(qreal, qreal))); |
|
89 | QObject::connect(axis()->d_ptr.data(), SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(handleRangeChanged(qreal, qreal))); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void ChartAxisElement::handleArrowVisibleChanged(bool visible) |
|
92 | void ChartAxisElement::handleArrowVisibleChanged(bool visible) | |
93 | { |
|
93 | { | |
94 | m_arrow->setVisible(visible); |
|
94 | m_arrow->setVisible(visible); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void ChartAxisElement::handleGridVisibleChanged(bool visible) |
|
97 | void ChartAxisElement::handleGridVisibleChanged(bool visible) | |
98 | { |
|
98 | { | |
99 | m_grid->setVisible(visible); |
|
99 | m_grid->setVisible(visible); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void ChartAxisElement::handleLabelsVisibleChanged(bool visible) |
|
102 | void ChartAxisElement::handleLabelsVisibleChanged(bool visible) | |
103 | { |
|
103 | { | |
104 | QGraphicsLayoutItem::updateGeometry(); |
|
104 | QGraphicsLayoutItem::updateGeometry(); | |
105 | presenter()->layout()->invalidate(); |
|
105 | presenter()->layout()->invalidate(); | |
106 | m_labels->setVisible(visible); |
|
106 | m_labels->setVisible(visible); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void ChartAxisElement::handleShadesVisibleChanged(bool visible) |
|
109 | void ChartAxisElement::handleShadesVisibleChanged(bool visible) | |
110 | { |
|
110 | { | |
111 | m_shades->setVisible(visible); |
|
111 | m_shades->setVisible(visible); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | void ChartAxisElement::handleTitleVisibleChanged(bool visible) |
|
114 | void ChartAxisElement::handleTitleVisibleChanged(bool visible) | |
115 | { |
|
115 | { | |
116 | QGraphicsLayoutItem::updateGeometry(); |
|
116 | QGraphicsLayoutItem::updateGeometry(); | |
117 | presenter()->layout()->invalidate(); |
|
117 | presenter()->layout()->invalidate(); | |
118 | m_title->setVisible(visible); |
|
118 | m_title->setVisible(visible); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void ChartAxisElement::handleLabelsAngleChanged(int angle) |
|
121 | void ChartAxisElement::handleLabelsAngleChanged(int angle) | |
122 | { |
|
122 | { | |
123 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
123 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
124 | item->setRotation(angle); |
|
124 | item->setRotation(angle); | |
125 |
|
125 | |||
126 | QGraphicsLayoutItem::updateGeometry(); |
|
126 | QGraphicsLayoutItem::updateGeometry(); | |
127 | presenter()->layout()->invalidate(); |
|
127 | presenter()->layout()->invalidate(); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | void ChartAxisElement::handleLabelsPenChanged(const QPen &pen) |
|
130 | void ChartAxisElement::handleLabelsPenChanged(const QPen &pen) | |
131 | { |
|
131 | { | |
132 | Q_UNUSED(pen) |
|
132 | Q_UNUSED(pen) | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | void ChartAxisElement::handleLabelsBrushChanged(const QBrush &brush) |
|
135 | void ChartAxisElement::handleLabelsBrushChanged(const QBrush &brush) | |
136 | { |
|
136 | { | |
137 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
137 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
138 | static_cast<QGraphicsTextItem *>(item)->setDefaultTextColor(brush.color()); |
|
138 | static_cast<QGraphicsTextItem *>(item)->setDefaultTextColor(brush.color()); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void ChartAxisElement::handleLabelsFontChanged(const QFont &font) |
|
141 | void ChartAxisElement::handleLabelsFontChanged(const QFont &font) | |
142 | { |
|
142 | { | |
143 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
143 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
144 | static_cast<QGraphicsTextItem *>(item)->setFont(font); |
|
144 | static_cast<QGraphicsTextItem *>(item)->setFont(font); | |
145 | QGraphicsLayoutItem::updateGeometry(); |
|
145 | QGraphicsLayoutItem::updateGeometry(); | |
146 | presenter()->layout()->invalidate(); |
|
146 | presenter()->layout()->invalidate(); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | void ChartAxisElement::handleTitleTextChanged(const QString &title) |
|
149 | void ChartAxisElement::handleTitleTextChanged(const QString &title) | |
150 | { |
|
150 | { | |
151 | QGraphicsLayoutItem::updateGeometry(); |
|
151 | QGraphicsLayoutItem::updateGeometry(); | |
152 | presenter()->layout()->invalidate(); |
|
152 | presenter()->layout()->invalidate(); | |
153 | m_title->setHtml(title); |
|
153 | m_title->setHtml(title); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void ChartAxisElement::handleTitlePenChanged(const QPen &pen) |
|
156 | void ChartAxisElement::handleTitlePenChanged(const QPen &pen) | |
157 | { |
|
157 | { | |
158 | Q_UNUSED(pen) |
|
158 | Q_UNUSED(pen) | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void ChartAxisElement::handleTitleBrushChanged(const QBrush &brush) |
|
161 | void ChartAxisElement::handleTitleBrushChanged(const QBrush &brush) | |
162 | { |
|
162 | { | |
163 | m_title->setDefaultTextColor(brush.color()); |
|
163 | m_title->setDefaultTextColor(brush.color()); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | void ChartAxisElement::handleTitleFontChanged(const QFont &font) |
|
166 | void ChartAxisElement::handleTitleFontChanged(const QFont &font) | |
167 | { |
|
167 | { | |
168 | if (m_title->font() != font) { |
|
168 | if (m_title->font() != font) { | |
169 | m_title->setFont(font); |
|
169 | m_title->setFont(font); | |
170 | QGraphicsLayoutItem::updateGeometry(); |
|
170 | QGraphicsLayoutItem::updateGeometry(); | |
171 | presenter()->layout()->invalidate(); |
|
171 | presenter()->layout()->invalidate(); | |
172 | } |
|
172 | } | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | void ChartAxisElement::handleVisibleChanged(bool visible) |
|
175 | void ChartAxisElement::handleVisibleChanged(bool visible) | |
176 | { |
|
176 | { | |
177 | setVisible(visible); |
|
177 | setVisible(visible); | |
178 | if (!visible) { |
|
178 | if (!visible) { | |
179 | m_grid->setVisible(visible); |
|
179 | m_grid->setVisible(visible); | |
180 | m_arrow->setVisible(visible); |
|
180 | m_arrow->setVisible(visible); | |
181 | m_shades->setVisible(visible); |
|
181 | m_shades->setVisible(visible); | |
182 | m_labels->setVisible(visible); |
|
182 | m_labels->setVisible(visible); | |
183 | m_title->setVisible(visible); |
|
183 | m_title->setVisible(visible); | |
184 | } else { |
|
184 | } else { | |
185 | m_grid->setVisible(axis()->isGridLineVisible()); |
|
185 | m_grid->setVisible(axis()->isGridLineVisible()); | |
186 | m_arrow->setVisible(axis()->isLineVisible()); |
|
186 | m_arrow->setVisible(axis()->isLineVisible()); | |
187 | m_shades->setVisible(axis()->shadesVisible()); |
|
187 | m_shades->setVisible(axis()->shadesVisible()); | |
188 | m_labels->setVisible(axis()->labelsVisible()); |
|
188 | m_labels->setVisible(axis()->labelsVisible()); | |
189 | m_title->setVisible(axis()->isTitleVisible()); |
|
189 | m_title->setVisible(axis()->isTitleVisible()); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | if (presenter()) presenter()->layout()->invalidate(); |
|
192 | if (presenter()) presenter()->layout()->invalidate(); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | void ChartAxisElement::handleRangeChanged(qreal min, qreal max) |
|
195 | void ChartAxisElement::handleRangeChanged(qreal min, qreal max) | |
196 | { |
|
196 | { | |
197 | Q_UNUSED(min); |
|
197 | Q_UNUSED(min); | |
198 | Q_UNUSED(max); |
|
198 | Q_UNUSED(max); | |
199 |
|
199 | |||
200 | if (!isEmpty()) { |
|
200 | if (!isEmpty()) { | |
201 | QVector<qreal> layout = calculateLayout(); |
|
201 | QVector<qreal> layout = calculateLayout(); | |
202 | updateLayout(layout); |
|
202 | updateLayout(layout); | |
203 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); |
|
203 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); | |
204 | QSizeF after = sizeHint(Qt::PreferredSize); |
|
204 | QSizeF after = sizeHint(Qt::PreferredSize); | |
205 |
|
205 | |||
206 | if (before != after) { |
|
206 | if (before != after) { | |
207 | QGraphicsLayoutItem::updateGeometry(); |
|
207 | QGraphicsLayoutItem::updateGeometry(); | |
208 | // We don't want to call invalidate on layout, since it will change minimum size of |
|
208 | // We don't want to call invalidate on layout, since it will change minimum size of | |
209 | // component, which we would like to avoid since it causes nasty flips when scrolling |
|
209 | // component, which we would like to avoid since it causes nasty flips when scrolling | |
210 | // or zooming, instead recalculate layout and use plotArea for extra space. |
|
210 | // or zooming, instead recalculate layout and use plotArea for extra space. | |
211 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); |
|
211 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); | |
212 | } |
|
212 | } | |
213 | } |
|
213 | } | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | bool ChartAxisElement::isEmpty() |
|
216 | bool ChartAxisElement::isEmpty() | |
217 | { |
|
217 | { | |
218 | return axisGeometry().isEmpty() |
|
218 | return axisGeometry().isEmpty() | |
219 | || gridGeometry().isEmpty() |
|
219 | || gridGeometry().isEmpty() | |
220 | || qFuzzyCompare(min(), max()); |
|
220 | || qFuzzyCompare(min(), max()); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | qreal ChartAxisElement::min() const |
|
223 | qreal ChartAxisElement::min() const | |
224 | { |
|
224 | { | |
225 | return m_axis->d_ptr->min(); |
|
225 | return m_axis->d_ptr->min(); | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | qreal ChartAxisElement::max() const |
|
228 | qreal ChartAxisElement::max() const | |
229 | { |
|
229 | { | |
230 | return m_axis->d_ptr->max(); |
|
230 | return m_axis->d_ptr->max(); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | static void appendFormattedLabel(const QString &capStr, const QByteArray &array, |
|
233 | static void appendFormattedLabel(const QString &capStr, const QByteArray &array, | |
234 | QStringList &labels, qreal value) |
|
234 | QStringList &labels, qreal value) | |
235 | { |
|
235 | { | |
236 | if (capStr.isEmpty()) { |
|
236 | if (capStr.isEmpty()) { | |
237 | labels << QString(); |
|
237 | labels << QString(); | |
238 | } else if (capStr.at(0) == QLatin1Char('d') |
|
238 | } else if (capStr.at(0) == QLatin1Char('d') | |
239 | || capStr.at(0) == QLatin1Char('i') |
|
239 | || capStr.at(0) == QLatin1Char('i') | |
240 | || capStr.at(0) == QLatin1Char('c')) { |
|
240 | || capStr.at(0) == QLatin1Char('c')) { | |
241 | labels << QString().sprintf(array, (qint64)value); |
|
241 | labels << QString().sprintf(array, (qint64)value); | |
242 | } else if (capStr.at(0) == QLatin1Char('u') |
|
242 | } else if (capStr.at(0) == QLatin1Char('u') | |
243 | || capStr.at(0) == QLatin1Char('o') |
|
243 | || capStr.at(0) == QLatin1Char('o') | |
244 | || capStr.at(0) == QLatin1Char('x') |
|
244 | || capStr.at(0) == QLatin1Char('x') | |
245 | || capStr.at(0) == QLatin1Char('X')) { |
|
245 | || capStr.at(0) == QLatin1Char('X')) { | |
246 | labels << QString().sprintf(array, (quint64)value); |
|
246 | labels << QString().sprintf(array, (quint64)value); | |
247 | } else if (capStr.at(0) == QLatin1Char('f') |
|
247 | } else if (capStr.at(0) == QLatin1Char('f') | |
248 | || capStr.at(0) == QLatin1Char('F') |
|
248 | || capStr.at(0) == QLatin1Char('F') | |
249 | || capStr.at(0) == QLatin1Char('e') |
|
249 | || capStr.at(0) == QLatin1Char('e') | |
250 | || capStr.at(0) == QLatin1Char('E') |
|
250 | || capStr.at(0) == QLatin1Char('E') | |
251 | || capStr.at(0) == QLatin1Char('g') |
|
251 | || capStr.at(0) == QLatin1Char('g') | |
252 | || capStr.at(0) == QLatin1Char('G')) { |
|
252 | || capStr.at(0) == QLatin1Char('G')) { | |
253 | labels << QString().sprintf(array, value); |
|
253 | labels << QString().sprintf(array, value); | |
254 | } else { |
|
254 | } else { | |
255 | labels << QString(); |
|
255 | labels << QString(); | |
256 | } |
|
256 | } | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, const QString &format) |
|
259 | QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, const QString &format) | |
260 | { |
|
260 | { | |
261 | QStringList labels; |
|
261 | QStringList labels; | |
262 |
|
262 | |||
263 | if (max <= min || ticks < 1) |
|
263 | if (max <= min || ticks < 1) | |
264 | return labels; |
|
264 | return labels; | |
265 |
|
265 | |||
266 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
266 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | |
267 | n++; |
|
267 | n++; | |
268 |
|
268 | |||
269 | if (format.isNull()) { |
|
269 | if (format.isNull()) { | |
270 | for (int i = 0; i < ticks; i++) { |
|
270 | for (int i = 0; i < ticks; i++) { | |
271 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
271 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
272 | labels << QString::number(value, 'f', n); |
|
272 | labels << QString::number(value, 'f', n); | |
273 | } |
|
273 | } | |
274 | } else { |
|
274 | } else { | |
275 | QByteArray array = format.toLatin1(); |
|
275 | QByteArray array = format.toLatin1(); | |
276 | QString capStr; |
|
276 | QString capStr; | |
277 | if (!labelFormatMatcher) |
|
277 | if (!labelFormatMatcher) | |
278 | labelFormatMatcher = new QRegExp(labelFormatMatchString); |
|
278 | labelFormatMatcher = new QRegExp(labelFormatMatchString); | |
279 | if (labelFormatMatcher->indexIn(format, 0) != -1) |
|
279 | if (labelFormatMatcher->indexIn(format, 0) != -1) | |
280 | capStr = labelFormatMatcher->cap(1); |
|
280 | capStr = labelFormatMatcher->cap(1); | |
281 | for (int i = 0; i < ticks; i++) { |
|
281 | for (int i = 0; i < ticks; i++) { | |
282 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
282 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
283 | appendFormattedLabel(capStr, array, labels, value); |
|
283 | appendFormattedLabel(capStr, array, labels, value); | |
284 | } |
|
284 | } | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | return labels; |
|
287 | return labels; | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format) |
|
290 | QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format) | |
291 | { |
|
291 | { | |
292 | QStringList labels; |
|
292 | QStringList labels; | |
293 |
|
293 | |||
294 | if (max <= min || ticks < 1) |
|
294 | if (max <= min || ticks < 1) | |
295 | return labels; |
|
295 | return labels; | |
296 |
|
296 | |||
297 | int n = 0; |
|
297 | int n = 0; | |
298 | if (ticks > 1) |
|
298 | if (ticks > 1) | |
299 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
299 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | |
300 | n++; |
|
300 | n++; | |
301 |
|
301 | |||
302 | int firstTick; |
|
302 | int firstTick; | |
303 | if (base > 1) |
|
303 | if (base > 1) | |
304 | firstTick = ceil(log10(min) / log10(base)); |
|
304 | firstTick = ceil(log10(min) / log10(base)); | |
305 | else |
|
305 | else | |
306 | firstTick = ceil(log10(max) / log10(base)); |
|
306 | firstTick = ceil(log10(max) / log10(base)); | |
307 |
|
307 | |||
308 | if (format.isNull()) { |
|
308 | if (format.isNull()) { | |
309 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
309 | for (int i = firstTick; i < ticks + firstTick; i++) { | |
310 | qreal value = qPow(base, i); |
|
310 | qreal value = qPow(base, i); | |
311 | labels << QString::number(value, 'f', n); |
|
311 | labels << QString::number(value, 'f', n); | |
312 | } |
|
312 | } | |
313 | } else { |
|
313 | } else { | |
314 | QByteArray array = format.toLatin1(); |
|
314 | QByteArray array = format.toLatin1(); | |
315 | QString capStr; |
|
315 | QString capStr; | |
316 | if (!labelFormatMatcher) |
|
316 | if (!labelFormatMatcher) | |
317 | labelFormatMatcher = new QRegExp(labelFormatMatchString); |
|
317 | labelFormatMatcher = new QRegExp(labelFormatMatchString); | |
318 | if (labelFormatMatcher->indexIn(format, 0) != -1) |
|
318 | if (labelFormatMatcher->indexIn(format, 0) != -1) | |
319 | capStr = labelFormatMatcher->cap(1); |
|
319 | capStr = labelFormatMatcher->cap(1); | |
320 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
320 | for (int i = firstTick; i < ticks + firstTick; i++) { | |
321 | qreal value = qPow(base, i); |
|
321 | qreal value = qPow(base, i); | |
322 | appendFormattedLabel(capStr, array, labels, value); |
|
322 | appendFormattedLabel(capStr, array, labels, value); | |
323 | } |
|
323 | } | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | return labels; |
|
326 | return labels; | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int ticks,const QString &format) |
|
329 | QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int ticks,const QString &format) | |
330 | { |
|
330 | { | |
331 | QStringList labels; |
|
331 | QStringList labels; | |
332 |
|
332 | |||
333 | if (max <= min || ticks < 1) |
|
333 | if (max <= min || ticks < 1) | |
334 | return labels; |
|
334 | return labels; | |
335 |
|
335 | |||
336 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); |
|
336 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); | |
337 | n++; |
|
337 | n++; | |
338 | for (int i = 0; i < ticks; i++) { |
|
338 | for (int i = 0; i < ticks; i++) { | |
339 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
339 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
340 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); |
|
340 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); | |
341 | } |
|
341 | } | |
342 | return labels; |
|
342 | return labels; | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | void ChartAxisElement::axisSelected() |
|
345 | void ChartAxisElement::axisSelected() | |
346 | { |
|
346 | { | |
347 | emit clicked(); |
|
347 | emit clicked(); | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | #include "moc_chartaxiselement_p.cpp" |
|
350 | #include "moc_chartaxiselement_p.cpp" | |
351 |
|
351 | |||
352 | QTCOMMERCIALCHART_END_NAMESPACE |
|
352 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,488 +1,472 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 | #include "chartpresenter_p.h" |
|
20 | #include "chartpresenter_p.h" | |
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "chartitem_p.h" |
|
22 | #include "chartitem_p.h" | |
23 | #include "qchart_p.h" |
|
23 | #include "qchart_p.h" | |
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 | #include "qabstractaxis_p.h" |
|
25 | #include "qabstractaxis_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "chartanimation_p.h" |
|
27 | #include "chartanimation_p.h" | |
28 | #include "qabstractseries_p.h" |
|
28 | #include "qabstractseries_p.h" | |
29 | #include "qareaseries.h" |
|
29 | #include "qareaseries.h" | |
30 | #include "chartaxiselement_p.h" |
|
30 | #include "chartaxiselement_p.h" | |
31 | #include "chartbackground_p.h" |
|
31 | #include "chartbackground_p.h" | |
32 | #include "cartesianchartlayout_p.h" |
|
32 | #include "cartesianchartlayout_p.h" | |
33 | #include "polarchartlayout_p.h" |
|
33 | #include "polarchartlayout_p.h" | |
34 | #include "charttitle_p.h" |
|
34 | #include "charttitle_p.h" | |
35 | #include <QTimer> |
|
35 | #include <QTimer> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | static QGraphicsTextItem *dummyTextItem = 0; |
|
|||
40 | static const char *truncateMatchString = "&#?[0-9a-zA-Z]*;$"; |
|
|||
41 | static QRegExp *truncateMatcher = 0; |
|
|||
42 |
|
||||
43 | class StaticDummyTextDeleter |
|
|||
44 | { |
|
|||
45 | public: |
|
|||
46 | StaticDummyTextDeleter() {} |
|
|||
47 | ~StaticDummyTextDeleter() |
|
|||
48 | { |
|
|||
49 | delete dummyTextItem; |
|
|||
50 | delete truncateMatcher; |
|
|||
51 | } |
|
|||
52 | }; |
|
|||
53 | StaticDummyTextDeleter staticDummyTextDeleter; |
|
|||
54 |
|
||||
55 | ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type) |
|
39 | ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type) | |
56 | : QObject(chart), |
|
40 | : QObject(chart), | |
57 | m_chart(chart), |
|
41 | m_chart(chart), | |
58 | m_options(QChart::NoAnimation), |
|
42 | m_options(QChart::NoAnimation), | |
59 | m_state(ShowState), |
|
43 | m_state(ShowState), | |
60 | m_background(0), |
|
44 | m_background(0), | |
61 | m_plotAreaBackground(0), |
|
45 | m_plotAreaBackground(0), | |
62 | m_title(0) |
|
46 | m_title(0) | |
63 | { |
|
47 | { | |
64 | if (type == QChart::ChartTypeCartesian) |
|
48 | if (type == QChart::ChartTypeCartesian) | |
65 | m_layout = new CartesianChartLayout(this); |
|
49 | m_layout = new CartesianChartLayout(this); | |
66 | else if (type == QChart::ChartTypePolar) |
|
50 | else if (type == QChart::ChartTypePolar) | |
67 | m_layout = new PolarChartLayout(this); |
|
51 | m_layout = new PolarChartLayout(this); | |
68 | Q_ASSERT(m_layout); |
|
52 | Q_ASSERT(m_layout); | |
69 | } |
|
53 | } | |
70 |
|
54 | |||
71 | ChartPresenter::~ChartPresenter() |
|
55 | ChartPresenter::~ChartPresenter() | |
72 | { |
|
56 | { | |
73 |
|
57 | |||
74 | } |
|
58 | } | |
75 |
|
59 | |||
76 | void ChartPresenter::setGeometry(const QRectF rect) |
|
60 | void ChartPresenter::setGeometry(const QRectF rect) | |
77 | { |
|
61 | { | |
78 | if (m_rect != rect) { |
|
62 | if (m_rect != rect) { | |
79 | m_rect = rect; |
|
63 | m_rect = rect; | |
80 | foreach (ChartItem *chart, m_chartItems) { |
|
64 | foreach (ChartItem *chart, m_chartItems) { | |
81 | chart->domain()->setSize(rect.size()); |
|
65 | chart->domain()->setSize(rect.size()); | |
82 | chart->setPos(rect.topLeft()); |
|
66 | chart->setPos(rect.topLeft()); | |
83 | } |
|
67 | } | |
84 | } |
|
68 | } | |
85 | } |
|
69 | } | |
86 |
|
70 | |||
87 | QRectF ChartPresenter::geometry() const |
|
71 | QRectF ChartPresenter::geometry() const | |
88 | { |
|
72 | { | |
89 | return m_rect; |
|
73 | return m_rect; | |
90 | } |
|
74 | } | |
91 |
|
75 | |||
92 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) |
|
76 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) | |
93 | { |
|
77 | { | |
94 | axis->d_ptr->initializeGraphics(rootItem()); |
|
78 | axis->d_ptr->initializeGraphics(rootItem()); | |
95 | axis->d_ptr->initializeAnimations(m_options); |
|
79 | axis->d_ptr->initializeAnimations(m_options); | |
96 | ChartAxisElement *item = axis->d_ptr->axisItem(); |
|
80 | ChartAxisElement *item = axis->d_ptr->axisItem(); | |
97 | item->setPresenter(this); |
|
81 | item->setPresenter(this); | |
98 | item->setThemeManager(m_chart->d_ptr->m_themeManager); |
|
82 | item->setThemeManager(m_chart->d_ptr->m_themeManager); | |
99 | m_axisItems<<item; |
|
83 | m_axisItems<<item; | |
100 | m_axes<<axis; |
|
84 | m_axes<<axis; | |
101 | m_layout->invalidate(); |
|
85 | m_layout->invalidate(); | |
102 | } |
|
86 | } | |
103 |
|
87 | |||
104 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) |
|
88 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) | |
105 | { |
|
89 | { | |
106 | ChartAxisElement *item = axis->d_ptr->m_item.take(); |
|
90 | ChartAxisElement *item = axis->d_ptr->m_item.take(); | |
107 | item->hide(); |
|
91 | item->hide(); | |
108 | item->disconnect(); |
|
92 | item->disconnect(); | |
109 | item->deleteLater(); |
|
93 | item->deleteLater(); | |
110 | m_axisItems.removeAll(item); |
|
94 | m_axisItems.removeAll(item); | |
111 | m_axes.removeAll(axis); |
|
95 | m_axes.removeAll(axis); | |
112 | m_layout->invalidate(); |
|
96 | m_layout->invalidate(); | |
113 | } |
|
97 | } | |
114 |
|
98 | |||
115 |
|
99 | |||
116 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) |
|
100 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) | |
117 | { |
|
101 | { | |
118 | series->d_ptr->initializeGraphics(rootItem()); |
|
102 | series->d_ptr->initializeGraphics(rootItem()); | |
119 | series->d_ptr->initializeAnimations(m_options); |
|
103 | series->d_ptr->initializeAnimations(m_options); | |
120 | ChartItem *chart = series->d_ptr->chartItem(); |
|
104 | ChartItem *chart = series->d_ptr->chartItem(); | |
121 | chart->setPresenter(this); |
|
105 | chart->setPresenter(this); | |
122 | chart->setThemeManager(m_chart->d_ptr->m_themeManager); |
|
106 | chart->setThemeManager(m_chart->d_ptr->m_themeManager); | |
123 | chart->domain()->setSize(m_rect.size()); |
|
107 | chart->domain()->setSize(m_rect.size()); | |
124 | chart->setPos(m_rect.topLeft()); |
|
108 | chart->setPos(m_rect.topLeft()); | |
125 | chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored |
|
109 | chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored | |
126 | m_chartItems<<chart; |
|
110 | m_chartItems<<chart; | |
127 | m_series<<series; |
|
111 | m_series<<series; | |
128 | m_layout->invalidate(); |
|
112 | m_layout->invalidate(); | |
129 | } |
|
113 | } | |
130 |
|
114 | |||
131 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) |
|
115 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) | |
132 | { |
|
116 | { | |
133 | ChartItem *chart = series->d_ptr->m_item.take(); |
|
117 | ChartItem *chart = series->d_ptr->m_item.take(); | |
134 | chart->hide(); |
|
118 | chart->hide(); | |
135 | chart->disconnect(); |
|
119 | chart->disconnect(); | |
136 | chart->deleteLater(); |
|
120 | chart->deleteLater(); | |
137 | m_chartItems.removeAll(chart); |
|
121 | m_chartItems.removeAll(chart); | |
138 | m_series.removeAll(series); |
|
122 | m_series.removeAll(series); | |
139 | m_layout->invalidate(); |
|
123 | m_layout->invalidate(); | |
140 | } |
|
124 | } | |
141 |
|
125 | |||
142 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
126 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
143 | { |
|
127 | { | |
144 | if (m_options != options) { |
|
128 | if (m_options != options) { | |
145 | m_options = options; |
|
129 | m_options = options; | |
146 |
|
130 | |||
147 | foreach(QAbstractSeries* series, m_series){ |
|
131 | foreach(QAbstractSeries* series, m_series){ | |
148 | series->d_ptr->initializeAnimations(m_options); |
|
132 | series->d_ptr->initializeAnimations(m_options); | |
149 | } |
|
133 | } | |
150 | foreach(QAbstractAxis* axis, m_axes){ |
|
134 | foreach(QAbstractAxis* axis, m_axes){ | |
151 | axis->d_ptr->initializeAnimations(m_options); |
|
135 | axis->d_ptr->initializeAnimations(m_options); | |
152 | } |
|
136 | } | |
153 | } |
|
137 | } | |
154 | } |
|
138 | } | |
155 |
|
139 | |||
156 | void ChartPresenter::setState(State state,QPointF point) |
|
140 | void ChartPresenter::setState(State state,QPointF point) | |
157 | { |
|
141 | { | |
158 | m_state=state; |
|
142 | m_state=state; | |
159 | m_statePoint=point; |
|
143 | m_statePoint=point; | |
160 | } |
|
144 | } | |
161 |
|
145 | |||
162 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
146 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
163 | { |
|
147 | { | |
164 | return m_options; |
|
148 | return m_options; | |
165 | } |
|
149 | } | |
166 |
|
150 | |||
167 | void ChartPresenter::createBackgroundItem() |
|
151 | void ChartPresenter::createBackgroundItem() | |
168 | { |
|
152 | { | |
169 | if (!m_background) { |
|
153 | if (!m_background) { | |
170 | m_background = new ChartBackground(rootItem()); |
|
154 | m_background = new ChartBackground(rootItem()); | |
171 | m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default |
|
155 | m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default | |
172 | m_background->setBrush(QChartPrivate::defaultBrush()); |
|
156 | m_background->setBrush(QChartPrivate::defaultBrush()); | |
173 | m_background->setZValue(ChartPresenter::BackgroundZValue); |
|
157 | m_background->setZValue(ChartPresenter::BackgroundZValue); | |
174 | } |
|
158 | } | |
175 | } |
|
159 | } | |
176 |
|
160 | |||
177 | void ChartPresenter::createPlotAreaBackgroundItem() |
|
161 | void ChartPresenter::createPlotAreaBackgroundItem() | |
178 | { |
|
162 | { | |
179 | if (!m_plotAreaBackground) { |
|
163 | if (!m_plotAreaBackground) { | |
180 | if (m_chart->chartType() == QChart::ChartTypeCartesian) |
|
164 | if (m_chart->chartType() == QChart::ChartTypeCartesian) | |
181 | m_plotAreaBackground = new QGraphicsRectItem(rootItem()); |
|
165 | m_plotAreaBackground = new QGraphicsRectItem(rootItem()); | |
182 | else |
|
166 | else | |
183 | m_plotAreaBackground = new QGraphicsEllipseItem(rootItem()); |
|
167 | m_plotAreaBackground = new QGraphicsEllipseItem(rootItem()); | |
184 | // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes |
|
168 | // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes | |
185 | // antialising artifacts with axis lines for some reason. |
|
169 | // antialising artifacts with axis lines for some reason. | |
186 | m_plotAreaBackground->setPen(QPen(Qt::transparent)); |
|
170 | m_plotAreaBackground->setPen(QPen(Qt::transparent)); | |
187 | m_plotAreaBackground->setBrush(Qt::NoBrush); |
|
171 | m_plotAreaBackground->setBrush(Qt::NoBrush); | |
188 | m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue); |
|
172 | m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue); | |
189 | m_plotAreaBackground->setVisible(false); |
|
173 | m_plotAreaBackground->setVisible(false); | |
190 | } |
|
174 | } | |
191 | } |
|
175 | } | |
192 |
|
176 | |||
193 | void ChartPresenter::createTitleItem() |
|
177 | void ChartPresenter::createTitleItem() | |
194 | { |
|
178 | { | |
195 | if (!m_title) { |
|
179 | if (!m_title) { | |
196 | m_title = new ChartTitle(rootItem()); |
|
180 | m_title = new ChartTitle(rootItem()); | |
197 | m_title->setZValue(ChartPresenter::BackgroundZValue); |
|
181 | m_title->setZValue(ChartPresenter::BackgroundZValue); | |
198 | } |
|
182 | } | |
199 | } |
|
183 | } | |
200 |
|
184 | |||
201 |
|
185 | |||
202 | void ChartPresenter::handleAnimationFinished() |
|
186 | void ChartPresenter::handleAnimationFinished() | |
203 | { |
|
187 | { | |
204 | m_animations.removeAll(qobject_cast<ChartAnimation *>(sender())); |
|
188 | m_animations.removeAll(qobject_cast<ChartAnimation *>(sender())); | |
205 | if (m_animations.empty()) |
|
189 | if (m_animations.empty()) | |
206 | emit animationsFinished(); |
|
190 | emit animationsFinished(); | |
207 | } |
|
191 | } | |
208 |
|
192 | |||
209 | void ChartPresenter::startAnimation(ChartAnimation *animation) |
|
193 | void ChartPresenter::startAnimation(ChartAnimation *animation) | |
210 | { |
|
194 | { | |
211 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); |
|
195 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); | |
212 | QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection); |
|
196 | QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection); | |
213 | if (!m_animations.isEmpty()) |
|
197 | if (!m_animations.isEmpty()) | |
214 | m_animations.append(animation); |
|
198 | m_animations.append(animation); | |
215 | QTimer::singleShot(0, animation, SLOT(start())); |
|
199 | QTimer::singleShot(0, animation, SLOT(start())); | |
216 | } |
|
200 | } | |
217 |
|
201 | |||
218 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) |
|
202 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) | |
219 | { |
|
203 | { | |
220 | createBackgroundItem(); |
|
204 | createBackgroundItem(); | |
221 | m_background->setBrush(brush); |
|
205 | m_background->setBrush(brush); | |
222 | m_layout->invalidate(); |
|
206 | m_layout->invalidate(); | |
223 | } |
|
207 | } | |
224 |
|
208 | |||
225 | QBrush ChartPresenter::backgroundBrush() const |
|
209 | QBrush ChartPresenter::backgroundBrush() const | |
226 | { |
|
210 | { | |
227 | if (!m_background) |
|
211 | if (!m_background) | |
228 | return QBrush(); |
|
212 | return QBrush(); | |
229 | return m_background->brush(); |
|
213 | return m_background->brush(); | |
230 | } |
|
214 | } | |
231 |
|
215 | |||
232 | void ChartPresenter::setBackgroundPen(const QPen &pen) |
|
216 | void ChartPresenter::setBackgroundPen(const QPen &pen) | |
233 | { |
|
217 | { | |
234 | createBackgroundItem(); |
|
218 | createBackgroundItem(); | |
235 | m_background->setPen(pen); |
|
219 | m_background->setPen(pen); | |
236 | m_layout->invalidate(); |
|
220 | m_layout->invalidate(); | |
237 | } |
|
221 | } | |
238 |
|
222 | |||
239 | QPen ChartPresenter::backgroundPen() const |
|
223 | QPen ChartPresenter::backgroundPen() const | |
240 | { |
|
224 | { | |
241 | if (!m_background) |
|
225 | if (!m_background) | |
242 | return QPen(); |
|
226 | return QPen(); | |
243 | return m_background->pen(); |
|
227 | return m_background->pen(); | |
244 | } |
|
228 | } | |
245 |
|
229 | |||
246 | void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush) |
|
230 | void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush) | |
247 | { |
|
231 | { | |
248 | createPlotAreaBackgroundItem(); |
|
232 | createPlotAreaBackgroundItem(); | |
249 | m_plotAreaBackground->setBrush(brush); |
|
233 | m_plotAreaBackground->setBrush(brush); | |
250 | m_layout->invalidate(); |
|
234 | m_layout->invalidate(); | |
251 | } |
|
235 | } | |
252 |
|
236 | |||
253 | QBrush ChartPresenter::plotAreaBackgroundBrush() const |
|
237 | QBrush ChartPresenter::plotAreaBackgroundBrush() const | |
254 | { |
|
238 | { | |
255 | if (!m_plotAreaBackground) |
|
239 | if (!m_plotAreaBackground) | |
256 | return QBrush(); |
|
240 | return QBrush(); | |
257 | return m_plotAreaBackground->brush(); |
|
241 | return m_plotAreaBackground->brush(); | |
258 | } |
|
242 | } | |
259 |
|
243 | |||
260 | void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen) |
|
244 | void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen) | |
261 | { |
|
245 | { | |
262 | createPlotAreaBackgroundItem(); |
|
246 | createPlotAreaBackgroundItem(); | |
263 | m_plotAreaBackground->setPen(pen); |
|
247 | m_plotAreaBackground->setPen(pen); | |
264 | m_layout->invalidate(); |
|
248 | m_layout->invalidate(); | |
265 | } |
|
249 | } | |
266 |
|
250 | |||
267 | QPen ChartPresenter::plotAreaBackgroundPen() const |
|
251 | QPen ChartPresenter::plotAreaBackgroundPen() const | |
268 | { |
|
252 | { | |
269 | if (!m_plotAreaBackground) |
|
253 | if (!m_plotAreaBackground) | |
270 | return QPen(); |
|
254 | return QPen(); | |
271 | return m_plotAreaBackground->pen(); |
|
255 | return m_plotAreaBackground->pen(); | |
272 | } |
|
256 | } | |
273 |
|
257 | |||
274 | void ChartPresenter::setTitle(const QString &title) |
|
258 | void ChartPresenter::setTitle(const QString &title) | |
275 | { |
|
259 | { | |
276 | createTitleItem(); |
|
260 | createTitleItem(); | |
277 | m_title->setText(title); |
|
261 | m_title->setText(title); | |
278 | m_layout->invalidate(); |
|
262 | m_layout->invalidate(); | |
279 | } |
|
263 | } | |
280 |
|
264 | |||
281 | QString ChartPresenter::title() const |
|
265 | QString ChartPresenter::title() const | |
282 | { |
|
266 | { | |
283 | if (!m_title) |
|
267 | if (!m_title) | |
284 | return QString(); |
|
268 | return QString(); | |
285 | return m_title->text(); |
|
269 | return m_title->text(); | |
286 | } |
|
270 | } | |
287 |
|
271 | |||
288 | void ChartPresenter::setTitleFont(const QFont &font) |
|
272 | void ChartPresenter::setTitleFont(const QFont &font) | |
289 | { |
|
273 | { | |
290 | createTitleItem(); |
|
274 | createTitleItem(); | |
291 | m_title->setFont(font); |
|
275 | m_title->setFont(font); | |
292 | m_layout->invalidate(); |
|
276 | m_layout->invalidate(); | |
293 | } |
|
277 | } | |
294 |
|
278 | |||
295 | QFont ChartPresenter::titleFont() const |
|
279 | QFont ChartPresenter::titleFont() const | |
296 | { |
|
280 | { | |
297 | if (!m_title) |
|
281 | if (!m_title) | |
298 | return QFont(); |
|
282 | return QFont(); | |
299 | return m_title->font(); |
|
283 | return m_title->font(); | |
300 | } |
|
284 | } | |
301 |
|
285 | |||
302 | void ChartPresenter::setTitleBrush(const QBrush &brush) |
|
286 | void ChartPresenter::setTitleBrush(const QBrush &brush) | |
303 | { |
|
287 | { | |
304 | createTitleItem(); |
|
288 | createTitleItem(); | |
305 | m_title->setDefaultTextColor(brush.color()); |
|
289 | m_title->setDefaultTextColor(brush.color()); | |
306 | m_layout->invalidate(); |
|
290 | m_layout->invalidate(); | |
307 | } |
|
291 | } | |
308 |
|
292 | |||
309 | QBrush ChartPresenter::titleBrush() const |
|
293 | QBrush ChartPresenter::titleBrush() const | |
310 | { |
|
294 | { | |
311 | if (!m_title) |
|
295 | if (!m_title) | |
312 | return QBrush(); |
|
296 | return QBrush(); | |
313 | return QBrush(m_title->defaultTextColor()); |
|
297 | return QBrush(m_title->defaultTextColor()); | |
314 | } |
|
298 | } | |
315 |
|
299 | |||
316 | void ChartPresenter::setBackgroundVisible(bool visible) |
|
300 | void ChartPresenter::setBackgroundVisible(bool visible) | |
317 | { |
|
301 | { | |
318 | createBackgroundItem(); |
|
302 | createBackgroundItem(); | |
319 | m_background->setVisible(visible); |
|
303 | m_background->setVisible(visible); | |
320 | } |
|
304 | } | |
321 |
|
305 | |||
322 |
|
306 | |||
323 | bool ChartPresenter::isBackgroundVisible() const |
|
307 | bool ChartPresenter::isBackgroundVisible() const | |
324 | { |
|
308 | { | |
325 | if (!m_background) |
|
309 | if (!m_background) | |
326 | return false; |
|
310 | return false; | |
327 | return m_background->isVisible(); |
|
311 | return m_background->isVisible(); | |
328 | } |
|
312 | } | |
329 |
|
313 | |||
330 | void ChartPresenter::setPlotAreaBackgroundVisible(bool visible) |
|
314 | void ChartPresenter::setPlotAreaBackgroundVisible(bool visible) | |
331 | { |
|
315 | { | |
332 | createPlotAreaBackgroundItem(); |
|
316 | createPlotAreaBackgroundItem(); | |
333 | m_plotAreaBackground->setVisible(visible); |
|
317 | m_plotAreaBackground->setVisible(visible); | |
334 | } |
|
318 | } | |
335 |
|
319 | |||
336 | bool ChartPresenter::isPlotAreaBackgroundVisible() const |
|
320 | bool ChartPresenter::isPlotAreaBackgroundVisible() const | |
337 | { |
|
321 | { | |
338 | if (!m_plotAreaBackground) |
|
322 | if (!m_plotAreaBackground) | |
339 | return false; |
|
323 | return false; | |
340 | return m_plotAreaBackground->isVisible(); |
|
324 | return m_plotAreaBackground->isVisible(); | |
341 | } |
|
325 | } | |
342 |
|
326 | |||
343 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) |
|
327 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) | |
344 | { |
|
328 | { | |
345 | createBackgroundItem(); |
|
329 | createBackgroundItem(); | |
346 | m_background->setDropShadowEnabled(enabled); |
|
330 | m_background->setDropShadowEnabled(enabled); | |
347 | } |
|
331 | } | |
348 |
|
332 | |||
349 | bool ChartPresenter::isBackgroundDropShadowEnabled() const |
|
333 | bool ChartPresenter::isBackgroundDropShadowEnabled() const | |
350 | { |
|
334 | { | |
351 | if (!m_background) |
|
335 | if (!m_background) | |
352 | return false; |
|
336 | return false; | |
353 | return m_background->isDropShadowEnabled(); |
|
337 | return m_background->isDropShadowEnabled(); | |
354 | } |
|
338 | } | |
355 |
|
339 | |||
356 |
|
340 | |||
357 | AbstractChartLayout *ChartPresenter::layout() |
|
341 | AbstractChartLayout *ChartPresenter::layout() | |
358 | { |
|
342 | { | |
359 | return m_layout; |
|
343 | return m_layout; | |
360 | } |
|
344 | } | |
361 |
|
345 | |||
362 | QLegend *ChartPresenter::legend() |
|
346 | QLegend *ChartPresenter::legend() | |
363 | { |
|
347 | { | |
364 | return m_chart->legend(); |
|
348 | return m_chart->legend(); | |
365 | } |
|
349 | } | |
366 |
|
350 | |||
367 | void ChartPresenter::setVisible(bool visible) |
|
351 | void ChartPresenter::setVisible(bool visible) | |
368 | { |
|
352 | { | |
369 | m_chart->setVisible(visible); |
|
353 | m_chart->setVisible(visible); | |
370 | } |
|
354 | } | |
371 |
|
355 | |||
372 | ChartBackground *ChartPresenter::backgroundElement() |
|
356 | ChartBackground *ChartPresenter::backgroundElement() | |
373 | { |
|
357 | { | |
374 | return m_background; |
|
358 | return m_background; | |
375 | } |
|
359 | } | |
376 |
|
360 | |||
377 | QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement() |
|
361 | QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement() | |
378 | { |
|
362 | { | |
379 | return m_plotAreaBackground; |
|
363 | return m_plotAreaBackground; | |
380 | } |
|
364 | } | |
381 |
|
365 | |||
382 | QList<ChartAxisElement *> ChartPresenter::axisItems() const |
|
366 | QList<ChartAxisElement *> ChartPresenter::axisItems() const | |
383 | { |
|
367 | { | |
384 | return m_axisItems; |
|
368 | return m_axisItems; | |
385 | } |
|
369 | } | |
386 |
|
370 | |||
387 | QList<ChartItem *> ChartPresenter::chartItems() const |
|
371 | QList<ChartItem *> ChartPresenter::chartItems() const | |
388 | { |
|
372 | { | |
389 | return m_chartItems; |
|
373 | return m_chartItems; | |
390 | } |
|
374 | } | |
391 |
|
375 | |||
392 | ChartTitle *ChartPresenter::titleElement() |
|
376 | ChartTitle *ChartPresenter::titleElement() | |
393 | { |
|
377 | { | |
394 | return m_title; |
|
378 | return m_title; | |
395 | } |
|
379 | } | |
396 |
|
380 | |||
397 | QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle) |
|
381 | QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle) | |
398 | { |
|
382 | { | |
399 | if (!dummyTextItem) |
|
383 | static QGraphicsTextItem dummyTextItem; | |
400 | dummyTextItem = new QGraphicsTextItem; |
|
|||
401 |
|
384 | |||
402 |
dummyTextItem |
|
385 | dummyTextItem.setFont(font); | |
403 |
dummyTextItem |
|
386 | dummyTextItem.setHtml(text); | |
404 |
QRectF boundingRect = dummyTextItem |
|
387 | QRectF boundingRect = dummyTextItem.boundingRect(); | |
405 |
|
388 | |||
406 | // Take rotation into account |
|
389 | // Take rotation into account | |
407 | if (angle) { |
|
390 | if (angle) { | |
408 | QTransform transform; |
|
391 | QTransform transform; | |
409 | transform.rotate(angle); |
|
392 | transform.rotate(angle); | |
410 | boundingRect = transform.mapRect(boundingRect); |
|
393 | boundingRect = transform.mapRect(boundingRect); | |
411 | } |
|
394 | } | |
412 |
|
395 | |||
413 | return boundingRect; |
|
396 | return boundingRect; | |
414 | } |
|
397 | } | |
415 |
|
398 | |||
416 | // boundingRect parameter returns the rotated bounding rect of the text |
|
399 | // boundingRect parameter returns the rotated bounding rect of the text | |
417 | QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qreal angle, |
|
400 | QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qreal angle, | |
418 | qreal maxSize, Qt::Orientation constraintOrientation, |
|
401 | qreal maxSize, Qt::Orientation constraintOrientation, | |
419 | QRectF &boundingRect) |
|
402 | QRectF &boundingRect) | |
420 | { |
|
403 | { | |
421 | QString truncatedString(text); |
|
404 | QString truncatedString(text); | |
422 | boundingRect = textBoundingRect(font, truncatedString, angle); |
|
405 | boundingRect = textBoundingRect(font, truncatedString, angle); | |
423 | qreal checkDimension = ((constraintOrientation == Qt::Horizontal) |
|
406 | qreal checkDimension = ((constraintOrientation == Qt::Horizontal) | |
424 | ? boundingRect.width() : boundingRect.height()); |
|
407 | ? boundingRect.width() : boundingRect.height()); | |
425 | if (checkDimension > maxSize) { |
|
408 | if (checkDimension > maxSize) { | |
426 | // It can be assumed that almost any amount of string manipulation is faster |
|
409 | // It can be assumed that almost any amount of string manipulation is faster | |
427 | // than calculating one bounding rectangle, so first prepare a list of truncated strings |
|
410 | // than calculating one bounding rectangle, so first prepare a list of truncated strings | |
428 | // to try. |
|
411 | // to try. | |
429 | if (!truncateMatcher) |
|
412 | static const char *truncateMatchString = "&#?[0-9a-zA-Z]*;$"; | |
430 |
|
|
413 | static QRegExp truncateMatcher(truncateMatchString); | |
|
414 | ||||
431 | QVector<QString> testStrings(text.length()); |
|
415 | QVector<QString> testStrings(text.length()); | |
432 | int count(0); |
|
416 | int count(0); | |
433 | static QLatin1Char closeTag('>'); |
|
417 | static QLatin1Char closeTag('>'); | |
434 | static QLatin1Char openTag('<'); |
|
418 | static QLatin1Char openTag('<'); | |
435 | static QLatin1Char semiColon(';'); |
|
419 | static QLatin1Char semiColon(';'); | |
436 | static QLatin1String ellipsis("..."); |
|
420 | static QLatin1String ellipsis("..."); | |
437 | while (truncatedString.length() > 1) { |
|
421 | while (truncatedString.length() > 1) { | |
438 | int chopIndex(-1); |
|
422 | int chopIndex(-1); | |
439 | int chopCount(1); |
|
423 | int chopCount(1); | |
440 | QChar lastChar(truncatedString.at(truncatedString.length() - 1)); |
|
424 | QChar lastChar(truncatedString.at(truncatedString.length() - 1)); | |
441 |
|
425 | |||
442 | if (lastChar == closeTag) |
|
426 | if (lastChar == closeTag) | |
443 | chopIndex = truncatedString.lastIndexOf(openTag); |
|
427 | chopIndex = truncatedString.lastIndexOf(openTag); | |
444 | else if (lastChar == semiColon) |
|
428 | else if (lastChar == semiColon) | |
445 |
chopIndex = truncateMatcher |
|
429 | chopIndex = truncateMatcher.indexIn(truncatedString, 0); | |
446 |
|
430 | |||
447 | if (chopIndex != -1) |
|
431 | if (chopIndex != -1) | |
448 | chopCount = truncatedString.length() - chopIndex; |
|
432 | chopCount = truncatedString.length() - chopIndex; | |
449 | truncatedString.chop(chopCount); |
|
433 | truncatedString.chop(chopCount); | |
450 | testStrings[count] = truncatedString + ellipsis; |
|
434 | testStrings[count] = truncatedString + ellipsis; | |
451 | count++; |
|
435 | count++; | |
452 | } |
|
436 | } | |
453 |
|
437 | |||
454 | // Binary search for best fit |
|
438 | // Binary search for best fit | |
455 | int minIndex(0); |
|
439 | int minIndex(0); | |
456 | int maxIndex(count - 1); |
|
440 | int maxIndex(count - 1); | |
457 | int bestIndex(count); |
|
441 | int bestIndex(count); | |
458 | QRectF checkRect; |
|
442 | QRectF checkRect; | |
459 | while (maxIndex >= minIndex) { |
|
443 | while (maxIndex >= minIndex) { | |
460 | int mid = (maxIndex + minIndex) / 2; |
|
444 | int mid = (maxIndex + minIndex) / 2; | |
461 | checkRect = textBoundingRect(font, testStrings.at(mid), angle); |
|
445 | checkRect = textBoundingRect(font, testStrings.at(mid), angle); | |
462 | checkDimension = ((constraintOrientation == Qt::Horizontal) |
|
446 | checkDimension = ((constraintOrientation == Qt::Horizontal) | |
463 | ? checkRect.width() : checkRect.height()); |
|
447 | ? checkRect.width() : checkRect.height()); | |
464 | if (checkDimension > maxSize) { |
|
448 | if (checkDimension > maxSize) { | |
465 | // Checked index too large, all under this are also too large |
|
449 | // Checked index too large, all under this are also too large | |
466 | minIndex = mid + 1; |
|
450 | minIndex = mid + 1; | |
467 | } else { |
|
451 | } else { | |
468 | // Checked index fits, all over this also fit |
|
452 | // Checked index fits, all over this also fit | |
469 | maxIndex = mid - 1; |
|
453 | maxIndex = mid - 1; | |
470 | bestIndex = mid; |
|
454 | bestIndex = mid; | |
471 | boundingRect = checkRect; |
|
455 | boundingRect = checkRect; | |
472 | } |
|
456 | } | |
473 | } |
|
457 | } | |
474 | // Default to "..." if nothing fits |
|
458 | // Default to "..." if nothing fits | |
475 | if (bestIndex == count) { |
|
459 | if (bestIndex == count) { | |
476 | boundingRect = textBoundingRect(font, ellipsis, angle); |
|
460 | boundingRect = textBoundingRect(font, ellipsis, angle); | |
477 | truncatedString = ellipsis; |
|
461 | truncatedString = ellipsis; | |
478 | } else { |
|
462 | } else { | |
479 | truncatedString = testStrings.at(bestIndex); |
|
463 | truncatedString = testStrings.at(bestIndex); | |
480 | } |
|
464 | } | |
481 | } |
|
465 | } | |
482 |
|
466 | |||
483 | return truncatedString; |
|
467 | return truncatedString; | |
484 | } |
|
468 | } | |
485 |
|
469 | |||
486 | #include "moc_chartpresenter_p.cpp" |
|
470 | #include "moc_chartpresenter_p.cpp" | |
487 |
|
471 | |||
488 | QTCOMMERCIALCHART_END_NAMESPACE |
|
472 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,784 +1,781 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "legendscroller_p.h" |
|
23 | #include "legendscroller_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
25 | #include "chartbackground_p.h" |
|
25 | #include "chartbackground_p.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include "abstractchartlayout_p.h" |
|
27 | #include "abstractchartlayout_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "chartdataset_p.h" |
|
30 | #include "chartdataset_p.h" | |
31 | #include <QGraphicsScene> |
|
31 | #include <QGraphicsScene> | |
32 | #include <QGraphicsSceneResizeEvent> |
|
32 | #include <QGraphicsSceneResizeEvent> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \enum QChart::ChartTheme |
|
37 | \enum QChart::ChartTheme | |
38 |
|
38 | |||
39 | This enum describes the theme used by the chart. |
|
39 | This enum describes the theme used by the chart. | |
40 |
|
40 | |||
41 | \value ChartThemeLight The default theme |
|
41 | \value ChartThemeLight The default theme | |
42 | \value ChartThemeBlueCerulean |
|
42 | \value ChartThemeBlueCerulean | |
43 | \value ChartThemeDark |
|
43 | \value ChartThemeDark | |
44 | \value ChartThemeBrownSand |
|
44 | \value ChartThemeBrownSand | |
45 | \value ChartThemeBlueNcs |
|
45 | \value ChartThemeBlueNcs | |
46 | \value ChartThemeHighContrast |
|
46 | \value ChartThemeHighContrast | |
47 | \value ChartThemeBlueIcy |
|
47 | \value ChartThemeBlueIcy | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \enum QChart::AnimationOption |
|
51 | \enum QChart::AnimationOption | |
52 |
|
52 | |||
53 | For enabling/disabling animations. Defaults to NoAnimation. |
|
53 | For enabling/disabling animations. Defaults to NoAnimation. | |
54 |
|
54 | |||
55 | \value NoAnimation |
|
55 | \value NoAnimation | |
56 | \value GridAxisAnimations |
|
56 | \value GridAxisAnimations | |
57 | \value SeriesAnimations |
|
57 | \value SeriesAnimations | |
58 | \value AllAnimations |
|
58 | \value AllAnimations | |
59 | */ |
|
59 | */ | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | \enum QChart::ChartType |
|
62 | \enum QChart::ChartType | |
63 |
|
63 | |||
64 | This enum describes the chart type. |
|
64 | This enum describes the chart type. | |
65 |
|
65 | |||
66 | \value ChartTypeUndefined |
|
66 | \value ChartTypeUndefined | |
67 | \value ChartTypeCartesian |
|
67 | \value ChartTypeCartesian | |
68 | \value ChartTypePolar |
|
68 | \value ChartTypePolar | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \class QChart |
|
72 | \class QChart | |
73 | \brief QtCommercial chart API. |
|
73 | \brief QtCommercial chart API. | |
74 |
|
74 | |||
75 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
75 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
76 | representation of different types of series and other chart related objects like legend and |
|
76 | representation of different types of series and other chart related objects like legend and | |
77 | axes. If you simply want to show a chart in a layout, you can use the |
|
77 | axes. If you simply want to show a chart in a layout, you can use the | |
78 | convenience class QChartView instead of QChart. |
|
78 | convenience class QChartView instead of QChart. | |
79 | \sa QChartView, QPolarChart |
|
79 | \sa QChartView, QPolarChart | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | \property QChart::animationOptions |
|
83 | \property QChart::animationOptions | |
84 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
84 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QChart::backgroundVisible |
|
88 | \property QChart::backgroundVisible | |
89 | Specifies whether the chart background is visible or not. |
|
89 | Specifies whether the chart background is visible or not. | |
90 | \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible |
|
90 | \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible | |
91 | */ |
|
91 | */ | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | \property QChart::dropShadowEnabled |
|
94 | \property QChart::dropShadowEnabled | |
95 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
95 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop | |
96 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
96 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \property QChart::minimumMargins |
|
100 | \property QChart::minimumMargins | |
101 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
101 | Minimum margins between the plot area (axes) and the edge of the chart widget. | |
102 | This property is deprecated; use margins property instead. |
|
102 | This property is deprecated; use margins property instead. | |
103 |
|
103 | |||
104 | \sa margins |
|
104 | \sa margins | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \property QChart::margins |
|
108 | \property QChart::margins | |
109 | Margins between the plot area (axes) and the edge of the chart widget. |
|
109 | Margins between the plot area (axes) and the edge of the chart widget. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \property QChart::theme |
|
113 | \property QChart::theme | |
114 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
114 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, | |
115 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few |
|
115 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few | |
116 | different themes. |
|
116 | different themes. | |
117 | \note Changing the theme will overwrite all customizations previously applied to the series. |
|
117 | \note Changing the theme will overwrite all customizations previously applied to the series. | |
118 | */ |
|
118 | */ | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | \property QChart::title |
|
121 | \property QChart::title | |
122 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting. |
|
122 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting. | |
123 | */ |
|
123 | */ | |
124 |
|
124 | |||
125 | /*! |
|
125 | /*! | |
126 | \property QChart::chartType |
|
126 | \property QChart::chartType | |
127 | Chart type indicates if the chart is a cartesian chart or a polar chart. |
|
127 | Chart type indicates if the chart is a cartesian chart or a polar chart. | |
128 | This property is set internally and it is read only. |
|
128 | This property is set internally and it is read only. | |
129 | \sa QPolarChart |
|
129 | \sa QPolarChart | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \property QChart::plotAreaBackgroundVisible |
|
133 | \property QChart::plotAreaBackgroundVisible | |
134 | Specifies whether the chart plot area background is visible or not. |
|
134 | Specifies whether the chart plot area background is visible or not. | |
135 | \note By default the plot area background is not visible and the plot area uses |
|
135 | \note By default the plot area background is not visible and the plot area uses | |
136 | the general chart background. |
|
136 | the general chart background. | |
137 | \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible |
|
137 | \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible | |
138 | */ |
|
138 | */ | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | \internal |
|
141 | \internal | |
142 | Constructs a chart object of \a type which is a child of a \a parent. |
|
142 | Constructs a chart object of \a type which is a child of a \a parent. | |
143 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
143 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
144 | This constructor is called only by subclasses. |
|
144 | This constructor is called only by subclasses. | |
145 | */ |
|
145 | */ | |
146 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
146 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
147 | : QGraphicsWidget(parent, wFlags), |
|
147 | : QGraphicsWidget(parent, wFlags), | |
148 | d_ptr(new QChartPrivate(this, type)) |
|
148 | d_ptr(new QChartPrivate(this, type)) | |
149 | { |
|
149 | { | |
150 | d_ptr->init(); |
|
150 | d_ptr->init(); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | Constructs a chart object which is a child of a \a parent. |
|
154 | Constructs a chart object which is a child of a \a parent. | |
155 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
155 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
156 | */ |
|
156 | */ | |
157 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
157 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
158 | : QGraphicsWidget(parent, wFlags), |
|
158 | : QGraphicsWidget(parent, wFlags), | |
159 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) |
|
159 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) | |
160 | { |
|
160 | { | |
161 | d_ptr->init(); |
|
161 | d_ptr->init(); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | Destroys the chart object and its children, like series and axis objects added to it. |
|
165 | Destroys the chart object and its children, like series and axis objects added to it. | |
166 | */ |
|
166 | */ | |
167 | QChart::~QChart() |
|
167 | QChart::~QChart() | |
168 | { |
|
168 | { | |
169 | //start by deleting dataset, it will remove all series and axes |
|
169 | //start by deleting dataset, it will remove all series and axes | |
170 | delete d_ptr->m_dataset; |
|
170 | delete d_ptr->m_dataset; | |
171 | d_ptr->m_dataset = 0; |
|
171 | d_ptr->m_dataset = 0; | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | Adds the \a series onto the chart and takes the ownership of it. |
|
175 | Adds the \a series onto the chart and takes the ownership of it. | |
176 |
|
176 | |||
177 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart |
|
177 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart | |
178 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to |
|
178 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to | |
179 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges |
|
179 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges | |
180 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other |
|
180 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other | |
181 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after |
|
181 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after | |
182 | a series has been added or explicitly attach axes for the series. |
|
182 | a series has been added or explicitly attach axes for the series. | |
183 |
|
183 | |||
184 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
184 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
185 | */ |
|
185 | */ | |
186 | void QChart::addSeries(QAbstractSeries *series) |
|
186 | void QChart::addSeries(QAbstractSeries *series) | |
187 | { |
|
187 | { | |
188 | Q_ASSERT(series); |
|
188 | Q_ASSERT(series); | |
189 | d_ptr->m_dataset->addSeries(series); |
|
189 | d_ptr->m_dataset->addSeries(series); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | Removes the \a series from the chart. |
|
193 | Removes the \a series from the chart. | |
194 | The chart releases its ownership of the specified \a series object. |
|
194 | The chart releases its ownership of the specified \a series object. | |
195 |
|
195 | |||
196 | \sa addSeries(), removeAllSeries() |
|
196 | \sa addSeries(), removeAllSeries() | |
197 | */ |
|
197 | */ | |
198 | void QChart::removeSeries(QAbstractSeries *series) |
|
198 | void QChart::removeSeries(QAbstractSeries *series) | |
199 | { |
|
199 | { | |
200 | Q_ASSERT(series); |
|
200 | Q_ASSERT(series); | |
201 | d_ptr->m_dataset->removeSeries(series); |
|
201 | d_ptr->m_dataset->removeSeries(series); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | /*! |
|
204 | /*! | |
205 | Removes and deletes all series objects that have been added to the chart. |
|
205 | Removes and deletes all series objects that have been added to the chart. | |
206 |
|
206 | |||
207 | \sa addSeries(), removeSeries() |
|
207 | \sa addSeries(), removeSeries() | |
208 | */ |
|
208 | */ | |
209 | void QChart::removeAllSeries() |
|
209 | void QChart::removeAllSeries() | |
210 | { |
|
210 | { | |
211 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
211 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ | |
212 | removeSeries(s); |
|
212 | removeSeries(s); | |
213 | delete s; |
|
213 | delete s; | |
214 | } |
|
214 | } | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | /*! |
|
217 | /*! | |
218 | Sets the \a brush that is used for painting the background of the chart area. |
|
218 | Sets the \a brush that is used for painting the background of the chart area. | |
219 | */ |
|
219 | */ | |
220 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
220 | void QChart::setBackgroundBrush(const QBrush &brush) | |
221 | { |
|
221 | { | |
222 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
222 | d_ptr->m_presenter->setBackgroundBrush(brush); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | /*! |
|
225 | /*! | |
226 | Gets the brush that is used for painting the background of the chart area. |
|
226 | Gets the brush that is used for painting the background of the chart area. | |
227 | */ |
|
227 | */ | |
228 | QBrush QChart::backgroundBrush() const |
|
228 | QBrush QChart::backgroundBrush() const | |
229 | { |
|
229 | { | |
230 | return d_ptr->m_presenter->backgroundBrush(); |
|
230 | return d_ptr->m_presenter->backgroundBrush(); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | /*! |
|
233 | /*! | |
234 | Sets the \a pen that is used for painting the background of the chart area. |
|
234 | Sets the \a pen that is used for painting the background of the chart area. | |
235 | */ |
|
235 | */ | |
236 | void QChart::setBackgroundPen(const QPen &pen) |
|
236 | void QChart::setBackgroundPen(const QPen &pen) | |
237 | { |
|
237 | { | |
238 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
238 | d_ptr->m_presenter->setBackgroundPen(pen); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | Gets the pen that is used for painting the background of the chart area. |
|
242 | Gets the pen that is used for painting the background of the chart area. | |
243 | */ |
|
243 | */ | |
244 | QPen QChart::backgroundPen() const |
|
244 | QPen QChart::backgroundPen() const | |
245 | { |
|
245 | { | |
246 | return d_ptr->m_presenter->backgroundPen(); |
|
246 | return d_ptr->m_presenter->backgroundPen(); | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | void QChart::setTitle(const QString &title) |
|
249 | void QChart::setTitle(const QString &title) | |
250 | { |
|
250 | { | |
251 | d_ptr->m_presenter->setTitle(title); |
|
251 | d_ptr->m_presenter->setTitle(title); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | QString QChart::title() const |
|
254 | QString QChart::title() const | |
255 | { |
|
255 | { | |
256 | return d_ptr->m_presenter->title(); |
|
256 | return d_ptr->m_presenter->title(); | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | /*! |
|
259 | /*! | |
260 | Sets the \a font that is used for drawing the chart title. |
|
260 | Sets the \a font that is used for drawing the chart title. | |
261 | */ |
|
261 | */ | |
262 | void QChart::setTitleFont(const QFont &font) |
|
262 | void QChart::setTitleFont(const QFont &font) | |
263 | { |
|
263 | { | |
264 | d_ptr->m_presenter->setTitleFont(font); |
|
264 | d_ptr->m_presenter->setTitleFont(font); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | /*! |
|
267 | /*! | |
268 | Gets the font that is used for drawing the chart title. |
|
268 | Gets the font that is used for drawing the chart title. | |
269 | */ |
|
269 | */ | |
270 | QFont QChart::titleFont() const |
|
270 | QFont QChart::titleFont() const | |
271 | { |
|
271 | { | |
272 | return d_ptr->m_presenter->titleFont(); |
|
272 | return d_ptr->m_presenter->titleFont(); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Sets the \a brush used for drawing the title text. |
|
276 | Sets the \a brush used for drawing the title text. | |
277 | */ |
|
277 | */ | |
278 | void QChart::setTitleBrush(const QBrush &brush) |
|
278 | void QChart::setTitleBrush(const QBrush &brush) | |
279 | { |
|
279 | { | |
280 | d_ptr->m_presenter->setTitleBrush(brush); |
|
280 | d_ptr->m_presenter->setTitleBrush(brush); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | /*! |
|
283 | /*! | |
284 | Returns the brush used for drawing the title text. |
|
284 | Returns the brush used for drawing the title text. | |
285 | */ |
|
285 | */ | |
286 | QBrush QChart::titleBrush() const |
|
286 | QBrush QChart::titleBrush() const | |
287 | { |
|
287 | { | |
288 | return d_ptr->m_presenter->titleBrush(); |
|
288 | return d_ptr->m_presenter->titleBrush(); | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | void QChart::setTheme(QChart::ChartTheme theme) |
|
291 | void QChart::setTheme(QChart::ChartTheme theme) | |
292 | { |
|
292 | { | |
293 | d_ptr->m_themeManager->setTheme(theme); |
|
293 | d_ptr->m_themeManager->setTheme(theme); | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | QChart::ChartTheme QChart::theme() const |
|
296 | QChart::ChartTheme QChart::theme() const | |
297 | { |
|
297 | { | |
298 | return d_ptr->m_themeManager->theme()->id(); |
|
298 | return d_ptr->m_themeManager->theme()->id(); | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | /*! |
|
301 | /*! | |
302 | Zooms in the view by a factor of two. |
|
302 | Zooms in the view by a factor of two. | |
303 | */ |
|
303 | */ | |
304 | void QChart::zoomIn() |
|
304 | void QChart::zoomIn() | |
305 | { |
|
305 | { | |
306 | d_ptr->zoomIn(2.0); |
|
306 | d_ptr->zoomIn(2.0); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | /*! |
|
309 | /*! | |
310 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
310 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
311 | \note This is not supported for polar charts. |
|
311 | \note This is not supported for polar charts. | |
312 | */ |
|
312 | */ | |
313 | void QChart::zoomIn(const QRectF &rect) |
|
313 | void QChart::zoomIn(const QRectF &rect) | |
314 | { |
|
314 | { | |
315 | if (d_ptr->m_type == QChart::ChartTypePolar) |
|
315 | if (d_ptr->m_type == QChart::ChartTypePolar) | |
316 | return; |
|
316 | return; | |
317 | d_ptr->zoomIn(rect); |
|
317 | d_ptr->zoomIn(rect); | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | /*! |
|
320 | /*! | |
321 | Zooms out the view by a factor of two. |
|
321 | Zooms out the view by a factor of two. | |
322 | */ |
|
322 | */ | |
323 | void QChart::zoomOut() |
|
323 | void QChart::zoomOut() | |
324 | { |
|
324 | { | |
325 | d_ptr->zoomOut(2.0); |
|
325 | d_ptr->zoomOut(2.0); | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | /*! |
|
328 | /*! | |
329 | Zooms in the view by a custom \a factor. |
|
329 | Zooms in the view by a custom \a factor. | |
330 |
|
330 | |||
331 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
331 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | |
332 | */ |
|
332 | */ | |
333 | void QChart::zoom(qreal factor) |
|
333 | void QChart::zoom(qreal factor) | |
334 | { |
|
334 | { | |
335 | if (qFuzzyCompare(factor, 0)) |
|
335 | if (qFuzzyCompare(factor, 0)) | |
336 | return; |
|
336 | return; | |
337 |
|
337 | |||
338 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
338 | if (qFuzzyCompare(factor, (qreal)1.0)) | |
339 | return; |
|
339 | return; | |
340 |
|
340 | |||
341 | if (factor < 0) |
|
341 | if (factor < 0) | |
342 | return; |
|
342 | return; | |
343 |
|
343 | |||
344 | if (factor > 1.0) |
|
344 | if (factor > 1.0) | |
345 | d_ptr->zoomIn(factor); |
|
345 | d_ptr->zoomIn(factor); | |
346 | else |
|
346 | else | |
347 | d_ptr->zoomOut(1.0 / factor); |
|
347 | d_ptr->zoomOut(1.0 / factor); | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | /*! |
|
350 | /*! | |
351 | Returns a pointer to the horizontal axis attached to the specified \a series. |
|
351 | Returns a pointer to the horizontal axis attached to the specified \a series. | |
352 | If no \a series is specified, the first horizontal axis added to the chart is returned. |
|
352 | If no \a series is specified, the first horizontal axis added to the chart is returned. | |
353 |
|
353 | |||
354 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
354 | \sa addAxis(), QAbstractSeries::attachAxis() | |
355 | */ |
|
355 | */ | |
356 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
356 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | |
357 | { |
|
357 | { | |
358 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); |
|
358 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); | |
359 | if (axisList.count()) |
|
359 | if (axisList.count()) | |
360 | return axisList[0]; |
|
360 | return axisList[0]; | |
361 | return 0; |
|
361 | return 0; | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | /*! |
|
364 | /*! | |
365 | Returns a pointer to the vertical axis attached to the specified \a series. |
|
365 | Returns a pointer to the vertical axis attached to the specified \a series. | |
366 | If no \a series is specified, the first vertical axis added to the chart is returned. |
|
366 | If no \a series is specified, the first vertical axis added to the chart is returned. | |
367 |
|
367 | |||
368 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
368 | \sa addAxis(), QAbstractSeries::attachAxis() | |
369 | */ |
|
369 | */ | |
370 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
370 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const | |
371 | { |
|
371 | { | |
372 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); |
|
372 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); | |
373 | if (axisList.count()) |
|
373 | if (axisList.count()) | |
374 | return axisList[0]; |
|
374 | return axisList[0]; | |
375 | return 0; |
|
375 | return 0; | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | /*! |
|
378 | /*! | |
379 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, |
|
379 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, | |
380 | then all axes added to the chart with the specified orientation are returned. |
|
380 | then all axes added to the chart with the specified orientation are returned. | |
381 | \sa addAxis(), createDefaultAxes() |
|
381 | \sa addAxis(), createDefaultAxes() | |
382 | */ |
|
382 | */ | |
383 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
383 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const | |
384 | { |
|
384 | { | |
385 | QList<QAbstractAxis *> result ; |
|
385 | QList<QAbstractAxis *> result ; | |
386 |
|
386 | |||
387 | if (series) { |
|
387 | if (series) { | |
388 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
388 | foreach (QAbstractAxis *axis, series->attachedAxes()){ | |
389 | if (orientation.testFlag(axis->orientation())) |
|
389 | if (orientation.testFlag(axis->orientation())) | |
390 | result << axis; |
|
390 | result << axis; | |
391 | } |
|
391 | } | |
392 | } else { |
|
392 | } else { | |
393 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ |
|
393 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ | |
394 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
394 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) | |
395 | result << axis; |
|
395 | result << axis; | |
396 | } |
|
396 | } | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | return result; |
|
399 | return result; | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 | /*! |
|
402 | /*! | |
403 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to |
|
403 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to | |
404 | the chart will be deleted. |
|
404 | the chart will be deleted. | |
405 |
|
405 | |||
406 | \note This function has to be called after all series have been added to the chart. The axes created by this function |
|
406 | \note This function has to be called after all series have been added to the chart. The axes created by this function | |
407 | will NOT get automatically attached to any series added to the chart after this function has been called. |
|
407 | will NOT get automatically attached to any series added to the chart after this function has been called. | |
408 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing |
|
408 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing | |
409 | if there are other series with properly attached axes also present. |
|
409 | if there are other series with properly attached axes also present. | |
410 |
|
410 | |||
411 | \table |
|
411 | \table | |
412 | \header |
|
412 | \header | |
413 | \o Series type |
|
413 | \o Series type | |
414 | \o X-axis |
|
414 | \o X-axis | |
415 | \o Y-axis |
|
415 | \o Y-axis | |
416 | \row |
|
416 | \row | |
417 | \o QXYSeries |
|
417 | \o QXYSeries | |
418 | \o QValueAxis |
|
418 | \o QValueAxis | |
419 | \o QValueAxis |
|
419 | \o QValueAxis | |
420 | \row |
|
420 | \row | |
421 | \o QBarSeries |
|
421 | \o QBarSeries | |
422 | \o QBarCategoryAxis |
|
422 | \o QBarCategoryAxis | |
423 | \o QValueAxis |
|
423 | \o QValueAxis | |
424 | \row |
|
424 | \row | |
425 | \o QPieSeries |
|
425 | \o QPieSeries | |
426 | \o None |
|
426 | \o None | |
427 | \o None |
|
427 | \o None | |
428 | \endtable |
|
428 | \endtable | |
429 |
|
429 | |||
430 | If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. |
|
430 | If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. | |
431 | If there are several series of different types added to the chart, then each series gets its own axes pair. |
|
431 | If there are several series of different types added to the chart, then each series gets its own axes pair. | |
432 |
|
432 | |||
433 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. |
|
433 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. | |
434 | QPieSeries does not create any axes. |
|
434 | QPieSeries does not create any axes. | |
435 |
|
435 | |||
436 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() |
|
436 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() | |
437 | */ |
|
437 | */ | |
438 | void QChart::createDefaultAxes() |
|
438 | void QChart::createDefaultAxes() | |
439 | { |
|
439 | { | |
440 | d_ptr->m_dataset->createDefaultAxes(); |
|
440 | d_ptr->m_dataset->createDefaultAxes(); | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
443 | /*! |
|
443 | /*! | |
444 | Returns the legend object of the chart. Ownership stays with the chart. |
|
444 | Returns the legend object of the chart. Ownership stays with the chart. | |
445 | */ |
|
445 | */ | |
446 | QLegend *QChart::legend() const |
|
446 | QLegend *QChart::legend() const | |
447 | { |
|
447 | { | |
448 | return d_ptr->m_legend; |
|
448 | return d_ptr->m_legend; | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | void QChart::setMinimumMargins(const QMargins &margins) |
|
451 | void QChart::setMinimumMargins(const QMargins &margins) | |
452 | { |
|
452 | { | |
453 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
453 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; | |
454 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
454 | d_ptr->m_presenter->layout()->setMargins(margins); | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
457 | QMargins QChart::minimumMargins() const |
|
457 | QMargins QChart::minimumMargins() const | |
458 | { |
|
458 | { | |
459 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
459 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; | |
460 | return d_ptr->m_presenter->layout()->margins(); |
|
460 | return d_ptr->m_presenter->layout()->margins(); | |
461 | } |
|
461 | } | |
462 |
|
462 | |||
463 | void QChart::setMargins(const QMargins &margins) |
|
463 | void QChart::setMargins(const QMargins &margins) | |
464 | { |
|
464 | { | |
465 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
465 | d_ptr->m_presenter->layout()->setMargins(margins); | |
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | QMargins QChart::margins() const |
|
468 | QMargins QChart::margins() const | |
469 | { |
|
469 | { | |
470 | return d_ptr->m_presenter->layout()->margins(); |
|
470 | return d_ptr->m_presenter->layout()->margins(); | |
471 | } |
|
471 | } | |
472 |
|
472 | |||
473 | QChart::ChartType QChart::chartType() const |
|
473 | QChart::ChartType QChart::chartType() const | |
474 | { |
|
474 | { | |
475 | return d_ptr->m_type; |
|
475 | return d_ptr->m_type; | |
476 | } |
|
476 | } | |
477 |
|
477 | |||
478 | /*! |
|
478 | /*! | |
479 | Returns the the rectangle within which the drawing of the chart is done. |
|
479 | Returns the the rectangle within which the drawing of the chart is done. | |
480 | It does not include the area defined by margins. |
|
480 | It does not include the area defined by margins. | |
481 | */ |
|
481 | */ | |
482 | QRectF QChart::plotArea() const |
|
482 | QRectF QChart::plotArea() const | |
483 | { |
|
483 | { | |
484 | return d_ptr->m_presenter->geometry(); |
|
484 | return d_ptr->m_presenter->geometry(); | |
485 | } |
|
485 | } | |
486 |
|
486 | |||
487 | /*! |
|
487 | /*! | |
488 | Sets the \a brush for the background of the plot area of the chart. |
|
488 | Sets the \a brush for the background of the plot area of the chart. | |
489 |
|
489 | |||
490 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() |
|
490 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() | |
491 | */ |
|
491 | */ | |
492 | void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) |
|
492 | void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) | |
493 | { |
|
493 | { | |
494 | d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); |
|
494 | d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); | |
495 | } |
|
495 | } | |
496 |
|
496 | |||
497 | /*! |
|
497 | /*! | |
498 | Returns the brush for the background of the plot area of the chart. |
|
498 | Returns the brush for the background of the plot area of the chart. | |
499 |
|
499 | |||
500 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() |
|
500 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() | |
501 | */ |
|
501 | */ | |
502 | QBrush QChart::plotAreaBackgroundBrush() const |
|
502 | QBrush QChart::plotAreaBackgroundBrush() const | |
503 | { |
|
503 | { | |
504 | return d_ptr->m_presenter->plotAreaBackgroundBrush(); |
|
504 | return d_ptr->m_presenter->plotAreaBackgroundBrush(); | |
505 | } |
|
505 | } | |
506 |
|
506 | |||
507 | /*! |
|
507 | /*! | |
508 | Sets the \a pen for the background of the plot area of the chart. |
|
508 | Sets the \a pen for the background of the plot area of the chart. | |
509 |
|
509 | |||
510 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() |
|
510 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() | |
511 | */ |
|
511 | */ | |
512 | void QChart::setPlotAreaBackgroundPen(const QPen &pen) |
|
512 | void QChart::setPlotAreaBackgroundPen(const QPen &pen) | |
513 | { |
|
513 | { | |
514 | d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); |
|
514 | d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); | |
515 | } |
|
515 | } | |
516 |
|
516 | |||
517 | /*! |
|
517 | /*! | |
518 | Returns the pen for the background of the plot area of the chart. |
|
518 | Returns the pen for the background of the plot area of the chart. | |
519 |
|
519 | |||
520 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() |
|
520 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() | |
521 | */ |
|
521 | */ | |
522 | QPen QChart::plotAreaBackgroundPen() const |
|
522 | QPen QChart::plotAreaBackgroundPen() const | |
523 | { |
|
523 | { | |
524 | return d_ptr->m_presenter->plotAreaBackgroundPen(); |
|
524 | return d_ptr->m_presenter->plotAreaBackgroundPen(); | |
525 | } |
|
525 | } | |
526 |
|
526 | |||
527 | void QChart::setPlotAreaBackgroundVisible(bool visible) |
|
527 | void QChart::setPlotAreaBackgroundVisible(bool visible) | |
528 | { |
|
528 | { | |
529 | d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); |
|
529 | d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); | |
530 | } |
|
530 | } | |
531 |
|
531 | |||
532 | bool QChart::isPlotAreaBackgroundVisible() const |
|
532 | bool QChart::isPlotAreaBackgroundVisible() const | |
533 | { |
|
533 | { | |
534 | return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); |
|
534 | return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); | |
535 | } |
|
535 | } | |
536 |
|
536 | |||
537 | void QChart::setAnimationOptions(AnimationOptions options) |
|
537 | void QChart::setAnimationOptions(AnimationOptions options) | |
538 | { |
|
538 | { | |
539 | d_ptr->m_presenter->setAnimationOptions(options); |
|
539 | d_ptr->m_presenter->setAnimationOptions(options); | |
540 | } |
|
540 | } | |
541 |
|
541 | |||
542 | QChart::AnimationOptions QChart::animationOptions() const |
|
542 | QChart::AnimationOptions QChart::animationOptions() const | |
543 | { |
|
543 | { | |
544 | return d_ptr->m_presenter->animationOptions(); |
|
544 | return d_ptr->m_presenter->animationOptions(); | |
545 | } |
|
545 | } | |
546 |
|
546 | |||
547 | /*! |
|
547 | /*! | |
548 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
548 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | |
549 |
|
549 | |||
550 | For polar charts, \a dx indicates the angle along angular axis instead of distance. |
|
550 | For polar charts, \a dx indicates the angle along angular axis instead of distance. | |
551 | */ |
|
551 | */ | |
552 | void QChart::scroll(qreal dx, qreal dy) |
|
552 | void QChart::scroll(qreal dx, qreal dy) | |
553 | { |
|
553 | { | |
554 | d_ptr->scroll(dx,dy); |
|
554 | d_ptr->scroll(dx,dy); | |
555 | } |
|
555 | } | |
556 |
|
556 | |||
557 | void QChart::setBackgroundVisible(bool visible) |
|
557 | void QChart::setBackgroundVisible(bool visible) | |
558 | { |
|
558 | { | |
559 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
559 | d_ptr->m_presenter->setBackgroundVisible(visible); | |
560 | } |
|
560 | } | |
561 |
|
561 | |||
562 | bool QChart::isBackgroundVisible() const |
|
562 | bool QChart::isBackgroundVisible() const | |
563 | { |
|
563 | { | |
564 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
564 | return d_ptr->m_presenter->isBackgroundVisible(); | |
565 | } |
|
565 | } | |
566 |
|
566 | |||
567 | void QChart::setDropShadowEnabled(bool enabled) |
|
567 | void QChart::setDropShadowEnabled(bool enabled) | |
568 | { |
|
568 | { | |
569 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
569 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); | |
570 | } |
|
570 | } | |
571 |
|
571 | |||
572 | bool QChart::isDropShadowEnabled() const |
|
572 | bool QChart::isDropShadowEnabled() const | |
573 | { |
|
573 | { | |
574 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
574 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); | |
575 | } |
|
575 | } | |
576 |
|
576 | |||
577 | /*! |
|
577 | /*! | |
578 | Returns all series that are added to the chart. |
|
578 | Returns all series that are added to the chart. | |
579 |
|
579 | |||
580 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
580 | \sa addSeries(), removeSeries(), removeAllSeries() | |
581 | */ |
|
581 | */ | |
582 | QList<QAbstractSeries *> QChart::series() const |
|
582 | QList<QAbstractSeries *> QChart::series() const | |
583 | { |
|
583 | { | |
584 | return d_ptr->m_dataset->series(); |
|
584 | return d_ptr->m_dataset->series(); | |
585 | } |
|
585 | } | |
586 |
|
586 | |||
587 | /*! |
|
587 | /*! | |
588 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. |
|
588 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. | |
589 | The chart takes ownership of both the \a axis and the \a series. |
|
589 | The chart takes ownership of both the \a axis and the \a series. | |
590 | Any horizontal axes previously attached to the \a series are deleted. |
|
590 | Any horizontal axes previously attached to the \a series are deleted. | |
591 |
|
591 | |||
592 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
592 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
593 | */ |
|
593 | */ | |
594 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) |
|
594 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) | |
595 | { |
|
595 | { | |
596 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); |
|
596 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); | |
597 |
|
597 | |||
598 | foreach (QAbstractAxis* a, list) { |
|
598 | foreach (QAbstractAxis* a, list) { | |
599 | d_ptr->m_dataset->removeAxis(a); |
|
599 | d_ptr->m_dataset->removeAxis(a); | |
600 | delete a; |
|
600 | delete a; | |
601 | } |
|
601 | } | |
602 |
|
602 | |||
603 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
603 | if (!d_ptr->m_dataset->axes().contains(axis)) | |
604 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); |
|
604 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); | |
605 | d_ptr->m_dataset->attachAxis(series, axis); |
|
605 | d_ptr->m_dataset->attachAxis(series, axis); | |
606 | } |
|
606 | } | |
607 |
|
607 | |||
608 | /*! |
|
608 | /*! | |
609 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. |
|
609 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. | |
610 | The chart takes ownership of both the \a axis and the \a series. |
|
610 | The chart takes ownership of both the \a axis and the \a series. | |
611 | Any vertical axes previously attached to the \a series are deleted. |
|
611 | Any vertical axes previously attached to the \a series are deleted. | |
612 |
|
612 | |||
613 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
613 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
614 | */ |
|
614 | */ | |
615 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) |
|
615 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) | |
616 | { |
|
616 | { | |
617 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); |
|
617 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); | |
618 |
|
618 | |||
619 | foreach (QAbstractAxis* a, list) { |
|
619 | foreach (QAbstractAxis* a, list) { | |
620 | d_ptr->m_dataset->removeAxis(a); |
|
620 | d_ptr->m_dataset->removeAxis(a); | |
621 | delete a; |
|
621 | delete a; | |
622 | } |
|
622 | } | |
623 |
|
623 | |||
624 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
624 | if (!d_ptr->m_dataset->axes().contains(axis)) | |
625 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); |
|
625 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); | |
626 | d_ptr->m_dataset->attachAxis(series, axis); |
|
626 | d_ptr->m_dataset->attachAxis(series, axis); | |
627 | } |
|
627 | } | |
628 |
|
628 | |||
629 | /*! |
|
629 | /*! | |
630 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
630 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. | |
631 |
|
631 | |||
632 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
632 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
633 | */ |
|
633 | */ | |
634 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
634 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) | |
635 | { |
|
635 | { | |
636 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
636 | d_ptr->m_dataset->addAxis(axis, alignment); | |
637 | } |
|
637 | } | |
638 |
|
638 | |||
639 | /*! |
|
639 | /*! | |
640 | Removes the \a axis from the chart. |
|
640 | Removes the \a axis from the chart. | |
641 | The chart releases its ownership of the specified \a axis object. |
|
641 | The chart releases its ownership of the specified \a axis object. | |
642 |
|
642 | |||
643 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
643 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() | |
644 | */ |
|
644 | */ | |
645 | void QChart::removeAxis(QAbstractAxis *axis) |
|
645 | void QChart::removeAxis(QAbstractAxis *axis) | |
646 | { |
|
646 | { | |
647 | d_ptr->m_dataset->removeAxis(axis); |
|
647 | d_ptr->m_dataset->removeAxis(axis); | |
648 | } |
|
648 | } | |
649 |
|
649 | |||
650 | /*! |
|
650 | /*! | |
651 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. |
|
651 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. | |
652 | */ |
|
652 | */ | |
653 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
653 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) | |
654 | { |
|
654 | { | |
655 | return d_ptr->m_dataset->mapToValue(position, series); |
|
655 | return d_ptr->m_dataset->mapToValue(position, series); | |
656 | } |
|
656 | } | |
657 |
|
657 | |||
658 | /*! |
|
658 | /*! | |
659 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. |
|
659 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. | |
660 | */ |
|
660 | */ | |
661 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
661 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) | |
662 | { |
|
662 | { | |
663 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
663 | return d_ptr->m_dataset->mapToPosition(value, series); | |
664 | } |
|
664 | } | |
665 |
|
665 | |||
666 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
666 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
667 |
|
667 | |||
668 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): |
|
668 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): | |
669 | q_ptr(q), |
|
669 | q_ptr(q), | |
670 | m_legend(0), |
|
670 | m_legend(0), | |
671 | m_dataset(new ChartDataSet(q)), |
|
671 | m_dataset(new ChartDataSet(q)), | |
672 | m_presenter(new ChartPresenter(q, type)), |
|
672 | m_presenter(new ChartPresenter(q, type)), | |
673 | m_themeManager(new ChartThemeManager(q)), |
|
673 | m_themeManager(new ChartThemeManager(q)), | |
674 | m_type(type) |
|
674 | m_type(type) | |
675 | { |
|
675 | { | |
676 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
676 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
677 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
677 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
678 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
678 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); | |
679 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
679 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
680 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
680 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
681 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
681 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
682 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
682 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); | |
683 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
683 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
684 | } |
|
684 | } | |
685 |
|
685 | |||
686 | QChartPrivate::~QChartPrivate() |
|
686 | QChartPrivate::~QChartPrivate() | |
687 | { |
|
687 | { | |
688 | } |
|
688 | } | |
689 |
|
689 | |||
690 | // Hackish solution to the problem of explicitly assigning the default pen/brush/font |
|
690 | // Hackish solution to the problem of explicitly assigning the default pen/brush/font | |
691 | // to a series or axis and having theme override it: |
|
691 | // to a series or axis and having theme override it: | |
692 | // Initialize pens, brushes, and fonts to something nobody is likely to ever use, |
|
692 | // Initialize pens, brushes, and fonts to something nobody is likely to ever use, | |
693 | // so that default theme initialization will always set these properly. |
|
693 | // so that default theme initialization will always set these properly. | |
694 | QPen &QChartPrivate::defaultPen() |
|
694 | QPen &QChartPrivate::defaultPen() | |
695 | { |
|
695 | { | |
696 |
static QPen |
|
696 | static QPen defaultPen(QColor(1, 2, 0), 0.93247536); | |
697 |
|
|
697 | return defaultPen; | |
698 | defaultPen = new QPen(QColor(1, 2, 0), 0.93247536); |
|
|||
699 | return *defaultPen; |
|
|||
700 | } |
|
698 | } | |
701 |
|
699 | |||
702 | QBrush &QChartPrivate::defaultBrush() |
|
700 | QBrush &QChartPrivate::defaultBrush() | |
703 | { |
|
701 | { | |
704 |
static QBrush |
|
702 | static QBrush defaultBrush(QColor(1, 2, 0), Qt::Dense7Pattern); | |
705 |
|
|
703 | return defaultBrush; | |
706 | defaultBrush = new QBrush(QColor(1, 2, 0), Qt::Dense7Pattern); |
|
|||
707 | return *defaultBrush; |
|
|||
708 | } |
|
704 | } | |
709 |
|
705 | |||
710 | QFont &QChartPrivate::defaultFont() |
|
706 | QFont &QChartPrivate::defaultFont() | |
711 | { |
|
707 | { | |
712 |
static |
|
708 | static bool defaultFontInitialized(false); | |
713 |
|
|
709 | static QFont defaultFont; | |
714 | defaultFont = new QFont(); |
|
710 | if (!defaultFontInitialized) { | |
715 |
defaultFont |
|
711 | defaultFont.setPointSizeF(8.34563465); | |
|
712 | defaultFontInitialized = true; | |||
716 | } |
|
713 | } | |
717 |
return |
|
714 | return defaultFont; | |
718 | } |
|
715 | } | |
719 |
|
716 | |||
720 | void QChartPrivate::init() |
|
717 | void QChartPrivate::init() | |
721 | { |
|
718 | { | |
722 | m_legend = new LegendScroller(q_ptr); |
|
719 | m_legend = new LegendScroller(q_ptr); | |
723 | q_ptr->setTheme(QChart::ChartThemeLight); |
|
720 | q_ptr->setTheme(QChart::ChartThemeLight); | |
724 | q_ptr->setLayout(m_presenter->layout()); |
|
721 | q_ptr->setLayout(m_presenter->layout()); | |
725 | } |
|
722 | } | |
726 |
|
723 | |||
727 | void QChartPrivate::zoomIn(qreal factor) |
|
724 | void QChartPrivate::zoomIn(qreal factor) | |
728 | { |
|
725 | { | |
729 | QRectF rect = m_presenter->geometry(); |
|
726 | QRectF rect = m_presenter->geometry(); | |
730 | rect.setWidth(rect.width() / factor); |
|
727 | rect.setWidth(rect.width() / factor); | |
731 | rect.setHeight(rect.height() / factor); |
|
728 | rect.setHeight(rect.height() / factor); | |
732 | rect.moveCenter(m_presenter->geometry().center()); |
|
729 | rect.moveCenter(m_presenter->geometry().center()); | |
733 | zoomIn(rect); |
|
730 | zoomIn(rect); | |
734 | } |
|
731 | } | |
735 |
|
732 | |||
736 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
733 | void QChartPrivate::zoomIn(const QRectF &rect) | |
737 | { |
|
734 | { | |
738 | if (!rect.isValid()) |
|
735 | if (!rect.isValid()) | |
739 | return; |
|
736 | return; | |
740 |
|
737 | |||
741 | QRectF r = rect.normalized(); |
|
738 | QRectF r = rect.normalized(); | |
742 | const QRectF geometry = m_presenter->geometry(); |
|
739 | const QRectF geometry = m_presenter->geometry(); | |
743 | r.translate(-geometry.topLeft()); |
|
740 | r.translate(-geometry.topLeft()); | |
744 |
|
741 | |||
745 | if (!r.isValid()) |
|
742 | if (!r.isValid()) | |
746 | return; |
|
743 | return; | |
747 |
|
744 | |||
748 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
745 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
749 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
746 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); | |
750 | m_dataset->zoomInDomain(r); |
|
747 | m_dataset->zoomInDomain(r); | |
751 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
748 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
752 |
|
749 | |||
753 | } |
|
750 | } | |
754 |
|
751 | |||
755 | void QChartPrivate::zoomOut(qreal factor) |
|
752 | void QChartPrivate::zoomOut(qreal factor) | |
756 | { |
|
753 | { | |
757 | const QRectF geometry = m_presenter->geometry(); |
|
754 | const QRectF geometry = m_presenter->geometry(); | |
758 |
|
755 | |||
759 | QRectF r; |
|
756 | QRectF r; | |
760 | r.setSize(geometry.size() / factor); |
|
757 | r.setSize(geometry.size() / factor); | |
761 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
758 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); | |
762 | if (!r.isValid()) |
|
759 | if (!r.isValid()) | |
763 | return; |
|
760 | return; | |
764 |
|
761 | |||
765 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
762 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
766 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
763 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); | |
767 | m_dataset->zoomOutDomain(r); |
|
764 | m_dataset->zoomOutDomain(r); | |
768 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
765 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
769 | } |
|
766 | } | |
770 |
|
767 | |||
771 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
768 | void QChartPrivate::scroll(qreal dx, qreal dy) | |
772 | { |
|
769 | { | |
773 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
770 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); | |
774 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
771 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); | |
775 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
772 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); | |
776 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
773 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); | |
777 |
|
774 | |||
778 | m_dataset->scrollDomain(dx, dy); |
|
775 | m_dataset->scrollDomain(dx, dy); | |
779 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
776 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
780 | } |
|
777 | } | |
781 |
|
778 | |||
782 | #include "moc_qchart.cpp" |
|
779 | #include "moc_qchart.cpp" | |
783 |
|
780 | |||
784 | QTCOMMERCIALCHART_END_NAMESPACE |
|
781 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now