@@ -0,0 +1,46 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include "chartitem_p.h" | |||
|
22 | #include "qabstractseries_p.h" | |||
|
23 | #include "domain_p.h" | |||
|
24 | ||||
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
26 | ||||
|
27 | ChartItem::ChartItem(QAbstractSeriesPrivate *series,QGraphicsItem* item): | |||
|
28 | ChartElement(item), | |||
|
29 | m_series(series) | |||
|
30 | { | |||
|
31 | ||||
|
32 | } | |||
|
33 | ||||
|
34 | QSharedPointer<Domain> ChartItem::domain() const | |||
|
35 | { | |||
|
36 | return m_series->domain(); | |||
|
37 | } | |||
|
38 | ||||
|
39 | void ChartItem::handleDomainUpdated() | |||
|
40 | { | |||
|
41 | qWarning() << __FUNCTION__<< "Slot not implemented"; | |||
|
42 | } | |||
|
43 | ||||
|
44 | #include "moc_chartitem_p.cpp" | |||
|
45 | ||||
|
46 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,259 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | #include "qabstractseries_p.h" | |||
|
21 | #include "qabstractaxis_p.h" | |||
|
22 | #include <QTime> | |||
|
23 | //themes | |||
|
24 | #include "chartthemesystem_p.h" | |||
|
25 | #include "chartthemelight_p.h" | |||
|
26 | #include "chartthemebluecerulean_p.h" | |||
|
27 | #include "chartthemedark_p.h" | |||
|
28 | #include "chartthemebrownsand_p.h" | |||
|
29 | #include "chartthemebluencs_p.h" | |||
|
30 | #include "chartthemehighcontrast_p.h" | |||
|
31 | #include "chartthemeblueicy_p.h" | |||
|
32 | ||||
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
34 | ||||
|
35 | ChartThemeManager::ChartThemeManager(QChart* chart) : | |||
|
36 | m_chart(chart) | |||
|
37 | { | |||
|
38 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |||
|
39 | } | |||
|
40 | ||||
|
41 | ||||
|
42 | void ChartThemeManager::setTheme(QChart::ChartTheme theme) | |||
|
43 | { | |||
|
44 | if(m_theme.isNull() || theme != m_theme->id()) | |||
|
45 | { | |||
|
46 | switch (theme) { | |||
|
47 | case QChart::ChartThemeLight: | |||
|
48 | m_theme.reset(new ChartThemeLight()); | |||
|
49 | break; | |||
|
50 | case QChart::ChartThemeBlueCerulean: | |||
|
51 | m_theme.reset(new ChartThemeBlueCerulean()); | |||
|
52 | break; | |||
|
53 | case QChart::ChartThemeDark: | |||
|
54 | m_theme.reset(new ChartThemeDark()); | |||
|
55 | break; | |||
|
56 | case QChart::ChartThemeBrownSand: | |||
|
57 | m_theme.reset(new ChartThemeBrownSand()); | |||
|
58 | break; | |||
|
59 | case QChart::ChartThemeBlueNcs: | |||
|
60 | m_theme.reset(new ChartThemeBlueNcs()); | |||
|
61 | break; | |||
|
62 | case QChart::ChartThemeHighContrast: | |||
|
63 | m_theme.reset(new ChartThemeHighContrast()); | |||
|
64 | break; | |||
|
65 | case QChart::ChartThemeBlueIcy: | |||
|
66 | m_theme.reset(new ChartThemeBlueIcy()); | |||
|
67 | break; | |||
|
68 | default: | |||
|
69 | m_theme.reset(new ChartThemeSystem()); | |||
|
70 | break; | |||
|
71 | } | |||
|
72 | ||||
|
73 | if(!m_theme.isNull()) | |||
|
74 | { | |||
|
75 | decorateChart(m_chart,m_theme.data(),true); | |||
|
76 | decorateLegend(m_chart->legend(),m_theme.data(),true); | |||
|
77 | foreach(QAbstractAxis* axis, m_axisList) { | |||
|
78 | axis->d_ptr->initializeTheme(m_theme.data(),true); | |||
|
79 | } | |||
|
80 | foreach(QAbstractSeries* series, m_seriesMap.keys()) { | |||
|
81 | series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),true); | |||
|
82 | } | |||
|
83 | ||||
|
84 | } | |||
|
85 | } | |||
|
86 | } | |||
|
87 | ||||
|
88 | void ChartThemeManager::decorateChart(QChart *chart,ChartTheme* theme,bool force) const | |||
|
89 | { | |||
|
90 | QBrush brush; | |||
|
91 | ||||
|
92 | if (force || brush == chart->backgroundBrush()) | |||
|
93 | chart->setBackgroundBrush(theme->chartBackgroundGradient()); | |||
|
94 | ||||
|
95 | chart->setTitleFont(theme->masterFont()); | |||
|
96 | chart->setTitleBrush(theme->labelBrush()); | |||
|
97 | chart->setDropShadowEnabled(theme->isBackgroundDropShadowEnabled()); | |||
|
98 | } | |||
|
99 | ||||
|
100 | void ChartThemeManager::decorateLegend(QLegend *legend, ChartTheme* theme, bool force) const | |||
|
101 | { | |||
|
102 | QPen pen; | |||
|
103 | QBrush brush; | |||
|
104 | QFont font; | |||
|
105 | ||||
|
106 | if (force || pen == legend->pen()) | |||
|
107 | legend->setPen(theme->axisLinePen()); | |||
|
108 | ||||
|
109 | if (force || brush == legend->brush()) | |||
|
110 | legend->setBrush(theme->chartBackgroundGradient()); | |||
|
111 | ||||
|
112 | if (force || font == legend->font()) | |||
|
113 | legend->setFont(theme->labelFont()); | |||
|
114 | ||||
|
115 | if (force || brush == legend->labelBrush()) | |||
|
116 | legend->setLabelBrush(theme->labelBrush()); | |||
|
117 | } | |||
|
118 | ||||
|
119 | int ChartThemeManager::createIndexKey(QList<int> keys) const | |||
|
120 | { | |||
|
121 | qSort(keys); | |||
|
122 | ||||
|
123 | int key = 0; | |||
|
124 | QList<int>::iterator i; | |||
|
125 | i = keys.begin(); | |||
|
126 | ||||
|
127 | while (i != keys.end()) { | |||
|
128 | if (*i != key) | |||
|
129 | break; | |||
|
130 | key++; | |||
|
131 | i++; | |||
|
132 | } | |||
|
133 | ||||
|
134 | return key; | |||
|
135 | } | |||
|
136 | ||||
|
137 | int ChartThemeManager::seriesCount(QAbstractSeries::SeriesType type) const | |||
|
138 | { | |||
|
139 | int count = 0; | |||
|
140 | QList<QAbstractSeries *> series = m_seriesMap.keys(); | |||
|
141 | foreach(QAbstractSeries *s, series) { | |||
|
142 | if (s->type() == type) | |||
|
143 | count++; | |||
|
144 | } | |||
|
145 | return count; | |||
|
146 | } | |||
|
147 | ||||
|
148 | void ChartThemeManager::handleSeriesAdded(QAbstractSeries *series) | |||
|
149 | { | |||
|
150 | int key = createIndexKey(m_seriesMap.values()); | |||
|
151 | m_seriesMap.insert(series,key); | |||
|
152 | series->d_ptr->initializeTheme(key,m_theme.data(),false); | |||
|
153 | } | |||
|
154 | ||||
|
155 | void ChartThemeManager::handleSeriesRemoved(QAbstractSeries *series) | |||
|
156 | { | |||
|
157 | m_seriesMap.remove(series); | |||
|
158 | } | |||
|
159 | ||||
|
160 | void ChartThemeManager::handleAxisAdded(QAbstractAxis *axis) | |||
|
161 | { | |||
|
162 | m_axisList.append(axis); | |||
|
163 | axis->d_ptr->initializeTheme(m_theme.data(),false); | |||
|
164 | } | |||
|
165 | ||||
|
166 | void ChartThemeManager::handleAxisRemoved(QAbstractAxis *axis) | |||
|
167 | { | |||
|
168 | m_axisList.removeAll(axis); | |||
|
169 | } | |||
|
170 | ||||
|
171 | void ChartThemeManager::updateSeries(QAbstractSeries *series) | |||
|
172 | { | |||
|
173 | if(m_seriesMap.contains(series)){ | |||
|
174 | series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),false); | |||
|
175 | } | |||
|
176 | } | |||
|
177 | QList<QGradient> ChartThemeManager::generateSeriesGradients(const QList<QColor>& colors) | |||
|
178 | { | |||
|
179 | QList<QGradient> result; | |||
|
180 | // Generate gradients in HSV color space | |||
|
181 | foreach (const QColor &color, colors) { | |||
|
182 | QLinearGradient g; | |||
|
183 | qreal h = color.hsvHueF(); | |||
|
184 | qreal s = color.hsvSaturationF(); | |||
|
185 | ||||
|
186 | // TODO: tune the algorithm to give nice results with most base colors defined in | |||
|
187 | // most themes. The rest of the gradients we can define manually in theme specific | |||
|
188 | // implementation. | |||
|
189 | QColor start = color; | |||
|
190 | start.setHsvF(h, 0.0, 1.0); | |||
|
191 | g.setColorAt(0.0, start); | |||
|
192 | ||||
|
193 | g.setColorAt(0.5, color); | |||
|
194 | ||||
|
195 | QColor end = color; | |||
|
196 | end.setHsvF(h, s, 0.25); | |||
|
197 | g.setColorAt(1.0, end); | |||
|
198 | ||||
|
199 | result << g; | |||
|
200 | } | |||
|
201 | ||||
|
202 | return result; | |||
|
203 | } | |||
|
204 | ||||
|
205 | ||||
|
206 | QColor ChartThemeManager::colorAt(const QColor &start, const QColor &end, qreal pos) | |||
|
207 | { | |||
|
208 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); | |||
|
209 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |||
|
210 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |||
|
211 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |||
|
212 | QColor c; | |||
|
213 | c.setRgbF(r, g, b); | |||
|
214 | return c; | |||
|
215 | } | |||
|
216 | ||||
|
217 | QColor ChartThemeManager::colorAt(const QGradient &gradient, qreal pos) | |||
|
218 | { | |||
|
219 | Q_ASSERT(pos >= 0 && pos <= 1.0); | |||
|
220 | ||||
|
221 | QGradientStops stops = gradient.stops(); | |||
|
222 | int count = stops.count(); | |||
|
223 | ||||
|
224 | // find previous stop relative to position | |||
|
225 | QGradientStop prev = stops.first(); | |||
|
226 | for (int i = 0; i < count; i++) { | |||
|
227 | QGradientStop stop = stops.at(i); | |||
|
228 | if (pos > stop.first) | |||
|
229 | prev = stop; | |||
|
230 | ||||
|
231 | // given position is actually a stop position? | |||
|
232 | if (pos == stop.first) { | |||
|
233 | //qDebug() << "stop color" << pos; | |||
|
234 | return stop.second; | |||
|
235 | } | |||
|
236 | } | |||
|
237 | ||||
|
238 | // find next stop relative to position | |||
|
239 | QGradientStop next = stops.last(); | |||
|
240 | for (int i = count - 1; i >= 0; i--) { | |||
|
241 | QGradientStop stop = stops.at(i); | |||
|
242 | if (pos < stop.first) | |||
|
243 | next = stop; | |||
|
244 | } | |||
|
245 | ||||
|
246 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |||
|
247 | ||||
|
248 | qreal range = next.first - prev.first; | |||
|
249 | qreal posDelta = pos - prev.first; | |||
|
250 | qreal relativePos = posDelta / range; | |||
|
251 | ||||
|
252 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |||
|
253 | ||||
|
254 | return colorAt(prev.second, next.second, relativePos); | |||
|
255 | } | |||
|
256 | ||||
|
257 | #include "moc_chartthememanager_p.cpp" | |||
|
258 | ||||
|
259 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,84 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | // W A R N I N G | |||
|
22 | // ------------- | |||
|
23 | // | |||
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |||
|
25 | // implementation detail. This header file may change from version to | |||
|
26 | // version without notice, or even be removed. | |||
|
27 | // | |||
|
28 | // We mean it. | |||
|
29 | ||||
|
30 | #ifndef CHARTTHEMEMANAGER_H | |||
|
31 | #define CHARTTHEMEMANAGER_H | |||
|
32 | ||||
|
33 | #include "qchartglobal.h" | |||
|
34 | #include "qchart.h" | |||
|
35 | #include <QColor> | |||
|
36 | #include <QGradientStops> | |||
|
37 | ||||
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
39 | class ChartTheme; | |||
|
40 | ||||
|
41 | class ChartThemeManager: public QObject | |||
|
42 | { | |||
|
43 | Q_OBJECT | |||
|
44 | public: | |||
|
45 | enum BackgroundShadesMode { | |||
|
46 | BackgroundShadesNone = 0, | |||
|
47 | BackgroundShadesVertical, | |||
|
48 | BackgroundShadesHorizontal, | |||
|
49 | BackgroundShadesBoth | |||
|
50 | }; | |||
|
51 | ||||
|
52 | public: | |||
|
53 | explicit ChartThemeManager(QChart* chart); | |||
|
54 | void setTheme(QChart::ChartTheme theme); | |||
|
55 | ChartTheme* theme() const { return m_theme.data(); } | |||
|
56 | void decorateChart(QChart *chart, ChartTheme* theme, bool force = false) const; | |||
|
57 | void decorateLegend(QLegend *legend, ChartTheme* theme, bool force = false) const; | |||
|
58 | void updateSeries(QAbstractSeries *series); | |||
|
59 | ||||
|
60 | public: | |||
|
61 | static QList<QGradient> generateSeriesGradients(const QList<QColor>& colors); | |||
|
62 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); | |||
|
63 | static QColor colorAt(const QGradient &gradient, qreal pos); | |||
|
64 | ||||
|
65 | private: | |||
|
66 | int createIndexKey(QList<int> keys) const; | |||
|
67 | int seriesCount(QAbstractSeries::SeriesType type) const; | |||
|
68 | ||||
|
69 | public Q_SLOTS: | |||
|
70 | void handleSeriesAdded(QAbstractSeries *series); | |||
|
71 | void handleSeriesRemoved(QAbstractSeries *series); | |||
|
72 | void handleAxisAdded(QAbstractAxis *axis); | |||
|
73 | void handleAxisRemoved(QAbstractAxis *axis); | |||
|
74 | ||||
|
75 | protected: | |||
|
76 | QScopedPointer<ChartTheme> m_theme; | |||
|
77 | QMap<QAbstractSeries *,int> m_seriesMap; | |||
|
78 | QList<QAbstractAxis *> m_axisList; | |||
|
79 | QChart* m_chart; | |||
|
80 | }; | |||
|
81 | ||||
|
82 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
83 | ||||
|
84 | #endif // CHARTTHEME_H |
@@ -25,11 +25,11 Widget::Widget(QWidget *parent) | |||||
25 | QValueAxis *axisX = new QValueAxis; |
|
25 | QValueAxis *axisX = new QValueAxis; | |
26 | axisX->setRange(0, 2000); |
|
26 | axisX->setRange(0, 2000); | |
27 | axisX->setLabelFormat("%g"); |
|
27 | axisX->setLabelFormat("%g"); | |
28 | axisX->setTitle("Samples"); |
|
28 | axisX->setTitleText("Samples"); | |
29 | QValueAxis *axisY = new QValueAxis; |
|
29 | QValueAxis *axisY = new QValueAxis; | |
30 | axisY->setRange(-1, 1); |
|
30 | axisY->setRange(-1, 1); | |
31 | axisY->setTitle("Audio level"); |
|
31 | axisY->setTitleText("Audio level"); | |
32 |
m_chart->setAxisX(axisX, m_series); |
|
32 | m_chart->setAxisX(axisX, m_series); | |
33 | m_chart->setAxisY(axisY, m_series); |
|
33 | m_chart->setAxisY(axisY, m_series); | |
34 | m_chart->legend()->hide(); |
|
34 | m_chart->legend()->hide(); | |
35 | m_chart->setTitle("Data from the microphone"); |
|
35 | m_chart->setTitle("Data from the microphone"); |
@@ -179,8 +179,6 QComboBox *ThemeWidget::createLegendBox() const | |||||
179 | QChart *ThemeWidget::createAreaChart() const |
|
179 | QChart *ThemeWidget::createAreaChart() const | |
180 | { |
|
180 | { | |
181 | QChart *chart = new QChart(); |
|
181 | QChart *chart = new QChart(); | |
182 | // chart->axisX()->setNiceNumbersEnabled(true); |
|
|||
183 | // chart->axisY()->setNiceNumbersEnabled(true); |
|
|||
184 | chart->setTitle("Area chart"); |
|
182 | chart->setTitle("Area chart"); | |
185 |
|
183 | |||
186 | // The lower series initialized to zero values |
|
184 | // The lower series initialized to zero values |
@@ -69,8 +69,8 class BarCategoryAxisXTitle: public BarCategoryAxisX | |||||
69 | QChart *createChart(const DataTable &table) |
|
69 | QChart *createChart(const DataTable &table) | |
70 | { |
|
70 | { | |
71 | QChart *chart = BarCategoryAxisX::createChart(table); |
|
71 | QChart *chart = BarCategoryAxisX::createChart(table); | |
72 | chart->axisX()->setTitle("Axis X"); |
|
72 | chart->axisX()->setTitleText("Axis X"); | |
73 | chart->axisY()->setTitle("Axis Y"); |
|
73 | chart->axisY()->setTitleText("Axis Y"); | |
74 | chart->setTitle(" BarCateogry X , Value Y, title"); |
|
74 | chart->setTitle(" BarCateogry X , Value Y, title"); | |
75 | return chart; |
|
75 | return chart; | |
76 | } |
|
76 | } |
@@ -73,8 +73,8 public: | |||||
73 | QChart *createChart(const DataTable &table) |
|
73 | QChart *createChart(const DataTable &table) | |
74 | { |
|
74 | { | |
75 | QChart *chart = BarCategoryAxisY::createChart(table); |
|
75 | QChart *chart = BarCategoryAxisY::createChart(table); | |
76 | chart->axisX()->setTitle("Axis X"); |
|
76 | chart->axisX()->setTitleText("Axis X"); | |
77 | chart->axisY()->setTitle("Axis Y"); |
|
77 | chart->axisY()->setTitleText("Axis Y"); | |
78 | chart->setTitle(" BarCateogry Y , Value X, title"); |
|
78 | chart->setTitle(" BarCateogry Y , Value X, title"); | |
79 | return chart; |
|
79 | return chart; | |
80 | } |
|
80 | } |
@@ -72,8 +72,8 public: | |||||
72 | QChart *createChart(const DataTable &table) |
|
72 | QChart *createChart(const DataTable &table) | |
73 | { |
|
73 | { | |
74 | QChart *chart = CategoryLineChart::createChart(table); |
|
74 | QChart *chart = CategoryLineChart::createChart(table); | |
75 | chart->axisX()->setTitle("Axis X"); |
|
75 | chart->axisX()->setTitleText("Axis X"); | |
76 | chart->axisY()->setTitle("Axis Y"); |
|
76 | chart->axisY()->setTitleText("Axis Y"); | |
77 | chart->setTitle("Category X , Category Y,title "); |
|
77 | chart->setTitle("Category X , Category Y,title "); | |
78 | return chart; |
|
78 | return chart; | |
79 | } |
|
79 | } |
@@ -69,8 +69,8 public: | |||||
69 | QChart *createChart(const DataTable &table) |
|
69 | QChart *createChart(const DataTable &table) | |
70 | { |
|
70 | { | |
71 | QChart *chart = DateTimeAxisX::createChart(table); |
|
71 | QChart *chart = DateTimeAxisX::createChart(table); | |
72 | chart->axisX()->setTitle("Axis X"); |
|
72 | chart->axisX()->setTitleText("Axis X"); | |
73 | chart->axisY()->setTitle("Axis Y"); |
|
73 | chart->axisY()->setTitleText("Axis Y"); | |
74 | chart->setTitle("DateTime X , Value Y, Title"); |
|
74 | chart->setTitle("DateTime X , Value Y, Title"); | |
75 | return chart; |
|
75 | return chart; | |
76 | } |
|
76 | } |
@@ -69,8 +69,8 public: | |||||
69 | QChart *createChart(const DataTable &table) |
|
69 | QChart *createChart(const DataTable &table) | |
70 | { |
|
70 | { | |
71 | QChart *chart = DateTimeAxisY::createChart(table); |
|
71 | QChart *chart = DateTimeAxisY::createChart(table); | |
72 | chart->axisX()->setTitle("Axis X"); |
|
72 | chart->axisX()->setTitleText("Axis X"); | |
73 | chart->axisY()->setTitle("Axis Y"); |
|
73 | chart->axisY()->setTitleText("Axis Y"); | |
74 | chart->setTitle("Value X , DateTime Y, Title"); |
|
74 | chart->setTitle("Value X , DateTime Y, Title"); | |
75 | return chart; |
|
75 | return chart; | |
76 | } |
|
76 | } |
@@ -64,8 +64,8 public: | |||||
64 | QChart *createChart(const DataTable &table) |
|
64 | QChart *createChart(const DataTable &table) | |
65 | { |
|
65 | { | |
66 | QChart *chart = ValueAxis::createChart(table); |
|
66 | QChart *chart = ValueAxis::createChart(table); | |
67 | chart->axisX()->setTitle("Axis X"); |
|
67 | chart->axisX()->setTitleText("Axis X"); | |
68 | chart->axisY()->setTitle("Axis Y"); |
|
68 | chart->axisY()->setTitleText("Axis Y"); | |
69 | chart->setTitle("Value X , Value Y, title"); |
|
69 | chart->setTitle("Value X , Value Y, title"); | |
70 | return chart; |
|
70 | return chart; | |
71 | } |
|
71 | } |
@@ -33,7 +33,7 public: | |||||
33 | QChart *createChart(const DataTable &table) |
|
33 | QChart *createChart(const DataTable &table) | |
34 | { |
|
34 | { | |
35 | QChart *chart = new QChart(); |
|
35 | QChart *chart = new QChart(); | |
36 |
chart->setTitle(" |
|
36 | chart->setTitle("Percent bar chart"); | |
37 | QPercentBarSeries *series = new QPercentBarSeries(chart); |
|
37 | QPercentBarSeries *series = new QPercentBarSeries(chart); | |
38 | for (int i(0); i < table.count(); i++) { |
|
38 | for (int i(0); i < table.count(); i++) { | |
39 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
39 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
@@ -50,8 +50,8 public: | |||||
50 | chart->setTitleFont(font); |
|
50 | chart->setTitleFont(font); | |
51 | chart->axisX()->setLabelsFont(font); |
|
51 | chart->axisX()->setLabelsFont(font); | |
52 | chart->axisY()->setLabelsFont(font); |
|
52 | chart->axisY()->setLabelsFont(font); | |
53 | chart->axisX()->setTitle("Axis X"); |
|
53 | chart->axisX()->setTitleText("Axis X"); | |
54 | chart->axisY()->setTitle("Axis Y"); |
|
54 | chart->axisY()->setTitleText("Axis Y"); | |
55 | chart->axisX()->setTitleFont(font); |
|
55 | chart->axisX()->setTitleFont(font); | |
56 | chart->axisY()->setTitleFont(font); |
|
56 | chart->axisY()->setTitleFont(font); | |
57 | return chart; |
|
57 | return chart; |
@@ -59,20 +59,14 public: | |||||
59 | chart->addSeries(series); |
|
59 | chart->addSeries(series); | |
60 | axisX = new QValueAxis(); |
|
60 | axisX = new QValueAxis(); | |
61 | axisX->setLinePenColor(series->pen().color()); |
|
61 | axisX->setLinePenColor(series->pen().color()); | |
62 | if (nameIndex % 2) |
|
|||
63 | axisX->setAlignment(Qt::AlignTop); |
|
|||
64 | else |
|
|||
65 | axisX->setAlignment(Qt::AlignBottom); |
|
|||
66 | axisY = new QValueAxis(); |
|
62 | axisY = new QValueAxis(); | |
67 | axisY->setLinePenColor(series->pen().color()); |
|
63 | axisY->setLinePenColor(series->pen().color()); | |
68 |
|
64 | |||
69 | if (nameIndex % 2) |
|
65 | chart->addAxis(axisX,nameIndex % 2?Qt::AlignTop:Qt::AlignBottom); | |
70 | axisY->setAlignment(Qt::AlignRight); |
|
66 | chart->addAxis(axisY,nameIndex % 2?Qt::AlignRight:Qt::AlignLeft); | |
71 | else |
|
67 | series->attachAxis(axisX); | |
72 | axisY->setAlignment(Qt::AlignLeft); |
|
68 | series->attachAxis(axisY); | |
73 |
|
69 | |||
74 | chart->setAxisX(axisX, series); |
|
|||
75 | chart->setAxisY(axisY, series); |
|
|||
76 | nameIndex++; |
|
70 | nameIndex++; | |
77 | } |
|
71 | } | |
78 |
|
72 |
@@ -59,20 +59,14 public: | |||||
59 | chart->addSeries(series); |
|
59 | chart->addSeries(series); | |
60 | axisX = new QValueAxis(); |
|
60 | axisX = new QValueAxis(); | |
61 | axisX->setLinePenColor(series->pen().color()); |
|
61 | axisX->setLinePenColor(series->pen().color()); | |
62 | if (nameIndex % 2) |
|
62 | ||
63 | axisX->setAlignment(Qt::AlignTop); |
|
|||
64 | else |
|
|||
65 | axisX->setAlignment(Qt::AlignBottom); |
|
|||
66 | axisY = new QValueAxis(); |
|
63 | axisY = new QValueAxis(); | |
67 | axisY->setLinePenColor(series->pen().color()); |
|
64 | axisY->setLinePenColor(series->pen().color()); | |
68 |
|
65 | |||
69 | if (nameIndex % 2) |
|
66 | chart->addAxis(axisX, nameIndex % 2?Qt::AlignTop:Qt::AlignBottom); | |
70 | axisY->setAlignment(Qt::AlignRight); |
|
67 | chart->addAxis(axisY, nameIndex % 2?Qt::AlignRight:Qt::AlignLeft); | |
71 | else |
|
68 | series->attachAxis(axisX); | |
72 | axisY->setAlignment(Qt::AlignLeft); |
|
69 | series->attachAxis(axisY); | |
73 |
|
||||
74 | chart->setAxisX(axisX, series); |
|
|||
75 | chart->setAxisY(axisY, series); |
|
|||
76 | nameIndex++; |
|
70 | nameIndex++; | |
77 | } |
|
71 | } | |
78 |
|
72 |
@@ -59,25 +59,16 public: | |||||
59 | chart->addSeries(series); |
|
59 | chart->addSeries(series); | |
60 | axisX = new QValueAxis(); |
|
60 | axisX = new QValueAxis(); | |
61 | axisX->setLinePenColor(series->pen().color()); |
|
61 | axisX->setLinePenColor(series->pen().color()); | |
62 | if (nameIndex % 2){ |
|
62 | axisX->setTitleText("ValueAxis for series" + QString::number(nameIndex)); | |
63 | axisX->setAlignment(Qt::AlignTop); |
|
|||
64 | } else{ |
|
|||
65 | axisX->setAlignment(Qt::AlignBottom); |
|
|||
66 | } |
|
|||
67 | axisX->setTitle("ValueAxis for series" + QString::number(nameIndex)); |
|
|||
68 |
|
63 | |||
69 | axisY = new QValueAxis(); |
|
64 | axisY = new QValueAxis(); | |
70 | axisY->setLinePenColor(series->pen().color()); |
|
65 | axisY->setLinePenColor(series->pen().color()); | |
|
66 | axisY->setTitleText("ValueAxis for series" + QString::number(nameIndex)); | |||
71 |
|
67 | |||
72 | if (nameIndex % 2){ |
|
68 | chart->addAxis(axisX, nameIndex % 2?Qt::AlignTop:Qt::AlignBottom); | |
73 | axisY->setAlignment(Qt::AlignRight); |
|
69 | chart->addAxis(axisY, nameIndex % 2?Qt::AlignRight:Qt::AlignLeft); | |
74 | }else{ |
|
70 | series->attachAxis(axisX); | |
75 | axisY->setAlignment(Qt::AlignLeft); |
|
71 | series->attachAxis(axisY); | |
76 | } |
|
|||
77 | axisY->setTitle("ValueAxis for series" + QString::number(nameIndex)); |
|
|||
78 |
|
||||
79 | chart->setAxisX(axisX, series); |
|
|||
80 | chart->setAxisY(axisY, series); |
|
|||
81 | nameIndex++; |
|
72 | nameIndex++; | |
82 | } |
|
73 | } | |
83 |
|
74 |
@@ -59,22 +59,15 public: | |||||
59 | chart->addSeries(series); |
|
59 | chart->addSeries(series); | |
60 | axisX = new QValueAxis(); |
|
60 | axisX = new QValueAxis(); | |
61 | axisX->setLinePenColor(series->pen().color()); |
|
61 | axisX->setLinePenColor(series->pen().color()); | |
62 | axisX->setTitle("ValueAxis for series" + QString::number(nameIndex)); |
|
62 | axisX->setTitleText("ValueAxis for series" + QString::number(nameIndex)); | |
63 | if (nameIndex % 2) |
|
|||
64 | axisX->setAlignment(Qt::AlignTop); |
|
|||
65 | else |
|
|||
66 | axisX->setAlignment(Qt::AlignBottom); |
|
|||
67 | axisY = new QValueAxis(); |
|
63 | axisY = new QValueAxis(); | |
68 | axisY->setLinePenColor(series->pen().color()); |
|
64 | axisY->setLinePenColor(series->pen().color()); | |
69 | axisY->setTitle("ValueAxis for series" + QString::number(nameIndex)); |
|
65 | axisY->setTitleText("ValueAxis for series" + QString::number(nameIndex)); | |
70 |
|
66 | |||
71 | if (nameIndex % 2) |
|
67 | chart->addAxis(axisX, nameIndex % 2?Qt::AlignTop:Qt::AlignBottom); | |
72 | axisY->setAlignment(Qt::AlignRight); |
|
68 | chart->addAxis(axisY, nameIndex % 2?Qt::AlignRight:Qt::AlignLeft); | |
73 | else |
|
69 | series->attachAxis(axisX); | |
74 | axisY->setAlignment(Qt::AlignLeft); |
|
70 | series->attachAxis(axisY); | |
75 |
|
||||
76 | chart->setAxisX(axisX, series); |
|
|||
77 | chart->setAxisY(axisY, series); |
|
|||
78 | nameIndex++; |
|
71 | nameIndex++; | |
79 | } |
|
72 | } | |
80 |
|
73 |
@@ -64,22 +64,16 public: | |||||
64 | chart->addSeries(series); |
|
64 | chart->addSeries(series); | |
65 | axisX = new QValueAxis(); |
|
65 | axisX = new QValueAxis(); | |
66 | axisX->setLinePenColor(series->pen().color()); |
|
66 | axisX->setLinePenColor(series->pen().color()); | |
67 | axisX->setTitle("ValueAxis for series" + QString::number(nameIndex)); |
|
67 | axisX->setTitleText("ValueAxis for series" + QString::number(nameIndex)); | |
68 | if (nameIndex % 2) |
|
68 | ||
69 | axisX->setAlignment(Qt::AlignTop); |
|
|||
70 | else |
|
|||
71 | axisX->setAlignment(Qt::AlignBottom); |
|
|||
72 | axisY = new QValueAxis(); |
|
69 | axisY = new QValueAxis(); | |
73 | axisY->setLinePenColor(series->pen().color()); |
|
70 | axisY->setLinePenColor(series->pen().color()); | |
74 | axisY->setTitle("ValueAxis for series" + QString::number(nameIndex)); |
|
71 | axisY->setTitleText("ValueAxis for series" + QString::number(nameIndex)); | |
75 |
|
||||
76 | if (nameIndex % 2) |
|
|||
77 | axisY->setAlignment(Qt::AlignRight); |
|
|||
78 | else |
|
|||
79 | axisY->setAlignment(Qt::AlignLeft); |
|
|||
80 |
|
72 | |||
81 | chart->setAxisX(axisX, series); |
|
73 | chart->addAxis(axisX, nameIndex % 2?Qt::AlignTop:Qt::AlignBottom); | |
82 | chart->setAxisY(axisY, series); |
|
74 | chart->addAxis(axisY, nameIndex % 2?Qt::AlignRight:Qt::AlignLeft); | |
|
75 | series->attachAxis(axisX); | |||
|
76 | series->attachAxis(axisY); | |||
83 | nameIndex++; |
|
77 | nameIndex++; | |
84 | } |
|
78 | } | |
85 |
|
79 | |||
@@ -96,7 +90,7 public: | |||||
96 |
|
90 | |||
97 | barcategory->setLinePen(set->brush().color()); |
|
91 | barcategory->setLinePen(set->brush().color()); | |
98 | barcategory->setGridLinePen(set->brush().color()); |
|
92 | barcategory->setGridLinePen(set->brush().color()); | |
99 | barcategory->setTitle("BarCategoryAxis Title"); |
|
93 | barcategory->setTitleText("BarCategoryAxis Title"); | |
100 |
|
94 | |||
101 | chart->setAxisX(barcategory, series); |
|
95 | chart->setAxisX(barcategory, series); | |
102 |
|
96 |
@@ -69,7 +69,7 int main(int argc, char *argv[]) | |||||
69 | QBarCategoryAxis *axis = new QBarCategoryAxis(); |
|
69 | QBarCategoryAxis *axis = new QBarCategoryAxis(); | |
70 | axis->append(categories); |
|
70 | axis->append(categories); | |
71 | chart->createDefaultAxes(); |
|
71 | chart->createDefaultAxes(); | |
72 | chart->setAxisX(axis, series); |
|
72 | // chart->setAxisX(axis, series); | |
73 | //![4] |
|
73 | //![4] | |
74 |
|
74 | |||
75 | //![5] |
|
75 | //![5] |
@@ -74,9 +74,9 int main(int argc, char *argv[]) | |||||
74 | QDateTimeAxis *axisX = new QDateTimeAxis; |
|
74 | QDateTimeAxis *axisX = new QDateTimeAxis; | |
75 | axisX->setTickCount(10); |
|
75 | axisX->setTickCount(10); | |
76 | axisX->setFormat("MMM yyyy"); |
|
76 | axisX->setFormat("MMM yyyy"); | |
77 | axisX->setTitle("Date"); |
|
77 | axisX->setTitleText("Date"); | |
78 | chart->setAxisX(axisX, series); |
|
78 | chart->setAxisX(axisX, series); | |
79 | chart->axisY(series)->setTitle("Sunspots count"); |
|
79 | chart->axisY(series)->setTitleText("Sunspots count"); | |
80 | //![4] |
|
80 | //![4] | |
81 |
|
81 | |||
82 | //![5] |
|
82 | //![5] |
@@ -49,23 +49,14 int main(int argc, char *argv[]) | |||||
49 | axisX->setTickCount(7 + i); |
|
49 | axisX->setTickCount(7 + i); | |
50 | axisX->setLinePenColor(series->pen().color()); |
|
50 | axisX->setLinePenColor(series->pen().color()); | |
51 |
|
51 | |||
52 | if (i % 2) |
|
|||
53 | axisX->setAlignment(Qt::AlignTop); |
|
|||
54 | else |
|
|||
55 | axisX->setAlignment(Qt::AlignBottom); |
|
|||
56 |
|
||||
57 | axisY = new QValueAxis; |
|
52 | axisY = new QValueAxis; | |
58 | axisY->setTickCount(7 + i); |
|
53 | axisY->setTickCount(7 + i); | |
59 | axisY->setLinePenColor(series->pen().color()); |
|
54 | axisY->setLinePenColor(series->pen().color()); | |
60 |
|
55 | |||
61 | if (i % 2) |
|
56 | chart->addAxis(axisX,i % 2?Qt::AlignTop:Qt::AlignBottom); | |
62 | axisY->setAlignment(Qt::AlignRight); |
|
57 | chart->addAxis(axisY,i % 2?Qt::AlignRight:Qt::AlignLeft); | |
63 | else |
|
58 | series->attachAxis(axisX); | |
64 | axisY->setAlignment(Qt::AlignLeft); |
|
59 | series->attachAxis(axisY); | |
65 |
|
||||
66 |
|
||||
67 | chart->setAxisX(axisX, series); |
|
|||
68 | chart->setAxisY(axisY, series); |
|
|||
69 | } |
|
60 | } | |
70 | //![2] |
|
61 | //![2] | |
71 |
|
62 |
@@ -45,7 +45,7 void DrilldownChart::changeSeries(DrilldownBarSeries *series) | |||||
45 |
|
45 | |||
46 | createDefaultAxes(); |
|
46 | createDefaultAxes(); | |
47 | setAxisX(axis, series); |
|
47 | setAxisX(axis, series); | |
48 | axisY()->setTitle("Crops"); |
|
48 | axisY()->setTitleText("Crops"); | |
49 |
|
49 | |||
50 | setTitle(series->name()); |
|
50 | setTitle(series->name()); | |
51 | } |
|
51 | } |
@@ -60,11 +60,11 int main(int argc, char *argv[]) | |||||
60 |
|
60 | |||
61 | QBarCategoryAxis *axis = new QBarCategoryAxis(); |
|
61 | QBarCategoryAxis *axis = new QBarCategoryAxis(); | |
62 | axis->append(categories); |
|
62 | axis->append(categories); | |
63 | axis->setTitle("Month"); |
|
63 | axis->setTitleText("Month"); | |
64 | chart->createDefaultAxes(); |
|
64 | chart->createDefaultAxes(); | |
65 | chart->setAxisX(axis, series); |
|
65 | chart->setAxisX(axis, series); | |
66 | chart->axisY(series)->setRange(-52, 52); |
|
66 | chart->axisY(series)->setRange(-52, 52); | |
67 | chart->axisY(series)->setTitle(QString::fromUtf8("Temperature [\u00B0C]")); |
|
67 | chart->axisY(series)->setTitleText(QString::fromUtf8("Temperature [\u00B0C]")); | |
68 | //![4] |
|
68 | //![4] | |
69 |
|
69 | |||
70 | //![5] |
|
70 | //![5] |
@@ -32,6 +32,7 | |||||
32 | #include "qcategoryaxis.h" |
|
32 | #include "qcategoryaxis.h" | |
33 | #include "qabstractseries_p.h" |
|
33 | #include "qabstractseries_p.h" | |
34 | #include "declarativemargins.h" |
|
34 | #include "declarativemargins.h" | |
|
35 | #include "chartdataset_p.h" | |||
35 | #include "qchart_p.h" |
|
36 | #include "qchart_p.h" | |
36 |
|
37 | |||
37 | #ifndef QT_ON_ARM |
|
38 | #ifndef QT_ON_ARM |
@@ -33,8 +33,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
33 |
|
33 | |||
34 | //TODO: optimize : remove points which are not visible |
|
34 | //TODO: optimize : remove points which are not visible | |
35 |
|
35 | |||
36 |
AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, |
|
36 | AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item) | |
37 | : ChartItem(presenter), |
|
37 | : ChartItem(areaSeries->d_func(),item), //TODO: fix me | |
38 | m_series(areaSeries), |
|
38 | m_series(areaSeries), | |
39 | m_upper(0), |
|
39 | m_upper(0), | |
40 | m_lower(0), |
|
40 | m_lower(0), | |
@@ -42,9 +42,9 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, ChartPresenter *presenter) | |||||
42 | { |
|
42 | { | |
43 | setAcceptHoverEvents(true); |
|
43 | setAcceptHoverEvents(true); | |
44 | setZValue(ChartPresenter::LineChartZValue); |
|
44 | setZValue(ChartPresenter::LineChartZValue); | |
45 |
m_upper = new AreaBoundItem(this, m_series->upperSeries() |
|
45 | m_upper = new AreaBoundItem(this, m_series->upperSeries()); | |
46 | if (m_series->lowerSeries()) |
|
46 | if (m_series->lowerSeries()) | |
47 |
m_lower = new AreaBoundItem(this, m_series->lowerSeries() |
|
47 | m_lower = new AreaBoundItem(this, m_series->lowerSeries()); | |
48 |
|
48 | |||
49 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated())); |
|
49 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated())); | |
50 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); |
|
50 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |
@@ -61,6 +61,15 AreaChartItem::~AreaChartItem() | |||||
61 | delete m_lower; |
|
61 | delete m_lower; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
|
64 | void AreaChartItem::setPresenter(ChartPresenter *presenter) | |||
|
65 | { | |||
|
66 | m_upper->setPresenter(presenter); | |||
|
67 | if (m_lower) { | |||
|
68 | m_lower->setPresenter(presenter); | |||
|
69 | } | |||
|
70 | ChartItem::setPresenter(presenter); | |||
|
71 | } | |||
|
72 | ||||
64 | QRectF AreaChartItem::boundingRect() const |
|
73 | QRectF AreaChartItem::boundingRect() const | |
65 | { |
|
74 | { | |
66 | return m_rect; |
|
75 | return m_rect; | |
@@ -74,6 +83,7 QPainterPath AreaChartItem::shape() const | |||||
74 | void AreaChartItem::updatePath() |
|
83 | void AreaChartItem::updatePath() | |
75 | { |
|
84 | { | |
76 | QPainterPath path; |
|
85 | QPainterPath path; | |
|
86 | QRectF rect(QPointF(0,0),domain()->size()); | |||
77 |
|
87 | |||
78 | path = m_upper->path(); |
|
88 | path = m_upper->path(); | |
79 |
|
89 | |||
@@ -82,8 +92,8 void AreaChartItem::updatePath() | |||||
82 | } else { |
|
92 | } else { | |
83 | QPointF first = path.pointAtPercent(0); |
|
93 | QPointF first = path.pointAtPercent(0); | |
84 | QPointF last = path.pointAtPercent(1); |
|
94 | QPointF last = path.pointAtPercent(1); | |
85 |
path.lineTo(last.x(), |
|
95 | path.lineTo(last.x(), rect.bottom()); | |
86 |
path.lineTo(first.x(), |
|
96 | path.lineTo(first.x(), rect.bottom()); | |
87 | } |
|
97 | } | |
88 | path.closeSubpath(); |
|
98 | path.closeSubpath(); | |
89 | prepareGeometryChange(); |
|
99 | prepareGeometryChange(); | |
@@ -101,38 +111,33 void AreaChartItem::handleUpdated() | |||||
101 | m_pointPen = m_series->pen(); |
|
111 | m_pointPen = m_series->pen(); | |
102 | m_pointPen.setWidthF(2 * m_pointPen.width()); |
|
112 | m_pointPen.setWidthF(2 * m_pointPen.width()); | |
103 | setOpacity(m_series->opacity()); |
|
113 | setOpacity(m_series->opacity()); | |
104 |
|
||||
105 | update(); |
|
114 | update(); | |
106 | } |
|
115 | } | |
107 |
|
116 | |||
108 | void AreaChartItem::handleDomainUpdated() |
|
117 | void AreaChartItem::handleDomainUpdated() | |
109 | { |
|
118 | { | |
110 |
|
|
119 | Domain* d = m_upper->domain().data(); | |
111 | m_upper->handleDomainUpdated(); |
|
120 | ||
|
121 | d->setSize(domain()->size()); | |||
|
122 | d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY()); | |||
|
123 | m_upper->handleDomainUpdated(); | |||
|
124 | ||||
112 | if (m_lower) { |
|
125 | if (m_lower) { | |
113 |
|
|
126 | Domain* d = m_lower->domain().data(); | |
114 | m_lower->handleDomainUpdated(); |
|
127 | d->setSize(domain()->size()); | |
|
128 | d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY()); | |||
|
129 | m_lower->handleDomainUpdated(); | |||
115 | } |
|
130 | } | |
116 | } |
|
131 | } | |
117 |
|
132 | |||
118 | void AreaChartItem::handleGeometryChanged(const QRectF &rect) |
|
|||
119 | { |
|
|||
120 | m_clipRect = rect.translated(-rect.topLeft()); |
|
|||
121 | setPos(rect.topLeft()); |
|
|||
122 | m_upper->handleGeometryChanged(rect); |
|
|||
123 | if (m_lower) |
|
|||
124 | m_lower->handleGeometryChanged(rect); |
|
|||
125 | } |
|
|||
126 |
|
||||
127 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
133 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
128 | { |
|
134 | { | |
129 | Q_UNUSED(widget) |
|
135 | Q_UNUSED(widget) | |
130 | Q_UNUSED(option) |
|
136 | Q_UNUSED(option) | |
131 |
|
||||
132 | painter->save(); |
|
137 | painter->save(); | |
133 | painter->setPen(m_linePen); |
|
138 | painter->setPen(m_linePen); | |
134 | painter->setBrush(m_brush); |
|
139 | painter->setBrush(m_brush); | |
135 |
painter->setClipRect( |
|
140 | painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); | |
136 | painter->drawPath(m_path); |
|
141 | painter->drawPath(m_path); | |
137 | if (m_pointsVisible) { |
|
142 | if (m_pointsVisible) { | |
138 | painter->setPen(m_pointPen); |
|
143 | painter->setPen(m_pointPen); | |
@@ -145,20 +150,20 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt | |||||
145 |
|
150 | |||
146 | void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
151 | void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
147 | { |
|
152 | { | |
148 | emit clicked(m_upper->calculateDomainPoint(event->pos())); |
|
153 | emit clicked(m_upper->domain()->calculateDomainPoint(event->pos())); | |
149 | ChartItem::mousePressEvent(event); |
|
154 | ChartItem::mousePressEvent(event); | |
150 | } |
|
155 | } | |
151 |
|
156 | |||
152 | void AreaChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
157 | void AreaChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
153 | { |
|
158 | { | |
154 |
emit hovered( |
|
159 | emit hovered(domain()->calculateDomainPoint(event->pos()), true); | |
155 | event->accept(); |
|
160 | event->accept(); | |
156 | // QGraphicsItem::hoverEnterEvent(event); |
|
161 | // QGraphicsItem::hoverEnterEvent(event); | |
157 | } |
|
162 | } | |
158 |
|
163 | |||
159 | void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
164 | void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
160 | { |
|
165 | { | |
161 |
emit hovered( |
|
166 | emit hovered(domain()->calculateDomainPoint(event->pos()), false); | |
162 | event->accept(); |
|
167 | event->accept(); | |
163 | // QGraphicsItem::hoverEnterEvent(event); |
|
168 | // QGraphicsItem::hoverEnterEvent(event); | |
164 | } |
|
169 | } |
@@ -43,7 +43,7 class AreaChartItem : public ChartItem | |||||
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 | public: |
|
45 | public: | |
46 |
AreaChartItem(QAreaSeries *areaSeries, |
|
46 | AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item = 0); | |
47 | ~AreaChartItem(); |
|
47 | ~AreaChartItem(); | |
48 |
|
48 | |||
49 | //from QGraphicsItem |
|
49 | //from QGraphicsItem | |
@@ -56,6 +56,7 public: | |||||
56 |
|
56 | |||
57 | void updatePath(); |
|
57 | void updatePath(); | |
58 |
|
58 | |||
|
59 | void setPresenter(ChartPresenter *presenter); | |||
59 | protected: |
|
60 | protected: | |
60 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
61 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
61 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
|
62 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
@@ -68,7 +69,6 Q_SIGNALS: | |||||
68 | public Q_SLOTS: |
|
69 | public Q_SLOTS: | |
69 | void handleUpdated(); |
|
70 | void handleUpdated(); | |
70 | void handleDomainUpdated(); |
|
71 | void handleDomainUpdated(); | |
71 | void handleGeometryChanged(const QRectF &size); |
|
|||
72 |
|
72 | |||
73 | private: |
|
73 | private: | |
74 | QAreaSeries *m_series; |
|
74 | QAreaSeries *m_series; | |
@@ -76,7 +76,6 private: | |||||
76 | LineChartItem *m_lower; |
|
76 | LineChartItem *m_lower; | |
77 | QPainterPath m_path; |
|
77 | QPainterPath m_path; | |
78 | QRectF m_rect; |
|
78 | QRectF m_rect; | |
79 | QRectF m_clipRect; |
|
|||
80 | QPen m_linePen; |
|
79 | QPen m_linePen; | |
81 | QPen m_pointPen; |
|
80 | QPen m_pointPen; | |
82 | QBrush m_brush; |
|
81 | QBrush m_brush; | |
@@ -87,14 +86,13 private: | |||||
87 | class AreaBoundItem : public LineChartItem |
|
86 | class AreaBoundItem : public LineChartItem | |
88 | { |
|
87 | { | |
89 | public: |
|
88 | public: | |
90 |
AreaBoundItem(AreaChartItem * |
|
89 | AreaBoundItem(AreaChartItem *area, QLineSeries *lineSeries,QGraphicsItem* item = 0) | |
91 |
: LineChartItem(lineSeries, |
|
90 | : LineChartItem(lineSeries, item), m_item(area) | |
92 | { |
|
91 | { | |
93 | setPresenter(presenter); |
|
|||
94 | } |
|
92 | } | |
95 | ~AreaBoundItem() {} |
|
93 | ~AreaBoundItem() {} | |
96 |
|
94 | |||
97 |
void updateGeometry() |
|
95 | void updateGeometry() | |
98 | { |
|
96 | { | |
99 | LineChartItem::updateGeometry(); |
|
97 | LineChartItem::updateGeometry(); | |
100 | m_item->updatePath(); |
|
98 | m_item->updatePath(); |
@@ -27,6 +27,7 | |||||
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "qvalueaxis.h" |
|
28 | #include "qvalueaxis.h" | |
29 | #include "qarealegendmarker.h" |
|
29 | #include "qarealegendmarker.h" | |
|
30 | #include "qchart_p.h" | |||
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
33 | |||
@@ -180,8 +181,8 QAreaSeries::QAreaSeries(QObject *parent) | |||||
180 | QAreaSeries::~QAreaSeries() |
|
181 | QAreaSeries::~QAreaSeries() | |
181 | { |
|
182 | { | |
182 | Q_D(QAreaSeries); |
|
183 | Q_D(QAreaSeries); | |
183 |
if (d->m_ |
|
184 | if (d->m_chart) | |
184 |
d->m_ |
|
185 | d->m_chart->removeSeries(this); | |
185 | } |
|
186 | } | |
186 |
|
187 | |||
187 | /*! |
|
188 | /*! | |
@@ -198,7 +199,10 QAbstractSeries::SeriesType QAreaSeries::type() const | |||||
198 | void QAreaSeries::setUpperSeries(QLineSeries *series) |
|
199 | void QAreaSeries::setUpperSeries(QLineSeries *series) | |
199 | { |
|
200 | { | |
200 | Q_D(QAreaSeries); |
|
201 | Q_D(QAreaSeries); | |
201 |
d->m_upperSeries |
|
202 | if(d->m_upperSeries!=series){ | |
|
203 | d->m_upperSeries = series; | |||
|
204 | //TODO: | |||
|
205 | } | |||
202 | } |
|
206 | } | |
203 |
|
207 | |||
204 | QLineSeries *QAreaSeries::upperSeries() const |
|
208 | QLineSeries *QAreaSeries::upperSeries() const | |
@@ -322,14 +326,14 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lo | |||||
322 | { |
|
326 | { | |
323 | } |
|
327 | } | |
324 |
|
328 | |||
325 |
void QAreaSeriesPrivate:: |
|
329 | void QAreaSeriesPrivate::initializeDomain() | |
326 | { |
|
330 | { | |
327 | Q_Q(QAreaSeries); |
|
331 | Q_Q(QAreaSeries); | |
328 |
|
332 | |||
329 |
qreal minX(domain |
|
333 | qreal minX(domain()->minX()); | |
330 |
qreal minY(domain |
|
334 | qreal minY(domain()->minY()); | |
331 |
qreal maxX(domain |
|
335 | qreal maxX(domain()->maxX()); | |
332 |
qreal maxY(domain |
|
336 | qreal maxY(domain()->maxY()); | |
333 |
|
337 | |||
334 | QLineSeries *upperSeries = q->upperSeries(); |
|
338 | QLineSeries *upperSeries = q->upperSeries(); | |
335 | QLineSeries *lowerSeries = q->lowerSeries(); |
|
339 | QLineSeries *lowerSeries = q->lowerSeries(); | |
@@ -358,21 +362,30 void QAreaSeriesPrivate::scaleDomain(Domain &domain) | |||||
358 | } |
|
362 | } | |
359 | } |
|
363 | } | |
360 |
|
364 | |||
361 |
domain |
|
365 | domain()->setRange(minX, maxX, minY, maxY); | |
362 | } |
|
366 | } | |
363 |
|
367 | |||
364 | ChartElement *QAreaSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
368 | void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
365 | { |
|
369 | { | |
366 | Q_Q(QAreaSeries); |
|
370 | Q_Q(QAreaSeries); | |
367 |
|
371 | AreaChartItem *area = new AreaChartItem(q,parent); | ||
368 | AreaChartItem *area = new AreaChartItem(q, presenter); |
|
372 | m_item.reset(area); | |
369 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
373 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
|
374 | } | |||
|
375 | void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) | |||
|
376 | { | |||
|
377 | Q_Q(QAreaSeries); | |||
|
378 | AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data()); | |||
|
379 | if (options.testFlag(QChart::SeriesAnimations)) { | |||
370 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
380 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); | |
371 | if (q->lowerSeries()) |
|
381 | if (q->lowerSeries()) | |
372 |
|
|
382 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); | |
|
383 | }else{ | |||
|
384 | area->upperLineItem()->setAnimation(0); | |||
|
385 | if (q->lowerSeries()) | |||
|
386 | area->lowerLineItem()->setAnimation(0); | |||
373 | } |
|
387 | } | |
374 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
388 | QAbstractSeriesPrivate::initializeAnimations(options); | |
375 | return area; |
|
|||
376 | } |
|
389 | } | |
377 |
|
390 | |||
378 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
391 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) | |
@@ -382,9 +395,10 QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) | |||||
382 | return list << new QAreaLegendMarker(q,legend); |
|
395 | return list << new QAreaLegendMarker(q,legend); | |
383 | } |
|
396 | } | |
384 |
|
397 | |||
385 | void QAreaSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
398 | ||
|
399 | void QAreaSeriesPrivate::initializeAxes() | |||
386 | { |
|
400 | { | |
387 | Q_UNUSED(axis); |
|
401 | ||
388 | } |
|
402 | } | |
389 |
|
403 | |||
390 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
404 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
@@ -393,6 +407,34 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orie | |||||
393 | return QAbstractAxis::AxisTypeValue; |
|
407 | return QAbstractAxis::AxisTypeValue; | |
394 | } |
|
408 | } | |
395 |
|
409 | |||
|
410 | QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |||
|
411 | { | |||
|
412 | Q_UNUSED(orientation); | |||
|
413 | return 0; | |||
|
414 | } | |||
|
415 | ||||
|
416 | void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |||
|
417 | { | |||
|
418 | Q_Q(QAreaSeries); | |||
|
419 | QPen pen; | |||
|
420 | QBrush brush; | |||
|
421 | ||||
|
422 | const QList<QGradient> gradients = theme->seriesGradients(); | |||
|
423 | const QList<QColor> colors = theme->seriesColors(); | |||
|
424 | ||||
|
425 | if (forced || pen == m_pen) { | |||
|
426 | pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); | |||
|
427 | pen.setWidthF(2); | |||
|
428 | q->setPen(pen); | |||
|
429 | } | |||
|
430 | ||||
|
431 | if (forced || brush == m_brush) { | |||
|
432 | QBrush brush(colors.at(index % colors.size())); | |||
|
433 | q->setBrush(brush); | |||
|
434 | } | |||
|
435 | } | |||
|
436 | ||||
|
437 | ||||
396 | #include "moc_qareaseries.cpp" |
|
438 | #include "moc_qareaseries.cpp" | |
397 | #include "moc_qareaseries_p.cpp" |
|
439 | #include "moc_qareaseries_p.cpp" | |
398 |
|
440 |
@@ -43,12 +43,16 class QAreaSeriesPrivate: public QAbstractSeriesPrivate | |||||
43 | public: |
|
43 | public: | |
44 | QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q); |
|
44 | QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q); | |
45 |
|
45 | |||
46 |
void |
|
46 | void initializeDomain(); | |
47 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
47 | void initializeAxes(); | |
48 | QList<QLegendMarker*> createLegendMarkers(QLegend* legend); |
|
48 | void initializeGraphics(QGraphicsItem* parent); | |
49 | void initializeAxis(QAbstractAxis *axis); |
|
49 | void initializeTheme(int index, ChartTheme* theme, bool forced = false); | |
|
50 | void initializeAnimations(QChart::AnimationOptions options); | |||
|
51 | ||||
|
52 | QList<QLegendMarker *> createLegendMarkers(QLegend *legend); | |||
50 |
|
53 | |||
51 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
54 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
|
55 | QAbstractAxis* createDefaultAxis(Qt::Orientation) const; | |||
52 |
|
56 | |||
53 | Q_SIGNALS: |
|
57 | Q_SIGNALS: | |
54 | void updated(); |
|
58 | void updated(); |
@@ -27,8 +27,8 | |||||
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 |
ChartBarCategoryAxisX::ChartBarCategoryAxisX(QBarCategoryAxis *axis, |
|
30 | ChartBarCategoryAxisX::ChartBarCategoryAxisX(QBarCategoryAxis *axis, QGraphicsItem* item) | |
31 |
: HorizontalAxis(axis, |
|
31 | : HorizontalAxis(axis, item, true), | |
32 | m_categoriesAxis(axis) |
|
32 | m_categoriesAxis(axis) | |
33 | { |
|
33 | { | |
34 |
|
34 | |||
@@ -93,12 +93,15 void ChartBarCategoryAxisX::updateGeometry() | |||||
93 |
|
93 | |||
94 | void ChartBarCategoryAxisX::handleAxisUpdated() |
|
94 | void ChartBarCategoryAxisX::handleAxisUpdated() | |
95 | { |
|
95 | { | |
|
96 | //TODO: | |||
|
97 | /* | |||
96 | if (m_categoriesAxis->categories() != m_categories) { |
|
98 | if (m_categoriesAxis->categories() != m_categories) { | |
97 | m_categories = m_categoriesAxis->categories(); |
|
99 | m_categories = m_categoriesAxis->categories(); | |
98 | if (ChartAxis::layout().count() == m_categoriesAxis->d_ptr->count() + 2) |
|
100 | if (ChartAxis::layout().count() == m_categoriesAxis->d_ptr->count() + 2) | |
99 | updateGeometry(); |
|
101 | updateGeometry(); | |
100 | } |
|
102 | } | |
101 | ChartAxis::handleAxisUpdated(); |
|
103 | */ | |
|
104 | //TODO: ChartAxis::handleAxisUpdated(); | |||
102 | } |
|
105 | } | |
103 |
|
106 | |||
104 | QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
107 | QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
@@ -40,7 +40,7 class QBarCategoryAxis; | |||||
40 | class ChartBarCategoryAxisX : public HorizontalAxis |
|
40 | class ChartBarCategoryAxisX : public HorizontalAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 |
ChartBarCategoryAxisX(QBarCategoryAxis *axis, |
|
43 | ChartBarCategoryAxisX(QBarCategoryAxis *axis, QGraphicsItem* item = 0); | |
44 | ~ChartBarCategoryAxisX(); |
|
44 | ~ChartBarCategoryAxisX(); | |
45 |
|
45 | |||
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
|
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
@@ -27,8 +27,8 | |||||
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 |
ChartBarCategoryAxisY::ChartBarCategoryAxisY(QBarCategoryAxis *axis, |
|
30 | ChartBarCategoryAxisY::ChartBarCategoryAxisY(QBarCategoryAxis *axis, QGraphicsItem* item) | |
31 |
: VerticalAxis(axis, |
|
31 | : VerticalAxis(axis, item, true), | |
32 | m_categoriesAxis(axis) |
|
32 | m_categoriesAxis(axis) | |
33 | { |
|
33 | { | |
34 | } |
|
34 | } | |
@@ -91,13 +91,14 void ChartBarCategoryAxisY::updateGeometry() | |||||
91 |
|
91 | |||
92 | void ChartBarCategoryAxisY::handleAxisUpdated() |
|
92 | void ChartBarCategoryAxisY::handleAxisUpdated() | |
93 | { |
|
93 | { | |
94 |
|
94 | //TODO: | ||
|
95 | /* | |||
95 | if (m_categoriesAxis->categories() != m_categories) { |
|
96 | if (m_categoriesAxis->categories() != m_categories) { | |
96 | m_categories = m_categoriesAxis->categories(); |
|
97 | m_categories = m_categoriesAxis->categories(); | |
97 | if (ChartAxis::layout().count() == m_categoriesAxis->d_ptr->count() + 2) |
|
98 | if (ChartAxis::layout().count() == m_categoriesAxis->d_ptr->count() + 2) | |
98 | updateGeometry(); |
|
99 | updateGeometry(); | |
99 |
|
|
100 | }*/ | |
100 | ChartAxis::handleAxisUpdated(); |
|
101 | //TODO :: ChartAxis::handleAxisUpdated(); | |
101 | } |
|
102 | } | |
102 |
|
103 | |||
103 | QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
104 | QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
@@ -40,7 +40,7 class ChartPresenter; | |||||
40 | class ChartBarCategoryAxisY : public VerticalAxis |
|
40 | class ChartBarCategoryAxisY : public VerticalAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 |
ChartBarCategoryAxisY(QBarCategoryAxis *axis, |
|
43 | ChartBarCategoryAxisY(QBarCategoryAxis *axis, QGraphicsItem* item = 0); | |
44 | ~ChartBarCategoryAxisY(); |
|
44 | ~ChartBarCategoryAxisY(); | |
45 |
|
45 | |||
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
|
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
@@ -23,7 +23,7 | |||||
23 | #include "chartbarcategoryaxisx_p.h" |
|
23 | #include "chartbarcategoryaxisx_p.h" | |
24 | #include "chartbarcategoryaxisy_p.h" |
|
24 | #include "chartbarcategoryaxisy_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 |
#include "chart |
|
26 | #include "qchart.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
@@ -87,7 +87,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
87 | Defines the minimum value on the axis. |
|
87 | Defines the minimum value on the axis. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 |
\qmlproperty QString Bar |
|
90 | \qmlproperty QString Bar if (d->m_chart) | |
|
91 | d->m_chart->removeAxis(this);CategoryAxis::min | |||
91 | Defines the minimum value on the axis. |
|
92 | Defines the minimum value on the axis. | |
92 | */ |
|
93 | */ | |
93 |
|
94 | |||
@@ -160,8 +161,8 QBarCategoryAxis::QBarCategoryAxis(QObject *parent): | |||||
160 | QBarCategoryAxis::~QBarCategoryAxis() |
|
161 | QBarCategoryAxis::~QBarCategoryAxis() | |
161 | { |
|
162 | { | |
162 | Q_D(QBarCategoryAxis); |
|
163 | Q_D(QBarCategoryAxis); | |
163 |
if (d->m_ |
|
164 | if (d->m_chart) | |
164 |
d->m_ |
|
165 | d->m_chart->removeAxis(this); | |
165 | } |
|
166 | } | |
166 |
|
167 | |||
167 | /*! |
|
168 | /*! | |
@@ -248,7 +249,7 void QBarCategoryAxis::remove(const QString &category) | |||||
248 | setRange(d->m_minCategory, d->m_categories.last()); |
|
249 | setRange(d->m_minCategory, d->m_categories.last()); | |
249 | } else { |
|
250 | } else { | |
250 | d->updateCategoryDomain(); |
|
251 | d->updateCategoryDomain(); | |
251 | d->emitUpdated(); |
|
252 | //TODO:: d->emitUpdated(); | |
252 | } |
|
253 | } | |
253 | } else { |
|
254 | } else { | |
254 | setRange(QString::null, QString::null); |
|
255 | setRange(QString::null, QString::null); | |
@@ -282,7 +283,7 void QBarCategoryAxis::insert(int index, const QString &category) | |||||
282 | setRange(d->m_minCategory, d->m_categories.last()); |
|
283 | setRange(d->m_minCategory, d->m_categories.last()); | |
283 | } else { |
|
284 | } else { | |
284 | d->updateCategoryDomain(); |
|
285 | d->updateCategoryDomain(); | |
285 | d->emitUpdated(); |
|
286 | //TODO:: d->emitUpdated(); | |
286 | } |
|
287 | } | |
287 |
|
288 | |||
288 | emit categoriesChanged(); |
|
289 | emit categoriesChanged(); | |
@@ -307,7 +308,7 void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCat | |||||
307 | } else if (d->m_maxCategory == oldCategory) { |
|
308 | } else if (d->m_maxCategory == oldCategory) { | |
308 | setRange(d->m_minCategory, newCategory); |
|
309 | setRange(d->m_minCategory, newCategory); | |
309 | } else { |
|
310 | } else { | |
310 | d->emitUpdated(); |
|
311 | //TODO:: d->emitUpdated(); | |
311 | } |
|
312 | } | |
312 | emit categoriesChanged(); |
|
313 | emit categoriesChanged(); | |
313 | emit countChanged(); |
|
314 | emit countChanged(); | |
@@ -375,7 +376,7 QString QBarCategoryAxis::at(int index) const | |||||
375 | void QBarCategoryAxis::setMin(const QString &min) |
|
376 | void QBarCategoryAxis::setMin(const QString &min) | |
376 | { |
|
377 | { | |
377 | Q_D(QBarCategoryAxis); |
|
378 | Q_D(QBarCategoryAxis); | |
378 | setRange(min, d->m_maxCategory); |
|
379 | d->setRange(min, d->m_maxCategory); | |
379 | } |
|
380 | } | |
380 |
|
381 | |||
381 | /*! |
|
382 | /*! | |
@@ -393,7 +394,7 QString QBarCategoryAxis::min() const | |||||
393 | void QBarCategoryAxis::setMax(const QString &max) |
|
394 | void QBarCategoryAxis::setMax(const QString &max) | |
394 | { |
|
395 | { | |
395 | Q_D(QBarCategoryAxis); |
|
396 | Q_D(QBarCategoryAxis); | |
396 | setRange(d->m_minCategory, max); |
|
397 | d->setRange(d->m_minCategory, max); | |
397 | } |
|
398 | } | |
398 |
|
399 | |||
399 | /*! |
|
400 | /*! | |
@@ -411,44 +412,7 QString QBarCategoryAxis::max() const | |||||
411 | void QBarCategoryAxis::setRange(const QString &minCategory, const QString &maxCategory) |
|
412 | void QBarCategoryAxis::setRange(const QString &minCategory, const QString &maxCategory) | |
412 | { |
|
413 | { | |
413 | Q_D(QBarCategoryAxis); |
|
414 | Q_D(QBarCategoryAxis); | |
414 |
|
415 | d->setRange(minCategory,maxCategory); | ||
415 | bool changed = false; |
|
|||
416 |
|
||||
417 | //special case in case or clearing all categories |
|
|||
418 | if (minCategory.isNull() && maxCategory.isNull()) { |
|
|||
419 | d->m_minCategory = minCategory; |
|
|||
420 | d->m_maxCategory = maxCategory; |
|
|||
421 | d->m_min = 0; |
|
|||
422 | d->m_max = 0; |
|
|||
423 | emit minChanged(minCategory); |
|
|||
424 | emit maxChanged(maxCategory); |
|
|||
425 | d->m_count = 0; |
|
|||
426 | emit rangeChanged(d->m_minCategory, d->m_maxCategory); |
|
|||
427 | d->emitUpdated(); |
|
|||
428 | } |
|
|||
429 |
|
||||
430 | if (d->m_categories.indexOf(maxCategory) < d->m_categories.indexOf(minCategory)) |
|
|||
431 | return; |
|
|||
432 |
|
||||
433 | if (!minCategory.isEmpty() && d->m_minCategory != minCategory && d->m_categories.contains(minCategory)) { |
|
|||
434 | d->m_minCategory = minCategory; |
|
|||
435 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; |
|
|||
436 | changed = true; |
|
|||
437 | emit minChanged(minCategory); |
|
|||
438 | } |
|
|||
439 |
|
||||
440 | if (!maxCategory.isEmpty() && d->m_maxCategory != maxCategory && d->m_categories.contains(maxCategory)) { |
|
|||
441 | d->m_maxCategory = maxCategory; |
|
|||
442 | d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5; |
|
|||
443 | changed = true; |
|
|||
444 | emit maxChanged(maxCategory); |
|
|||
445 | } |
|
|||
446 |
|
||||
447 | if (changed) { |
|
|||
448 | d->m_count = d->m_max - d->m_min; |
|
|||
449 | emit rangeChanged(d->m_minCategory, d->m_maxCategory); |
|
|||
450 | d->emitUpdated(); |
|
|||
451 | } |
|
|||
452 | } |
|
416 | } | |
453 |
|
417 | |||
454 | /*! |
|
418 | /*! | |
@@ -487,55 +451,114 void QBarCategoryAxisPrivate::setMax(const QVariant &max) | |||||
487 |
|
451 | |||
488 | void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
452 | void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
489 | { |
|
453 | { | |
490 | Q_Q(QBarCategoryAxis); |
|
|||
491 | QString value1 = min.toString(); |
|
454 | QString value1 = min.toString(); | |
492 | QString value2 = max.toString(); |
|
455 | QString value2 = max.toString(); | |
493 |
|
|
456 | setRange(value1, value2); | |
494 | } |
|
457 | } | |
495 |
|
458 | |||
496 |
void QBarCategoryAxisPrivate:: |
|
459 | void QBarCategoryAxisPrivate::setRange(qreal min, qreal max) | |
497 | { |
|
460 | { | |
498 | Q_Q(QBarCategoryAxis); |
|
461 | Q_Q(QBarCategoryAxis); | |
499 | Domain *domain = qobject_cast<Domain *>(sender()); |
|
|||
500 |
|
||||
501 | if (m_orientation == Qt::Horizontal) { |
|
|||
502 | m_min = domain->minX(); |
|
|||
503 | m_max = domain->maxX(); |
|
|||
504 | } else if (m_orientation == Qt::Vertical) { |
|
|||
505 | m_min = domain->minY(); |
|
|||
506 | m_max = domain->maxY(); |
|
|||
507 | } |
|
|||
508 |
|
462 | |||
|
463 | bool categoryChanged = false; | |||
509 | bool changed = false; |
|
464 | bool changed = false; | |
510 |
|
465 | |||
511 | int min = m_min + 0.5; |
|
466 | if (min > max) | |
512 | if (min >= 0 && min < m_categories.count()) { |
|
467 | return; | |
513 | QString minCategory = m_categories.at(min); |
|
468 | ||
514 | if (m_minCategory != minCategory && !minCategory.isEmpty()) { |
|
469 | if (!qFuzzyIsNull(m_min - min)) { | |
515 |
|
|
470 | m_min = min; | |
516 |
|
|
471 | changed = true; | |
517 | emit q->minChanged(minCategory); |
|
472 | ||
|
473 | int imin = m_min + 0.5; | |||
|
474 | if (imin >= 0 && imin < m_categories.count()) { | |||
|
475 | QString minCategory = m_categories.at(imin); | |||
|
476 | if (m_minCategory != minCategory && !minCategory.isEmpty()) { | |||
|
477 | m_minCategory = minCategory; | |||
|
478 | categoryChanged = true; | |||
|
479 | emit q->minChanged(minCategory); | |||
|
480 | } | |||
518 | } |
|
481 | } | |
|
482 | ||||
519 | } |
|
483 | } | |
520 | int max = m_max - 0.5; |
|
484 | ||
521 | if (max >= 0 && max < m_categories.count()) { |
|
485 | if (!qFuzzyIsNull(m_max - max)) { | |
522 | QString maxCategory = m_categories.at(max); |
|
486 | m_max = max; | |
523 | if (m_maxCategory != maxCategory && !maxCategory.isEmpty()) { |
|
487 | changed = true; | |
524 | m_maxCategory = maxCategory; |
|
488 | ||
525 | emit q->maxChanged(maxCategory); |
|
489 | int imax = m_max - 0.5; | |
|
490 | if (imax >= 0 && imax < m_categories.count()) { | |||
|
491 | QString maxCategory = m_categories.at(imax); | |||
|
492 | if (m_maxCategory != maxCategory && !maxCategory.isEmpty()) { | |||
|
493 | m_maxCategory = maxCategory; | |||
|
494 | categoryChanged = true; | |||
|
495 | emit q->maxChanged(maxCategory); | |||
|
496 | } | |||
526 | } |
|
497 | } | |
527 | } |
|
498 | } | |
528 |
|
499 | |||
529 | if (changed) |
|
500 | if (categoryChanged){ | |
530 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
501 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |
|
502 | } | |||
|
503 | ||||
|
504 | if (changed) { | |||
|
505 | emit rangeChanged(m_min,m_max); | |||
|
506 | } | |||
531 | } |
|
507 | } | |
532 |
|
508 | |||
533 | ChartAxis *QBarCategoryAxisPrivate::createGraphics(ChartPresenter *presenter) |
|
509 | void QBarCategoryAxisPrivate::setRange(const QString &minCategory, const QString &maxCategory) | |
|
510 | { | |||
|
511 | Q_Q(QBarCategoryAxis); | |||
|
512 | bool changed = false; | |||
|
513 | ||||
|
514 | //special case in case or clearing all categories | |||
|
515 | if (minCategory.isNull() && maxCategory.isNull()) { | |||
|
516 | m_minCategory = minCategory; | |||
|
517 | m_maxCategory = maxCategory; | |||
|
518 | m_min = 0; | |||
|
519 | m_max = 0; | |||
|
520 | m_count = 0; | |||
|
521 | emit q->minChanged(minCategory); | |||
|
522 | emit q->maxChanged(maxCategory); | |||
|
523 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |||
|
524 | emit rangeChanged(m_min,m_max); | |||
|
525 | } | |||
|
526 | ||||
|
527 | if (m_categories.indexOf(maxCategory) < m_categories.indexOf(minCategory)) | |||
|
528 | return; | |||
|
529 | ||||
|
530 | if (!minCategory.isEmpty() && m_minCategory != minCategory && m_categories.contains(minCategory)) { | |||
|
531 | m_minCategory = minCategory; | |||
|
532 | m_min = m_categories.indexOf(m_minCategory) - 0.5; | |||
|
533 | changed = true; | |||
|
534 | emit q->minChanged(minCategory); | |||
|
535 | } | |||
|
536 | ||||
|
537 | if (!maxCategory.isEmpty() && m_maxCategory != maxCategory && m_categories.contains(maxCategory)) { | |||
|
538 | m_maxCategory = maxCategory; | |||
|
539 | m_max = m_categories.indexOf(m_maxCategory) + 0.5; | |||
|
540 | changed = true; | |||
|
541 | emit q->maxChanged(maxCategory); | |||
|
542 | } | |||
|
543 | ||||
|
544 | if (changed) { | |||
|
545 | m_count = m_max - m_min; | |||
|
546 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |||
|
547 | emit rangeChanged(m_min,m_max); | |||
|
548 | } | |||
|
549 | } | |||
|
550 | ||||
|
551 | void QBarCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |||
534 | { |
|
552 | { | |
535 | Q_Q(QBarCategoryAxis); |
|
553 | Q_Q(QBarCategoryAxis); | |
536 | if (m_orientation == Qt::Vertical) |
|
554 | ChartAxis* axis(0); | |
537 | return new ChartBarCategoryAxisY(q, presenter); |
|
555 | if (orientation() == Qt::Vertical) | |
538 |
|
|
556 | axis = new ChartBarCategoryAxisY(q,parent); | |
|
557 | if (orientation() == Qt::Horizontal) | |||
|
558 | axis = new ChartBarCategoryAxisX(q,parent); | |||
|
559 | ||||
|
560 | m_item.reset(axis); | |||
|
561 | QAbstractAxisPrivate::initializeGraphics(parent); | |||
539 | } |
|
562 | } | |
540 |
|
563 | |||
541 | void QBarCategoryAxisPrivate::updateCategoryDomain() |
|
564 | void QBarCategoryAxisPrivate::updateCategoryDomain() | |
@@ -546,14 +569,13 void QBarCategoryAxisPrivate::updateCategoryDomain() | |||||
546 | } |
|
569 | } | |
547 |
|
570 | |||
548 |
|
571 | |||
549 | void QBarCategoryAxisPrivate::intializeDomain(Domain *domain) |
|
572 | void QBarCategoryAxisPrivate::initializeDomain(Domain *domain) | |
550 | { |
|
573 | { | |
551 |
|
||||
552 | Q_Q(QBarCategoryAxis); |
|
574 | Q_Q(QBarCategoryAxis); | |
553 | if (m_max == m_min) { |
|
575 | if (m_max == m_min) { | |
554 | int min; |
|
576 | int min; | |
555 | int max; |
|
577 | int max; | |
556 |
if ( |
|
578 | if (orientation() == Qt::Vertical) { | |
557 | min = domain->minY() + 0.5; |
|
579 | min = domain->minY() + 0.5; | |
558 | max = domain->maxY() - 0.5; |
|
580 | max = domain->maxY() - 0.5; | |
559 | } else { |
|
581 | } else { | |
@@ -564,7 +586,7 void QBarCategoryAxisPrivate::intializeDomain(Domain *domain) | |||||
564 | if (min > 0 && min < m_categories.count() && max > 0 && max < m_categories.count()) |
|
586 | if (min > 0 && min < m_categories.count() && max > 0 && max < m_categories.count()) | |
565 | q->setRange(m_categories.at(min), m_categories.at(max)); |
|
587 | q->setRange(m_categories.at(min), m_categories.at(max)); | |
566 | } else { |
|
588 | } else { | |
567 |
if ( |
|
589 | if (orientation() == Qt::Vertical) | |
568 | domain->setRangeY(m_min, m_max); |
|
590 | domain->setRangeY(m_min, m_max); | |
569 | else |
|
591 | else | |
570 | domain->setRangeX(m_min, m_max); |
|
592 | domain->setRangeX(m_min, m_max); |
@@ -46,19 +46,23 public: | |||||
46 | ~QBarCategoryAxisPrivate(); |
|
46 | ~QBarCategoryAxisPrivate(); | |
47 |
|
47 | |||
48 | public: |
|
48 | public: | |
49 | ChartAxis *createGraphics(ChartPresenter *presenter); |
|
49 | void initializeGraphics(QGraphicsItem* parent); | |
50 | void intializeDomain(Domain *domain); |
|
50 | void initializeDomain(Domain *domain); | |
51 | void handleDomainUpdated(); |
|
|||
52 | void updateCategoryDomain(); |
|
51 | void updateCategoryDomain(); | |
|
52 | ||||
|
53 | //interface for manipulating range form base class | |||
|
54 | void setRange(const QVariant &min, const QVariant &max); | |||
|
55 | void setMin(const QVariant &min); | |||
|
56 | void setMax(const QVariant &max); | |||
|
57 | ||||
|
58 | //interface manipulating range form domain | |||
53 | qreal min() { return m_min; } |
|
59 | qreal min() { return m_min; } | |
54 | qreal max() { return m_max; } |
|
60 | qreal max() { return m_max; } | |
55 | int count() const { return m_count; } |
|
61 | void setRange(qreal min,qreal max); | |
56 |
|
62 | |||
57 | private: |
|
63 | private: | |
58 | //range handling |
|
64 | //range handling | |
59 | void setMin(const QVariant &min); |
|
65 | void setRange(const QString &minCategory, const QString &maxCategory); | |
60 | void setMax(const QVariant &max); |
|
|||
61 | void setRange(const QVariant &min, const QVariant &max); |
|
|||
62 |
|
66 | |||
63 | private: |
|
67 | private: | |
64 | QStringList m_categories; |
|
68 | QStringList m_categories; |
@@ -28,8 +28,8 | |||||
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 |
ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis, |
|
31 | ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item) | |
32 |
: HorizontalAxis(axis, |
|
32 | : HorizontalAxis(axis, item, true), | |
33 | m_axis(axis) |
|
33 | m_axis(axis) | |
34 | { |
|
34 | { | |
35 | } |
|
35 | } | |
@@ -75,7 +75,7 void ChartCategoryAxisX::updateGeometry() | |||||
75 | void ChartCategoryAxisX::handleAxisUpdated() |
|
75 | void ChartCategoryAxisX::handleAxisUpdated() | |
76 | { |
|
76 | { | |
77 | updateGeometry(); |
|
77 | updateGeometry(); | |
78 | ChartAxis::handleAxisUpdated(); |
|
78 | //TODO :: ChartAxis::handleAxisUpdated(); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
81 | QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
@@ -40,7 +40,7 class ChartPresenter; | |||||
40 | class ChartCategoryAxisX : public HorizontalAxis |
|
40 | class ChartCategoryAxisX : public HorizontalAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 |
ChartCategoryAxisX(QCategoryAxis *axis, |
|
43 | ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item = 0); | |
44 | ~ChartCategoryAxisX(); |
|
44 | ~ChartCategoryAxisX(); | |
45 |
|
45 | |||
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
|
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
@@ -29,8 +29,8 | |||||
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 |
ChartCategoryAxisY::ChartCategoryAxisY(QCategoryAxis *axis, |
|
32 | ChartCategoryAxisY::ChartCategoryAxisY(QCategoryAxis *axis, QGraphicsItem* item) | |
33 |
: VerticalAxis(axis, |
|
33 | : VerticalAxis(axis, item, true), | |
34 | m_axis(axis) |
|
34 | m_axis(axis) | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
@@ -75,7 +75,7 void ChartCategoryAxisY::updateGeometry() | |||||
75 | void ChartCategoryAxisY::handleAxisUpdated() |
|
75 | void ChartCategoryAxisY::handleAxisUpdated() | |
76 | { |
|
76 | { | |
77 | updateGeometry(); |
|
77 | updateGeometry(); | |
78 | ChartAxis::handleAxisUpdated(); |
|
78 | //TODO:: ChartAxis::handleAxisUpdated(); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
81 | QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
@@ -40,7 +40,7 class ChartPresenter; | |||||
40 | class ChartCategoryAxisY : public VerticalAxis |
|
40 | class ChartCategoryAxisY : public VerticalAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 |
ChartCategoryAxisY(QCategoryAxis *axis, |
|
43 | ChartCategoryAxisY(QCategoryAxis *axis, QGraphicsItem* item = 0); | |
44 | ~ChartCategoryAxisY(); |
|
44 | ~ChartCategoryAxisY(); | |
45 |
|
45 | |||
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
|
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
@@ -22,6 +22,7 | |||||
22 | #include "qcategoryaxis_p.h" |
|
22 | #include "qcategoryaxis_p.h" | |
23 | #include "chartcategoryaxisx_p.h" |
|
23 | #include "chartcategoryaxisx_p.h" | |
24 | #include "chartcategoryaxisy_p.h" |
|
24 | #include "chartcategoryaxisy_p.h" | |
|
25 | #include "qchart.h" | |||
25 | #include <qmath.h> |
|
26 | #include <qmath.h> | |
26 | #include <QDebug> |
|
27 | #include <QDebug> | |
27 |
|
28 | |||
@@ -114,6 +115,9 QCategoryAxis::QCategoryAxis(QObject *parent): | |||||
114 | */ |
|
115 | */ | |
115 | QCategoryAxis::~QCategoryAxis() |
|
116 | QCategoryAxis::~QCategoryAxis() | |
116 | { |
|
117 | { | |
|
118 | Q_D(QCategoryAxis); | |||
|
119 | if (d->m_chart) | |||
|
120 | d->m_chart->removeAxis(this); | |||
117 | } |
|
121 | } | |
118 |
|
122 | |||
119 | /*! |
|
123 | /*! | |
@@ -223,7 +227,7 void QCategoryAxis::remove(const QString &categoryLabel) | |||||
223 | d->m_categoriesMap.insert(label, range); |
|
227 | d->m_categoriesMap.insert(label, range); | |
224 | } |
|
228 | } | |
225 | } |
|
229 | } | |
226 | d->emitUpdated(); |
|
230 | //TODO:: d->emitUpdated(); | |
227 | } |
|
231 | } | |
228 | } |
|
232 | } | |
229 |
|
233 | |||
@@ -247,7 +251,7 void QCategoryAxis::replaceLabel(const QString &oldLabel, const QString &newLabe | |||||
247 | Range range = d->m_categoriesMap.value(oldLabel); |
|
251 | Range range = d->m_categoriesMap.value(oldLabel); | |
248 | d->m_categoriesMap.remove(oldLabel); |
|
252 | d->m_categoriesMap.remove(oldLabel); | |
249 | d->m_categoriesMap.insert(newLabel, range); |
|
253 | d->m_categoriesMap.insert(newLabel, range); | |
250 | d->emitUpdated(); |
|
254 | //TODO:: d->emitUpdated(); | |
251 | } |
|
255 | } | |
252 | } |
|
256 | } | |
253 |
|
257 | |||
@@ -296,19 +300,17 int QCategoryAxisPrivate::ticksCount() const | |||||
296 | return m_categories.count() + 1; |
|
300 | return m_categories.count() + 1; | |
297 | } |
|
301 | } | |
298 |
|
302 | |||
299 | void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max, int count) |
|
303 | void QCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
300 | { |
|
|||
301 | Q_UNUSED(count); |
|
|||
302 | Q_UNUSED(min); |
|
|||
303 | Q_UNUSED(max); |
|
|||
304 | } |
|
|||
305 |
|
||||
306 | ChartAxis *QCategoryAxisPrivate::createGraphics(ChartPresenter *presenter) |
|
|||
307 | { |
|
304 | { | |
308 | Q_Q(QCategoryAxis); |
|
305 | Q_Q(QCategoryAxis); | |
309 | if (m_orientation == Qt::Vertical) |
|
306 | ChartAxis* axis(0); | |
310 | return new ChartCategoryAxisY(q, presenter); |
|
307 | if (orientation() == Qt::Vertical) | |
311 |
|
|
308 | axis = new ChartCategoryAxisY(q,parent); | |
|
309 | else if(orientation() == Qt::Horizontal) | |||
|
310 | axis = new ChartCategoryAxisX(q,parent); | |||
|
311 | ||||
|
312 | m_item.reset(axis); | |||
|
313 | QAbstractAxisPrivate::initializeGraphics(parent); | |||
312 | } |
|
314 | } | |
313 |
|
315 | |||
314 | #include "moc_qcategoryaxis.cpp" |
|
316 | #include "moc_qcategoryaxis.cpp" |
@@ -45,15 +45,12 public: | |||||
45 | QCategoryAxisPrivate(QCategoryAxis *q); |
|
45 | QCategoryAxisPrivate(QCategoryAxis *q); | |
46 | ~QCategoryAxisPrivate(); |
|
46 | ~QCategoryAxisPrivate(); | |
47 |
|
47 | |||
48 | ChartAxis *createGraphics(ChartPresenter *presenter); |
|
48 | void initializeGraphics(QGraphicsItem* parent); | |
49 | int ticksCount() const; |
|
49 | int ticksCount() const; | |
50 |
|
50 | |||
51 | Q_SIGNALS: |
|
51 | Q_SIGNALS: | |
52 | void changed(qreal min, qreal max, int tickCount, bool niceNumbers); |
|
52 | void changed(qreal min, qreal max, int tickCount, bool niceNumbers); | |
53 |
|
53 | |||
54 | public Q_SLOTS: |
|
|||
55 | void handleAxisRangeChanged(qreal min, qreal max, int count); |
|
|||
56 |
|
||||
57 | private: |
|
54 | private: | |
58 | QMap<QString , Range> m_categoriesMap; |
|
55 | QMap<QString , Range> m_categoriesMap; | |
59 | QStringList m_categories; |
|
56 | QStringList m_categories; |
@@ -32,34 +32,56 | |||||
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 |
ChartAxis::ChartAxis(QAbstractAxis *axis, |
|
35 | ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis) | |
36 |
: ChartElement( |
|
36 | : ChartElement(item), | |
37 |
m_ |
|
37 | m_axis(axis), | |
38 | m_labelsAngle(0), |
|
38 | m_labelsAngle(0), | |
39 |
m_grid(new QGraphicsItemGroup( |
|
39 | m_grid(new QGraphicsItemGroup(item)), | |
40 |
m_ |
|
40 | m_arrow(new QGraphicsItemGroup(item)), | |
41 |
m_ |
|
41 | m_shades(new QGraphicsItemGroup(item)), | |
42 |
m_ |
|
42 | m_labels(new QGraphicsItemGroup(item)), | |
43 |
m_title(new QGraphicsSimpleTextItem( |
|
43 | m_title(new QGraphicsSimpleTextItem(item)), | |
44 | m_min(0), |
|
|||
45 | m_max(0), |
|
|||
46 | m_animation(0), |
|
44 | m_animation(0), | |
47 | m_labelPadding(5), |
|
45 | m_labelPadding(5), | |
48 | m_intervalAxis(intervalAxis) |
|
46 | m_intervalAxis(intervalAxis) | |
49 | { |
|
47 | { | |
|
48 | Q_ASSERT(item); | |||
50 | //initial initialization |
|
49 | //initial initialization | |
51 | m_arrow->setZValue(ChartPresenter::AxisZValue); |
|
|||
52 | m_arrow->setHandlesChildEvents(false); |
|
50 | m_arrow->setHandlesChildEvents(false); | |
|
51 | m_arrow->setZValue(ChartPresenter::AxisZValue); | |||
|
52 | m_arrow->setVisible(m_axis->isLineVisible()); | |||
53 | m_labels->setZValue(ChartPresenter::AxisZValue); |
|
53 | m_labels->setZValue(ChartPresenter::AxisZValue); | |
|
54 | m_labels->setVisible(m_axis->labelsVisible()); | |||
54 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
55 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
|
56 | m_shades->setVisible(m_axis->shadesVisible()); | |||
55 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
57 | m_grid->setZValue(ChartPresenter::GridZValue); | |
|
58 | m_grid->setVisible(m_axis->isGridLineVisible()); | |||
56 | m_title->setZValue(ChartPresenter::GridZValue); |
|
59 | m_title->setZValue(ChartPresenter::GridZValue); | |
|
60 | connectSlots(); | |||
57 |
|
61 | |||
58 | QObject::connect(m_chartAxis->d_ptr.data(), SIGNAL(updated()), this, SLOT(handleAxisUpdated())); |
|
62 | setFlag(QGraphicsItem::ItemHasNoContents,true); | |
59 |
|
63 | } | ||
60 | QGraphicsSimpleTextItem item; |
|
|||
61 | m_font = item.font(); |
|
|||
62 |
|
64 | |||
|
65 | void ChartAxis::connectSlots() | |||
|
66 | { | |||
|
67 | QObject::connect(m_axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleVisibleChanged(bool))); | |||
|
68 | QObject::connect(m_axis,SIGNAL(lineVisibleChanged(bool)),this,SLOT(handleArrowVisibleChanged(bool))); | |||
|
69 | QObject::connect(m_axis,SIGNAL(gridLineVisibleChanged(bool)),this,SLOT(handleGridVisibleChanged(bool))); | |||
|
70 | QObject::connect(m_axis,SIGNAL(labelsVisibleChanged(bool)),this,SLOT(handleLabelsVisibleChanged(bool))); | |||
|
71 | QObject::connect(m_axis,SIGNAL(shadesVisibleChanged(bool)),this,SLOT(handleShadesVisibleChanged(bool))); | |||
|
72 | QObject::connect(m_axis,SIGNAL(labelsAngleChanged(int)),this,SLOT(handleLabelsAngleChanged(int))); | |||
|
73 | QObject::connect(m_axis,SIGNAL(linePenChanged(const QPen&)),this,SLOT(handleArrowPenChanged(const QPen&))); | |||
|
74 | QObject::connect(m_axis,SIGNAL(labelsPenChanged(const QPen&)),this,SLOT(handleLabelsPenChanged(const QPen&))); | |||
|
75 | QObject::connect(m_axis,SIGNAL(labelsBrushChanged(const QBrush&)),this,SLOT(handleLabelsBrushChanged(const QBrush&))); | |||
|
76 | QObject::connect(m_axis,SIGNAL(labelsFontChanged(const QFont&)),this,SLOT(handleLabelsFontChanged(const QFont&))); | |||
|
77 | QObject::connect(m_axis,SIGNAL(gridLinePenChanged(const QPen&)),this,SLOT(handleGridPenChanged(const QPen&))); | |||
|
78 | QObject::connect(m_axis,SIGNAL(shadesPenChanged(const QPen&)),this,SLOT(handleShadesPenChanged(const QPen&))); | |||
|
79 | QObject::connect(m_axis,SIGNAL(shadesBrushChanged(const QBrush&)),this,SLOT(handleShadesBrushChanged(const QBrush&))); | |||
|
80 | QObject::connect(m_axis,SIGNAL(titleTextChanged(const QString&)),this,SLOT(handleTitleTextChanged(const QString&))); | |||
|
81 | QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&))); | |||
|
82 | QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&))); | |||
|
83 | QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&))); | |||
|
84 | QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal))); | |||
63 | } |
|
85 | } | |
64 |
|
86 | |||
65 | ChartAxis::~ChartAxis() |
|
87 | ChartAxis::~ChartAxis() | |
@@ -78,23 +100,41 void ChartAxis::setLayout(QVector<qreal> &layout) | |||||
78 |
|
100 | |||
79 | void ChartAxis::createItems(int count) |
|
101 | void ChartAxis::createItems(int count) | |
80 | { |
|
102 | { | |
81 |
if (m_arrow->child |
|
103 | if (m_arrow->children().size() == 0){ | |
82 | m_arrow->addToGroup(new AxisItem(this, presenter()->rootItem())); |
|
104 | QGraphicsLineItem* arrow = new ArrowItem(this, this); | |
|
105 | arrow->setPen(m_axis->linePen()); | |||
|
106 | m_arrow->addToGroup(arrow); | |||
|
107 | } | |||
83 |
|
108 | |||
84 |
if (m_intervalAxis && m_grid->child |
|
109 | if (m_intervalAxis && m_grid->children().size() == 0) { | |
85 | for (int i = 0 ; i < 2 ; i ++) |
|
110 | for (int i = 0 ; i < 2 ; i ++){ | |
86 | m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); |
|
111 | QGraphicsLineItem* item = new QGraphicsLineItem(this); | |
|
112 | item->setPen(m_axis->gridLinePen()); | |||
|
113 | m_grid->addToGroup(item); | |||
|
114 | } | |||
87 | } |
|
115 | } | |
88 |
|
116 | |||
89 | for (int i = 0; i < count; ++i) { |
|
117 | for (int i = 0; i < count; ++i) { | |
90 | m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); |
|
118 | QGraphicsLineItem* arrow = new QGraphicsLineItem(this); | |
91 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(presenter()->rootItem()); |
|
119 | arrow->setPen(m_axis->linePen()); | |
92 | label->setFont(m_font); |
|
120 | QGraphicsLineItem* grid = new QGraphicsLineItem(this); | |
|
121 | grid->setPen(m_axis->gridLinePen()); | |||
|
122 | QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(this); | |||
|
123 | label->setFont(m_axis->labelsFont()); | |||
|
124 | label->setPen(m_axis->labelsPen()); | |||
|
125 | label->setBrush(m_axis->labelsBrush()); | |||
|
126 | m_arrow->addToGroup(arrow); | |||
|
127 | m_grid->addToGroup(grid); | |||
93 | m_labels->addToGroup(label); |
|
128 | m_labels->addToGroup(label); | |
94 | m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); |
|
129 | ||
95 | if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2) |
|
130 | if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2){ | |
96 | m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem())); |
|
131 | QGraphicsRectItem* shades = new QGraphicsRectItem(this); | |
|
132 | shades->setPen(m_axis->shadesPen()); | |||
|
133 | shades->setBrush(m_axis->shadesBrush()); | |||
|
134 | m_shades->addToGroup(shades); | |||
|
135 | } | |||
97 | } |
|
136 | } | |
|
137 | ||||
98 | } |
|
138 | } | |
99 |
|
139 | |||
100 | void ChartAxis::deleteItems(int count) |
|
140 | void ChartAxis::deleteItems(int count) | |
@@ -122,8 +162,6 void ChartAxis::updateLayout(QVector<qreal> &layout) | |||||
122 | else if (diff < 0) |
|
162 | else if (diff < 0) | |
123 | createItems(-diff); |
|
163 | createItems(-diff); | |
124 |
|
164 | |||
125 | if (diff < 0) handleAxisUpdated(); |
|
|||
126 |
|
||||
127 | if (m_animation) { |
|
165 | if (m_animation) { | |
128 | switch (presenter()->state()) { |
|
166 | switch (presenter()->state()) { | |
129 | case ChartPresenter::ZoomInState: |
|
167 | case ChartPresenter::ZoomInState: | |
@@ -154,67 +192,103 void ChartAxis::updateLayout(QVector<qreal> &layout) | |||||
154 | } |
|
192 | } | |
155 | } |
|
193 | } | |
156 |
|
194 | |||
157 | void ChartAxis::setArrowOpacity(qreal opacity) |
|
195 | void ChartAxis::setLabelPadding(int padding) | |
|
196 | { | |||
|
197 | m_labelPadding = padding; | |||
|
198 | } | |||
|
199 | ||||
|
200 | bool ChartAxis::isEmpty() | |||
|
201 | { | |||
|
202 | return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max()); | |||
|
203 | } | |||
|
204 | ||||
|
205 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) | |||
|
206 | { | |||
|
207 | m_gridRect = grid; | |||
|
208 | m_axisRect = axis; | |||
|
209 | ||||
|
210 | if (isEmpty()) | |||
|
211 | return; | |||
|
212 | ||||
|
213 | QVector<qreal> layout = calculateLayout(); | |||
|
214 | updateLayout(layout); | |||
|
215 | } | |||
|
216 | ||||
|
217 | qreal ChartAxis::min() const | |||
158 | { |
|
218 | { | |
159 | m_arrow->setOpacity(opacity); |
|
219 | return m_axis->d_ptr->min(); | |
160 | } |
|
220 | } | |
161 |
|
221 | |||
162 |
qreal ChartAxis:: |
|
222 | qreal ChartAxis::max() const | |
163 | { |
|
223 | { | |
164 | return m_arrow->opacity(); |
|
224 | return m_axis->d_ptr->max(); | |
165 | } |
|
225 | } | |
166 |
|
226 | |||
167 | void ChartAxis::setArrowVisibility(bool visible) |
|
227 | QFont ChartAxis::font() const | |
168 | { |
|
228 | { | |
169 | m_arrow->setOpacity(visible); |
|
229 | return m_axis->labelsFont(); | |
170 | } |
|
230 | } | |
171 |
|
231 | |||
172 | void ChartAxis::setGridOpacity(qreal opacity) |
|
232 | QFont ChartAxis::titleFont() const | |
173 | { |
|
233 | { | |
174 | m_grid->setOpacity(opacity); |
|
234 | return m_axis->titleFont(); | |
175 | } |
|
235 | } | |
176 |
|
236 | |||
177 |
|
|
237 | QString ChartAxis::titleText() const | |
178 | { |
|
238 | { | |
179 | return m_grid->opacity(); |
|
239 | return m_axis->titleText(); | |
180 | } |
|
240 | } | |
181 |
|
241 | |||
182 | void ChartAxis::setGridVisibility(bool visible) |
|
242 | void ChartAxis::axisSelected() | |
183 | { |
|
243 | { | |
184 | m_grid->setOpacity(visible); |
|
244 | emit clicked(); | |
185 | } |
|
245 | } | |
186 |
|
246 | |||
187 | void ChartAxis::setLabelsOpacity(qreal opacity) |
|
247 | Qt::Orientation ChartAxis::orientation() const | |
188 | { |
|
248 | { | |
189 | m_labels->setOpacity(opacity); |
|
249 | return m_axis->orientation(); | |
190 | } |
|
250 | } | |
191 |
|
251 | |||
192 |
|
|
252 | Qt::Alignment ChartAxis::alignment() const | |
|
253 | { | |||
|
254 | return m_axis->alignment(); | |||
|
255 | } | |||
|
256 | ||||
|
257 | void ChartAxis::setLabels(const QStringList &labels) | |||
|
258 | { | |||
|
259 | m_labelsList = labels; | |||
|
260 | } | |||
|
261 | ||||
|
262 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |||
193 | { |
|
263 | { | |
194 | return m_labels->opacity(); |
|
264 | Q_UNUSED(which); | |
|
265 | Q_UNUSED(constraint); | |||
|
266 | return QSizeF(); | |||
195 | } |
|
267 | } | |
196 |
|
268 | |||
197 | void ChartAxis::setLabelsVisibility(bool visible) |
|
269 | //handlers | |
|
270 | ||||
|
271 | void ChartAxis::handleArrowVisibleChanged(bool visible) | |||
198 | { |
|
272 | { | |
199 |
m_ |
|
273 | m_arrow->setVisible(visible); | |
200 | } |
|
274 | } | |
201 |
|
275 | |||
202 | void ChartAxis::setShadesOpacity(qreal opacity) |
|
276 | void ChartAxis::handleGridVisibleChanged(bool visible) | |
203 | { |
|
277 | { | |
204 | m_shades->setOpacity(opacity); |
|
278 | m_grid->setVisible(visible); | |
205 | } |
|
279 | } | |
206 |
|
280 | |||
207 | qreal ChartAxis::shadesOpacity() const |
|
281 | void ChartAxis::handleLabelsVisibleChanged(bool visible) | |
208 | { |
|
282 | { | |
209 | return m_shades->opacity(); |
|
283 | m_labels->setVisible(visible); | |
210 | } |
|
284 | } | |
211 |
|
285 | |||
212 |
void ChartAxis:: |
|
286 | void ChartAxis::handleShadesVisibleChanged(bool visible) | |
213 | { |
|
287 | { | |
214 | m_shades->setVisible(visible); |
|
288 | m_shades->setVisible(visible); | |
215 | } |
|
289 | } | |
216 |
|
290 | |||
217 |
void ChartAxis:: |
|
291 | void ChartAxis::handleLabelsAngleChanged(int angle) | |
218 | { |
|
292 | { | |
219 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
293 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
220 | item->setRotation(angle); |
|
294 | item->setRotation(angle); | |
@@ -222,145 +296,69 void ChartAxis::setLabelsAngle(int angle) | |||||
222 | m_labelsAngle = angle; |
|
296 | m_labelsAngle = angle; | |
223 | } |
|
297 | } | |
224 |
|
298 | |||
225 |
void ChartAxis:: |
|
299 | void ChartAxis::handleLabelsPenChanged(const QPen &pen) | |
226 | { |
|
300 | { | |
227 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
301 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
228 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); |
|
302 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); | |
229 | } |
|
303 | } | |
230 |
|
304 | |||
231 |
void ChartAxis:: |
|
305 | void ChartAxis::handleLabelsBrushChanged(const QBrush &brush) | |
232 | { |
|
306 | { | |
233 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
307 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
234 | static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); |
|
308 | static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); | |
235 | } |
|
309 | } | |
236 |
|
310 | |||
237 |
void ChartAxis:: |
|
311 | void ChartAxis::handleLabelsFontChanged(const QFont &font) | |
238 | { |
|
312 | { | |
239 | if (m_font != font) { |
|
313 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
240 | m_font = font; |
|
314 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); | |
241 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
315 | QGraphicsLayoutItem::updateGeometry(); | |
242 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); |
|
316 | presenter()->layout()->invalidate(); | |
243 | QGraphicsLayoutItem::updateGeometry(); |
|
|||
244 | presenter()->layout()->invalidate(); |
|
|||
245 | } |
|
|||
246 | } |
|
317 | } | |
247 |
|
318 | |||
248 |
void ChartAxis:: |
|
319 | void ChartAxis::handleShadesBrushChanged(const QBrush &brush) | |
249 | { |
|
320 | { | |
250 | foreach (QGraphicsItem *item , m_shades->childItems()) |
|
321 | foreach (QGraphicsItem *item , m_shades->childItems()) | |
251 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); |
|
322 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); | |
252 | } |
|
323 | } | |
253 |
|
324 | |||
254 |
void ChartAxis:: |
|
325 | void ChartAxis::handleShadesPenChanged(const QPen &pen) | |
255 | { |
|
326 | { | |
256 | foreach (QGraphicsItem *item , m_shades->childItems()) |
|
327 | foreach (QGraphicsItem *item , m_shades->childItems()) | |
257 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); |
|
328 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); | |
258 | } |
|
329 | } | |
259 |
|
330 | |||
260 |
void ChartAxis:: |
|
331 | void ChartAxis::handleArrowPenChanged(const QPen &pen) | |
261 | { |
|
332 | { | |
262 | foreach (QGraphicsItem *item , m_arrow->childItems()) |
|
333 | foreach (QGraphicsItem *item , m_arrow->childItems()) | |
263 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
334 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
264 | } |
|
335 | } | |
265 |
|
336 | |||
266 |
void ChartAxis:: |
|
337 | void ChartAxis::handleGridPenChanged(const QPen &pen) | |
267 | { |
|
338 | { | |
268 | foreach (QGraphicsItem *item , m_grid->childItems()) |
|
339 | foreach (QGraphicsItem *item , m_grid->childItems()) | |
269 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
340 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
270 | } |
|
341 | } | |
271 |
|
342 | |||
272 | void ChartAxis::setLabelPadding(int padding) |
|
343 | void ChartAxis::handleTitleTextChanged(const QString &title) | |
273 | { |
|
|||
274 | m_labelPadding = padding; |
|
|||
275 | } |
|
|||
276 |
|
||||
277 | bool ChartAxis::isEmpty() |
|
|||
278 | { |
|
|||
279 | return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(m_min, m_max); |
|
|||
280 | } |
|
|||
281 |
|
||||
282 | void ChartAxis::handleDomainUpdated() |
|
|||
283 | { |
|
344 | { | |
284 | Domain *domain = qobject_cast<Domain *>(sender()); |
|
345 | Q_UNUSED(title) | |
285 | qreal min(0); |
|
346 | QGraphicsLayoutItem::updateGeometry(); | |
286 | qreal max(0); |
|
347 | presenter()->layout()->invalidate(); | |
287 |
|
||||
288 | if (m_chartAxis->orientation() == Qt::Horizontal) { |
|
|||
289 | min = domain->minX(); |
|
|||
290 | max = domain->maxX(); |
|
|||
291 | } else if (m_chartAxis->orientation() == Qt::Vertical) { |
|
|||
292 | min = domain->minY(); |
|
|||
293 | max = domain->maxY(); |
|
|||
294 | } |
|
|||
295 |
|
||||
296 | if (!qFuzzyCompare(m_min, min) || !qFuzzyCompare(m_max, max)) { |
|
|||
297 | m_min = min; |
|
|||
298 | m_max = max; |
|
|||
299 |
|
||||
300 | if (!isEmpty()) { |
|
|||
301 |
|
||||
302 | QVector<qreal> layout = calculateLayout(); |
|
|||
303 | updateLayout(layout); |
|
|||
304 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); |
|
|||
305 | QSizeF after = sizeHint(Qt::PreferredSize); |
|
|||
306 |
|
||||
307 | if (before != after) { |
|
|||
308 | QGraphicsLayoutItem::updateGeometry(); |
|
|||
309 | //we don't want to call invalidate on layout, since it will change minimum size of component, |
|
|||
310 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, |
|
|||
311 | //instead recalculate layout and use plotArea for extra space. |
|
|||
312 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); |
|
|||
313 | } |
|
|||
314 | } |
|
|||
315 | } |
|
|||
316 | } |
|
348 | } | |
317 |
|
349 | |||
318 | void ChartAxis::handleAxisUpdated() |
|
|||
319 | { |
|
|||
320 | if (isEmpty()) |
|
|||
321 | return; |
|
|||
322 |
|
||||
323 | bool visible = m_chartAxis->isVisible(); |
|
|||
324 |
|
||||
325 | //TODO: split this into separate signal/slots ? |
|
|||
326 | setArrowVisibility(visible && m_chartAxis->isLineVisible()); |
|
|||
327 | setGridVisibility(visible && m_chartAxis->isGridLineVisible()); |
|
|||
328 | setLabelsVisibility(visible && m_chartAxis->labelsVisible()); |
|
|||
329 | setShadesVisibility(visible && m_chartAxis->shadesVisible()); |
|
|||
330 | setLabelsAngle(m_chartAxis->labelsAngle()); |
|
|||
331 | setArrowPen(m_chartAxis->linePen()); |
|
|||
332 | setLabelsPen(m_chartAxis->labelsPen()); |
|
|||
333 | setLabelsBrush(m_chartAxis->labelsBrush()); |
|
|||
334 | setLabelsFont(m_chartAxis->labelsFont()); |
|
|||
335 | setGridPen(m_chartAxis->gridLinePen()); |
|
|||
336 | setShadesPen(m_chartAxis->shadesPen()); |
|
|||
337 | setShadesBrush(m_chartAxis->shadesBrush()); |
|
|||
338 | setTitleText(m_chartAxis->title()); |
|
|||
339 | setTitleFont(m_chartAxis->titleFont()); |
|
|||
340 | setTitlePen(m_chartAxis->titlePen()); |
|
|||
341 | setTitleBrush(m_chartAxis->titleBrush()); |
|
|||
342 | } |
|
|||
343 |
|
||||
344 | void ChartAxis::setTitleText(const QString &title) |
|
|||
345 | { |
|
|||
346 | if (m_titleText != title) { |
|
|||
347 | m_titleText = title; |
|
|||
348 | QGraphicsLayoutItem::updateGeometry(); |
|
|||
349 | presenter()->layout()->invalidate(); |
|
|||
350 | } |
|
|||
351 | } |
|
|||
352 |
|
350 | |||
353 |
void ChartAxis:: |
|
351 | void ChartAxis::handleTitlePenChanged(const QPen &pen) | |
354 | { |
|
352 | { | |
355 | m_title->setPen(pen); |
|
353 | m_title->setPen(pen); | |
356 | } |
|
354 | } | |
357 |
|
355 | |||
358 |
void ChartAxis:: |
|
356 | void ChartAxis::handleTitleBrushChanged(const QBrush &brush) | |
359 | { |
|
357 | { | |
360 | m_title->setBrush(brush); |
|
358 | m_title->setBrush(brush); | |
361 | } |
|
359 | } | |
362 |
|
360 | |||
363 |
void ChartAxis:: |
|
361 | void ChartAxis::handleTitleFontChanged(const QFont &font) | |
364 | { |
|
362 | { | |
365 | if(m_title->font() != font){ |
|
363 | if(m_title->font() != font){ | |
366 | m_title->setFont(font); |
|
364 | m_title->setFont(font); | |
@@ -369,80 +367,59 void ChartAxis::setTitleFont(const QFont &font) | |||||
369 | } |
|
367 | } | |
370 | } |
|
368 | } | |
371 |
|
369 | |||
372 | QFont ChartAxis::titleFont() const |
|
370 | void ChartAxis::handleVisibleChanged(bool visible) | |
373 | { |
|
|||
374 | return m_title->font(); |
|
|||
375 | } |
|
|||
376 |
|
||||
377 | void ChartAxis::hide() |
|
|||
378 | { |
|
371 | { | |
379 | setArrowVisibility(false); |
|
372 | setVisible(visible); | |
380 | setGridVisibility(false); |
|
|||
381 | setLabelsVisibility(false); |
|
|||
382 | setShadesVisibility(false); |
|
|||
383 | } |
|
373 | } | |
384 |
|
374 | |||
385 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) |
|
375 | void ChartAxis::handleRangeChanged(qreal min, qreal max) | |
386 | { |
|
376 | { | |
387 | m_gridRect = grid; |
|
377 | Q_UNUSED(min); | |
388 | m_axisRect = axis; |
|
378 | Q_UNUSED(max); | |
389 |
|
||||
390 | if (isEmpty()) |
|
|||
391 | return; |
|
|||
392 |
|
||||
393 | QVector<qreal> layout = calculateLayout(); |
|
|||
394 | updateLayout(layout); |
|
|||
395 |
|
379 | |||
396 | } |
|
380 | if (!isEmpty()) { | |
397 |
|
381 | |||
398 | void ChartAxis::axisSelected() |
|
382 | QVector<qreal> layout = calculateLayout(); | |
399 | { |
|
383 | updateLayout(layout); | |
400 | //TODO: axis clicked; |
|
384 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); | |
401 | } |
|
385 | QSizeF after = sizeHint(Qt::PreferredSize); | |
402 |
|
386 | |||
403 | Qt::Orientation ChartAxis::orientation() const |
|
387 | if (before != after) { | |
404 | { |
|
388 | QGraphicsLayoutItem::updateGeometry(); | |
405 | return m_chartAxis->orientation(); |
|
389 | //we don't want to call invalidate on layout, since it will change minimum size of component, | |
406 | } |
|
390 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, | |
|
391 | //instead recalculate layout and use plotArea for extra space. | |||
|
392 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); | |||
|
393 | } | |||
|
394 | } | |||
407 |
|
395 | |||
408 | Qt::Alignment ChartAxis::alignment() const |
|
|||
409 | { |
|
|||
410 | return m_chartAxis->alignment(); |
|
|||
411 | } |
|
|||
412 |
|
||||
413 | bool ChartAxis::isVisible() |
|
|||
414 | { |
|
|||
415 | return m_chartAxis->isVisible(); |
|
|||
416 | } |
|
396 | } | |
417 |
|
397 | |||
418 | void ChartAxis::setLabels(const QStringList &labels) |
|
398 | //helpers | |
419 | { |
|
|||
420 | m_labelsList = labels; |
|
|||
421 | } |
|
|||
422 |
|
399 | |||
423 |
QStringList ChartAxis::createValueLabels(int ticks) |
|
400 | QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const QString& format) | |
424 | { |
|
401 | { | |
425 | Q_ASSERT(m_max > m_min); |
|
402 | //TODO: Q_ASSERT(m_max > m_min); | |
426 | Q_ASSERT(ticks > 1); |
|
403 | //TODO: Q_ASSERT(ticks > 1); | |
427 |
|
404 | |||
428 | QStringList labels; |
|
405 | QStringList labels; | |
429 |
|
406 | |||
430 | int n = qMax(int(-qFloor(log10((m_max - m_min) / (ticks - 1)))), 0); |
|
407 | if(max <= min || ticks < 1){ | |
431 | n++; |
|
408 | return labels; | |
432 |
|
409 | } | ||
433 | QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis); |
|
|||
434 |
|
410 | |||
435 | QString format = axis->labelFormat(); |
|
411 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | |
|
412 | n++; | |||
436 |
|
413 | |||
437 | if (format.isNull()) { |
|
414 | if (format.isNull()) { | |
438 | for (int i = 0; i < ticks; i++) { |
|
415 | for (int i = 0; i < ticks; i++) { | |
439 |
qreal value = |
|
416 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
440 | labels << QString::number(value, 'f', n); |
|
417 | labels << QString::number(value, 'f', n); | |
441 | } |
|
418 | } | |
442 | } else { |
|
419 | } else { | |
443 | QByteArray array = format.toLatin1(); |
|
420 | QByteArray array = format.toLatin1(); | |
444 | for (int i = 0; i < ticks; i++) { |
|
421 | for (int i = 0; i < ticks; i++) { | |
445 |
qreal value = |
|
422 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
446 | if (format.contains("d") |
|
423 | if (format.contains("d") | |
447 | || format.contains("i") |
|
424 | || format.contains("i") | |
448 | || format.contains("c")) |
|
425 | || format.contains("c")) | |
@@ -461,27 +438,25 QStringList ChartAxis::createValueLabels(int ticks) const | |||||
461 | return labels; |
|
438 | return labels; | |
462 | } |
|
439 | } | |
463 |
|
440 | |||
464 |
QStringList ChartAxis::createDateTimeLabels(const QString |
|
441 | QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format) | |
465 | { |
|
442 | { | |
466 | Q_ASSERT(m_max > m_min); |
|
443 | //TODO: Q_ASSERT(m_max > m_min); | |
467 | Q_ASSERT(ticks > 1); |
|
444 | //TODO: Q_ASSERT(ticks > 1); | |
468 | QStringList labels; |
|
445 | QStringList labels; | |
469 | int n = qMax(int(-floor(log10((m_max - m_min) / (ticks - 1)))), 0); |
|
446 | ||
|
447 | if(max <= min || ticks < 1) { | |||
|
448 | return labels; | |||
|
449 | } | |||
|
450 | ||||
|
451 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); | |||
470 | n++; |
|
452 | n++; | |
471 | for (int i = 0; i < ticks; i++) { |
|
453 | for (int i = 0; i < ticks; i++) { | |
472 |
qreal value = |
|
454 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
473 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); |
|
455 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); | |
474 | } |
|
456 | } | |
475 | return labels; |
|
457 | return labels; | |
476 | } |
|
458 | } | |
477 |
|
459 | |||
478 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
|||
479 | { |
|
|||
480 | Q_UNUSED(which); |
|
|||
481 | Q_UNUSED(constraint); |
|
|||
482 | return QSizeF(); |
|
|||
483 | } |
|
|||
484 |
|
||||
485 | #include "moc_chartaxis_p.cpp" |
|
460 | #include "moc_chartaxis_p.cpp" | |
486 |
|
461 | |||
487 | QTCOMMERCIALCHART_END_NAMESPACE |
|
462 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -48,48 +48,16 class ChartAxis : public ChartElement, public QGraphicsLayoutItem | |||||
48 | Q_INTERFACES(QGraphicsLayoutItem) |
|
48 | Q_INTERFACES(QGraphicsLayoutItem) | |
49 | public: |
|
49 | public: | |
50 |
|
50 | |||
51 |
ChartAxis(QAbstractAxis *axis, |
|
51 | ChartAxis(QAbstractAxis *axis, QGraphicsItem* item = 0, bool intervalAxis = false); | |
52 | ~ChartAxis(); |
|
52 | ~ChartAxis(); | |
53 |
|
53 | |||
54 |
QAbstractAxis* axis() const { return m_ |
|
54 | QAbstractAxis* axis() const { return m_axis; } | |
55 |
|
55 | |||
56 | void setArrowOpacity(qreal opacity); |
|
|||
57 | qreal arrowOpacity() const; |
|
|||
58 | void setArrowVisibility(bool visible); |
|
|||
59 |
|
||||
60 | void setGridOpacity(qreal opacity); |
|
|||
61 | qreal gridOpacity() const; |
|
|||
62 | void setGridVisibility(bool visible); |
|
|||
63 |
|
||||
64 | void setLabelsOpacity(qreal opacity); |
|
|||
65 | qreal labelsOpacity() const; |
|
|||
66 | void setLabelsVisibility(bool visible); |
|
|||
67 |
|
||||
68 | void setShadesOpacity(qreal opacity); |
|
|||
69 | qreal shadesOpacity() const; |
|
|||
70 | void setShadesVisibility(bool visible); |
|
|||
71 |
|
||||
72 | void setLabelsAngle(int angle); |
|
|||
73 | int labelsAngle()const { return m_labelsAngle; } |
|
|||
74 |
|
||||
75 | void setShadesBrush(const QBrush &brush); |
|
|||
76 | void setShadesPen(const QPen &pen); |
|
|||
77 |
|
||||
78 | void setArrowPen(const QPen &pen); |
|
|||
79 | void setGridPen(const QPen &pen); |
|
|||
80 |
|
||||
81 | void setLabelsPen(const QPen &pen); |
|
|||
82 | void setLabelsBrush(const QBrush &brush); |
|
|||
83 | void setLabelsFont(const QFont &font); |
|
|||
84 | void setLabelPadding(int padding); |
|
56 | void setLabelPadding(int padding); | |
85 | int labelPadding() const { return m_labelPadding;}; |
|
57 | int labelPadding() const { return m_labelPadding;}; | |
86 |
|
58 | |||
87 | void setTitlePen(const QPen &pen); |
|
|||
88 | void setTitleBrush(const QBrush &brush); |
|
|||
89 | void setTitleFont(const QFont &font); |
|
|||
90 | QFont titleFont() const; |
|
59 | QFont titleFont() const; | |
91 | void setTitleText(const QString &title); |
|
60 | QString titleText() const; | |
92 | QString titleText() const {return m_titleText; }; |
|
|||
93 |
|
61 | |||
94 | void setLayout(QVector<qreal> &layout); |
|
62 | void setLayout(QVector<qreal> &layout); | |
95 | QVector<qreal> layout() const { return m_layoutVector; } |
|
63 | QVector<qreal> layout() const { return m_layoutVector; } | |
@@ -100,9 +68,6 public: | |||||
100 | Qt::Orientation orientation() const; |
|
68 | Qt::Orientation orientation() const; | |
101 | Qt::Alignment alignment() const; |
|
69 | Qt::Alignment alignment() const; | |
102 |
|
70 | |||
103 | bool isVisible(); |
|
|||
104 | void hide(); |
|
|||
105 |
|
||||
106 | void setGeometry(const QRectF &axis, const QRectF &grid); |
|
71 | void setGeometry(const QRectF &axis, const QRectF &grid); | |
107 | QRectF axisGeometry() const { return m_axisRect; } |
|
72 | QRectF axisGeometry() const { return m_axisRect; } | |
108 | QRectF gridGeometry() const { return m_gridRect; } |
|
73 | QRectF gridGeometry() const { return m_gridRect; } | |
@@ -115,6 +80,20 public: | |||||
115 |
|
80 | |||
116 | virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; |
|
81 | virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; | |
117 |
|
82 | |||
|
83 | ||||
|
84 | QRectF boundingRect() const{ | |||
|
85 | return QRectF(); | |||
|
86 | } | |||
|
87 | ||||
|
88 | void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) | |||
|
89 | { | |||
|
90 | ||||
|
91 | } | |||
|
92 | ||||
|
93 | //helpers | |||
|
94 | static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format); | |||
|
95 | static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format); | |||
|
96 | ||||
118 | protected: |
|
97 | protected: | |
119 | void setGeometry(const QRectF &size) { Q_UNUSED(size);}; |
|
98 | void setGeometry(const QRectF &size) { Q_UNUSED(size);}; | |
120 | virtual void updateGeometry() = 0; |
|
99 | virtual void updateGeometry() = 0; | |
@@ -126,15 +105,33 protected: | |||||
126 | QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();}; |
|
105 | QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();}; | |
127 | QGraphicsSimpleTextItem* titleItem() const { return m_title.data();} |
|
106 | QGraphicsSimpleTextItem* titleItem() const { return m_title.data();} | |
128 |
|
107 | |||
129 |
QFont font() const |
|
108 | QFont font() const; | |
130 |
qreal min() const |
|
109 | qreal min() const; | |
131 |
qreal max() const |
|
110 | qreal max() const; | |
132 | QStringList createValueLabels(int ticks) const; |
|
|||
133 | QStringList createDateTimeLabels(const QString &format, int ticks) const; |
|
|||
134 |
|
111 | |||
|
112 | //handlers | |||
135 | public Q_SLOTS: |
|
113 | public Q_SLOTS: | |
136 | virtual void handleAxisUpdated(); |
|
114 | void handleVisibleChanged(bool visible); | |
137 | virtual void handleDomainUpdated(); |
|
115 | void handleArrowVisibleChanged(bool visible); | |
|
116 | void handleGridVisibleChanged(bool visible); | |||
|
117 | void handleLabelsVisibleChanged(bool visible); | |||
|
118 | void handleShadesVisibleChanged(bool visible); | |||
|
119 | void handleLabelsAngleChanged(int angle); | |||
|
120 | void handleShadesBrushChanged(const QBrush &brush); | |||
|
121 | void handleShadesPenChanged(const QPen &pen); | |||
|
122 | void handleArrowPenChanged(const QPen &pen); | |||
|
123 | void handleGridPenChanged(const QPen &pen); | |||
|
124 | void handleLabelsPenChanged(const QPen &pen); | |||
|
125 | void handleLabelsBrushChanged(const QBrush &brush); | |||
|
126 | void handleLabelsFontChanged(const QFont &font); | |||
|
127 | void handleTitlePenChanged(const QPen &pen); | |||
|
128 | void handleTitleBrushChanged(const QBrush &brush); | |||
|
129 | void handleTitleFontChanged(const QFont &font); | |||
|
130 | void handleTitleTextChanged(const QString &title); | |||
|
131 | void handleRangeChanged(qreal min , qreal max); | |||
|
132 | ||||
|
133 | Q_SIGNALS: | |||
|
134 | void clicked(); | |||
138 |
|
135 | |||
139 | private: |
|
136 | private: | |
140 | inline bool isEmpty(); |
|
137 | inline bool isEmpty(); | |
@@ -142,37 +139,34 private: | |||||
142 | void deleteItems(int count); |
|
139 | void deleteItems(int count); | |
143 | void updateLayout(QVector<qreal> &layout); |
|
140 | void updateLayout(QVector<qreal> &layout); | |
144 | void axisSelected(); |
|
141 | void axisSelected(); | |
|
142 | void connectSlots(); | |||
145 |
|
143 | |||
146 | private: |
|
144 | private: | |
147 |
QAbstractAxis *m_ |
|
145 | QAbstractAxis *m_axis; | |
148 | int m_labelsAngle; |
|
146 | int m_labelsAngle; | |
149 | QRectF m_axisRect; |
|
147 | QRectF m_axisRect; | |
150 | QRectF m_gridRect; |
|
148 | QRectF m_gridRect; | |
151 | QScopedPointer<QGraphicsItemGroup> m_grid; |
|
149 | QScopedPointer<QGraphicsItemGroup> m_grid; | |
|
150 | QScopedPointer<QGraphicsItemGroup> m_arrow; | |||
152 | QScopedPointer<QGraphicsItemGroup> m_shades; |
|
151 | QScopedPointer<QGraphicsItemGroup> m_shades; | |
153 | QScopedPointer<QGraphicsItemGroup> m_labels; |
|
152 | QScopedPointer<QGraphicsItemGroup> m_labels; | |
154 | QScopedPointer<QGraphicsItemGroup> m_arrow; |
|
|||
155 | QScopedPointer<QGraphicsSimpleTextItem> m_title; |
|
153 | QScopedPointer<QGraphicsSimpleTextItem> m_title; | |
156 | QVector<qreal> m_layoutVector; |
|
154 | QVector<qreal> m_layoutVector; | |
157 | qreal m_min; |
|
|||
158 | qreal m_max; |
|
|||
159 | AxisAnimation *m_animation; |
|
155 | AxisAnimation *m_animation; | |
160 | QFont m_font; |
|
|||
161 | QString m_titleText; |
|
|||
162 | int m_labelPadding; |
|
156 | int m_labelPadding; | |
163 | QStringList m_labelsList; |
|
157 | QStringList m_labelsList; | |
164 | bool m_intervalAxis; |
|
158 | bool m_intervalAxis; | |
165 |
|
159 | |||
166 | friend class AxisAnimation; |
|
160 | friend class AxisAnimation; | |
167 |
friend class A |
|
161 | friend class ArrowItem; | |
168 |
|
162 | |||
169 | }; |
|
163 | }; | |
170 |
|
164 | |||
171 |
class A |
|
165 | class ArrowItem: public QGraphicsLineItem | |
172 | { |
|
166 | { | |
173 |
|
167 | |||
174 | public: |
|
168 | public: | |
175 |
explicit A |
|
169 | explicit ArrowItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} | |
176 |
|
170 | |||
177 | protected: |
|
171 | protected: | |
178 | void mousePressEvent(QGraphicsSceneMouseEvent *event) { |
|
172 | void mousePressEvent(QGraphicsSceneMouseEvent *event) { |
@@ -29,11 +29,11 | |||||
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 |
ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis, |
|
32 | ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis, QGraphicsItem* item) | |
33 |
: HorizontalAxis(axis, |
|
33 | : HorizontalAxis(axis, item), | |
34 | m_tickCount(0), |
|
|||
35 | m_axis(axis) |
|
34 | m_axis(axis) | |
36 | { |
|
35 | { | |
|
36 | QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int))); | |||
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartDateTimeAxisX::~ChartDateTimeAxisX() |
|
39 | ChartDateTimeAxisX::~ChartDateTimeAxisX() | |
@@ -42,13 +42,15 ChartDateTimeAxisX::~ChartDateTimeAxisX() | |||||
42 |
|
42 | |||
43 | QVector<qreal> ChartDateTimeAxisX::calculateLayout() const |
|
43 | QVector<qreal> ChartDateTimeAxisX::calculateLayout() const | |
44 | { |
|
44 | { | |
45 | Q_ASSERT(m_tickCount >= 2); |
|
45 | int tickCount = m_axis->tickCount(); | |
|
46 | ||||
|
47 | Q_ASSERT(tickCount >= 2); | |||
46 |
|
48 | |||
47 | QVector<qreal> points; |
|
49 | QVector<qreal> points; | |
48 |
points.resize( |
|
50 | points.resize(tickCount); | |
49 | const QRectF &gridRect = gridGeometry(); |
|
51 | const QRectF &gridRect = gridGeometry(); | |
50 |
const qreal deltaX = gridRect.width() / ( |
|
52 | const qreal deltaX = gridRect.width() / (tickCount - 1); | |
51 |
for (int i = 0; i < |
|
53 | for (int i = 0; i < tickCount; ++i) { | |
52 | int x = i * deltaX + gridRect.left(); |
|
54 | int x = i * deltaX + gridRect.left(); | |
53 | points[i] = x; |
|
55 | points[i] = x; | |
54 | } |
|
56 | } | |
@@ -60,17 +62,14 void ChartDateTimeAxisX::updateGeometry() | |||||
60 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
62 | const QVector<qreal>& layout = ChartAxis::layout(); | |
61 | if (layout.isEmpty()) |
|
63 | if (layout.isEmpty()) | |
62 | return; |
|
64 | return; | |
63 |
setLabels(createDateTimeLabels(m |
|
65 | setLabels(createDateTimeLabels(min(),max(), layout.size(),m_axis->format())); | |
64 | HorizontalAxis::updateGeometry(); |
|
66 | HorizontalAxis::updateGeometry(); | |
65 | } |
|
67 | } | |
66 |
|
68 | |||
67 |
void ChartDateTimeAxisX::handle |
|
69 | void ChartDateTimeAxisX::handleTickCountChanged(int tick) | |
68 | { |
|
70 | { | |
69 | if (m_tickCount != m_axis->tickCount()) { |
|
71 | Q_UNUSED(tick) | |
70 | m_tickCount = m_axis->tickCount(); |
|
72 | if(presenter()) presenter()->layout()->invalidate(); | |
71 | presenter()->layout()->invalidate(); |
|
|||
72 | } |
|
|||
73 | ChartAxis::handleAxisUpdated(); |
|
|||
74 | } |
|
73 | } | |
75 |
|
74 | |||
76 | QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
75 | QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
@@ -81,10 +80,14 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||||
81 | QSizeF sh; |
|
80 | QSizeF sh; | |
82 |
|
81 | |||
83 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
82 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |
84 |
QStringList ticksList = createDateTimeLabels(m_axis->format() |
|
83 | QStringList ticksList = createDateTimeLabels(min(),max(),m_axis->tickCount(),m_axis->format()); | |
85 | qreal width = 0; |
|
84 | qreal width = 0; | |
86 | qreal height = 0; |
|
85 | qreal height = 0; | |
87 |
|
86 | |||
|
87 | if(ticksList.empty()){ | |||
|
88 | return sh; | |||
|
89 | } | |||
|
90 | ||||
88 |
|
91 | |||
89 | switch (which) { |
|
92 | switch (which) { | |
90 | case Qt::MinimumSize:{ |
|
93 | case Qt::MinimumSize:{ | |
@@ -112,4 +115,6 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||||
112 | return sh; |
|
115 | return sh; | |
113 | } |
|
116 | } | |
114 |
|
117 | |||
|
118 | #include "moc_chartdatetimeaxisx_p.cpp" | |||
|
119 | ||||
115 | QTCOMMERCIALCHART_END_NAMESPACE |
|
120 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -39,18 +39,19 class ChartPresenter; | |||||
39 |
|
39 | |||
40 | class ChartDateTimeAxisX : public HorizontalAxis |
|
40 | class ChartDateTimeAxisX : public HorizontalAxis | |
41 | { |
|
41 | { | |
|
42 | Q_OBJECT | |||
42 | public: |
|
43 | public: | |
43 |
ChartDateTimeAxisX(QDateTimeAxis *axis, |
|
44 | ChartDateTimeAxisX(QDateTimeAxis *axis, QGraphicsItem* item = 0); | |
44 | ~ChartDateTimeAxisX(); |
|
45 | ~ChartDateTimeAxisX(); | |
45 |
|
46 | |||
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
|
47 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; | |
47 | protected: |
|
48 | protected: | |
48 | void handleAxisUpdated(); |
|
|||
49 | QVector<qreal> calculateLayout() const; |
|
49 | QVector<qreal> calculateLayout() const; | |
50 | void updateGeometry(); |
|
50 | void updateGeometry(); | |
|
51 | private Q_SLOTS: | |||
|
52 | void handleTickCountChanged(int tick); | |||
51 |
|
53 | |||
52 | private: |
|
54 | private: | |
53 | int m_tickCount; |
|
|||
54 | QDateTimeAxis *m_axis; |
|
55 | QDateTimeAxis *m_axis; | |
55 | }; |
|
56 | }; | |
56 |
|
57 |
@@ -29,11 +29,11 | |||||
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 |
ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis, |
|
32 | ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis, QGraphicsItem* item) | |
33 |
: VerticalAxis(axis, |
|
33 | : VerticalAxis(axis, item), | |
34 | m_tickCount(0), |
|
|||
35 | m_axis(axis) |
|
34 | m_axis(axis) | |
36 | { |
|
35 | { | |
|
36 | QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int))); | |||
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartDateTimeAxisY::~ChartDateTimeAxisY() |
|
39 | ChartDateTimeAxisY::~ChartDateTimeAxisY() | |
@@ -42,13 +42,15 ChartDateTimeAxisY::~ChartDateTimeAxisY() | |||||
42 |
|
42 | |||
43 | QVector<qreal> ChartDateTimeAxisY::calculateLayout() const |
|
43 | QVector<qreal> ChartDateTimeAxisY::calculateLayout() const | |
44 | { |
|
44 | { | |
45 | Q_ASSERT(m_tickCount >= 2); |
|
45 | int tickCount = m_axis->tickCount(); | |
|
46 | ||||
|
47 | Q_ASSERT(tickCount >= 2); | |||
46 |
|
48 | |||
47 | QVector<qreal> points; |
|
49 | QVector<qreal> points; | |
48 |
points.resize( |
|
50 | points.resize(tickCount); | |
49 | const QRectF &gridRect = gridGeometry(); |
|
51 | const QRectF &gridRect = gridGeometry(); | |
50 |
const qreal deltaY = gridRect.height() / ( |
|
52 | const qreal deltaY = gridRect.height() / (tickCount - 1); | |
51 |
for (int i = 0; i < |
|
53 | for (int i = 0; i < tickCount; ++i) { | |
52 | int y = i * -deltaY + gridRect.bottom(); |
|
54 | int y = i * -deltaY + gridRect.bottom(); | |
53 | points[i] = y; |
|
55 | points[i] = y; | |
54 | } |
|
56 | } | |
@@ -61,17 +63,14 void ChartDateTimeAxisY::updateGeometry() | |||||
61 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
63 | const QVector<qreal> &layout = ChartAxis::layout(); | |
62 | if (layout.isEmpty()) |
|
64 | if (layout.isEmpty()) | |
63 | return; |
|
65 | return; | |
64 |
setLabels(createDateTimeLabels(m |
|
66 | setLabels(createDateTimeLabels(min(),max(), layout.size(),m_axis->format())); | |
65 | VerticalAxis::updateGeometry(); |
|
67 | VerticalAxis::updateGeometry(); | |
66 | } |
|
68 | } | |
67 |
|
69 | |||
68 |
void ChartDateTimeAxisY::handle |
|
70 | void ChartDateTimeAxisY::handleTickCountChanged(int tick) | |
69 | { |
|
71 | { | |
70 | if (m_tickCount != m_axis->tickCount()) { |
|
72 | Q_UNUSED(tick) | |
71 | m_tickCount = m_axis->tickCount(); |
|
73 | if(presenter()) presenter()->layout()->invalidate(); | |
72 | presenter()->layout()->invalidate(); |
|
|||
73 | } |
|
|||
74 | ChartAxis::handleAxisUpdated(); |
|
|||
75 | } |
|
74 | } | |
76 |
|
75 | |||
77 | QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
76 | QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
@@ -82,10 +81,14 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||||
82 | QSizeF sh; |
|
81 | QSizeF sh; | |
83 |
|
82 | |||
84 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
83 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
85 |
QStringList ticksList = createDateTimeLabels(m_axis->format() |
|
84 | QStringList ticksList = createDateTimeLabels(min(),max(),m_axis->tickCount(),m_axis->format()); | |
86 | qreal width = 0; |
|
85 | qreal width = 0; | |
87 | qreal height = 0; |
|
86 | qreal height = 0; | |
88 |
|
87 | |||
|
88 | if(ticksList.empty()){ | |||
|
89 | return sh; | |||
|
90 | } | |||
|
91 | ||||
89 | switch (which) { |
|
92 | switch (which) { | |
90 | case Qt::MinimumSize: { |
|
93 | case Qt::MinimumSize: { | |
91 | width = fn.boundingRect("...").width() + labelPadding(); |
|
94 | width = fn.boundingRect("...").width() + labelPadding(); | |
@@ -111,4 +114,6 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||||
111 | return sh; |
|
114 | return sh; | |
112 | } |
|
115 | } | |
113 |
|
116 | |||
|
117 | #include "moc_chartdatetimeaxisy_p.cpp" | |||
|
118 | ||||
114 | QTCOMMERCIALCHART_END_NAMESPACE |
|
119 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -39,17 +39,18 class ChartPresenter; | |||||
39 |
|
39 | |||
40 | class ChartDateTimeAxisY : public VerticalAxis |
|
40 | class ChartDateTimeAxisY : public VerticalAxis | |
41 | { |
|
41 | { | |
|
42 | Q_OBJECT | |||
42 | public: |
|
43 | public: | |
43 |
ChartDateTimeAxisY(QDateTimeAxis *axis, |
|
44 | ChartDateTimeAxisY(QDateTimeAxis *axis, QGraphicsItem* item = 0); | |
44 | ~ChartDateTimeAxisY(); |
|
45 | ~ChartDateTimeAxisY(); | |
45 |
|
46 | |||
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
|
47 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; | |
47 | protected: |
|
48 | protected: | |
48 | QVector<qreal> calculateLayout() const; |
|
49 | QVector<qreal> calculateLayout() const; | |
49 | void updateGeometry(); |
|
50 | void updateGeometry(); | |
50 | void handleAxisUpdated(); |
|
51 | private Q_SLOTS: | |
|
52 | void handleTickCountChanged(int tick); | |||
51 | private: |
|
53 | private: | |
52 | int m_tickCount; |
|
|||
53 | QDateTimeAxis *m_axis; |
|
54 | QDateTimeAxis *m_axis; | |
54 | }; |
|
55 | }; | |
55 |
|
56 |
@@ -23,6 +23,7 | |||||
23 | #include "chartdatetimeaxisx_p.h" |
|
23 | #include "chartdatetimeaxisx_p.h" | |
24 | #include "chartdatetimeaxisy_p.h" |
|
24 | #include "chartdatetimeaxisy_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
|
26 | #include "qchart.h" | |||
26 | #include <float.h> |
|
27 | #include <float.h> | |
27 | #include <cmath> |
|
28 | #include <cmath> | |
28 |
|
29 | |||
@@ -177,33 +178,35 QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstra | |||||
177 | */ |
|
178 | */ | |
178 | QDateTimeAxis::~QDateTimeAxis() |
|
179 | QDateTimeAxis::~QDateTimeAxis() | |
179 | { |
|
180 | { | |
180 |
|
181 | Q_D(QDateTimeAxis); | ||
|
182 | if (d->m_chart) | |||
|
183 | d->m_chart->removeAxis(this); | |||
181 | } |
|
184 | } | |
182 |
|
185 | |||
183 | void QDateTimeAxis::setMin(QDateTime min) |
|
186 | void QDateTimeAxis::setMin(QDateTime min) | |
184 | { |
|
187 | { | |
185 | Q_D(QDateTimeAxis); |
|
188 | Q_D(QDateTimeAxis); | |
186 | if (min.isValid()) |
|
189 | if (min.isValid()) | |
187 | setRange(min, qMax(d->m_max, min)); |
|
190 | d->setRange(min.toMSecsSinceEpoch(), qMax(d->m_max, qreal(min.toMSecsSinceEpoch()))); | |
188 | } |
|
191 | } | |
189 |
|
192 | |||
190 | QDateTime QDateTimeAxis::min() const |
|
193 | QDateTime QDateTimeAxis::min() const | |
191 | { |
|
194 | { | |
192 | Q_D(const QDateTimeAxis); |
|
195 | Q_D(const QDateTimeAxis); | |
193 | return d->m_min; |
|
196 | return QDateTime::fromMSecsSinceEpoch(d->m_min); | |
194 | } |
|
197 | } | |
195 |
|
198 | |||
196 | void QDateTimeAxis::setMax(QDateTime max) |
|
199 | void QDateTimeAxis::setMax(QDateTime max) | |
197 | { |
|
200 | { | |
198 | Q_D(QDateTimeAxis); |
|
201 | Q_D(QDateTimeAxis); | |
199 | if (max.isValid()) |
|
202 | if (max.isValid()) | |
200 | setRange(qMin(d->m_min, max), max); |
|
203 | d->setRange(qMin(d->m_min, qreal(max.toMSecsSinceEpoch())), max.toMSecsSinceEpoch()); | |
201 | } |
|
204 | } | |
202 |
|
205 | |||
203 | QDateTime QDateTimeAxis::max() const |
|
206 | QDateTime QDateTimeAxis::max() const | |
204 | { |
|
207 | { | |
205 | Q_D(const QDateTimeAxis); |
|
208 | Q_D(const QDateTimeAxis); | |
206 | return d->m_max; |
|
209 | return QDateTime::fromMSecsSinceEpoch(d->m_max); | |
207 | } |
|
210 | } | |
208 |
|
211 | |||
209 | /*! |
|
212 | /*! | |
@@ -216,23 +219,7 void QDateTimeAxis::setRange(QDateTime min, QDateTime max) | |||||
216 | if (!min.isValid() || !max.isValid() || min > max) |
|
219 | if (!min.isValid() || !max.isValid() || min > max) | |
217 | return; |
|
220 | return; | |
218 |
|
221 | |||
219 | bool changed = false; |
|
222 | d->setRange(min.toMSecsSinceEpoch(),max.toMSecsSinceEpoch()); | |
220 | if (d->m_min != min) { |
|
|||
221 | d->m_min = min; |
|
|||
222 | changed = true; |
|
|||
223 | emit minChanged(min); |
|
|||
224 | } |
|
|||
225 |
|
||||
226 | if (d->m_max != max) { |
|
|||
227 | d->m_max = max; |
|
|||
228 | changed = true; |
|
|||
229 | emit maxChanged(max); |
|
|||
230 | } |
|
|||
231 |
|
||||
232 | if (changed) { |
|
|||
233 | emit rangeChanged(d->m_min, d->m_max); |
|
|||
234 | d->emitUpdated(); |
|
|||
235 | } |
|
|||
236 | } |
|
223 | } | |
237 |
|
224 | |||
238 | void QDateTimeAxis::setFormat(QString format) |
|
225 | void QDateTimeAxis::setFormat(QString format) | |
@@ -258,7 +245,7 void QDateTimeAxis::setTickCount(int count) | |||||
258 | Q_D(QDateTimeAxis); |
|
245 | Q_D(QDateTimeAxis); | |
259 | if (d->m_tickCount != count && count >= 2) { |
|
246 | if (d->m_tickCount != count && count >= 2) { | |
260 | d->m_tickCount = count; |
|
247 | d->m_tickCount = count; | |
261 | d->emitUpdated(); |
|
248 | emit tickCountChanged(count); | |
262 | } |
|
249 | } | |
263 | } |
|
250 | } | |
264 |
|
251 | |||
@@ -284,8 +271,8 QAbstractAxis::AxisType QDateTimeAxis::type() const | |||||
284 |
|
271 | |||
285 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q) |
|
272 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q) | |
286 | : QAbstractAxisPrivate(q), |
|
273 | : QAbstractAxisPrivate(q), | |
287 | m_min(QDateTime::fromMSecsSinceEpoch(0)), |
|
274 | m_min(0), | |
288 | m_max(QDateTime::fromMSecsSinceEpoch(0)), |
|
275 | m_max(0), | |
289 | m_tickCount(5) |
|
276 | m_tickCount(5) | |
290 | { |
|
277 | { | |
291 | m_format = "dd-MM-yyyy\nh:mm"; |
|
278 | m_format = "dd-MM-yyyy\nh:mm"; | |
@@ -296,16 +283,28 QDateTimeAxisPrivate::~QDateTimeAxisPrivate() | |||||
296 |
|
283 | |||
297 | } |
|
284 | } | |
298 |
|
285 | |||
299 |
void QDateTimeAxisPrivate:: |
|
286 | void QDateTimeAxisPrivate::setRange(qreal min,qreal max) | |
300 | { |
|
287 | { | |
301 | Q_Q(QDateTimeAxis); |
|
288 | Q_Q(QDateTimeAxis); | |
302 | Domain *domain = qobject_cast<Domain *>(sender()); |
|
|||
303 | Q_ASSERT(domain); |
|
|||
304 |
|
289 | |||
305 | if (orientation() == Qt::Horizontal) |
|
290 | bool changed = false; | |
306 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); |
|
291 | ||
307 | else if (orientation() == Qt::Vertical) |
|
292 | if (m_min != min) { | |
308 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); |
|
293 | m_min = min; | |
|
294 | changed = true; | |||
|
295 | emit q->minChanged(QDateTime::fromMSecsSinceEpoch(min)); | |||
|
296 | } | |||
|
297 | ||||
|
298 | if (m_max != max) { | |||
|
299 | m_max = max; | |||
|
300 | changed = true; | |||
|
301 | emit q->maxChanged(QDateTime::fromMSecsSinceEpoch(max)); | |||
|
302 | } | |||
|
303 | ||||
|
304 | if (changed) { | |||
|
305 | emit q->rangeChanged(QDateTime::fromMSecsSinceEpoch(min), QDateTime::fromMSecsSinceEpoch(max)); | |||
|
306 | emit rangeChanged(m_min,m_max); | |||
|
307 | } | |||
309 | } |
|
308 | } | |
310 |
|
309 | |||
311 |
|
310 | |||
@@ -331,27 +330,31 void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |||||
331 | q->setRange(min.toDateTime(), max.toDateTime()); |
|
330 | q->setRange(min.toDateTime(), max.toDateTime()); | |
332 | } |
|
331 | } | |
333 |
|
332 | |||
334 | ChartAxis *QDateTimeAxisPrivate::createGraphics(ChartPresenter *presenter) |
|
333 | void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
335 | { |
|
334 | { | |
336 | Q_Q(QDateTimeAxis); |
|
335 | Q_Q(QDateTimeAxis); | |
337 | if (m_orientation == Qt::Vertical) |
|
336 | ChartAxis* axis(0); | |
338 | return new ChartDateTimeAxisY(q, presenter); |
|
337 | if (orientation() == Qt::Vertical) | |
339 |
|
|
338 | axis = new ChartDateTimeAxisY(q,parent); | |
|
339 | if (orientation() == Qt::Horizontal) | |||
|
340 | axis = new ChartDateTimeAxisX(q,parent); | |||
|
341 | ||||
|
342 | m_item.reset(axis); | |||
|
343 | QAbstractAxisPrivate::initializeGraphics(parent); | |||
340 | } |
|
344 | } | |
341 |
|
345 | |||
342 | void QDateTimeAxisPrivate::intializeDomain(Domain *domain) |
|
346 | void QDateTimeAxisPrivate::initializeDomain(Domain *domain) | |
343 | { |
|
347 | { | |
344 | Q_Q(QDateTimeAxis); |
|
|||
345 | if (m_max == m_min) { |
|
348 | if (m_max == m_min) { | |
346 |
if ( |
|
349 | if (orientation() == Qt::Vertical) | |
347 |
|
|
350 | setRange(domain->minY(), domain->maxY()); | |
348 | else |
|
351 | else | |
349 |
|
|
352 | setRange(domain->minX(), domain->maxX()); | |
350 | } else { |
|
353 | } else { | |
351 |
if ( |
|
354 | if (orientation() == Qt::Vertical) | |
352 |
domain->setRangeY(m_min |
|
355 | domain->setRangeY(m_min, m_max); | |
353 | else |
|
356 | else | |
354 |
domain->setRangeX(m_min |
|
357 | domain->setRangeX(m_min, m_max); | |
355 | } |
|
358 | } | |
356 | } |
|
359 | } | |
357 |
|
360 |
@@ -32,7 +32,7 class QDateTimeAxisPrivate; | |||||
32 | class QTCOMMERCIALCHART_EXPORT QDateTimeAxis : public QAbstractAxis |
|
32 | class QTCOMMERCIALCHART_EXPORT QDateTimeAxis : public QAbstractAxis | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount) |
|
35 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged) | |
36 | Q_PROPERTY(QDateTime min READ min WRITE setMin NOTIFY minChanged) |
|
36 | Q_PROPERTY(QDateTime min READ min WRITE setMin NOTIFY minChanged) | |
37 | Q_PROPERTY(QDateTime max READ max WRITE setMax NOTIFY maxChanged) |
|
37 | Q_PROPERTY(QDateTime max READ max WRITE setMax NOTIFY maxChanged) | |
38 | Q_PROPERTY(QString format READ format WRITE setFormat NOTIFY formatChanged) |
|
38 | Q_PROPERTY(QString format READ format WRITE setFormat NOTIFY formatChanged) | |
@@ -66,6 +66,7 Q_SIGNALS: | |||||
66 | void maxChanged(QDateTime max); |
|
66 | void maxChanged(QDateTime max); | |
67 | void rangeChanged(QDateTime min, QDateTime max); |
|
67 | void rangeChanged(QDateTime min, QDateTime max); | |
68 | void formatChanged(QString format); |
|
68 | void formatChanged(QString format); | |
|
69 | void tickCountChanged(int tick); | |||
69 |
|
70 | |||
70 | private: |
|
71 | private: | |
71 | Q_DECLARE_PRIVATE(QDateTimeAxis) |
|
72 | Q_DECLARE_PRIVATE(QDateTimeAxis) |
@@ -44,22 +44,25 public: | |||||
44 | ~QDateTimeAxisPrivate(); |
|
44 | ~QDateTimeAxisPrivate(); | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | ChartAxis *createGraphics(ChartPresenter *presenter); |
|
47 | void initializeGraphics(QGraphicsItem* parent); | |
48 | void intializeDomain(Domain *domain); |
|
48 | void initializeDomain(Domain *domain); | |
49 | void handleDomainUpdated(); |
|
|||
50 | qreal min() { return m_min.toMSecsSinceEpoch(); } |
|
|||
51 | qreal max() { return m_max.toMSecsSinceEpoch(); } |
|
|||
52 | int count() const { /*TODO:*/ return 0;} |
|
|||
53 |
|
49 | |||
54 | protected: |
|
50 | //interface for manipulating range form base class | |
55 | void setMin(const QVariant &min); |
|
51 | void setMin(const QVariant &min); | |
56 | void setMax(const QVariant &max); |
|
52 | void setMax(const QVariant &max); | |
57 | void setRange(const QVariant &min, const QVariant &max); |
|
53 | void setRange(const QVariant &min, const QVariant &max); | |
|
54 | ||||
|
55 | //interface manipulating range form domain | |||
|
56 | qreal min() { return m_min; } | |||
|
57 | qreal max() { return m_max; } | |||
|
58 | void setRange(qreal min,qreal max); | |||
|
59 | ||||
|
60 | protected: | |||
58 | int tickCount() const; |
|
61 | int tickCount() const; | |
59 |
|
62 | |||
60 | protected: |
|
63 | protected: | |
61 |
|
|
64 | qreal m_min; | |
62 |
|
|
65 | qreal m_max; | |
63 | int m_tickCount; |
|
66 | int m_tickCount; | |
64 | QString m_format; |
|
67 | QString m_format; | |
65 | Q_DECLARE_PUBLIC(QDateTimeAxis) |
|
68 | Q_DECLARE_PUBLIC(QDateTimeAxis) |
@@ -26,8 +26,8 | |||||
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 |
HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, |
|
29 | HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis) | |
30 |
: ChartAxis(axis, |
|
30 | : ChartAxis(axis, item, intervalAxis) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
@@ -198,7 +198,7 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) co | |||||
198 | break; |
|
198 | break; | |
199 | case Qt::MaximumSize: |
|
199 | case Qt::MaximumSize: | |
200 | case Qt::PreferredSize: |
|
200 | case Qt::PreferredSize: | |
201 | sh = QSizeF(fn.boundingRect(axis()->title()).width(), fn.height()); |
|
201 | sh = QSizeF(fn.boundingRect(axis()->titleText()).width(), fn.height()); | |
202 | break; |
|
202 | break; | |
203 | default: |
|
203 | default: | |
204 | break; |
|
204 | break; |
@@ -37,7 +37,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
37 | class HorizontalAxis : public ChartAxis |
|
37 | class HorizontalAxis : public ChartAxis | |
38 | { |
|
38 | { | |
39 | public: |
|
39 | public: | |
40 |
HorizontalAxis(QAbstractAxis *axis, |
|
40 | HorizontalAxis(QAbstractAxis *axis, QGraphicsItem* item = 0, bool intervalAxis = false); | |
41 | ~HorizontalAxis(); |
|
41 | ~HorizontalAxis(); | |
42 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; |
|
42 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; | |
43 | protected: |
|
43 | protected: |
@@ -20,6 +20,8 | |||||
20 |
|
20 | |||
21 | #include "qabstractaxis.h" |
|
21 | #include "qabstractaxis.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
|
23 | #include "chartdataset_p.h" | |||
|
24 | #include "charttheme_p.h" | |||
23 |
|
25 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
27 | |||
@@ -308,7 +310,7 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) | |||||
308 |
|
310 | |||
309 | QAbstractAxis::~QAbstractAxis() |
|
311 | QAbstractAxis::~QAbstractAxis() | |
310 | { |
|
312 | { | |
311 |
if (d_ptr->m_ |
|
313 | if (d_ptr->m_chart) | |
312 | qFatal("Still binded axis detected !"); |
|
314 | qFatal("Still binded axis detected !"); | |
313 | } |
|
315 | } | |
314 |
|
316 | |||
@@ -319,7 +321,7 void QAbstractAxis::setLinePen(const QPen &pen) | |||||
319 | { |
|
321 | { | |
320 | if (d_ptr->m_axisPen != pen) { |
|
322 | if (d_ptr->m_axisPen != pen) { | |
321 | d_ptr->m_axisPen = pen; |
|
323 | d_ptr->m_axisPen = pen; | |
322 | d_ptr->emitUpdated(); |
|
324 | emit linePenChanged(pen); | |
323 | } |
|
325 | } | |
324 | } |
|
326 | } | |
325 |
|
327 | |||
@@ -331,6 +333,7 QPen QAbstractAxis::linePen() const | |||||
331 | return d_ptr->m_axisPen; |
|
333 | return d_ptr->m_axisPen; | |
332 | } |
|
334 | } | |
333 |
|
335 | |||
|
336 | //TODO: remove me | |||
334 | void QAbstractAxis::setLinePenColor(QColor color) |
|
337 | void QAbstractAxis::setLinePenColor(QColor color) | |
335 | { |
|
338 | { | |
336 | QPen p = d_ptr->m_axisPen; |
|
339 | QPen p = d_ptr->m_axisPen; | |
@@ -353,7 +356,6 void QAbstractAxis::setLineVisible(bool visible) | |||||
353 | { |
|
356 | { | |
354 | if (d_ptr->m_arrowVisible != visible) { |
|
357 | if (d_ptr->m_arrowVisible != visible) { | |
355 | d_ptr->m_arrowVisible = visible; |
|
358 | d_ptr->m_arrowVisible = visible; | |
356 | d_ptr->emitUpdated(); |
|
|||
357 | emit lineVisibleChanged(visible); |
|
359 | emit lineVisibleChanged(visible); | |
358 | } |
|
360 | } | |
359 | } |
|
361 | } | |
@@ -367,8 +369,7 void QAbstractAxis::setGridLineVisible(bool visible) | |||||
367 | { |
|
369 | { | |
368 | if (d_ptr->m_gridLineVisible != visible) { |
|
370 | if (d_ptr->m_gridLineVisible != visible) { | |
369 | d_ptr->m_gridLineVisible = visible; |
|
371 | d_ptr->m_gridLineVisible = visible; | |
370 | d_ptr->emitUpdated(); |
|
372 | emit gridLineVisibleChanged(visible); | |
371 | emit gridVisibleChanged(visible); |
|
|||
372 | } |
|
373 | } | |
373 | } |
|
374 | } | |
374 |
|
375 | |||
@@ -384,7 +385,7 void QAbstractAxis::setGridLinePen(const QPen &pen) | |||||
384 | { |
|
385 | { | |
385 | if (d_ptr->m_gridLinePen != pen) { |
|
386 | if (d_ptr->m_gridLinePen != pen) { | |
386 | d_ptr->m_gridLinePen = pen; |
|
387 | d_ptr->m_gridLinePen = pen; | |
387 | d_ptr->emitUpdated(); |
|
388 | emit gridLinePenChanged(pen); | |
388 | } |
|
389 | } | |
389 | } |
|
390 | } | |
390 |
|
391 | |||
@@ -400,7 +401,6 void QAbstractAxis::setLabelsVisible(bool visible) | |||||
400 | { |
|
401 | { | |
401 | if (d_ptr->m_labelsVisible != visible) { |
|
402 | if (d_ptr->m_labelsVisible != visible) { | |
402 | d_ptr->m_labelsVisible = visible; |
|
403 | d_ptr->m_labelsVisible = visible; | |
403 | d_ptr->emitUpdated(); |
|
|||
404 | emit labelsVisibleChanged(visible); |
|
404 | emit labelsVisibleChanged(visible); | |
405 | } |
|
405 | } | |
406 | } |
|
406 | } | |
@@ -417,7 +417,7 void QAbstractAxis::setLabelsPen(const QPen &pen) | |||||
417 | { |
|
417 | { | |
418 | if (d_ptr->m_labelsPen != pen) { |
|
418 | if (d_ptr->m_labelsPen != pen) { | |
419 | d_ptr->m_labelsPen = pen; |
|
419 | d_ptr->m_labelsPen = pen; | |
420 | d_ptr->emitUpdated(); |
|
420 | emit labelsPenChanged(pen); | |
421 | } |
|
421 | } | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
@@ -436,7 +436,7 void QAbstractAxis::setLabelsBrush(const QBrush &brush) | |||||
436 | { |
|
436 | { | |
437 | if (d_ptr->m_labelsBrush != brush) { |
|
437 | if (d_ptr->m_labelsBrush != brush) { | |
438 | d_ptr->m_labelsBrush = brush; |
|
438 | d_ptr->m_labelsBrush = brush; | |
439 | d_ptr->emitUpdated(); |
|
439 | emit labelsBrushChanged(brush); | |
440 | } |
|
440 | } | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
@@ -455,7 +455,7 void QAbstractAxis::setLabelsFont(const QFont &font) | |||||
455 | { |
|
455 | { | |
456 | if (d_ptr->m_labelsFont != font) { |
|
456 | if (d_ptr->m_labelsFont != font) { | |
457 | d_ptr->m_labelsFont = font; |
|
457 | d_ptr->m_labelsFont = font; | |
458 | d_ptr->emitUpdated(); |
|
458 | emit labelsFontChanged(font); | |
459 | } |
|
459 | } | |
460 | } |
|
460 | } | |
461 |
|
461 | |||
@@ -471,7 +471,7 void QAbstractAxis::setLabelsAngle(int angle) | |||||
471 | { |
|
471 | { | |
472 | if (d_ptr->m_labelsAngle != angle) { |
|
472 | if (d_ptr->m_labelsAngle != angle) { | |
473 | d_ptr->m_labelsAngle = angle; |
|
473 | d_ptr->m_labelsAngle = angle; | |
474 | d_ptr->emitUpdated(); |
|
474 | emit labelsAngleChanged(angle); | |
475 | } |
|
475 | } | |
476 | } |
|
476 | } | |
477 |
|
477 | |||
@@ -479,7 +479,7 int QAbstractAxis::labelsAngle() const | |||||
479 | { |
|
479 | { | |
480 | return d_ptr->m_labelsAngle; |
|
480 | return d_ptr->m_labelsAngle; | |
481 | } |
|
481 | } | |
482 |
|
482 | //TODO: remove me | ||
483 | void QAbstractAxis::setLabelsColor(QColor color) |
|
483 | void QAbstractAxis::setLabelsColor(QColor color) | |
484 | { |
|
484 | { | |
485 | QBrush b = d_ptr->m_labelsBrush; |
|
485 | QBrush b = d_ptr->m_labelsBrush; | |
@@ -499,7 +499,7 void QAbstractAxis::setTitleVisible(bool visible) | |||||
499 | { |
|
499 | { | |
500 | if (d_ptr->m_titleVisible != visible) { |
|
500 | if (d_ptr->m_titleVisible != visible) { | |
501 | d_ptr->m_titleVisible = visible; |
|
501 | d_ptr->m_titleVisible = visible; | |
502 | d_ptr->emitUpdated(); |
|
502 | emit labelsVisibleChanged(visible); | |
503 | } |
|
503 | } | |
504 | } |
|
504 | } | |
505 |
|
505 | |||
@@ -515,7 +515,7 void QAbstractAxis::setTitlePen(const QPen &pen) | |||||
515 | { |
|
515 | { | |
516 | if (d_ptr->m_titlePen != pen) { |
|
516 | if (d_ptr->m_titlePen != pen) { | |
517 | d_ptr->m_titlePen = pen; |
|
517 | d_ptr->m_titlePen = pen; | |
518 | d_ptr->emitUpdated(); |
|
518 | emit titlePenChanged(pen); | |
519 | } |
|
519 | } | |
520 | } |
|
520 | } | |
521 |
|
521 | |||
@@ -534,7 +534,7 void QAbstractAxis::setTitleBrush(const QBrush &brush) | |||||
534 | { |
|
534 | { | |
535 | if (d_ptr->m_titleBrush != brush) { |
|
535 | if (d_ptr->m_titleBrush != brush) { | |
536 | d_ptr->m_titleBrush = brush; |
|
536 | d_ptr->m_titleBrush = brush; | |
537 | d_ptr->emitUpdated(); |
|
537 | emit titleBrushChanged(brush); | |
538 | } |
|
538 | } | |
539 | } |
|
539 | } | |
540 |
|
540 | |||
@@ -553,7 +553,7 void QAbstractAxis::setTitleFont(const QFont &font) | |||||
553 | { |
|
553 | { | |
554 | if (d_ptr->m_titleFont != font) { |
|
554 | if (d_ptr->m_titleFont != font) { | |
555 | d_ptr->m_titleFont = font; |
|
555 | d_ptr->m_titleFont = font; | |
556 | d_ptr->emitUpdated(); |
|
556 | emit titleFontChanged(font); | |
557 | } |
|
557 | } | |
558 | } |
|
558 | } | |
559 |
|
559 | |||
@@ -565,15 +565,15 QFont QAbstractAxis::titleFont() const | |||||
565 | return d_ptr->m_titleFont; |
|
565 | return d_ptr->m_titleFont; | |
566 | } |
|
566 | } | |
567 |
|
567 | |||
568 | void QAbstractAxis::setTitle(const QString &title) |
|
568 | void QAbstractAxis::setTitleText(const QString &title) | |
569 | { |
|
569 | { | |
570 | if (d_ptr->m_title != title) { |
|
570 | if (d_ptr->m_title != title) { | |
571 | d_ptr->m_title = title; |
|
571 | d_ptr->m_title = title; | |
572 | d_ptr->emitUpdated(); |
|
572 | emit titleTextChanged(title); | |
573 | } |
|
573 | } | |
574 | } |
|
574 | } | |
575 |
|
575 | |||
576 | QString QAbstractAxis::title() const |
|
576 | QString QAbstractAxis::titleText() const | |
577 | { |
|
577 | { | |
578 | return d_ptr->m_title; |
|
578 | return d_ptr->m_title; | |
579 | } |
|
579 | } | |
@@ -583,7 +583,6 void QAbstractAxis::setShadesVisible(bool visible) | |||||
583 | { |
|
583 | { | |
584 | if (d_ptr->m_shadesVisible != visible) { |
|
584 | if (d_ptr->m_shadesVisible != visible) { | |
585 | d_ptr->m_shadesVisible = visible; |
|
585 | d_ptr->m_shadesVisible = visible; | |
586 | d_ptr->emitUpdated(); |
|
|||
587 | emit shadesVisibleChanged(visible); |
|
586 | emit shadesVisibleChanged(visible); | |
588 | } |
|
587 | } | |
589 | } |
|
588 | } | |
@@ -600,7 +599,7 void QAbstractAxis::setShadesPen(const QPen &pen) | |||||
600 | { |
|
599 | { | |
601 | if (d_ptr->m_shadesPen != pen) { |
|
600 | if (d_ptr->m_shadesPen != pen) { | |
602 | d_ptr->m_shadesPen = pen; |
|
601 | d_ptr->m_shadesPen = pen; | |
603 | d_ptr->emitUpdated(); |
|
602 | emit shadesPenChanged(pen); | |
604 | } |
|
603 | } | |
605 | } |
|
604 | } | |
606 |
|
605 | |||
@@ -619,8 +618,7 void QAbstractAxis::setShadesBrush(const QBrush &brush) | |||||
619 | { |
|
618 | { | |
620 | if (d_ptr->m_shadesBrush != brush) { |
|
619 | if (d_ptr->m_shadesBrush != brush) { | |
621 | d_ptr->m_shadesBrush = brush; |
|
620 | d_ptr->m_shadesBrush = brush; | |
622 | d_ptr->emitUpdated(); |
|
621 | emit shadesBrushChanged(brush); | |
623 | emit shadesColorChanged(brush.color()); |
|
|||
624 | } |
|
622 | } | |
625 | } |
|
623 | } | |
626 |
|
624 | |||
@@ -635,8 +633,11 QBrush QAbstractAxis::shadesBrush() const | |||||
635 | void QAbstractAxis::setShadesColor(QColor color) |
|
633 | void QAbstractAxis::setShadesColor(QColor color) | |
636 | { |
|
634 | { | |
637 | QBrush b = d_ptr->m_shadesBrush; |
|
635 | QBrush b = d_ptr->m_shadesBrush; | |
638 |
b. |
|
636 | if (b.color() != color) { | |
639 | setShadesBrush(b); |
|
637 | b.setColor(color); | |
|
638 | setShadesBrush(b); | |||
|
639 | emit shadesColorChanged(color); | |||
|
640 | } | |||
640 | } |
|
641 | } | |
641 |
|
642 | |||
642 | QColor QAbstractAxis::shadesColor() const |
|
643 | QColor QAbstractAxis::shadesColor() const | |
@@ -646,9 +647,12 QColor QAbstractAxis::shadesColor() const | |||||
646 |
|
647 | |||
647 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
648 | void QAbstractAxis::setShadesBorderColor(QColor color) | |
648 | { |
|
649 | { | |
649 |
|
|
650 | QPen p = d_ptr->m_shadesPen; | |
650 | p.setColor(color); |
|
651 | if (p.color() != color) { | |
651 | setShadesPen(p); |
|
652 | p.setColor(color); | |
|
653 | setShadesPen(p); | |||
|
654 | emit shadesColorChanged(color); | |||
|
655 | } | |||
652 | } |
|
656 | } | |
653 |
|
657 | |||
654 | QColor QAbstractAxis::shadesBorderColor() const |
|
658 | QColor QAbstractAxis::shadesBorderColor() const | |
@@ -669,7 +673,6 void QAbstractAxis::setVisible(bool visible) | |||||
669 | { |
|
673 | { | |
670 | if (d_ptr->m_visible != visible) { |
|
674 | if (d_ptr->m_visible != visible) { | |
671 | d_ptr->m_visible = visible; |
|
675 | d_ptr->m_visible = visible; | |
672 | d_ptr->emitUpdated(); |
|
|||
673 | emit visibleChanged(visible); |
|
676 | emit visibleChanged(visible); | |
674 | } |
|
677 | } | |
675 | } |
|
678 | } | |
@@ -729,26 +732,21 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) | |||||
729 | // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function |
|
732 | // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function | |
730 | Qt::Orientation QAbstractAxis::orientation() |
|
733 | Qt::Orientation QAbstractAxis::orientation() | |
731 | { |
|
734 | { | |
732 |
return d_ptr-> |
|
735 | return d_ptr->orientation(); | |
733 | } |
|
736 | } | |
734 |
|
737 | |||
735 | Qt::Alignment QAbstractAxis::alignment() const |
|
738 | Qt::Alignment QAbstractAxis::alignment() const | |
736 | { |
|
739 | { | |
737 |
return d_ptr-> |
|
740 | return d_ptr->alignment(); | |
738 | } |
|
|||
739 |
|
||||
740 | void QAbstractAxis::setAlignment(Qt::Alignment alignment) |
|
|||
741 | { |
|
|||
742 | d_ptr->m_alignment = alignment; |
|
|||
743 | } |
|
741 | } | |
744 |
|
742 | |||
745 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
743 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
746 |
|
744 | |||
747 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) |
|
745 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) | |
748 | : q_ptr(q), |
|
746 | : q_ptr(q), | |
|
747 | m_chart(0), | |||
749 | m_orientation(Qt::Orientation(0)), |
|
748 | m_orientation(Qt::Orientation(0)), | |
750 | m_alignment(0), |
|
749 | m_alignment(0), | |
751 | m_dataset(0), |
|
|||
752 | m_visible(true), |
|
750 | m_visible(true), | |
753 | m_arrowVisible(true), |
|
751 | m_arrowVisible(true), | |
754 | m_gridLineVisible(true), |
|
752 | m_gridLineVisible(true), | |
@@ -764,29 +762,103 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) | |||||
764 |
|
762 | |||
765 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
763 | QAbstractAxisPrivate::~QAbstractAxisPrivate() | |
766 | { |
|
764 | { | |
|
765 | } | |||
767 |
|
766 | |||
|
767 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) | |||
|
768 | { | |||
|
769 | switch(alignment) { | |||
|
770 | case Qt::AlignTop: | |||
|
771 | case Qt::AlignBottom: | |||
|
772 | m_orientation = Qt::Horizontal; | |||
|
773 | break; | |||
|
774 | case Qt::AlignLeft: | |||
|
775 | case Qt::AlignRight: | |||
|
776 | m_orientation = Qt::Vertical; | |||
|
777 | break; | |||
|
778 | default: | |||
|
779 | qWarning()<<"No alignment specified !"; | |||
|
780 | break; | |||
|
781 | }; | |||
|
782 | m_alignment=alignment; | |||
768 | } |
|
783 | } | |
769 |
|
784 | |||
770 | void QAbstractAxisPrivate::emitUpdated() |
|
785 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) | |
771 | { |
|
786 | { | |
772 | if (!m_dirty) { |
|
787 | QPen pen; | |
773 | m_dirty = true; |
|
788 | QBrush brush; | |
774 | emit updated(); |
|
789 | QFont font; | |
|
790 | ||||
|
791 | bool axisX = m_orientation == Qt::Horizontal; | |||
|
792 | ||||
|
793 | if (m_arrowVisible) { | |||
|
794 | ||||
|
795 | if (forced || brush == m_labelsBrush){ | |||
|
796 | q_ptr->setLabelsBrush(theme->labelBrush()); | |||
|
797 | } | |||
|
798 | //TODO: introduce axis brush | |||
|
799 | if (forced || brush == m_titleBrush){ | |||
|
800 | q_ptr->setTitleBrush(theme->labelBrush()); | |||
|
801 | } | |||
|
802 | if (forced || pen == m_labelsPen){ | |||
|
803 | q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons | |||
|
804 | } | |||
|
805 | if (forced || pen == m_titlePen){ | |||
|
806 | q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons | |||
|
807 | } | |||
|
808 | if (forced || m_shadesVisible) { | |||
|
809 | ||||
|
810 | if (forced || brush == m_shadesBrush){ | |||
|
811 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); | |||
|
812 | } | |||
|
813 | if (forced || pen == m_shadesPen){ | |||
|
814 | q_ptr->setShadesPen(theme->backgroundShadesPen()); | |||
|
815 | } | |||
|
816 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth | |||
|
817 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) | |||
|
818 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { | |||
|
819 | q_ptr->setShadesVisible(true); | |||
|
820 | } | |||
|
821 | } | |||
|
822 | ||||
|
823 | if (forced || pen == m_axisPen) { | |||
|
824 | q_ptr->setLinePen(theme->axisLinePen()); | |||
|
825 | } | |||
|
826 | ||||
|
827 | if (forced || pen == m_gridLinePen) { | |||
|
828 | q_ptr->setGridLinePen(theme->girdLinePen()); | |||
|
829 | } | |||
|
830 | ||||
|
831 | if (forced || font == m_labelsFont){ | |||
|
832 | q_ptr->setLabelsFont(theme->labelFont()); | |||
|
833 | } | |||
|
834 | //TODO: discuss with Tero | |||
|
835 | if (forced || font == m_titleFont){ | |||
|
836 | QFont font(m_labelsFont); | |||
|
837 | font.setBold(true); | |||
|
838 | q_ptr->setTitleFont(font); | |||
|
839 | } | |||
775 | } |
|
840 | } | |
776 | } |
|
841 | } | |
777 |
|
842 | |||
778 | void QAbstractAxisPrivate::setDirty(bool dirty) |
|
843 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) | |
|
844 | { | |||
|
845 | setRange(min,max); | |||
|
846 | } | |||
|
847 | ||||
|
848 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |||
779 | { |
|
849 | { | |
780 | m_dirty = dirty; |
|
850 | Q_UNUSED(parent); | |
781 | } |
|
851 | } | |
782 |
|
852 | |||
783 |
void QAbstractAxisPrivate:: |
|
853 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) | |
784 | { |
|
854 | { | |
785 | m_orientation = orientation; |
|
855 | ChartAxis* axis = m_item.data(); | |
786 | if (m_orientation == Qt::Horizontal && !m_alignment) |
|
856 | Q_ASSERT(axis); | |
787 | m_alignment = Qt::AlignBottom; |
|
857 | if(options.testFlag(QChart::GridAxisAnimations)) { | |
788 | else if (m_orientation == Qt::Vertical && !m_alignment) |
|
858 | axis->setAnimation(new AxisAnimation(axis)); | |
789 | m_alignment = Qt::AlignLeft; |
|
859 | }else{ | |
|
860 | axis->setAnimation(0); | |||
|
861 | } | |||
790 | } |
|
862 | } | |
791 |
|
863 | |||
792 |
|
864 |
@@ -33,21 +33,39 class QAbstractAxisPrivate; | |||||
33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject |
|
33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
|
36 | //visibility | |||
36 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
37 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) | |
|
38 | //arrow | |||
37 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) |
|
39 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) | |
|
40 | Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged) | |||
|
41 | //TODO: make wrapping of color for qml | |||
38 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) |
|
42 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) | |
|
43 | //labels | |||
39 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
44 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) | |
40 |
Q_PROPERTY( |
|
45 | Q_PROPERTY(QPen lablesPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged) | |
41 |
Q_PROPERTY(Q |
|
46 | Q_PROPERTY(QBrush lablesBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged) | |
|
47 | //TODO: fix labels angles to work with layout | |||
|
48 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged) | |||
|
49 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged) | |||
|
50 | //TODO: make wrapping of color for qml | |||
42 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
51 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) | |
43 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
52 | //grid | |
|
53 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridLineVisibleChanged) | |||
|
54 | Q_PROPERTY(QPen girdLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged) | |||
|
55 | //shades | |||
44 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
56 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) | |
|
57 | //TODO: make wrapping of color for qml | |||
45 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
58 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) | |
|
59 | //TODO: make wrapping of border for qml | |||
46 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
60 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) | |
|
61 | Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged) | |||
|
62 | Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged) | |||
|
63 | //title | |||
|
64 | Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged) | |||
|
65 | Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged) | |||
|
66 | Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged) | |||
47 | Q_PROPERTY(bool titleVisible READ titleVisible WRITE setTitleVisible) |
|
67 | Q_PROPERTY(bool titleVisible READ titleVisible WRITE setTitleVisible) | |
48 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) |
|
68 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) | |
49 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
|||
50 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) |
|
|||
51 |
|
69 | |||
52 | public: |
|
70 | public: | |
53 |
|
71 | |||
@@ -69,12 +87,13 public: | |||||
69 |
|
87 | |||
70 | virtual AxisType type() const = 0; |
|
88 | virtual AxisType type() const = 0; | |
71 |
|
89 | |||
72 | //visibilty handling |
|
90 | //visibility handling | |
73 | bool isVisible() const; |
|
91 | bool isVisible() const; | |
74 | void setVisible(bool visible = true); |
|
92 | void setVisible(bool visible = true); | |
|
93 | void show(); | |||
|
94 | void hide(); | |||
75 |
|
95 | |||
76 |
|
96 | //arrow handling | ||
77 | //axis handling |
|
|||
78 | bool isLineVisible() const; |
|
97 | bool isLineVisible() const; | |
79 | void setLineVisible(bool visible = true); |
|
98 | void setLineVisible(bool visible = true); | |
80 | void setLinePen(const QPen &pen); |
|
99 | void setLinePen(const QPen &pen); | |
@@ -111,9 +130,8 public: | |||||
111 | QBrush titleBrush() const; |
|
130 | QBrush titleBrush() const; | |
112 | void setTitleFont(const QFont &font); |
|
131 | void setTitleFont(const QFont &font); | |
113 | QFont titleFont() const; |
|
132 | QFont titleFont() const; | |
114 | void setTitle(const QString &title); |
|
133 | void setTitleText(const QString &title); | |
115 | QString title() const; |
|
134 | QString titleText() const; | |
116 |
|
||||
117 |
|
135 | |||
118 | //shades handling |
|
136 | //shades handling | |
119 | bool shadesVisible() const; |
|
137 | bool shadesVisible() const; | |
@@ -127,28 +145,37 public: | |||||
127 | void setShadesBorderColor(QColor color); |
|
145 | void setShadesBorderColor(QColor color); | |
128 | QColor shadesBorderColor() const; |
|
146 | QColor shadesBorderColor() const; | |
129 |
|
147 | |||
130 | Qt::Orientation orientation(); |
|
148 | Qt::Orientation orientation(); //TODO: missing const <- BC | |
131 | Qt::Alignment alignment() const; |
|
149 | Qt::Alignment alignment() const; | |
132 | void setAlignment(Qt::Alignment alignment); |
|
|||
133 |
|
150 | |||
134 | //range handling |
|
151 | //range handling | |
135 | void setMin(const QVariant &min); |
|
152 | void setMin(const QVariant &min); | |
136 | void setMax(const QVariant &max); |
|
153 | void setMax(const QVariant &max); | |
137 | void setRange(const QVariant &min, const QVariant &max); |
|
154 | void setRange(const QVariant &min, const QVariant &max); | |
138 |
|
155 | |||
139 | void show(); |
|
|||
140 | void hide(); |
|
|||
141 |
|
||||
142 | Q_SIGNALS: |
|
156 | Q_SIGNALS: | |
143 | void visibleChanged(bool visible); |
|
157 | void visibleChanged(bool visible); | |
|
158 | void linePenChanged(const QPen& pen); | |||
144 | void lineVisibleChanged(bool visible); |
|
159 | void lineVisibleChanged(bool visible); | |
145 | void labelsVisibleChanged(bool visible); |
|
160 | void labelsVisibleChanged(bool visible); | |
146 | void gridVisibleChanged(bool visible); |
|
161 | void labelsPenChanged(const QPen& pen); | |
|
162 | void labelsBrushChanged(const QBrush& brush); | |||
|
163 | void labelsFontChanged(const QFont& pen); | |||
|
164 | void labelsAngleChanged(int angle); | |||
|
165 | void gridLinePenChanged(const QPen& pen); | |||
|
166 | void gridLineVisibleChanged(bool visible); | |||
147 | void colorChanged(QColor color); |
|
167 | void colorChanged(QColor color); | |
148 | void labelsColorChanged(QColor color); |
|
168 | void labelsColorChanged(QColor color); | |
|
169 | void titleTextChanged(const QString& title); | |||
|
170 | void titlePenChanged(const QPen& pen); | |||
|
171 | void titleBrushChanged(const QBrush brush); | |||
|
172 | void titleVisibleChanged(bool visible); | |||
|
173 | void titleFontChanged(const QFont& font); | |||
149 | void shadesVisibleChanged(bool visible); |
|
174 | void shadesVisibleChanged(bool visible); | |
150 | void shadesColorChanged(QColor color); |
|
175 | void shadesColorChanged(QColor color); | |
151 | void shadesBorderColorChanged(QColor color); |
|
176 | void shadesBorderColorChanged(QColor color); | |
|
177 | void shadesPenChanged(const QPen& pen); | |||
|
178 | void shadesBrushChanged(const QBrush brush); | |||
152 |
|
179 | |||
153 | protected: |
|
180 | protected: | |
154 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
181 | QScopedPointer<QAbstractAxisPrivate> d_ptr; | |
@@ -156,6 +183,7 protected: | |||||
156 | friend class ChartDataSet; |
|
183 | friend class ChartDataSet; | |
157 | friend class ChartAxis; |
|
184 | friend class ChartAxis; | |
158 | friend class ChartPresenter; |
|
185 | friend class ChartPresenter; | |
|
186 | friend class ChartThemeManager; | |||
159 | }; |
|
187 | }; | |
160 |
|
188 | |||
161 | QTCOMMERCIALCHART_END_NAMESPACE |
|
189 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -31,13 +31,20 | |||||
31 | #define QABSTRACTAXIS_P_H |
|
31 | #define QABSTRACTAXIS_P_H | |
32 |
|
32 | |||
33 | #include "qabstractaxis.h" |
|
33 | #include "qabstractaxis.h" | |
|
34 | #include "chartaxis_p.h" | |||
|
35 | #include "qchart.h" | |||
|
36 | #include <QDebug> | |||
|
37 | ||||
|
38 | class QGraphicsItem; | |||
34 |
|
39 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
41 | |||
37 | class ChartPresenter; |
|
42 | class ChartPresenter; | |
38 | class ChartAxis; |
|
|||
39 | class Domain; |
|
43 | class Domain; | |
40 |
class Chart |
|
44 | class QChart; | |
|
45 | class QAbstractSeries; | |||
|
46 | class ChartTheme; | |||
|
47 | class ChartElement; | |||
41 |
|
48 | |||
42 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject |
|
49 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject | |
43 | { |
|
50 | { | |
@@ -47,38 +54,43 public: | |||||
47 | ~QAbstractAxisPrivate(); |
|
54 | ~QAbstractAxisPrivate(); | |
48 |
|
55 | |||
49 | public: |
|
56 | public: | |
50 | virtual ChartAxis *createGraphics(ChartPresenter *presenter) = 0; |
|
57 | Qt::Alignment alignment() const { return m_alignment; } | |
51 | virtual void intializeDomain(Domain *domain) = 0; |
|
|||
52 |
|
||||
53 | void emitUpdated(); |
|
|||
54 | void setDirty(bool dirty); |
|
|||
55 | bool isDirty() { return m_dirty; } |
|
|||
56 | void setOrientation(Qt::Orientation orientation); |
|
|||
57 | Qt::Orientation orientation() const { return m_orientation; } |
|
58 | Qt::Orientation orientation() const { return m_orientation; } | |
|
59 | void setAlignment( Qt::Alignment alignment); | |||
58 |
|
60 | |||
59 |
virtual void |
|
61 | virtual void initializeDomain(Domain *domain) = 0; | |
60 | virtual qreal min() = 0; |
|
62 | virtual void initializeGraphics(QGraphicsItem* parent) = 0; | |
|
63 | virtual void initializeTheme(ChartTheme* theme, bool forced = false); | |||
|
64 | virtual void initializeAnimations(QChart::AnimationOptions options); | |||
61 |
|
65 | |||
|
66 | //interface for manipulating range form base class | |||
|
67 | virtual void setMin(const QVariant &min) = 0; | |||
62 | virtual void setMax(const QVariant &max) = 0; |
|
68 | virtual void setMax(const QVariant &max) = 0; | |
63 | virtual qreal max() = 0; |
|
69 | virtual void setRange(const QVariant &min, const QVariant &max) = 0; | |
64 |
|
70 | |||
65 | virtual int count() const = 0; |
|
71 | //interface manipulating range form domain | |
|
72 | virtual void setRange(qreal min, qreal max) = 0; | |||
|
73 | virtual qreal min() = 0; | |||
|
74 | virtual qreal max() = 0; | |||
66 |
|
75 | |||
67 | virtual void setRange(const QVariant &min, const QVariant &max) = 0; |
|
76 | ChartAxis* axisItem() { return m_item.data(); } | |
68 |
|
77 | |||
69 | public Q_SLOTS: |
|
78 | public Q_SLOTS: | |
70 | virtual void handleDomainUpdated() = 0; |
|
79 | void handleRangeChanged(qreal min, qreal max); | |
71 |
|
80 | |||
72 | Q_SIGNALS: |
|
81 | Q_SIGNALS: | |
73 | void updated(); |
|
82 | void rangeChanged(qreal min, qreal max); | |
74 |
|
83 | |||
75 | protected: |
|
84 | protected: | |
76 | QAbstractAxis *q_ptr; |
|
85 | QAbstractAxis *q_ptr; | |
77 | Qt::Orientation m_orientation; |
|
86 | QChart *m_chart; | |
|
87 | QScopedPointer<ChartAxis> m_item; | |||
|
88 | private: | |||
|
89 | QList<QAbstractSeries*> m_series; | |||
|
90 | ||||
78 | Qt::Alignment m_alignment; |
|
91 | Qt::Alignment m_alignment; | |
79 | ChartDataSet *m_dataset; |
|
92 | Qt::Orientation m_orientation; | |
80 |
|
93 | |||
81 | private: |
|
|||
82 | bool m_visible; |
|
94 | bool m_visible; | |
83 |
|
95 | |||
84 | bool m_arrowVisible; |
|
96 | bool m_arrowVisible; | |
@@ -109,6 +121,7 private: | |||||
109 |
|
121 | |||
110 | friend class QAbstractAxis; |
|
122 | friend class QAbstractAxis; | |
111 | friend class ChartDataSet; |
|
123 | friend class ChartDataSet; | |
|
124 | friend class ChartPresenter; | |||
112 | }; |
|
125 | }; | |
113 |
|
126 | |||
114 | QTCOMMERCIALCHART_END_NAMESPACE |
|
127 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -26,14 +26,16 | |||||
26 | #include <QGraphicsLayout> |
|
26 | #include <QGraphicsLayout> | |
27 | #include <QFontMetrics> |
|
27 | #include <QFontMetrics> | |
28 | #include <qmath.h> |
|
28 | #include <qmath.h> | |
|
29 | #include <QDebug> | |||
29 |
|
30 | |||
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
33 | |||
33 |
ChartValueAxisX::ChartValueAxisX(QValueAxis *axis, |
|
34 | ChartValueAxisX::ChartValueAxisX(QValueAxis *axis, QGraphicsItem* item ) | |
34 |
: HorizontalAxis(axis, |
|
35 | : HorizontalAxis(axis, item), | |
35 |
|
|
36 | m_axis(axis) | |
36 | { |
|
37 | { | |
|
38 | QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int))); | |||
37 | } |
|
39 | } | |
38 |
|
40 | |||
39 | ChartValueAxisX::~ChartValueAxisX() |
|
41 | ChartValueAxisX::~ChartValueAxisX() | |
@@ -42,14 +44,16 ChartValueAxisX::~ChartValueAxisX() | |||||
42 |
|
44 | |||
43 | QVector<qreal> ChartValueAxisX::calculateLayout() const |
|
45 | QVector<qreal> ChartValueAxisX::calculateLayout() const | |
44 | { |
|
46 | { | |
45 | Q_ASSERT(m_tickCount >= 2); |
|
47 | int tickCount = m_axis->tickCount(); | |
|
48 | ||||
|
49 | Q_ASSERT(tickCount >= 2); | |||
46 |
|
50 | |||
47 | QVector<qreal> points; |
|
51 | QVector<qreal> points; | |
48 |
points.resize( |
|
52 | points.resize(tickCount); | |
49 |
|
53 | |||
50 | const QRectF &gridRect = gridGeometry(); |
|
54 | const QRectF &gridRect = gridGeometry(); | |
51 |
const qreal deltaX = gridRect.width() / ( |
|
55 | const qreal deltaX = gridRect.width() / (tickCount - 1); | |
52 |
for (int i = 0; i < |
|
56 | for (int i = 0; i < tickCount; ++i) { | |
53 | points[i] = i * deltaX + gridRect.left(); |
|
57 | points[i] = i * deltaX + gridRect.left(); | |
54 | } |
|
58 | } | |
55 | return points; |
|
59 | return points; | |
@@ -60,18 +64,16 void ChartValueAxisX::updateGeometry() | |||||
60 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
64 | const QVector<qreal>& layout = ChartAxis::layout(); | |
61 | if (layout.isEmpty()) |
|
65 | if (layout.isEmpty()) | |
62 | return; |
|
66 | return; | |
63 | setLabels(createValueLabels(layout.size())); |
|
67 | setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat())); | |
64 | HorizontalAxis::updateGeometry(); |
|
68 | HorizontalAxis::updateGeometry(); | |
65 | } |
|
69 | } | |
66 |
|
70 | |||
67 |
void ChartValueAxisX::handle |
|
71 | void ChartValueAxisX::handleTickCountChanged(int tick) | |
68 | { |
|
72 | { | |
69 | if (m_tickCount != m_axis->tickCount()) { |
|
73 | Q_UNUSED(tick); | |
70 | m_tickCount = m_axis->tickCount(); |
|
74 | if(presenter()) presenter()->layout()->invalidate(); | |
71 | presenter()->layout()->invalidate(); |
|
75 | //QVector<qreal> layout = calculateLayout(); | |
72 | } |
|
76 | //updateLayout(layout); | |
73 |
|
||||
74 | ChartAxis::handleAxisUpdated(); |
|
|||
75 | } |
|
77 | } | |
76 |
|
78 | |||
77 | QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
79 | QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
@@ -82,13 +84,18 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||||
82 | QSizeF sh; |
|
84 | QSizeF sh; | |
83 |
|
85 | |||
84 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
86 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |
85 | QStringList ticksList = createValueLabels(m_tickCount); |
|
87 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); | |
86 | qreal width = 0; |
|
88 | qreal width = 0; | |
87 | qreal height = 0; |
|
89 | qreal height = 0; | |
88 |
|
90 | |||
|
91 | int count = 1; | |||
|
92 | ||||
|
93 | if(!ticksList.empty()) { | |||
|
94 | count = qMax(ticksList.last().count(),ticksList.first().count()); | |||
|
95 | } | |||
|
96 | ||||
89 | switch (which) { |
|
97 | switch (which) { | |
90 | case Qt::MinimumSize:{ |
|
98 | case Qt::MinimumSize:{ | |
91 | int count = qMax(ticksList.last().count(),ticksList.first().count()); |
|
|||
92 | count = qMin(count,5); |
|
99 | count = qMin(count,5); | |
93 | width = fn.averageCharWidth() * count; |
|
100 | width = fn.averageCharWidth() * count; | |
94 | height = fn.height() + labelPadding(); |
|
101 | height = fn.height() + labelPadding(); | |
@@ -98,7 +105,6 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||||
98 | break; |
|
105 | break; | |
99 | } |
|
106 | } | |
100 | case Qt::PreferredSize:{ |
|
107 | case Qt::PreferredSize:{ | |
101 | int count = qMax(ticksList.last().count(),ticksList.first().count()); |
|
|||
102 | width=fn.averageCharWidth() * count; |
|
108 | width=fn.averageCharWidth() * count; | |
103 | height=fn.height()+labelPadding(); |
|
109 | height=fn.height()+labelPadding(); | |
104 | width=qMax(width,base.width()); |
|
110 | width=qMax(width,base.width()); | |
@@ -113,4 +119,6 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||||
113 | return sh; |
|
119 | return sh; | |
114 | } |
|
120 | } | |
115 |
|
121 | |||
|
122 | #include "moc_chartvalueaxisx_p.cpp" | |||
|
123 | ||||
116 | QTCOMMERCIALCHART_END_NAMESPACE |
|
124 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -34,24 +34,23 | |||||
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class ChartPresenter; |
|
|||
38 | class QValueAxis; |
|
37 | class QValueAxis; | |
|
38 | class ChartPresenter; | |||
39 |
|
39 | |||
40 | class ChartValueAxisX : public HorizontalAxis |
|
40 | class ChartValueAxisX : public HorizontalAxis | |
41 | { |
|
41 | { | |
|
42 | Q_OBJECT | |||
42 | public: |
|
43 | public: | |
43 |
ChartValueAxisX(QValueAxis *axis, |
|
44 | ChartValueAxisX(QValueAxis *axis, QGraphicsItem* item = 0); | |
44 | ~ChartValueAxisX(); |
|
45 | ~ChartValueAxisX(); | |
45 |
|
46 | |||
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
|
47 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; | |
47 |
|
||||
48 | protected: |
|
48 | protected: | |
49 | void handleAxisUpdated(); |
|
|||
50 | QVector<qreal> calculateLayout() const; |
|
49 | QVector<qreal> calculateLayout() const; | |
51 | void updateGeometry(); |
|
50 | void updateGeometry(); | |
52 |
|
51 | private Q_SLOTS: | ||
|
52 | void handleTickCountChanged(int tick); | |||
53 | private: |
|
53 | private: | |
54 | int m_tickCount; |
|
|||
55 | QValueAxis *m_axis; |
|
54 | QValueAxis *m_axis; | |
56 | }; |
|
55 | }; | |
57 |
|
56 |
@@ -30,11 +30,11 | |||||
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 |
ChartValueAxisY::ChartValueAxisY(QValueAxis *axis, |
|
33 | ChartValueAxisY::ChartValueAxisY(QValueAxis *axis, QGraphicsItem* item) | |
34 |
: VerticalAxis(axis, |
|
34 | : VerticalAxis(axis, item), | |
35 | m_tickCount(0), |
|
|||
36 | m_axis(axis) |
|
35 | m_axis(axis) | |
37 | { |
|
36 | { | |
|
37 | QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int))); | |||
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | ChartValueAxisY::~ChartValueAxisY() |
|
40 | ChartValueAxisY::~ChartValueAxisY() | |
@@ -43,15 +43,17 ChartValueAxisY::~ChartValueAxisY() | |||||
43 |
|
43 | |||
44 | QVector<qreal> ChartValueAxisY::calculateLayout() const |
|
44 | QVector<qreal> ChartValueAxisY::calculateLayout() const | |
45 | { |
|
45 | { | |
46 | Q_ASSERT(m_tickCount >= 2); |
|
46 | int tickCount = m_axis->tickCount(); | |
|
47 | ||||
|
48 | Q_ASSERT(tickCount >= 2); | |||
47 |
|
49 | |||
48 | QVector<qreal> points; |
|
50 | QVector<qreal> points; | |
49 |
points.resize( |
|
51 | points.resize(tickCount); | |
50 |
|
52 | |||
51 | const QRectF &gridRect = gridGeometry(); |
|
53 | const QRectF &gridRect = gridGeometry(); | |
52 |
|
54 | |||
53 |
const qreal deltaY = gridRect.height() / ( |
|
55 | const qreal deltaY = gridRect.height() / (tickCount - 1); | |
54 |
for (int i = 0; i < |
|
56 | for (int i = 0; i < tickCount; ++i) { | |
55 | points[i] = i * -deltaY + gridRect.bottom(); |
|
57 | points[i] = i * -deltaY + gridRect.bottom(); | |
56 | } |
|
58 | } | |
57 |
|
59 | |||
@@ -63,18 +65,16 void ChartValueAxisY::updateGeometry() | |||||
63 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
65 | const QVector<qreal> &layout = ChartAxis::layout(); | |
64 | if (layout.isEmpty()) |
|
66 | if (layout.isEmpty()) | |
65 | return; |
|
67 | return; | |
66 | setLabels(createValueLabels(layout.size())); |
|
68 | setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat())); | |
67 | VerticalAxis::updateGeometry(); |
|
69 | VerticalAxis::updateGeometry(); | |
68 | } |
|
70 | } | |
69 |
|
71 | |||
70 |
void ChartValueAxisY::handle |
|
72 | void ChartValueAxisY::handleTickCountChanged(int tick) | |
71 | { |
|
73 | { | |
72 | if (m_tickCount != m_axis->tickCount()) { |
|
74 | Q_UNUSED(tick); | |
73 | m_tickCount = m_axis->tickCount(); |
|
75 | if(presenter()) presenter()->layout()->invalidate(); | |
74 | presenter()->layout()->invalidate(); |
|
76 | //QVector<qreal> layout = calculateLayout(); | |
75 | } |
|
77 | //updateLayout(layout); | |
76 |
|
||||
77 | ChartAxis::handleAxisUpdated(); |
|
|||
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
80 | QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
@@ -84,10 +84,16 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||||
84 | QFontMetrics fn(font()); |
|
84 | QFontMetrics fn(font()); | |
85 | QSizeF sh; |
|
85 | QSizeF sh; | |
86 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
86 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
87 | QStringList ticksList = createValueLabels(m_tickCount); |
|
87 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); | |
88 | qreal width = 0; |
|
88 | qreal width = 0; | |
89 | qreal height = 0; |
|
89 | qreal height = 0; | |
90 |
|
90 | |||
|
91 | int count = 1; | |||
|
92 | ||||
|
93 | if(!ticksList.empty()){ | |||
|
94 | count = qMax(ticksList.last().count(),ticksList.first().count()); | |||
|
95 | } | |||
|
96 | ||||
91 | switch (which) { |
|
97 | switch (which) { | |
92 | case Qt::MinimumSize: { |
|
98 | case Qt::MinimumSize: { | |
93 | width = fn.boundingRect("...").width() + labelPadding(); |
|
99 | width = fn.boundingRect("...").width() + labelPadding(); | |
@@ -99,7 +105,6 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||||
99 | } |
|
105 | } | |
100 | case Qt::PreferredSize: |
|
106 | case Qt::PreferredSize: | |
101 | { |
|
107 | { | |
102 | int count = qMax(ticksList.first().count() , ticksList.last().count()); |
|
|||
103 | width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance |
|
108 | width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance | |
104 | width += base.width(); |
|
109 | width += base.width(); | |
105 | height = fn.height() * ticksList.count(); |
|
110 | height = fn.height() * ticksList.count(); | |
@@ -113,4 +118,6 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||||
113 | return sh; |
|
118 | return sh; | |
114 | } |
|
119 | } | |
115 |
|
120 | |||
|
121 | #include "moc_chartvalueaxisy_p.cpp" | |||
|
122 | ||||
116 | QTCOMMERCIALCHART_END_NAMESPACE |
|
123 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -39,17 +39,18 class ChartPresenter; | |||||
39 |
|
39 | |||
40 | class ChartValueAxisY : public VerticalAxis |
|
40 | class ChartValueAxisY : public VerticalAxis | |
41 | { |
|
41 | { | |
|
42 | Q_OBJECT | |||
42 | public: |
|
43 | public: | |
43 |
ChartValueAxisY(QValueAxis *axis, |
|
44 | ChartValueAxisY(QValueAxis *axis, QGraphicsItem* item = 0); | |
44 | ~ChartValueAxisY(); |
|
45 | ~ChartValueAxisY(); | |
45 |
|
46 | |||
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
|
47 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; | |
47 | protected: |
|
48 | protected: | |
48 | QVector<qreal> calculateLayout() const; |
|
49 | QVector<qreal> calculateLayout() const; | |
49 | void updateGeometry(); |
|
50 | void updateGeometry(); | |
50 | void handleAxisUpdated(); |
|
51 | private Q_SLOTS: | |
|
52 | void handleTickCountChanged(int tick); | |||
51 | private: |
|
53 | private: | |
52 | int m_tickCount; |
|
|||
53 | QValueAxis *m_axis; |
|
54 | QValueAxis *m_axis; | |
54 | }; |
|
55 | }; | |
55 |
|
56 |
@@ -24,7 +24,8 | |||||
24 | #include "chartvalueaxisy_p.h" |
|
24 | #include "chartvalueaxisy_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include <qmath.h> |
|
27 | #include "chartpresenter_p.h" | |
|
28 | #include "charttheme_p.h" | |||
28 |
|
29 | |||
29 |
|
30 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
@@ -174,8 +175,8 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent) | |||||
174 | QValueAxis::~QValueAxis() |
|
175 | QValueAxis::~QValueAxis() | |
175 | { |
|
176 | { | |
176 | Q_D(QValueAxis); |
|
177 | Q_D(QValueAxis); | |
177 |
if (d->m_ |
|
178 | if (d->m_chart) | |
178 |
d->m_ |
|
179 | d->m_chart->removeAxis(this); | |
179 | } |
|
180 | } | |
180 |
|
181 | |||
181 | void QValueAxis::setMin(qreal min) |
|
182 | void QValueAxis::setMin(qreal min) | |
@@ -209,34 +210,7 qreal QValueAxis::max() const | |||||
209 | void QValueAxis::setRange(qreal min, qreal max) |
|
210 | void QValueAxis::setRange(qreal min, qreal max) | |
210 | { |
|
211 | { | |
211 | Q_D(QValueAxis); |
|
212 | Q_D(QValueAxis); | |
212 | bool changed = false; |
|
213 | d->setRange(min,max); | |
213 |
|
||||
214 | if (min > max) |
|
|||
215 | return; |
|
|||
216 |
|
||||
217 | if (d->m_niceNumbers) { |
|
|||
218 | int ticks = d->m_tickCount; |
|
|||
219 | d->looseNiceNumbers(min, max, ticks); |
|
|||
220 | if (ticks != d->m_tickCount) |
|
|||
221 | setTickCount(ticks); |
|
|||
222 | } |
|
|||
223 |
|
||||
224 | if (!qFuzzyCompare(d->m_min, min)) { |
|
|||
225 | d->m_min = min; |
|
|||
226 | changed = true; |
|
|||
227 | emit minChanged(min); |
|
|||
228 | } |
|
|||
229 |
|
||||
230 | if (!qFuzzyCompare(d->m_max, max)) { |
|
|||
231 | d->m_max = max; |
|
|||
232 | changed = true; |
|
|||
233 | emit maxChanged(max); |
|
|||
234 | } |
|
|||
235 |
|
||||
236 | if (changed) { |
|
|||
237 | emit rangeChanged(min, max); |
|
|||
238 | d->emitUpdated(); |
|
|||
239 | } |
|
|||
240 | } |
|
214 | } | |
241 |
|
215 | |||
242 | /*! |
|
216 | /*! | |
@@ -247,7 +221,7 void QValueAxis::setTickCount(int count) | |||||
247 | Q_D(QValueAxis); |
|
221 | Q_D(QValueAxis); | |
248 | if (d->m_tickCount != count && count >= 2) { |
|
222 | if (d->m_tickCount != count && count >= 2) { | |
249 | d->m_tickCount = count; |
|
223 | d->m_tickCount = count; | |
250 | d->emitUpdated(); |
|
224 | emit tickCountChanged(count); | |
251 | } |
|
225 | } | |
252 | } |
|
226 | } | |
253 |
|
227 | |||
@@ -263,18 +237,14 int QValueAxis::tickCount() const | |||||
263 |
|
237 | |||
264 | void QValueAxis::setNiceNumbersEnabled(bool enable) |
|
238 | void QValueAxis::setNiceNumbersEnabled(bool enable) | |
265 | { |
|
239 | { | |
266 |
Q_D( |
|
240 | Q_UNUSED(enable); | |
267 | if (d->m_niceNumbers != enable) { |
|
241 | qWarning()<<"This function is depreciated.Use applyNiceNumbers()."; | |
268 | d->m_niceNumbers = enable; |
|
|||
269 | if (enable && !qFuzzyCompare(d->m_max, d->m_min)) |
|
|||
270 | setRange(d->m_min, d->m_max); |
|
|||
271 | } |
|
|||
272 | } |
|
242 | } | |
273 |
|
243 | |||
274 |
bool |
|
244 | bool QValueAxis::niceNumbersEnabled() const | |
275 | { |
|
245 | { | |
276 | Q_D(const QValueAxis); |
|
246 | qWarning()<<"This function is depreciated.Use applyNiceNumbers()."; | |
277 | return d->m_niceNumbers; |
|
247 | return false; | |
278 | } |
|
248 | } | |
279 |
|
249 | |||
280 | void QValueAxis::setLabelFormat(const QString &format) |
|
250 | void QValueAxis::setLabelFormat(const QString &format) | |
@@ -297,6 +267,17 QAbstractAxis::AxisType QValueAxis::type() const | |||||
297 | return AxisTypeValue; |
|
267 | return AxisTypeValue; | |
298 | } |
|
268 | } | |
299 |
|
269 | |||
|
270 | void QValueAxis::applyNiceNumbers() | |||
|
271 | { | |||
|
272 | Q_D(QValueAxis); | |||
|
273 | qreal min = d->m_min; | |||
|
274 | qreal max = d->m_max; | |||
|
275 | int ticks = d->m_tickCount; | |||
|
276 | Domain::looseNiceNumbers(min,max,ticks); | |||
|
277 | d->setRange(min,max); | |||
|
278 | setTickCount(ticks); | |||
|
279 | } | |||
|
280 | ||||
300 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
281 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
301 |
|
282 | |||
302 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) |
|
283 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) | |
@@ -304,7 +285,6 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) | |||||
304 | m_min(0), |
|
285 | m_min(0), | |
305 | m_max(0), |
|
286 | m_max(0), | |
306 | m_tickCount(5), |
|
287 | m_tickCount(5), | |
307 | m_niceNumbers(false), |
|
|||
308 | m_format(QString::null) |
|
288 | m_format(QString::null) | |
309 | { |
|
289 | { | |
310 |
|
290 | |||
@@ -315,19 +295,6 QValueAxisPrivate::~QValueAxisPrivate() | |||||
315 |
|
295 | |||
316 | } |
|
296 | } | |
317 |
|
297 | |||
318 | void QValueAxisPrivate::handleDomainUpdated() |
|
|||
319 | { |
|
|||
320 | Q_Q(QValueAxis); |
|
|||
321 | Domain *domain = qobject_cast<Domain *>(sender()); |
|
|||
322 | Q_ASSERT(domain); |
|
|||
323 |
|
||||
324 | if (orientation() == Qt::Horizontal) |
|
|||
325 | q->setRange(domain->minX(), domain->maxX()); |
|
|||
326 | else if (orientation() == Qt::Vertical) |
|
|||
327 | q->setRange(domain->minY(), domain->maxY()); |
|
|||
328 | } |
|
|||
329 |
|
||||
330 |
|
||||
331 | void QValueAxisPrivate::setMin(const QVariant &min) |
|
298 | void QValueAxisPrivate::setMin(const QVariant &min) | |
332 | { |
|
299 | { | |
333 | Q_Q(QValueAxis); |
|
300 | Q_Q(QValueAxis); | |
@@ -358,62 +325,64 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |||||
358 | q->setRange(value1, value2); |
|
325 | q->setRange(value1, value2); | |
359 | } |
|
326 | } | |
360 |
|
327 | |||
361 | ChartAxis *QValueAxisPrivate::createGraphics(ChartPresenter *presenter) |
|
328 | void QValueAxisPrivate::setRange(qreal min, qreal max) | |
362 | { |
|
329 | { | |
363 |
|
|
330 | Q_Q(QValueAxis); | |
364 | if (m_orientation == Qt::Vertical) |
|
331 | bool changed = false; | |
365 | return new ChartValueAxisY(q, presenter); |
|
|||
366 | return new ChartValueAxisX(q, presenter); |
|
|||
367 | } |
|
|||
368 |
|
332 | |||
369 | void QValueAxisPrivate::intializeDomain(Domain *domain) |
|
333 | if (min > max) | |
370 | { |
|
334 | return; | |
371 | Q_Q(QValueAxis); |
|
335 | ||
372 |
if (qFuzzyCompare(m_m |
|
336 | if (!qFuzzyCompare(m_min,min)) { | |
373 | if (m_orientation == Qt::Vertical) |
|
337 | m_min = min; | |
374 | q->setRange(domain->minY(), domain->maxY()); |
|
338 | changed = true; | |
375 | else |
|
339 | emit q->minChanged(min); | |
376 | q->setRange(domain->minX(), domain->maxX()); |
|
340 | } | |
377 | } else { |
|
341 | ||
378 | if (m_orientation == Qt::Vertical) |
|
342 | if (!qFuzzyCompare(m_max,max)) { | |
379 | domain->setRangeY(m_min, m_max); |
|
343 | m_max = max; | |
380 | else |
|
344 | changed = true; | |
381 | domain->setRangeX(m_min, m_max); |
|
345 | emit q->maxChanged(max); | |
382 | } |
|
346 | } | |
383 | } |
|
|||
384 |
|
347 | |||
385 | //algorithm defined by Paul S.Heckbert GraphicalGems I |
|
348 | if (changed) { | |
|
349 | emit q->rangeChanged(min, max); | |||
|
350 | emit rangeChanged(min,max); | |||
|
351 | } | |||
|
352 | } | |||
386 |
|
353 | |||
387 | void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const |
|
354 | void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
388 | { |
|
355 | { | |
389 | qreal range = niceNumber(max - min, true); //range with ceiling |
|
356 | Q_Q(QValueAxis); | |
390 | qreal step = niceNumber(range / (ticksCount - 1), false); |
|
357 | ChartAxis* axis(0); | |
391 | min = qFloor(min / step); |
|
358 | if (orientation() == Qt::Vertical) | |
392 | max = qCeil(max / step); |
|
359 | axis = new ChartValueAxisY(q,parent); | |
393 | ticksCount = int(max - min) + 1; |
|
360 | if (orientation() == Qt::Horizontal) | |
394 | min *= step; |
|
361 | axis = new ChartValueAxisX(q,parent); | |
395 | max *= step; |
|
362 | ||
|
363 | m_item.reset(axis); | |||
|
364 | QAbstractAxisPrivate::initializeGraphics(parent); | |||
396 | } |
|
365 | } | |
397 |
|
366 | |||
398 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n |
|
|||
399 |
|
367 | |||
400 | qreal QValueAxisPrivate::niceNumber(qreal x, bool ceiling) const |
|
368 | void QValueAxisPrivate::initializeDomain(Domain *domain) | |
401 | { |
|
369 | { | |
402 | qreal z = qPow(10, qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x |
|
370 | if (orientation() == Qt::Vertical) { | |
403 | qreal q = x / z; //q<10 && q>=1; |
|
371 | if(!qFuzzyIsNull(m_max - m_min)) { | |
404 |
|
372 | domain->setRangeY(m_min, m_max); | ||
405 | if (ceiling) { |
|
373 | } | |
406 | if (q <= 1.0) q = 1; |
|
374 | else { | |
407 | else if (q <= 2.0) q = 2; |
|
375 | setRange(domain->minY(), domain->maxY()); | |
408 | else if (q <= 5.0) q = 5; |
|
376 | } | |
409 | else q = 10; |
|
377 | } | |
410 | } else { |
|
378 | if (orientation() == Qt::Horizontal) { | |
411 | if (q < 1.5) q = 1; |
|
379 | if(!qFuzzyIsNull(m_max - m_min)) { | |
412 | else if (q < 3.0) q = 2; |
|
380 | domain->setRangeX(m_min, m_max); | |
413 | else if (q < 7.0) q = 5; |
|
381 | } | |
414 |
else |
|
382 | else { | |
|
383 | setRange(domain->minX(), domain->maxX()); | |||
|
384 | } | |||
415 | } |
|
385 | } | |
416 | return q * z; |
|
|||
417 | } |
|
386 | } | |
418 |
|
387 | |||
419 | #include "moc_qvalueaxis.cpp" |
|
388 | #include "moc_qvalueaxis.cpp" |
@@ -30,7 +30,7 class QValueAxisPrivate; | |||||
30 | class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis |
|
30 | class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount) |
|
33 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged) | |
34 | Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled) |
|
34 | Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled) | |
35 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) |
|
35 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) | |
36 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) |
|
36 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) | |
@@ -60,6 +60,9 public: | |||||
60 | void setLabelFormat(const QString &format); |
|
60 | void setLabelFormat(const QString &format); | |
61 | QString labelFormat() const; |
|
61 | QString labelFormat() const; | |
62 |
|
62 | |||
|
63 | void applyNiceNumbers(); | |||
|
64 | ||||
|
65 | //TODO: depreciated ! | |||
63 | void setNiceNumbersEnabled(bool enable = true); |
|
66 | void setNiceNumbersEnabled(bool enable = true); | |
64 | bool niceNumbersEnabled() const; |
|
67 | bool niceNumbersEnabled() const; | |
65 |
|
68 | |||
@@ -67,6 +70,7 Q_SIGNALS: | |||||
67 | void minChanged(qreal min); |
|
70 | void minChanged(qreal min); | |
68 | void maxChanged(qreal max); |
|
71 | void maxChanged(qreal max); | |
69 | void rangeChanged(qreal min, qreal max); |
|
72 | void rangeChanged(qreal min, qreal max); | |
|
73 | void tickCountChanged(int ticks); | |||
70 |
|
74 | |||
71 | private: |
|
75 | private: | |
72 | Q_DECLARE_PRIVATE(QValueAxis) |
|
76 | Q_DECLARE_PRIVATE(QValueAxis) |
@@ -43,12 +43,12 public: | |||||
43 | ~QValueAxisPrivate(); |
|
43 | ~QValueAxisPrivate(); | |
44 |
|
44 | |||
45 | public: |
|
45 | public: | |
46 | ChartAxis *createGraphics(ChartPresenter *presenter); |
|
46 | void initializeGraphics(QGraphicsItem* parent); | |
47 | void intializeDomain(Domain *domain); |
|
47 | void initializeDomain(Domain *domain); | |
48 | void handleDomainUpdated(); |
|
48 | ||
49 | qreal min() { return m_min; }; |
|
49 | qreal min() { return m_min; }; | |
50 | qreal max() { return m_max; }; |
|
50 | qreal max() { return m_max; }; | |
51 | int count() const { return m_tickCount; } |
|
51 | void setRange(qreal min,qreal max); | |
52 |
|
52 | |||
53 | protected: |
|
53 | protected: | |
54 | void setMin(const QVariant &min); |
|
54 | void setMin(const QVariant &min); | |
@@ -56,14 +56,9 protected: | |||||
56 | void setRange(const QVariant &min, const QVariant &max); |
|
56 | void setRange(const QVariant &min, const QVariant &max); | |
57 |
|
57 | |||
58 | private: |
|
58 | private: | |
59 | void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const; |
|
|||
60 | qreal niceNumber(qreal x, bool ceiling) const; |
|
|||
61 |
|
||||
62 | private: |
|
|||
63 | qreal m_min; |
|
59 | qreal m_min; | |
64 | qreal m_max; |
|
60 | qreal m_max; | |
65 | int m_tickCount; |
|
61 | int m_tickCount; | |
66 | bool m_niceNumbers; |
|
|||
67 | QString m_format; |
|
62 | QString m_format; | |
68 | Q_DECLARE_PUBLIC(QValueAxis) |
|
63 | Q_DECLARE_PUBLIC(QValueAxis) | |
69 | }; |
|
64 | }; |
@@ -25,8 +25,8 | |||||
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 |
VerticalAxis::VerticalAxis(QAbstractAxis *axis, |
|
28 | VerticalAxis::VerticalAxis(QAbstractAxis *axis, QGraphicsItem* item, bool intervalAxis) | |
29 |
: ChartAxis(axis, |
|
29 | : ChartAxis(axis, item, intervalAxis) | |
30 | { |
|
30 | { | |
31 |
|
31 | |||
32 | } |
|
32 | } | |
@@ -200,7 +200,7 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons | |||||
200 | break; |
|
200 | break; | |
201 | case Qt::MaximumSize: |
|
201 | case Qt::MaximumSize: | |
202 | case Qt::PreferredSize: |
|
202 | case Qt::PreferredSize: | |
203 | sh = QSizeF(fn.height(), fn.boundingRect(axis()->title()).width()); |
|
203 | sh = QSizeF(fn.height(), fn.boundingRect(axis()->titleText()).width()); | |
204 | break; |
|
204 | break; | |
205 | default: |
|
205 | default: | |
206 | break; |
|
206 | break; |
@@ -37,7 +37,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
37 | class VerticalAxis : public ChartAxis |
|
37 | class VerticalAxis : public ChartAxis | |
38 | { |
|
38 | { | |
39 | public: |
|
39 | public: | |
40 |
VerticalAxis(QAbstractAxis *axis, |
|
40 | VerticalAxis(QAbstractAxis *axis, QGraphicsItem* item = 0, bool intervalAxis = false); | |
41 | ~VerticalAxis(); |
|
41 | ~VerticalAxis(); | |
42 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; |
|
42 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; | |
43 | protected: |
|
43 | protected: |
@@ -33,8 +33,8 | |||||
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 |
AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, |
|
36 | AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : | |
37 |
ChartItem( |
|
37 | ChartItem(series->d_func(),item), | |
38 | m_animation(0), |
|
38 | m_animation(0), | |
39 | m_series(series) |
|
39 | m_series(series) | |
40 | { |
|
40 | { | |
@@ -100,13 +100,14 void AbstractBarChartItem::handleDomainUpdated() | |||||
100 | m_domainMaxX = domain()->maxX(); |
|
100 | m_domainMaxX = domain()->maxX(); | |
101 | m_domainMinY = domain()->minY(); |
|
101 | m_domainMinY = domain()->minY(); | |
102 | m_domainMaxY = domain()->maxY(); |
|
102 | m_domainMaxY = domain()->maxY(); | |
103 | handleLayoutChanged(); |
|
|||
104 | } |
|
|||
105 |
|
103 | |||
106 | void AbstractBarChartItem::handleGeometryChanged(const QRectF &rect) |
|
104 | QRectF rect(QPointF(0,0),domain()->size()); | |
107 | { |
|
105 | ||
108 | prepareGeometryChange(); |
|
106 | if(m_rect != rect){ | |
109 | m_rect = rect; |
|
107 | prepareGeometryChange(); | |
|
108 | m_rect = rect; | |||
|
109 | } | |||
|
110 | ||||
110 | handleLayoutChanged(); |
|
111 | handleLayoutChanged(); | |
111 | } |
|
112 | } | |
112 |
|
113 | |||
@@ -157,7 +158,7 void AbstractBarChartItem::handleDataStructureChanged() | |||||
157 | } |
|
158 | } | |
158 | } |
|
159 | } | |
159 |
|
160 | |||
160 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
161 | if(themeManager()) themeManager()->updateSeries(m_series); | |
161 | handleLayoutChanged(); |
|
162 | handleLayoutChanged(); | |
162 | } |
|
163 | } | |
163 |
|
164 |
@@ -47,7 +47,7 class AbstractBarChartItem : public ChartItem | |||||
47 | { |
|
47 | { | |
48 | Q_OBJECT |
|
48 | Q_OBJECT | |
49 | public: |
|
49 | public: | |
50 |
AbstractBarChartItem(QAbstractBarSeries *series, |
|
50 | AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); | |
51 | virtual ~AbstractBarChartItem(); |
|
51 | virtual ~AbstractBarChartItem(); | |
52 |
|
52 | |||
53 | public: |
|
53 | public: | |
@@ -63,7 +63,6 public: | |||||
63 |
|
63 | |||
64 | public Q_SLOTS: |
|
64 | public Q_SLOTS: | |
65 | void handleDomainUpdated(); |
|
65 | void handleDomainUpdated(); | |
66 | void handleGeometryChanged(const QRectF &size); |
|
|||
67 | void handleLayoutChanged(); |
|
66 | void handleLayoutChanged(); | |
68 | void handleLabelsVisibleChanged(bool visible); |
|
67 | void handleLabelsVisibleChanged(bool visible); | |
69 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items |
|
68 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items |
@@ -25,8 +25,8 | |||||
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 |
HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, |
|
28 | HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) | |
29 |
: AbstractBarChartItem(series, |
|
29 | : AbstractBarChartItem(series, item) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 |
@@ -39,7 +39,7 class HorizontalBarChartItem : public AbstractBarChartItem | |||||
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 |
HorizontalBarChartItem(QAbstractBarSeries *series, |
|
42 | HorizontalBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); | |
43 |
|
43 | |||
44 | private: |
|
44 | private: | |
45 | virtual QVector<QRectF> calculateLayout(); |
|
45 | virtual QVector<QRectF> calculateLayout(); |
@@ -72,8 +72,8 QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) | |||||
72 | QHorizontalBarSeries::~QHorizontalBarSeries() |
|
72 | QHorizontalBarSeries::~QHorizontalBarSeries() | |
73 | { |
|
73 | { | |
74 | Q_D(QHorizontalBarSeries); |
|
74 | Q_D(QHorizontalBarSeries); | |
75 |
if (d->m_ |
|
75 | if (d->m_chart) | |
76 |
d->m_ |
|
76 | d->m_chart->removeSeries(this); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
@@ -92,12 +92,12 QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q | |||||
92 |
|
92 | |||
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 |
void QHorizontalBarSeriesPrivate:: |
|
95 | void QHorizontalBarSeriesPrivate::initializeDomain() | |
96 | { |
|
96 | { | |
97 |
qreal minX(domain |
|
97 | qreal minX(domain()->minX()); | |
98 |
qreal minY(domain |
|
98 | qreal minY(domain()->minY()); | |
99 |
qreal maxX(domain |
|
99 | qreal maxX(domain()->maxX()); | |
100 |
qreal maxY(domain |
|
100 | qreal maxY(domain()->maxY()); | |
101 |
|
101 | |||
102 | qreal y = categoryCount(); |
|
102 | qreal y = categoryCount(); | |
103 | minX = qMin(minX, min()); |
|
103 | minX = qMin(minX, min()); | |
@@ -105,18 +105,27 void QHorizontalBarSeriesPrivate::scaleDomain(Domain &domain) | |||||
105 | maxX = qMax(maxX, max()); |
|
105 | maxX = qMax(maxX, max()); | |
106 | maxY = qMax(maxY, y - (qreal)0.5); |
|
106 | maxY = qMax(maxY, y - (qreal)0.5); | |
107 |
|
107 | |||
108 |
domain |
|
108 | domain()->setRange(minX, maxX, minY, maxY); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 |
|
|
111 | void QHorizontalBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
112 | { |
|
112 | { | |
113 | Q_Q(QHorizontalBarSeries); |
|
113 | Q_Q(QHorizontalBarSeries); | |
|
114 | HorizontalBarChartItem *bar = new HorizontalBarChartItem(q,parent); | |||
|
115 | m_item.reset(bar); | |||
|
116 | QAbstractSeriesPrivate::initializeGraphics(parent); | |||
|
117 | } | |||
114 |
|
118 | |||
115 | HorizontalBarChartItem *bar = new HorizontalBarChartItem(q, presenter); |
|
119 | void QHorizontalBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
116 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
120 | { | |
|
121 | HorizontalBarChartItem *bar = static_cast<HorizontalBarChartItem *>(m_item.data()); | |||
|
122 | Q_ASSERT(bar); | |||
|
123 | if (options.testFlag(QChart::SeriesAnimations)) { | |||
117 | bar->setAnimation(new HorizontalBarAnimation(bar)); |
|
124 | bar->setAnimation(new HorizontalBarAnimation(bar)); | |
118 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
125 | }else{ | |
119 | return bar; |
|
126 | bar->setAnimation(0); | |
|
127 | } | |||
|
128 | QAbstractSeriesPrivate::initializeAnimations(options); | |||
120 | } |
|
129 | } | |
121 |
|
130 | |||
122 | #include "moc_qhorizontalbarseries.cpp" |
|
131 | #include "moc_qhorizontalbarseries.cpp" |
@@ -39,8 +39,9 class QHorizontalBarSeriesPrivate: public QAbstractBarSeriesPrivate | |||||
39 | { |
|
39 | { | |
40 | public: |
|
40 | public: | |
41 | QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q); |
|
41 | QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q); | |
42 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
42 | void initializeGraphics(QGraphicsItem* parent); | |
43 | void scaleDomain(Domain &domain); |
|
43 | void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); | |
|
44 | void initializeDomain(); | |||
44 | private: |
|
45 | private: | |
45 | Q_DECLARE_PUBLIC(QHorizontalBarSeries) |
|
46 | Q_DECLARE_PUBLIC(QHorizontalBarSeries) | |
46 | }; |
|
47 | }; |
@@ -25,8 +25,8 | |||||
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 |
HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries *series, |
|
28 | HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) | |
29 |
: AbstractBarChartItem(series, |
|
29 | : AbstractBarChartItem(series, item) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 |
@@ -39,7 +39,7 class HorizontalPercentBarChartItem : public AbstractBarChartItem | |||||
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 |
HorizontalPercentBarChartItem(QAbstractBarSeries *series, |
|
42 | HorizontalPercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); | |
43 |
|
43 | |||
44 | private: |
|
44 | private: | |
45 | virtual QVector<QRectF> calculateLayout(); |
|
45 | virtual QVector<QRectF> calculateLayout(); |
@@ -77,8 +77,8 QAbstractSeries::SeriesType QHorizontalPercentBarSeries::type() const | |||||
77 | QHorizontalPercentBarSeries::~QHorizontalPercentBarSeries() |
|
77 | QHorizontalPercentBarSeries::~QHorizontalPercentBarSeries() | |
78 | { |
|
78 | { | |
79 | Q_D(QHorizontalPercentBarSeries); |
|
79 | Q_D(QHorizontalPercentBarSeries); | |
80 |
if (d->m_ |
|
80 | if (d->m_chart) | |
81 |
d->m_ |
|
81 | d->m_chart->removeSeries(this); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
@@ -88,12 +88,12 QHorizontalPercentBarSeriesPrivate::QHorizontalPercentBarSeriesPrivate(QHorizont | |||||
88 |
|
88 | |||
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 |
void QHorizontalPercentBarSeriesPrivate:: |
|
91 | void QHorizontalPercentBarSeriesPrivate::initializeDomain() | |
92 | { |
|
92 | { | |
93 |
qreal minX(domain |
|
93 | qreal minX(domain()->minX()); | |
94 |
qreal minY(domain |
|
94 | qreal minY(domain()->minY()); | |
95 |
qreal maxX(domain |
|
95 | qreal maxX(domain()->maxX()); | |
96 |
qreal maxY(domain |
|
96 | qreal maxY(domain()->maxY()); | |
97 |
|
97 | |||
98 | qreal y = categoryCount(); |
|
98 | qreal y = categoryCount(); | |
99 | minX = 0; |
|
99 | minX = 0; | |
@@ -101,20 +101,28 void QHorizontalPercentBarSeriesPrivate::scaleDomain(Domain &domain) | |||||
101 | minY = qMin(minY, - (qreal)0.5); |
|
101 | minY = qMin(minY, - (qreal)0.5); | |
102 | maxY = qMax(maxY, y - (qreal)0.5); |
|
102 | maxY = qMax(maxY, y - (qreal)0.5); | |
103 |
|
103 | |||
104 |
domain |
|
104 | domain()->setRange(minX, maxX, minY, maxY); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 |
|
|
107 | void QHorizontalPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
108 | { |
|
108 | { | |
109 | Q_Q(QHorizontalPercentBarSeries); |
|
109 | Q_Q(QHorizontalPercentBarSeries); | |
|
110 | HorizontalPercentBarChartItem *bar = new HorizontalPercentBarChartItem(q,parent); | |||
|
111 | m_item.reset(bar); | |||
|
112 | QAbstractSeriesPrivate::initializeGraphics(parent); | |||
|
113 | } | |||
110 |
|
114 | |||
111 | HorizontalPercentBarChartItem *bar = new HorizontalPercentBarChartItem(q, presenter); |
|
115 | void QHorizontalPercentBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
112 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
116 | { | |
|
117 | HorizontalPercentBarChartItem *bar = static_cast<HorizontalPercentBarChartItem *>(m_item.data()); | |||
|
118 | Q_ASSERT(bar); | |||
|
119 | if (options.testFlag(QChart::SeriesAnimations)) { | |||
113 | bar->setAnimation(new HorizontalPercentBarAnimation(bar)); |
|
120 | bar->setAnimation(new HorizontalPercentBarAnimation(bar)); | |
114 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
121 | }else{ | |
115 | return bar; |
|
122 | bar->setAnimation(0); | |
|
123 | } | |||
|
124 | QAbstractSeriesPrivate::initializeAnimations(options); | |||
116 | } |
|
125 | } | |
117 |
|
||||
118 | #include "moc_qhorizontalpercentbarseries.cpp" |
|
126 | #include "moc_qhorizontalpercentbarseries.cpp" | |
119 |
|
127 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
128 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -39,8 +39,9 class QHorizontalPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate | |||||
39 | { |
|
39 | { | |
40 | public: |
|
40 | public: | |
41 | QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q); |
|
41 | QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q); | |
42 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
42 | void initializeGraphics(QGraphicsItem* parent); | |
43 | void scaleDomain(Domain &domain); |
|
43 | void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); | |
|
44 | void initializeDomain(); | |||
44 | private: |
|
45 | private: | |
45 | Q_DECLARE_PUBLIC(QHorizontalPercentBarSeries) |
|
46 | Q_DECLARE_PUBLIC(QHorizontalPercentBarSeries) | |
46 | }; |
|
47 | }; |
@@ -25,8 +25,8 | |||||
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 |
HorizontalStackedBarChartItem::HorizontalStackedBarChartItem(QAbstractBarSeries *series, |
|
28 | HorizontalStackedBarChartItem::HorizontalStackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) | |
29 |
: AbstractBarChartItem(series, |
|
29 | : AbstractBarChartItem(series, item) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 |
@@ -39,7 +39,7 class HorizontalStackedBarChartItem : public AbstractBarChartItem | |||||
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 |
HorizontalStackedBarChartItem(QAbstractBarSeries *series, |
|
42 | HorizontalStackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); | |
43 |
|
43 | |||
44 | private: |
|
44 | private: | |
45 | virtual QVector<QRectF> calculateLayout(); |
|
45 | virtual QVector<QRectF> calculateLayout(); |
@@ -68,8 +68,8 QHorizontalStackedBarSeries::QHorizontalStackedBarSeries(QObject *parent) | |||||
68 | QHorizontalStackedBarSeries::~QHorizontalStackedBarSeries() |
|
68 | QHorizontalStackedBarSeries::~QHorizontalStackedBarSeries() | |
69 | { |
|
69 | { | |
70 | Q_D(QHorizontalStackedBarSeries); |
|
70 | Q_D(QHorizontalStackedBarSeries); | |
71 |
if (d->m_ |
|
71 | if (d->m_chart) | |
72 |
d->m_ |
|
72 | d->m_chart->removeSeries(this); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | /*! |
|
75 | /*! | |
@@ -87,12 +87,12 QHorizontalStackedBarSeriesPrivate::QHorizontalStackedBarSeriesPrivate(QHorizont | |||||
87 |
|
87 | |||
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 |
void QHorizontalStackedBarSeriesPrivate:: |
|
90 | void QHorizontalStackedBarSeriesPrivate::initializeDomain() | |
91 | { |
|
91 | { | |
92 |
qreal minX(domain |
|
92 | qreal minX(domain()->minX()); | |
93 |
qreal minY(domain |
|
93 | qreal minY(domain()->minY()); | |
94 |
qreal maxX(domain |
|
94 | qreal maxX(domain()->maxX()); | |
95 |
qreal maxY(domain |
|
95 | qreal maxY(domain()->maxY()); | |
96 |
|
96 | |||
97 | qreal y = categoryCount(); |
|
97 | qreal y = categoryCount(); | |
98 | minX = qMin(minX, bottom()); |
|
98 | minX = qMin(minX, bottom()); | |
@@ -100,20 +100,28 void QHorizontalStackedBarSeriesPrivate::scaleDomain(Domain &domain) | |||||
100 | maxX = qMax(maxX, top()); |
|
100 | maxX = qMax(maxX, top()); | |
101 | maxY = qMax(maxY, y - (qreal)0.5); |
|
101 | maxY = qMax(maxY, y - (qreal)0.5); | |
102 |
|
102 | |||
103 |
domain |
|
103 | domain()->setRange(minX, maxX, minY, maxY); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 |
|
|
106 | void QHorizontalStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem *parent) | |
107 | { |
|
107 | { | |
108 | Q_Q(QHorizontalStackedBarSeries); |
|
108 | Q_Q(QHorizontalStackedBarSeries); | |
|
109 | HorizontalStackedBarChartItem *bar = new HorizontalStackedBarChartItem(q,parent); | |||
|
110 | m_item.reset(bar); | |||
|
111 | QAbstractSeriesPrivate::initializeGraphics(parent); | |||
|
112 | } | |||
109 |
|
113 | |||
110 | HorizontalStackedBarChartItem *bar = new HorizontalStackedBarChartItem(q, presenter); |
|
114 | void QHorizontalStackedBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
111 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
115 | { | |
|
116 | HorizontalStackedBarChartItem *bar = static_cast<HorizontalStackedBarChartItem *>(m_item.data()); | |||
|
117 | Q_ASSERT(bar); | |||
|
118 | if (options.testFlag(QChart::SeriesAnimations)) { | |||
112 | bar->setAnimation(new HorizontalStackedBarAnimation(bar)); |
|
119 | bar->setAnimation(new HorizontalStackedBarAnimation(bar)); | |
113 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
120 | }else{ | |
114 | return bar; |
|
121 | bar->setAnimation(0); | |
|
122 | } | |||
|
123 | QAbstractSeriesPrivate::initializeAnimations(options); | |||
115 | } |
|
124 | } | |
116 |
|
||||
117 | #include "moc_qhorizontalstackedbarseries.cpp" |
|
125 | #include "moc_qhorizontalstackedbarseries.cpp" | |
118 |
|
126 | |||
119 | QTCOMMERCIALCHART_END_NAMESPACE |
|
127 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -39,8 +39,9 class QHorizontalStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate | |||||
39 | { |
|
39 | { | |
40 | public: |
|
40 | public: | |
41 | QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q); |
|
41 | QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q); | |
42 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
42 | void initializeGraphics(QGraphicsItem* parent); | |
43 | void scaleDomain(Domain &domain); |
|
43 | void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); | |
|
44 | void initializeDomain(); | |||
44 | private: |
|
45 | private: | |
45 | Q_DECLARE_PUBLIC(QHorizontalStackedBarSeries) |
|
46 | Q_DECLARE_PUBLIC(QHorizontalStackedBarSeries) | |
46 | }; |
|
47 | }; |
@@ -622,12 +622,12 qreal QAbstractBarSeriesPrivate::bottom() | |||||
622 | } |
|
622 | } | |
623 |
|
623 | |||
624 |
|
624 | |||
625 |
void QAbstractBarSeriesPrivate:: |
|
625 | void QAbstractBarSeriesPrivate::initializeDomain() | |
626 | { |
|
626 | { | |
627 |
qreal minX(domain |
|
627 | qreal minX(domain()->minX()); | |
628 |
qreal minY(domain |
|
628 | qreal minY(domain()->minY()); | |
629 |
qreal maxX(domain |
|
629 | qreal maxX(domain()->maxX()); | |
630 |
qreal maxY(domain |
|
630 | qreal maxY(domain()->maxY()); | |
631 |
|
631 | |||
632 | qreal seriesMinX = this->minX(); |
|
632 | qreal seriesMinX = this->minX(); | |
633 | qreal seriesMaxX = this->maxX(); |
|
633 | qreal seriesMaxX = this->maxX(); | |
@@ -637,14 +637,7 void QAbstractBarSeriesPrivate::scaleDomain(Domain &domain) | |||||
637 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
637 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); | |
638 | maxY = qMax(maxY, y); |
|
638 | maxY = qMax(maxY, y); | |
639 |
|
639 | |||
640 |
domain |
|
640 | domain()->setRange(minX, maxX, minY, maxY); | |
641 | } |
|
|||
642 |
|
||||
643 | ChartElement *QAbstractBarSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
|||
644 | { |
|
|||
645 | Q_UNUSED(presenter); |
|
|||
646 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; |
|
|||
647 | return 0; |
|
|||
648 | } |
|
641 | } | |
649 |
|
642 | |||
650 | QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
643 | QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend) | |
@@ -746,27 +739,30 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |||||
746 | return true; |
|
739 | return true; | |
747 | } |
|
740 | } | |
748 |
|
741 | |||
749 |
void QAbstractBarSeriesPrivate::initializeAx |
|
742 | void QAbstractBarSeriesPrivate::initializeAxes() | |
750 | { |
|
743 | { | |
751 | Q_Q(QAbstractBarSeries); |
|
744 | Q_Q(QAbstractBarSeries); | |
752 |
|
745 | |||
753 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { |
|
746 | foreach(QAbstractAxis* axis, m_axes) { | |
754 | switch (q->type()) { |
|
747 | ||
755 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
748 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { | |
756 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
749 | switch (q->type()) { | |
757 |
case QAbstractSeries::SeriesTypeHorizontal |
|
750 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
758 | if (axis->orientation() == Qt::Vertical) |
|
751 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
|
752 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |||
|
753 | if (axis->orientation() == Qt::Vertical) | |||
759 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
754 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); | |
760 | break; |
|
755 | break; | |
761 | case QAbstractSeries::SeriesTypeBar: |
|
756 | case QAbstractSeries::SeriesTypeBar: | |
762 | case QAbstractSeries::SeriesTypePercentBar: |
|
757 | case QAbstractSeries::SeriesTypePercentBar: | |
763 | case QAbstractSeries::SeriesTypeStackedBar: |
|
758 | case QAbstractSeries::SeriesTypeStackedBar: | |
764 | if (axis->orientation() == Qt::Horizontal) |
|
759 | if (axis->orientation() == Qt::Horizontal) | |
765 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
760 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); | |
766 | break; |
|
761 | break; | |
767 | default: |
|
762 | default: | |
768 | qWarning() << "Unexpected series type"; |
|
763 | qWarning() << "Unexpected series type"; | |
769 | break; |
|
764 | break; | |
|
765 | } | |||
770 | } |
|
766 | } | |
771 | } |
|
767 | } | |
772 | } |
|
768 | } | |
@@ -806,6 +802,57 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis) | |||||
806 | } |
|
802 | } | |
807 | } |
|
803 | } | |
808 |
|
804 | |||
|
805 | QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |||
|
806 | { | |||
|
807 | Q_UNUSED(orientation); | |||
|
808 | return 0; | |||
|
809 | } | |||
|
810 | ||||
|
811 | void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |||
|
812 | { | |||
|
813 | const QList<QGradient> gradients = theme->seriesGradients(); | |||
|
814 | ||||
|
815 | QBrush brush; | |||
|
816 | QPen pen; | |||
|
817 | ||||
|
818 | qreal takeAtPos = 0.5; | |||
|
819 | qreal step = 0.2; | |||
|
820 | if (m_barSets.count() > 1) { | |||
|
821 | step = 1.0 / (qreal) m_barSets.count(); | |||
|
822 | if (m_barSets.count() % gradients.count()) | |||
|
823 | step *= gradients.count(); | |||
|
824 | else | |||
|
825 | step *= (gradients.count() - 1); | |||
|
826 | } | |||
|
827 | ||||
|
828 | for (int i(0); i < m_barSets.count(); i++) { | |||
|
829 | int colorIndex = (index + i) % gradients.count(); | |||
|
830 | if (i > 0 && i %gradients.count() == 0) { | |||
|
831 | // There is no dedicated base color for each sets, generate more colors | |||
|
832 | takeAtPos += step; | |||
|
833 | if (takeAtPos == 1.0) | |||
|
834 | takeAtPos += step; | |||
|
835 | takeAtPos -= (int) takeAtPos; | |||
|
836 | } | |||
|
837 | if (forced || brush == m_barSets.at(i)->brush()) | |||
|
838 | m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos)); | |||
|
839 | ||||
|
840 | // Pick label color from the opposite end of the gradient. | |||
|
841 | // 0.3 as a boundary seems to work well. | |||
|
842 | if (forced || brush == m_barSets.at(i)->labelBrush()) { | |||
|
843 | if (takeAtPos < 0.3) | |||
|
844 | m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1)); | |||
|
845 | else | |||
|
846 | m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0)); | |||
|
847 | } | |||
|
848 | ||||
|
849 | if (forced || pen == m_barSets.at(i)->pen()) { | |||
|
850 | QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); | |||
|
851 | m_barSets.at(i)->setPen(c); | |||
|
852 | } | |||
|
853 | } | |||
|
854 | } | |||
|
855 | ||||
809 | #include "moc_qabstractbarseries.cpp" |
|
856 | #include "moc_qabstractbarseries.cpp" | |
810 | #include "moc_qabstractbarseries_p.cpp" |
|
857 | #include "moc_qabstractbarseries_p.cpp" | |
811 |
|
858 |
@@ -54,12 +54,14 public: | |||||
54 | void setVisible(bool visible); |
|
54 | void setVisible(bool visible); | |
55 | void setLabelsVisible(bool visible); |
|
55 | void setLabelsVisible(bool visible); | |
56 |
|
56 | |||
57 |
void |
|
57 | void initializeDomain(); | |
58 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
58 | void initializeAxes(); | |
59 | QList<QLegendMarker*> createLegendMarkers(QLegend* legend); |
|
59 | void initializeTheme(int index, ChartTheme* theme, bool forced = false); | |
|
60 | ||||
|
61 | QList<QLegendMarker*> createLegendMarkers(QLegend *legend); | |||
60 |
|
62 | |||
61 | void initializeAxis(QAbstractAxis *axis); |
|
|||
62 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
63 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
|
64 | QAbstractAxis* createDefaultAxis(Qt::Orientation orientation) const; | |||
63 |
|
65 | |||
64 | bool append(QBarSet *set); |
|
66 | bool append(QBarSet *set); | |
65 | bool remove(QBarSet *set); |
|
67 | bool remove(QBarSet *set); |
@@ -26,8 +26,8 | |||||
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 |
BarChartItem::BarChartItem(QAbstractBarSeries *series, |
|
29 | BarChartItem::BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : | |
30 |
AbstractBarChartItem(series, |
|
30 | AbstractBarChartItem(series, item) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 |
@@ -41,7 +41,7 class BarChartItem : public AbstractBarChartItem | |||||
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 | public: |
|
43 | public: | |
44 |
BarChartItem(QAbstractBarSeries *series, |
|
44 | BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | virtual QVector<QRectF> calculateLayout(); |
|
47 | virtual QVector<QRectF> calculateLayout(); |
@@ -79,8 +79,8 QAbstractSeries::SeriesType QBarSeries::type() const | |||||
79 | QBarSeries::~QBarSeries() |
|
79 | QBarSeries::~QBarSeries() | |
80 | { |
|
80 | { | |
81 | Q_D(QBarSeries); |
|
81 | Q_D(QBarSeries); | |
82 |
if (d->m_ |
|
82 | if (d->m_chart) | |
83 |
d->m_ |
|
83 | d->m_chart->removeSeries(this); | |
84 | } |
|
84 | } | |
85 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
85 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
86 |
|
86 | |||
@@ -89,12 +89,12 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate( | |||||
89 |
|
89 | |||
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 |
void QBarSeriesPrivate:: |
|
92 | void QBarSeriesPrivate::initializeDomain() | |
93 | { |
|
93 | { | |
94 |
qreal minX(domain |
|
94 | qreal minX(domain()->minX()); | |
95 |
qreal minY(domain |
|
95 | qreal minY(domain()->minY()); | |
96 |
qreal maxX(domain |
|
96 | qreal maxX(domain()->maxX()); | |
97 |
qreal maxY(domain |
|
97 | qreal maxY(domain()->maxY()); | |
98 |
|
98 | |||
99 | qreal x = categoryCount(); |
|
99 | qreal x = categoryCount(); | |
100 | minX = qMin(minX, - (qreal)0.5); |
|
100 | minX = qMin(minX, - (qreal)0.5); | |
@@ -102,19 +102,28 void QBarSeriesPrivate::scaleDomain(Domain &domain) | |||||
102 | maxX = qMax(maxX, x - (qreal)0.5); |
|
102 | maxX = qMax(maxX, x - (qreal)0.5); | |
103 | maxY = qMax(maxY, max()); |
|
103 | maxY = qMax(maxY, max()); | |
104 |
|
104 | |||
105 |
domain |
|
105 | domain()->setRange(minX, maxX, minY, maxY); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 |
|
108 | |||
109 | ChartElement *QBarSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
109 | void QBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
110 | { |
|
110 | { | |
111 | Q_Q(QBarSeries); |
|
111 | Q_Q(QBarSeries); | |
|
112 | BarChartItem *bar = new BarChartItem(q,parent); | |||
|
113 | m_item.reset(bar); | |||
|
114 | QAbstractSeriesPrivate::initializeGraphics(parent); | |||
|
115 | } | |||
112 |
|
116 | |||
113 | BarChartItem *bar = new BarChartItem(q, presenter); |
|
117 | void QBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
114 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
118 | { | |
|
119 | BarChartItem *bar = static_cast<BarChartItem *>(m_item.data()); | |||
|
120 | Q_ASSERT(bar); | |||
|
121 | if (options.testFlag(QChart::SeriesAnimations)) { | |||
115 | bar->setAnimation(new BarAnimation(bar)); |
|
122 | bar->setAnimation(new BarAnimation(bar)); | |
116 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
123 | }else{ | |
117 | return bar; |
|
124 | bar->setAnimation(0); | |
|
125 | } | |||
|
126 | QAbstractSeriesPrivate::initializeAnimations(options); | |||
118 | } |
|
127 | } | |
119 |
|
128 | |||
120 | #include "moc_qbarseries.cpp" |
|
129 | #include "moc_qbarseries.cpp" |
@@ -40,8 +40,10 class QBarSeriesPrivate: public QAbstractBarSeriesPrivate | |||||
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 | QBarSeriesPrivate(QBarSeries *q); |
|
42 | QBarSeriesPrivate(QBarSeries *q); | |
43 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
43 | void initializeGraphics(QGraphicsItem* parent); | |
44 | void scaleDomain(Domain &domain); |
|
44 | void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); | |
|
45 | void initializeDomain(); | |||
|
46 | ||||
45 | private: |
|
47 | private: | |
46 | Q_DECLARE_PUBLIC(QBarSeries) |
|
48 | Q_DECLARE_PUBLIC(QBarSeries) | |
47 | }; |
|
49 | }; |
@@ -26,8 +26,8 | |||||
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 |
PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, |
|
29 | PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : | |
30 |
AbstractBarChartItem(series, |
|
30 | AbstractBarChartItem(series, item) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 |
@@ -42,7 +42,7 class PercentBarChartItem : public AbstractBarChartItem | |||||
42 | { |
|
42 | { | |
43 | Q_OBJECT |
|
43 | Q_OBJECT | |
44 | public: |
|
44 | public: | |
45 |
PercentBarChartItem(QAbstractBarSeries *series, |
|
45 | PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 | virtual QVector<QRectF> calculateLayout(); |
|
48 | virtual QVector<QRectF> calculateLayout(); |
@@ -69,8 +69,8 QPercentBarSeries::QPercentBarSeries(QObject *parent) | |||||
69 | QPercentBarSeries::~QPercentBarSeries() |
|
69 | QPercentBarSeries::~QPercentBarSeries() | |
70 | { |
|
70 | { | |
71 | Q_D(QPercentBarSeries); |
|
71 | Q_D(QPercentBarSeries); | |
72 |
if (d->m_ |
|
72 | if (d->m_chart) | |
73 |
d->m_ |
|
73 | d->m_chart->removeSeries(this); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
@@ -88,12 +88,12 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbst | |||||
88 |
|
88 | |||
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 |
void QPercentBarSeriesPrivate:: |
|
91 | void QPercentBarSeriesPrivate::initializeDomain() | |
92 | { |
|
92 | { | |
93 |
qreal minX(domain |
|
93 | qreal minX(domain()->minX()); | |
94 |
qreal minY(domain |
|
94 | qreal minY(domain()->minY()); | |
95 |
qreal maxX(domain |
|
95 | qreal maxX(domain()->maxX()); | |
96 |
qreal maxY(domain |
|
96 | qreal maxY(domain()->maxY()); | |
97 |
|
97 | |||
98 | qreal x = categoryCount(); |
|
98 | qreal x = categoryCount(); | |
99 | minX = qMin(minX, - (qreal)0.5); |
|
99 | minX = qMin(minX, - (qreal)0.5); | |
@@ -101,21 +101,29 void QPercentBarSeriesPrivate::scaleDomain(Domain &domain) | |||||
101 | minY = 0; |
|
101 | minY = 0; | |
102 | maxY = 100; |
|
102 | maxY = 100; | |
103 |
|
103 | |||
104 |
domain |
|
104 | domain()->setRange(minX, maxX, minY, maxY); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 |
|
107 | |||
108 | ChartElement *QPercentBarSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
108 | void QPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
109 | { |
|
109 | { | |
110 | Q_Q(QPercentBarSeries); |
|
110 | Q_Q(QPercentBarSeries); | |
|
111 | PercentBarChartItem *bar = new PercentBarChartItem(q,parent); | |||
|
112 | m_item.reset(bar); | |||
|
113 | QAbstractSeriesPrivate::initializeGraphics(parent); | |||
|
114 | } | |||
111 |
|
115 | |||
112 | PercentBarChartItem *bar = new PercentBarChartItem(q, presenter); |
|
116 | void QPercentBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
113 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
117 | { | |
|
118 | PercentBarChartItem *bar = static_cast<PercentBarChartItem *>(m_item.data()); | |||
|
119 | Q_ASSERT(bar); | |||
|
120 | if (options.testFlag(QChart::SeriesAnimations)) { | |||
114 | bar->setAnimation(new PercentBarAnimation(bar)); |
|
121 | bar->setAnimation(new PercentBarAnimation(bar)); | |
115 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
122 | }else{ | |
116 | return bar; |
|
123 | bar->setAnimation(0); | |
|
124 | } | |||
|
125 | QAbstractSeriesPrivate::initializeAnimations(options); | |||
117 | } |
|
126 | } | |
118 |
|
||||
119 | #include "moc_qpercentbarseries.cpp" |
|
127 | #include "moc_qpercentbarseries.cpp" | |
120 |
|
128 | |||
121 | QTCOMMERCIALCHART_END_NAMESPACE |
|
129 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -40,8 +40,9 class QPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate | |||||
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 | QPercentBarSeriesPrivate(QPercentBarSeries *q); |
|
42 | QPercentBarSeriesPrivate(QPercentBarSeries *q); | |
43 |
void |
|
43 | void initializeDomain(); | |
44 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
44 | void initializeGraphics(QGraphicsItem* parent); | |
|
45 | void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); | |||
45 | private: |
|
46 | private: | |
46 | Q_DECLARE_PUBLIC(QPercentBarSeries) |
|
47 | Q_DECLARE_PUBLIC(QPercentBarSeries) | |
47 | }; |
|
48 | }; |
@@ -70,8 +70,8 QStackedBarSeries::QStackedBarSeries(QObject *parent) | |||||
70 | QStackedBarSeries::~QStackedBarSeries() |
|
70 | QStackedBarSeries::~QStackedBarSeries() | |
71 | { |
|
71 | { | |
72 | Q_D(QStackedBarSeries); |
|
72 | Q_D(QStackedBarSeries); | |
73 |
if (d->m_ |
|
73 | if (d->m_chart) | |
74 |
d->m_ |
|
74 | d->m_chart->removeSeries(this); | |
75 | } |
|
75 | } | |
76 | /*! |
|
76 | /*! | |
77 | Returns QChartSeries::SeriesTypeStackedBar. |
|
77 | Returns QChartSeries::SeriesTypeStackedBar. | |
@@ -88,12 +88,12 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbst | |||||
88 |
|
88 | |||
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 |
void QStackedBarSeriesPrivate:: |
|
91 | void QStackedBarSeriesPrivate::initializeDomain() | |
92 | { |
|
92 | { | |
93 |
qreal minX(domain |
|
93 | qreal minX(domain()->minX()); | |
94 |
qreal minY(domain |
|
94 | qreal minY(domain()->minY()); | |
95 |
qreal maxX(domain |
|
95 | qreal maxX(domain()->maxX()); | |
96 |
qreal maxY(domain |
|
96 | qreal maxY(domain()->maxY()); | |
97 |
|
97 | |||
98 | qreal x = categoryCount(); |
|
98 | qreal x = categoryCount(); | |
99 | minX = qMin(minX, - (qreal)0.5); |
|
99 | minX = qMin(minX, - (qreal)0.5); | |
@@ -101,20 +101,28 void QStackedBarSeriesPrivate::scaleDomain(Domain &domain) | |||||
101 | maxX = qMax(maxX, x - (qreal)0.5); |
|
101 | maxX = qMax(maxX, x - (qreal)0.5); | |
102 | maxY = qMax(maxY, top()); |
|
102 | maxY = qMax(maxY, top()); | |
103 |
|
103 | |||
104 |
domain |
|
104 | domain()->setRange(minX, maxX, minY, maxY); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | ChartElement *QStackedBarSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
107 | void QStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
108 | { |
|
108 | { | |
109 | Q_Q(QStackedBarSeries); |
|
109 | Q_Q(QStackedBarSeries); | |
|
110 | StackedBarChartItem *bar = new StackedBarChartItem(q,parent); | |||
|
111 | m_item.reset(bar); | |||
|
112 | QAbstractSeriesPrivate::initializeGraphics(parent); | |||
|
113 | } | |||
110 |
|
114 | |||
111 | StackedBarChartItem *bar = new StackedBarChartItem(q, presenter); |
|
115 | void QStackedBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
112 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
116 | { | |
|
117 | StackedBarChartItem *bar = static_cast<StackedBarChartItem *>(m_item.data()); | |||
|
118 | Q_ASSERT(bar); | |||
|
119 | if (options.testFlag(QChart::SeriesAnimations)) { | |||
113 | bar->setAnimation(new StackedBarAnimation(bar)); |
|
120 | bar->setAnimation(new StackedBarAnimation(bar)); | |
114 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
121 | }else{ | |
115 | return bar; |
|
122 | bar->setAnimation(0); | |
|
123 | } | |||
|
124 | QAbstractSeriesPrivate::initializeAnimations(options); | |||
116 | } |
|
125 | } | |
117 |
|
||||
118 | #include "moc_qstackedbarseries.cpp" |
|
126 | #include "moc_qstackedbarseries.cpp" | |
119 |
|
127 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
128 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -40,8 +40,9 class QStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate | |||||
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 | QStackedBarSeriesPrivate(QStackedBarSeries *q); |
|
42 | QStackedBarSeriesPrivate(QStackedBarSeries *q); | |
43 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
43 | void initializeGraphics(QGraphicsItem* parent); | |
44 | void scaleDomain(Domain &domain); |
|
44 | void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); | |
|
45 | void initializeDomain(); | |||
45 | private: |
|
46 | private: | |
46 | Q_DECLARE_PUBLIC(QStackedBarSeries) |
|
47 | Q_DECLARE_PUBLIC(QStackedBarSeries) | |
47 | }; |
|
48 | }; |
@@ -26,8 +26,8 | |||||
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 |
StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, |
|
29 | StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : | |
30 |
AbstractBarChartItem(series, |
|
30 | AbstractBarChartItem(series, item) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 |
@@ -41,7 +41,7 class StackedBarChartItem : public AbstractBarChartItem | |||||
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 | public: |
|
43 | public: | |
44 |
StackedBarChartItem(QAbstractBarSeries *series, |
|
44 | StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item =0); | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | virtual QVector<QRectF> calculateLayout(); |
|
47 | virtual QVector<QRectF> calculateLayout(); |
This diff has been collapsed as it changes many lines, (573 lines changed) Show them Hide them | |||||
@@ -19,7 +19,9 | |||||
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
|
22 | #include "chartpresenter_p.h" | |||
22 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
|
24 | #include "qchart_p.h" | |||
23 | #include "qvalueaxis.h" |
|
25 | #include "qvalueaxis.h" | |
24 | #include "qbarcategoryaxis.h" |
|
26 | #include "qbarcategoryaxis.h" | |
25 | #include "qvalueaxis_p.h" |
|
27 | #include "qvalueaxis_p.h" | |
@@ -29,6 +31,7 | |||||
29 | #include "qstackedbarseries.h" |
|
31 | #include "qstackedbarseries.h" | |
30 | #include "qpercentbarseries.h" |
|
32 | #include "qpercentbarseries.h" | |
31 | #include "qpieseries.h" |
|
33 | #include "qpieseries.h" | |
|
34 | #include "chartitem_p.h" | |||
32 |
|
35 | |||
33 | #ifndef QT_ON_ARM |
|
36 | #ifndef QT_ON_ARM | |
34 | #include "qdatetimeaxis.h" |
|
37 | #include "qdatetimeaxis.h" | |
@@ -36,8 +39,9 | |||||
36 |
|
39 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
41 | |||
39 |
ChartDataSet::ChartDataSet(QChart * |
|
42 | ChartDataSet::ChartDataSet(QChart *chart) | |
40 |
: QObject( |
|
43 | : QObject(chart), | |
|
44 | m_chart(chart) | |||
41 | { |
|
45 | { | |
42 |
|
46 | |||
43 | } |
|
47 | } | |
@@ -45,451 +49,358 ChartDataSet::ChartDataSet(QChart *parent) | |||||
45 | ChartDataSet::~ChartDataSet() |
|
49 | ChartDataSet::~ChartDataSet() | |
46 | { |
|
50 | { | |
47 | removeAllSeries(); |
|
51 | removeAllSeries(); | |
|
52 | removeAllAxes(); | |||
48 | } |
|
53 | } | |
49 |
|
54 | |||
|
55 | /* | |||
|
56 | * This method adds series to chartdataset, series ownership is taken from caller. | |||
|
57 | */ | |||
50 | void ChartDataSet::addSeries(QAbstractSeries *series) |
|
58 | void ChartDataSet::addSeries(QAbstractSeries *series) | |
51 | { |
|
59 | { | |
52 | Domain *domain = m_seriesDomainMap.value(series); |
|
60 | if (m_seriesList.contains(series)) { | |
|
61 | qWarning() << QObject::tr("Can not add series. Series already on the chart."); | |||
|
62 | return; | |||
|
63 | } | |||
|
64 | ||||
|
65 | series->d_ptr->initializeDomain(); | |||
|
66 | m_seriesList.append(series); | |||
|
67 | ||||
|
68 | series->setParent(this); // take ownership | |||
|
69 | series->d_ptr->m_chart = m_chart; | |||
|
70 | ||||
|
71 | emit seriesAdded(series); | |||
|
72 | } | |||
53 |
|
73 | |||
54 | if (domain) { |
|
74 | /* | |
55 | qWarning() << "Can not add series. Series already on the chart"; |
|
75 | * This method adds axis to chartdataset, axis ownership is taken from caller. | |
|
76 | */ | |||
|
77 | void ChartDataSet::addAxis(QAbstractAxis *axis,Qt::Alignment aligment) | |||
|
78 | { | |||
|
79 | if (m_axisList.contains(axis)) { | |||
|
80 | qWarning() << QObject::tr("Can not add axis. Axis already on the chart."); | |||
56 | return; |
|
81 | return; | |
57 | } |
|
82 | } | |
58 |
|
83 | |||
59 | domain = new Domain(series); |
|
84 | axis->d_ptr->setAlignment(aligment); | |
60 | m_seriesDomainMap.insert(series, domain); |
|
|||
61 | series->d_ptr->scaleDomain(*domain); |
|
|||
62 |
|
85 | |||
63 | createSeriesIndex(series); |
|
86 | if(!axis->alignment()) { | |
|
87 | qWarning()<< QObject::tr("No alignment specified !"); | |||
|
88 | return; | |||
|
89 | }; | |||
64 |
|
90 | |||
65 | series->setParent(this); // take ownership |
|
91 | QSharedPointer<Domain> domain(new Domain()); | |
66 | series->d_ptr->m_chart = qobject_cast<QChart *>(parent()); |
|
92 | axis->d_ptr->initializeDomain(domain.data()); | |
67 | series->d_ptr->m_dataset = this; |
|
|||
68 |
|
93 | |||
69 | emit seriesAdded(series, domain); |
|
94 | axis->setParent(this); | |
|
95 | axis->d_ptr->m_chart = m_chart; | |||
|
96 | m_axisList.append(axis); | |||
70 |
|
97 | |||
|
98 | emit axisAdded(axis); | |||
71 | } |
|
99 | } | |
72 |
|
100 | |||
|
101 | /* | |||
|
102 | * This method removes series form chartdataset, series ownership is passed back to caller. | |||
|
103 | */ | |||
73 | void ChartDataSet::removeSeries(QAbstractSeries *series) |
|
104 | void ChartDataSet::removeSeries(QAbstractSeries *series) | |
74 | { |
|
105 | { | |
75 |
|
106 | |||
76 |
if (!m_series |
|
107 | if (! m_seriesList.contains(series)) { | |
77 | qWarning() << "Can not remove series. Series not found on the chart."; |
|
108 | qWarning() << QObject::tr("Can not remove series. Series not found on the chart."); | |
78 | return; |
|
109 | return; | |
79 | } |
|
110 | } | |
80 |
|
111 | |||
81 | emit seriesRemoved(series); |
|
112 | emit seriesRemoved(series); | |
82 |
|
113 | m_seriesList.removeAll(series); | ||
83 | Domain *domain = m_seriesDomainMap.take(series); |
|
|||
84 | delete domain; |
|
|||
85 | domain = 0; |
|
|||
86 |
|
||||
87 | removeSeriesIndex(series); |
|
|||
88 |
|
114 | |||
89 | series->setParent(0); |
|
115 | series->setParent(0); | |
90 | series->d_ptr->m_chart = 0; |
|
116 | series->d_ptr->m_chart = 0; | |
91 |
series->d_ptr->m_d |
|
117 | series->d_ptr->m_domain.clear(); | |
92 |
|
||||
93 | removeAxes(series); |
|
|||
94 | } |
|
|||
95 |
|
||||
96 |
|
118 | |||
|
119 | QList<QAbstractAxis*> axes = series->d_ptr->m_axes; | |||
97 |
|
120 | |||
98 | void ChartDataSet::createSeriesIndex(QAbstractSeries *series) |
|
121 | foreach(QAbstractAxis* axis, axes) { | |
99 | { |
|
122 | axis->d_ptr->m_series.removeAll(series); | |
100 | QMapIterator<int, QAbstractSeries *> i(m_indexSeriesMap); |
|
123 | series->d_ptr->m_axes.removeAll(axis); | |
101 |
|
||||
102 | int key = 0; |
|
|||
103 | while (i.hasNext()) { |
|
|||
104 | i.next(); |
|
|||
105 | if (i.key() != key) |
|
|||
106 | break; |
|
|||
107 | key++; |
|
|||
108 | } |
|
124 | } | |
109 |
|
||||
110 | m_indexSeriesMap.insert(key, series); |
|
|||
111 | } |
|
125 | } | |
112 |
|
126 | |||
113 | void ChartDataSet::removeSeriesIndex(QAbstractSeries *series) |
|
127 | /* | |
114 | { |
|
128 | * This method removes axis form chartdataset, series ownership is passed back to caller. | |
115 | int key = seriesIndex(series); |
|
129 | */ | |
116 | Q_ASSERT(key != -1); |
|
130 | void ChartDataSet::removeAxis(QAbstractAxis *axis) | |
117 | m_indexSeriesMap.remove(key); |
|
|||
118 | } |
|
|||
119 |
|
||||
120 | void ChartDataSet::createDefaultAxes() |
|
|||
121 | { |
|
131 | { | |
122 | if (m_seriesDomainMap.isEmpty()) |
|
132 | if (! m_axisList.contains(axis)) { | |
|
133 | qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart."); | |||
123 | return; |
|
134 | return; | |
124 |
|
||||
125 | QAbstractAxis::AxisTypes typeX(0); |
|
|||
126 | QAbstractAxis::AxisTypes typeY(0); |
|
|||
127 |
|
||||
128 | // Remove possibly existing axes |
|
|||
129 | QMapIterator<QAbstractSeries *, Domain *> i(m_seriesDomainMap); |
|
|||
130 | while (i.hasNext()) { |
|
|||
131 | i.next(); |
|
|||
132 | removeAxes(i.key()); |
|
|||
133 | } |
|
135 | } | |
134 |
|
136 | |||
135 | i.toFront(); |
|
137 | emit axisRemoved(axis); | |
|
138 | m_axisList.removeAll(axis); | |||
136 |
|
139 | |||
137 | // Select the required axis x and axis y types based on the types of the current series |
|
140 | axis->setParent(0); | |
138 | while (i.hasNext()) { |
|
141 | axis->d_ptr->m_chart = 0; | |
139 | i.next(); |
|
|||
140 | QAbstractAxis *axisX = m_seriesAxisXMap.value(i.key()); |
|
|||
141 | QAbstractAxis *axisY = m_seriesAxisYMap.value(i.key()); |
|
|||
142 | if (axisX) |
|
|||
143 | typeX &= axisX->type(); |
|
|||
144 | else |
|
|||
145 | typeX |= i.key()->d_ptr->defaultAxisType(Qt::Horizontal); |
|
|||
146 | if (axisY) |
|
|||
147 | typeY &= axisY->type(); |
|
|||
148 | else |
|
|||
149 | typeY |= i.key()->d_ptr->defaultAxisType(Qt::Vertical); |
|
|||
150 | } |
|
|||
151 |
|
142 | |||
152 | // Create the axes of the types selected |
|
143 | QList<QAbstractSeries*> series = axis->d_ptr->m_series; | |
153 | createAxes(typeX, Qt::Horizontal); |
|
|||
154 | createAxes(typeY, Qt::Vertical); |
|
|||
155 | } |
|
|||
156 |
|
144 | |||
157 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) |
|
145 | foreach(QAbstractSeries* s, series) { | |
158 | { |
|
146 | s->d_ptr->m_axes.removeAll(axis); | |
159 | QMapIterator<QAbstractSeries *, Domain *> i(m_seriesDomainMap); |
|
147 | axis->d_ptr->m_series.removeAll(s); | |
160 |
|
||||
161 | // TODO: Add a descriptive comment of what happens here |
|
|||
162 | if (type.testFlag(QAbstractAxis::AxisTypeValue) && type.testFlag(QAbstractAxis::AxisTypeBarCategory)) { |
|
|||
163 | while (i.hasNext()) { |
|
|||
164 | i.next(); |
|
|||
165 | QAbstractAxis *axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation), orientation); |
|
|||
166 | if (axis) { |
|
|||
167 | initializeAxis(axis, i.key()); |
|
|||
168 | emit axisAdded(axis, i.value()); |
|
|||
169 | } |
|
|||
170 | } |
|
|||
171 | } else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { |
|
|||
172 | QAbstractAxis *axis = createAxis(QAbstractAxis::AxisType(int(type)), orientation); |
|
|||
173 | i.toFront(); |
|
|||
174 | while (i.hasNext()) { |
|
|||
175 | i.next(); |
|
|||
176 | initializeAxis(axis, i.key()); |
|
|||
177 | } |
|
|||
178 | emit axisAdded(axis, i.value()); |
|
|||
179 | } |
|
148 | } | |
180 | } |
|
149 | } | |
181 |
|
150 | |||
182 | QAbstractAxis *ChartDataSet::createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation) |
|
151 | /* | |
|
152 | * This method attach axis to series, return true if success. | |||
|
153 | */ | |||
|
154 | bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis) | |||
183 | { |
|
155 | { | |
184 | QAbstractAxis *axis = 0; |
|
156 | Q_ASSERT(series); | |
|
157 | Q_ASSERT(axis); | |||
185 |
|
158 | |||
186 | switch (type) { |
|
159 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; | |
187 | case QAbstractAxis::AxisTypeValue: |
|
160 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; | |
188 | axis = new QValueAxis(this); |
|
161 | QSharedPointer<Domain> domain = series->d_ptr->m_domain; | |
189 | break; |
|
|||
190 | case QAbstractAxis::AxisTypeBarCategory: |
|
|||
191 | axis = new QBarCategoryAxis(this); |
|
|||
192 | break; |
|
|||
193 | case QAbstractAxis::AxisTypeCategory: |
|
|||
194 | axis = new QCategoryAxis(this); |
|
|||
195 | break; |
|
|||
196 | #ifndef Q_WS_QWS |
|
|||
197 | case QAbstractAxis::AxisTypeDateTime: |
|
|||
198 | axis = new QDateTimeAxis(this); |
|
|||
199 | break; |
|
|||
200 | #endif |
|
|||
201 | default: |
|
|||
202 | axis = 0; |
|
|||
203 | break; |
|
|||
204 | } |
|
|||
205 |
|
162 | |||
206 | if (axis) |
|
163 | if (!m_seriesList.contains(series)) { | |
207 | axis->d_ptr->setOrientation(orientation); |
|
164 | qWarning() << QObject::tr("Can not find series on the chart."); | |
|
165 | return false; | |||
|
166 | } | |||
208 |
|
167 | |||
209 | return axis; |
|
168 | if (axis && !m_axisList.contains(axis)) { | |
210 | } |
|
169 | qWarning() << QObject::tr("Can not find axis on the chart."); | |
|
170 | return false; | |||
|
171 | } | |||
211 |
|
172 | |||
212 | void ChartDataSet::initializeAxis(QAbstractAxis *axis, QAbstractSeries *series) |
|
173 | if (attachedAxisList.contains(axis)) { | |
213 | { |
|
174 | qWarning() << QObject::tr("Axis already attached to series."); | |
214 | Domain *domain = m_seriesDomainMap.value(series); |
|
175 | return false; | |
215 | axis->d_ptr->m_dataset = this; |
|
|||
216 | series->d_ptr->initializeAxis(axis); |
|
|||
217 | axis->d_ptr->intializeDomain(domain); |
|
|||
218 | if (axis->orientation() == Qt::Horizontal) { |
|
|||
219 | QObject::connect(axis->d_ptr.data(), SIGNAL(updated()), domain, SLOT(handleAxisUpdated())); |
|
|||
220 | QObject::connect(domain, SIGNAL(updated()), axis->d_ptr.data(), SLOT(handleDomainUpdated())); |
|
|||
221 | m_seriesAxisXMap.insert(series, axis); |
|
|||
222 | } else { |
|
|||
223 | QObject::connect(axis->d_ptr.data(), SIGNAL(updated()), domain, SLOT(handleAxisUpdated())); |
|
|||
224 | QObject::connect(domain, SIGNAL(updated()), axis->d_ptr.data(), SLOT(handleDomainUpdated())); |
|
|||
225 | m_seriesAxisYMap.insert(series, axis); |
|
|||
226 | } |
|
176 | } | |
227 | axis->d_ptr->emitUpdated(); |
|
|||
228 | } |
|
|||
229 |
|
177 | |||
230 | void ChartDataSet::removeAxes(QAbstractSeries *series) |
|
178 | Q_ASSERT(!attachedSeriesList.contains(series)); | |
231 | { |
|
179 | Q_ASSERT(!domain.isNull()); | |
232 | QAbstractAxis *axisX = m_seriesAxisXMap.take(series); |
|
|||
233 |
|
180 | |||
234 | if (axisX) { |
|
181 | if(attachedSeriesList.isEmpty()){ | |
235 | QList<QAbstractAxis *> axesX = m_seriesAxisXMap.values(); |
|
|||
236 | int x = axesX.indexOf(axisX); |
|
|||
237 |
|
182 | |||
238 | if (x == -1) { |
|
183 | }else{ | |
239 | emit axisRemoved(axisX); |
|
184 | domain = attachedSeriesList.first()->d_ptr->domain(); | |
240 | axisX->d_ptr->m_dataset = 0; |
|
185 | Q_ASSERT(!domain.isNull()); | |
241 | axisX->deleteLater(); |
|
186 | series->d_ptr->setDomain(domain); | |
242 | } |
|
|||
243 | } |
|
187 | } | |
244 |
|
188 | |||
245 | QAbstractAxis *axisY = m_seriesAxisYMap.take(series); |
|
189 | series->d_ptr->m_axes<<axis; | |
|
190 | axis->d_ptr->m_series<<series; | |||
246 |
|
191 | |||
247 | if (axisY) { |
|
192 | series->d_ptr->initializeAxes(); | |
248 | QList<QAbstractAxis *> axesY = m_seriesAxisYMap.values(); |
|
193 | axis->d_ptr->initializeDomain(domain.data()); | |
249 |
|
194 | |||
250 | int y = axesY.indexOf(axisY); |
|
195 | if(axis->orientation()==Qt::Vertical){ | |
|
196 | QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); | |||
|
197 | QObject::connect(domain.data(), SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |||
|
198 | } | |||
251 |
|
199 | |||
252 | if (y == -1) { |
|
200 | if(axis->orientation()==Qt::Horizontal){ | |
253 | emit axisRemoved(axisY); |
|
201 | QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); | |
254 | axisY->d_ptr->m_dataset = 0; |
|
202 | QObject::connect(domain.data(), SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |
255 | axisY->deleteLater(); |
|
|||
256 | } |
|
|||
257 | } |
|
203 | } | |
|
204 | ||||
|
205 | return true; | |||
258 | } |
|
206 | } | |
259 |
|
207 | |||
260 | void ChartDataSet::removeAxis(QAbstractAxis *axis) |
|
208 | /* | |
|
209 | * This method detach axis to series, return true if success. | |||
|
210 | */ | |||
|
211 | bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis) | |||
261 | { |
|
212 | { | |
262 | if (!axis->d_ptr->m_dataset) { |
|
213 | Q_ASSERT(series); | |
263 | qWarning() << "UnBound axis found !"; |
|
214 | Q_ASSERT(axis); | |
264 | return; |
|
|||
265 | } |
|
|||
266 |
|
215 | |||
267 | QMap<QAbstractSeries *, QAbstractAxis *> *seriesAxisMap; |
|
216 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; | |
|
217 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; | |||
|
218 | QSharedPointer<Domain> domain = series->d_ptr->m_domain; | |||
268 |
|
219 | |||
269 | if (axis->orientation() == Qt::Vertical) |
|
220 | if (!m_seriesList.contains(series)) { | |
270 | seriesAxisMap = &m_seriesAxisYMap; |
|
221 | qWarning() << QObject::tr("Can not find series on the chart."); | |
271 | else |
|
222 | return false; | |
272 | seriesAxisMap = &m_seriesAxisXMap; |
|
223 | } | |
273 |
|
224 | |||
274 | QMapIterator<QAbstractSeries *, QAbstractAxis *> i(*seriesAxisMap); |
|
225 | if (axis && !m_axisList.contains(axis)) { | |
|
226 | qWarning() << QObject::tr("Can not find axis on the chart."); | |||
|
227 | return false; | |||
|
228 | } | |||
275 |
|
229 | |||
276 | while (i.hasNext()) { |
|
230 | if (!attachedAxisList.contains(axis)) { | |
277 | i.next(); |
|
231 | qWarning() << QObject::tr("Axis not attached to series."); | |
278 | if (i.value() == axis) |
|
232 | return false; | |
279 | removeSeries(i.key()); |
|
|||
280 | } |
|
233 | } | |
281 | } |
|
|||
282 |
|
234 | |||
283 | void ChartDataSet::removeAllSeries() |
|
235 | Q_ASSERT(axis->d_ptr->m_series.contains(series)); | |
284 | { |
|
236 | ||
285 | QList<QAbstractSeries *> series = m_seriesDomainMap.keys(); |
|
237 | series->d_ptr->m_axes.removeAll(axis); | |
286 | foreach (QAbstractSeries *s , series) |
|
238 | axis->d_ptr->m_series.removeAll(series); | |
287 | removeSeries(s); |
|
|||
288 |
|
239 | |||
289 | Q_ASSERT(m_seriesAxisXMap.count() == 0); |
|
240 | if(axis->orientation()==Qt::Vertical){ | |
290 | Q_ASSERT(m_seriesAxisXMap.count() == 0); |
|
241 | QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); | |
291 | Q_ASSERT(m_seriesDomainMap.count() == 0); |
|
242 | QObject::disconnect(domain.data(), SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |
|
243 | } | |||
|
244 | ||||
|
245 | if(axis->orientation()==Qt::Horizontal){ | |||
|
246 | QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); | |||
|
247 | QObject::disconnect(domain.data(), SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |||
|
248 | } | |||
292 |
|
249 | |||
293 | qDeleteAll(series); |
|
250 | return true; | |
294 | } |
|
251 | } | |
295 |
|
252 | |||
296 | void ChartDataSet::zoomInDomain(const QRectF &rect, const QSizeF &size) |
|
253 | void ChartDataSet::createDefaultAxes() | |
297 | { |
|
254 | { | |
298 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
255 | if (m_seriesList.isEmpty()) | |
|
256 | return; | |||
299 |
|
257 | |||
|
258 | QAbstractAxis::AxisTypes typeX(0); | |||
|
259 | QAbstractAxis::AxisTypes typeY(0); | |||
300 |
|
260 | |||
301 | blockAxisSignals(true); |
|
261 | // Remove possibly existing axes | |
|
262 | removeAllAxes(); | |||
302 |
|
263 | |||
303 | QMapIterator<QAbstractSeries *, Domain *> i(m_seriesDomainMap); |
|
264 | Q_ASSERT(m_axisList.isEmpty()); | |
304 |
|
265 | |||
305 | while (i.hasNext()) { |
|
266 | // Select the required axis x and axis y types based on the types of the current series | |
306 | i.next(); |
|
267 | foreach(QAbstractSeries* s, m_seriesList) { | |
307 | i.value()->zoomIn(rect, size); |
|
268 | typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal); | |
|
269 | typeY |= s->d_ptr->defaultAxisType(Qt::Vertical); | |||
308 | } |
|
270 | } | |
309 |
|
271 | |||
310 | blockAxisSignals(false); |
|
272 | // Create the axes of the types selected | |
|
273 | createAxes(typeX, Qt::Horizontal); | |||
|
274 | createAxes(typeY, Qt::Vertical); | |||
311 |
|
275 | |||
312 | } |
|
276 | } | |
313 |
|
277 | |||
314 | void ChartDataSet::zoomOutDomain(const QRectF &rect, const QSizeF &size) |
|
278 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) | |
315 | { |
|
279 | { | |
316 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
280 | QAbstractAxis *axis = 0; | |
317 |
|
281 | //decide what axis should be created | ||
318 | blockAxisSignals(true); |
|
|||
319 |
|
||||
320 | QMapIterator<QAbstractSeries *, Domain *> i(m_seriesDomainMap); |
|
|||
321 |
|
282 | |||
322 | while (i.hasNext()) { |
|
283 | switch (type) { | |
323 | i.next(); |
|
284 | case QAbstractAxis::AxisTypeValue: | |
324 | i.value()->zoomOut(rect, size); |
|
285 | axis = new QValueAxis(this); | |
|
286 | break; | |||
|
287 | case QAbstractAxis::AxisTypeBarCategory: | |||
|
288 | axis = new QBarCategoryAxis(this); | |||
|
289 | break; | |||
|
290 | case QAbstractAxis::AxisTypeCategory: | |||
|
291 | axis = new QCategoryAxis(this); | |||
|
292 | break; | |||
|
293 | #ifndef Q_WS_QWS | |||
|
294 | case QAbstractAxis::AxisTypeDateTime: | |||
|
295 | axis = new QDateTimeAxis(this); | |||
|
296 | break; | |||
|
297 | #endif | |||
|
298 | default: | |||
|
299 | axis = 0; | |||
|
300 | break; | |||
325 | } |
|
301 | } | |
326 |
|
302 | |||
327 | blockAxisSignals(false); |
|
303 | if (axis) { | |
328 | } |
|
304 | //create one axis for all | |
329 |
|
305 | |||
330 | void ChartDataSet::blockAxisSignals(bool enabled) |
|
306 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); | |
331 | { |
|
307 | ||
332 | QMapIterator<QAbstractSeries *, Domain *> i(m_seriesDomainMap); |
|
308 | foreach(QAbstractSeries *s, m_seriesList) { | |
333 | while (i.hasNext()) { |
|
309 | attachAxis(s,axis); | |
334 | i.next(); |
|
|||
335 | QAbstractAxis *axisX = m_seriesAxisXMap.value(i.key()); |
|
|||
336 | QAbstractAxis *axisY = m_seriesAxisYMap.value(i.key()); |
|
|||
337 | if (axisX) { |
|
|||
338 | axisX->d_ptr->blockSignals(enabled); |
|
|||
339 | if (!enabled) { |
|
|||
340 | axisX->d_ptr->setDirty(false); |
|
|||
341 | axisX->d_ptr->emitUpdated(); |
|
|||
342 | } |
|
|||
343 | } |
|
|||
344 | if (axisY) { |
|
|||
345 | axisY->d_ptr->blockSignals(enabled); |
|
|||
346 | if (!enabled) { |
|
|||
347 | axisY->d_ptr->setDirty(false); |
|
|||
348 | axisY->d_ptr->emitUpdated(); |
|
|||
349 | } |
|
|||
350 | } |
|
310 | } | |
351 | } |
|
|||
352 | } |
|
|||
353 |
|
311 | |||
354 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
|||
355 | { |
|
|||
356 | int count = 0; |
|
|||
357 | QMapIterator<QAbstractSeries *, Domain *> i(m_seriesDomainMap); |
|
|||
358 | while (i.hasNext()) { |
|
|||
359 | i.next(); |
|
|||
360 | if (i.key()->type() == type) |
|
|||
361 | count++; |
|
|||
362 | } |
|
312 | } | |
363 | return count; |
|
313 | else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { | |
364 | } |
|
314 | //create separate axis | |
365 |
|
315 | foreach(QAbstractSeries *s, m_seriesList) { | ||
366 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
316 | QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation); | |
367 | { |
|
317 | if(axis) { | |
368 | QMapIterator<int, QAbstractSeries *> i(m_indexSeriesMap); |
|
318 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); | |
369 | while (i.hasNext()) { |
|
319 | attachAxis(s,axis); | |
370 | i.next(); |
|
320 | } | |
371 | if (i.value() == series) |
|
321 | } | |
372 | return i.key(); |
|
|||
373 | } |
|
322 | } | |
374 | return -1; |
|
|||
375 | } |
|
323 | } | |
376 |
|
324 | |||
377 | QAbstractAxis *ChartDataSet::axisX(QAbstractSeries *series) const |
|
325 | void ChartDataSet::removeAllSeries() | |
378 | { |
|
326 | { | |
379 | if (series == 0) { |
|
327 | foreach (QAbstractSeries *s , m_seriesList) | |
380 |
|
328 | removeSeries(s); | ||
381 | QMapIterator<QAbstractSeries *, QAbstractAxis *> i(m_seriesAxisXMap); |
|
|||
382 |
|
329 | |||
383 | while (i.hasNext()) { |
|
330 | Q_ASSERT(m_seriesList.count() == 0); | |
384 | i.next(); |
|
331 | qDeleteAll(m_seriesList); | |
385 | if (i.value()->isVisible()) |
|
|||
386 | return i.value(); |
|
|||
387 | } |
|
|||
388 | return 0; |
|
|||
389 | } |
|
|||
390 | return m_seriesAxisXMap.value(series); |
|
|||
391 | } |
|
332 | } | |
392 |
|
333 | |||
393 | QAbstractAxis *ChartDataSet::axisY(QAbstractSeries *series) const |
|
334 | void ChartDataSet::removeAllAxes() | |
394 | { |
|
335 | { | |
395 | if (series == 0) { |
|
336 | foreach (QAbstractAxis *a , m_axisList) | |
396 | QMapIterator<QAbstractSeries *, QAbstractAxis *> i(m_seriesAxisYMap); |
|
337 | removeAxis(a); | |
397 |
|
338 | |||
398 | while (i.hasNext()) { |
|
339 | Q_ASSERT(m_axisList.count() == 0); | |
399 | i.next(); |
|
340 | qDeleteAll(m_axisList); | |
400 | if (i.value()->isVisible()) return i.value(); |
|
|||
401 | } |
|
|||
402 | return 0; |
|
|||
403 | } |
|
|||
404 | return m_seriesAxisYMap.value(series); |
|
|||
405 | } |
|
341 | } | |
406 |
|
342 | |||
407 | void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation) |
|
343 | void ChartDataSet::zoomInDomain(const QRectF &rect) | |
408 | { |
|
344 | { | |
409 | Q_ASSERT(axis); |
|
345 | QList<Domain*> domains; | |
410 |
|
346 | foreach(QAbstractSeries *s, m_seriesList) { | ||
411 | if (!series) { |
|
347 | Domain* domain = s->d_ptr->m_domain.data(); | |
412 | qWarning() << "Series not found on the chart."; |
|
348 | if(domains.contains(domain)) continue; | |
413 | return; |
|
349 | s->d_ptr->m_domain->blockAxisSignals(true); | |
|
350 | domains<<domain; | |||
414 | } |
|
351 | } | |
415 |
|
352 | |||
416 | Domain *domain = m_seriesDomainMap.value(series); |
|
353 | foreach(Domain *domain, domains) | |
|
354 | domain->zoomIn(rect); | |||
417 |
|
355 | |||
418 | if (!domain) { |
|
356 | foreach(Domain *domain, domains) | |
419 | qWarning() << "Series not found on the chart."; |
|
357 | domain->blockAxisSignals(false); | |
420 | return; |
|
358 | } | |
421 | } |
|
|||
422 |
|
||||
423 | if (orientation == Qt::Horizontal && axis->orientation() == Qt::Vertical) { |
|
|||
424 | qWarning() << "Axis already defined as axis Y"; |
|
|||
425 | return; |
|
|||
426 | } |
|
|||
427 |
|
359 | |||
428 | if (orientation == Qt::Vertical && axis->orientation() == Qt::Horizontal) { |
|
360 | void ChartDataSet::zoomOutDomain(const QRectF &rect) | |
429 | qWarning() << "Axis already defined as axis X"; |
|
361 | { | |
430 | return; |
|
362 | QList<Domain*> domains; | |
|
363 | foreach(QAbstractSeries *s, m_seriesList) { | |||
|
364 | Domain* domain = s->d_ptr->m_domain.data(); | |||
|
365 | if(domains.contains(domain)) continue; | |||
|
366 | s->d_ptr->m_domain->blockAxisSignals(true); | |||
|
367 | domains<<domain; | |||
431 | } |
|
368 | } | |
432 |
|
369 | |||
433 | axis->d_ptr->setOrientation(orientation); |
|
370 | foreach(Domain *domain, domains) | |
434 |
|
371 | domain->zoomOut(rect); | ||
435 | QMap<QAbstractSeries *, QAbstractAxis *> *seriesAxisMap; |
|
|||
436 |
|
372 | |||
437 | if (orientation == Qt::Vertical) |
|
373 | foreach(Domain *domain, domains) | |
438 | seriesAxisMap = &m_seriesAxisYMap; |
|
374 | domain->blockAxisSignals(false); | |
439 | else |
|
375 | } | |
440 | seriesAxisMap = &m_seriesAxisXMap; |
|
|||
441 |
|
||||
442 | if (seriesAxisMap->value(series) == axis) { |
|
|||
443 | qWarning() << "The axis already set for the series"; |
|
|||
444 | return; |
|
|||
445 | } |
|
|||
446 |
|
376 | |||
447 | QAbstractAxis *oldAxis = seriesAxisMap->take(series); |
|
377 | void ChartDataSet::scrollDomain(qreal dx, qreal dy) | |
448 | QList<QAbstractAxis *> axes = seriesAxisMap->values(); |
|
378 | { | |
449 | if (oldAxis) { |
|
379 | QList<Domain*> domains; | |
450 | if (axes.indexOf(oldAxis) == -1) { |
|
380 | foreach(QAbstractSeries *s, m_seriesList) { | |
451 | emit axisRemoved(oldAxis); |
|
381 | Domain* domain = s->d_ptr->m_domain.data(); | |
452 | oldAxis->disconnect(); |
|
382 | if(domains.contains(domain)) continue; | |
453 | QObject::disconnect(domain, 0, oldAxis, 0); |
|
383 | s->d_ptr->m_domain->blockAxisSignals(true); | |
454 | oldAxis->d_ptr->m_dataset = 0; |
|
384 | domains<<domain; | |
455 | oldAxis->deleteLater(); |
|
|||
456 | } |
|
|||
457 | } |
|
385 | } | |
458 |
|
386 | |||
459 | if (axes.indexOf(axis) == -1) { |
|
387 | foreach(Domain *domain, domains) | |
460 | initializeAxis(axis, series); |
|
388 | domain->move(dx, dy); | |
461 | emit axisAdded(axis, domain); |
|
|||
462 | } else { |
|
|||
463 | initializeAxis(axis, series); |
|
|||
464 | } |
|
|||
465 | } |
|
|||
466 |
|
389 | |||
467 | Domain *ChartDataSet::domain(QAbstractSeries *series) const |
|
390 | foreach(Domain *domain, domains) | |
468 | { |
|
391 | domain->blockAxisSignals(false); | |
469 | return m_seriesDomainMap.value(series); |
|
|||
470 | } |
|
392 | } | |
471 |
|
393 | |||
472 | void ChartDataSet::scrollDomain(qreal dx, qreal dy, const QSizeF &size) |
|
394 | QList<QAbstractAxis*> ChartDataSet::axes() const | |
473 | { |
|
395 | { | |
474 | blockAxisSignals(true); |
|
396 | return m_axisList; | |
475 | QMapIterator<QAbstractSeries *, Domain *> i(m_seriesDomainMap); |
|
|||
476 | while (i.hasNext()) { |
|
|||
477 | i.next(); |
|
|||
478 | i.value()->move(dx, dy, size); |
|
|||
479 | } |
|
|||
480 | blockAxisSignals(false); |
|
|||
481 | } |
|
397 | } | |
482 |
|
398 | |||
483 | QList<QAbstractSeries *> ChartDataSet::series() const |
|
399 | QList<QAbstractSeries *> ChartDataSet::series() const | |
484 | { |
|
400 | { | |
485 |
return m_series |
|
401 | return m_seriesList; | |
486 | } |
|
402 | } | |
487 | /* |
|
403 | ||
488 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
|||
489 | { |
|
|||
490 | emit seriesUpdated(series); |
|
|||
491 | } |
|
|||
492 | */ |
|
|||
493 | #include "moc_chartdataset_p.cpp" |
|
404 | #include "moc_chartdataset_p.cpp" | |
494 |
|
405 | |||
495 | QTCOMMERCIALCHART_END_NAMESPACE |
|
406 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -38,59 +38,48 | |||||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class QAbstractAxis; |
|
40 | class QAbstractAxis; | |
|
41 | class ChartPresenter; | |||
41 |
|
42 | |||
42 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject |
|
43 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject | |
43 | { |
|
44 | { | |
44 | Q_OBJECT |
|
45 | Q_OBJECT | |
45 | public: |
|
46 | public: | |
46 |
ChartDataSet(QChart * |
|
47 | ChartDataSet(QChart *chart); | |
47 | virtual ~ChartDataSet(); |
|
48 | virtual ~ChartDataSet(); | |
48 |
|
49 | |||
49 | void addSeries(QAbstractSeries *series); |
|
50 | void addSeries(QAbstractSeries *series); | |
50 | void removeSeries(QAbstractSeries *series); |
|
51 | void removeSeries(QAbstractSeries *series); | |
|
52 | QList<QAbstractSeries *> series() const; | |||
51 | void removeAllSeries(); |
|
53 | void removeAllSeries(); | |
52 | // void updateSeries(QAbstractSeries* series); |
|
|||
53 |
|
||||
54 | void zoomInDomain(const QRectF &rect, const QSizeF &size); |
|
|||
55 | void zoomOutDomain(const QRectF &rect, const QSizeF &size); |
|
|||
56 | void scrollDomain(qreal dx, qreal dy, const QSizeF &size); |
|
|||
57 |
|
||||
58 | int seriesCount(QAbstractSeries::SeriesType type); |
|
|||
59 | int seriesIndex(QAbstractSeries *series); |
|
|||
60 |
|
||||
61 | QAbstractAxis *axisX(QAbstractSeries *series) const; |
|
|||
62 | QAbstractAxis *axisY(QAbstractSeries *series) const; |
|
|||
63 |
|
54 | |||
64 |
void |
|
55 | void addAxis(QAbstractAxis *axis,Qt::Alignment aligment); | |
|
56 | void removeAxis(QAbstractAxis *axis); | |||
|
57 | QList<QAbstractAxis*> axes() const; | |||
|
58 | void removeAllAxes(); | |||
65 |
|
59 | |||
66 | QList<QAbstractSeries *> series() const; |
|
60 | bool attachAxis(QAbstractSeries* series,QAbstractAxis *axis); | |
67 | Domain *domain(QAbstractSeries *series) const; |
|
61 | bool detachAxis(QAbstractSeries* series,QAbstractAxis *axis); | |
68 |
|
62 | |||
69 | void removeAxis(QAbstractAxis *axis); |
|
|||
70 | void createDefaultAxes(); |
|
63 | void createDefaultAxes(); | |
71 |
|
64 | |||
|
65 | void zoomInDomain(const QRectF &rect); | |||
|
66 | void zoomOutDomain(const QRectF &rect); | |||
|
67 | void scrollDomain(qreal dx, qreal dy); | |||
|
68 | ||||
72 | Q_SIGNALS: |
|
69 | Q_SIGNALS: | |
73 |
void |
|
70 | void axisAdded(QAbstractAxis* axis); | |
74 |
void |
|
71 | void axisRemoved(QAbstractAxis* axis); | |
75 |
|
|
72 | void seriesAdded(QAbstractSeries* series); | |
76 | void axisAdded(QAbstractAxis *axis, Domain *domain); |
|
73 | void seriesRemoved(QAbstractSeries* series); | |
77 | void axisRemoved(QAbstractAxis *axis); |
|
|||
78 |
|
74 | |||
79 | private: |
|
75 | private: | |
80 | void calculateDomain(QAbstractSeries *series, Domain *domain); |
|
|||
81 | void createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation); |
|
76 | void createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation); | |
82 | QAbstractAxis *createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation); |
|
77 | QAbstractAxis *createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation); | |
83 | void initializeAxis(QAbstractAxis *axis, QAbstractSeries *series); |
|
|||
84 | void removeAxes(QAbstractSeries *series); |
|
|||
85 | void blockAxisSignals(bool enabled); |
|
|||
86 | void createSeriesIndex(QAbstractSeries *series); |
|
|||
87 | void removeSeriesIndex(QAbstractSeries *series); |
|
|||
88 |
|
78 | |||
89 | private: |
|
79 | private: | |
90 |
Q |
|
80 | QList<QAbstractSeries *> m_seriesList; | |
91 |
Q |
|
81 | QList<QAbstractAxis *> m_axisList; | |
92 | QMap<QAbstractSeries *, Domain *> m_seriesDomainMap; |
|
82 | QChart* m_chart; | |
93 | QMap<int, QAbstractSeries *> m_indexSeriesMap; |
|
|||
94 | }; |
|
83 | }; | |
95 |
|
84 | |||
96 | QTCOMMERCIALCHART_END_NAMESPACE |
|
85 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -24,11 +24,12 | |||||
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 |
ChartElement::ChartElement( |
|
27 | ChartElement::ChartElement(QGraphicsItem* item): | |
28 |
|
|
28 | QGraphicsObject(item), | |
29 |
m_presenter( |
|
29 | m_presenter(0), | |
30 |
m_ |
|
30 | m_themeManager(0) | |
31 | { |
|
31 | { | |
|
32 | ||||
32 | } |
|
33 | } | |
33 |
|
34 | |||
34 | void ChartElement::setPresenter(ChartPresenter *presenter) |
|
35 | void ChartElement::setPresenter(ChartPresenter *presenter) | |
@@ -41,37 +42,14 ChartPresenter *ChartElement::presenter() const | |||||
41 | return m_presenter; |
|
42 | return m_presenter; | |
42 | } |
|
43 | } | |
43 |
|
44 | |||
44 | void ChartElement::setDomain(Domain *domain) |
|
45 | void ChartElement::setThemeManager(ChartThemeManager *manager) | |
45 | { |
|
|||
46 | m_domain = domain; |
|
|||
47 | } |
|
|||
48 |
|
||||
49 | Domain *ChartElement::domain() const |
|
|||
50 | { |
|
|||
51 | return m_domain; |
|
|||
52 | } |
|
|||
53 |
|
||||
54 | void ChartElement::handleGeometryChanged(const QRectF &rect) |
|
|||
55 | { |
|
|||
56 | Q_UNUSED(rect); |
|
|||
57 | qWarning() << "Slot not implemented"; |
|
|||
58 | } |
|
|||
59 |
|
||||
60 | void ChartElement::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
|||
61 | { |
|
46 | { | |
62 | Q_UNUSED(minX); |
|
47 | m_themeManager = manager; | |
63 | Q_UNUSED(maxX); |
|
|||
64 | Q_UNUSED(minY); |
|
|||
65 | Q_UNUSED(maxY); |
|
|||
66 | qWarning() << "Slot not implemented"; |
|
|||
67 | } |
|
48 | } | |
68 |
|
49 | |||
69 | void ChartElement::handleDomainUpdated() |
|
50 | ChartThemeManager* ChartElement::themeManager() const | |
70 | { |
|
51 | { | |
71 | qWarning() << "Slot not implemented"; |
|
52 | return m_themeManager; | |
72 | } |
|
53 | } | |
73 |
|
54 | |||
74 |
|
||||
75 | #include "moc_chartelement_p.cpp" |
|
|||
76 |
|
||||
77 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -33,34 +33,31 | |||||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include <QObject> |
|
34 | #include <QObject> | |
35 | #include <QRect> |
|
35 | #include <QRect> | |
|
36 | #include <QGraphicsObject> | |||
36 |
|
37 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
39 | |||
39 | class ChartAnimator; |
|
40 | class ChartAnimator; | |
40 | class ChartPresenter; |
|
41 | class ChartPresenter; | |
41 | class ChartAnimation; |
|
42 | class ChartAnimation; | |
|
43 | class ChartThemeManager; | |||
42 | class Domain; |
|
44 | class Domain; | |
43 |
|
45 | |||
44 | class ChartElement: public QObject |
|
46 | class ChartElement: public QGraphicsObject | |
45 | { |
|
47 | { | |
46 | Q_OBJECT |
|
48 | ||
47 | public: |
|
49 | public: | |
48 |
explicit ChartElement( |
|
50 | explicit ChartElement(QGraphicsItem* item = 0); | |
49 |
|
51 | |||
50 | public Q_SLOTS: |
|
|||
51 | virtual void handleGeometryChanged(const QRectF &rect); |
|
|||
52 | virtual void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
|||
53 | virtual void handleDomainUpdated(); |
|
|||
54 | virtual ChartAnimation *animation() const { return 0; } |
|
52 | virtual ChartAnimation *animation() const { return 0; } | |
55 |
|
53 | virtual void setPresenter(ChartPresenter *presenter); | ||
56 | void setPresenter(ChartPresenter *presenter); |
|
|||
57 | ChartPresenter *presenter() const; |
|
54 | ChartPresenter *presenter() const; | |
58 | void setDomain(Domain *domain); |
|
55 | virtual void setThemeManager(ChartThemeManager *manager); | |
59 | Domain *domain() const; |
|
56 | ChartThemeManager* themeManager() const; | |
60 |
|
57 | |||
61 | private: |
|
58 | private: | |
62 | ChartPresenter *m_presenter; |
|
59 | ChartPresenter *m_presenter; | |
63 | Domain *m_domain; |
|
60 | ChartThemeManager *m_themeManager; | |
64 | }; |
|
61 | }; | |
65 |
|
62 | |||
66 | QTCOMMERCIALCHART_END_NAMESPACE |
|
63 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -36,11 +36,17 | |||||
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 |
class ChartItem : public |
|
39 | class ChartItem : public ChartElement | |
40 | { |
|
40 | { | |
|
41 | Q_OBJECT | |||
41 | enum ChartItemTypes { AXIS_ITEM = UserType + 1, XYLINE_ITEM }; |
|
42 | enum ChartItemTypes { AXIS_ITEM = UserType + 1, XYLINE_ITEM }; | |
42 | public: |
|
43 | public: | |
43 | ChartItem(ChartPresenter *presenter) : QGraphicsItem(presenter ? presenter->rootItem() : 0), ChartElement(presenter) {} |
|
44 | ChartItem(QAbstractSeriesPrivate *series,QGraphicsItem* item); | |
|
45 | QSharedPointer<Domain> domain() const; | |||
|
46 | public Q_SLOTS: | |||
|
47 | virtual void handleDomainUpdated(); | |||
|
48 | private: | |||
|
49 | QAbstractSeriesPrivate* m_series; | |||
44 | }; |
|
50 | }; | |
45 |
|
51 | |||
46 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -49,7 +49,6 void ChartLayout::setGeometry(const QRectF &rect) | |||||
49 | return; |
|
49 | return; | |
50 |
|
50 | |||
51 | QList<ChartAxis *> axes = m_presenter->axisItems(); |
|
51 | QList<ChartAxis *> axes = m_presenter->axisItems(); | |
52 | QList<ChartElement *> charts = m_presenter->chartItems(); |
|
|||
53 | ChartTitle *title = m_presenter->titleElement(); |
|
52 | ChartTitle *title = m_presenter->titleElement(); | |
54 | QLegend *legend = m_presenter->legend(); |
|
53 | QLegend *legend = m_presenter->legend(); | |
55 | ChartBackground *background = m_presenter->backgroundElement(); |
|
54 | ChartBackground *background = m_presenter->backgroundElement(); | |
@@ -66,7 +65,7 void ChartLayout::setGeometry(const QRectF &rect) | |||||
66 |
|
65 | |||
67 | contentGeometry = calculateAxisGeometry(contentGeometry, axes); |
|
66 | contentGeometry = calculateAxisGeometry(contentGeometry, axes); | |
68 |
|
67 | |||
69 |
m_ |
|
68 | m_presenter->setGeometry(contentGeometry); | |
70 |
|
69 | |||
71 | QGraphicsLayout::setGeometry(rect); |
|
70 | QGraphicsLayout::setGeometry(rect); | |
72 | } |
|
71 | } | |
@@ -120,6 +119,7 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch | |||||
120 | if (!axis->isVisible()) |
|
119 | if (!axis->isVisible()) | |
121 | continue; |
|
120 | continue; | |
122 |
|
121 | |||
|
122 | ||||
123 | QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize); |
|
123 | QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize); | |
124 | //this is used to get single thick font size |
|
124 | //this is used to get single thick font size | |
125 | QSizeF minSize = axis->effectiveSizeHint(Qt::MinimumSize); |
|
125 | QSizeF minSize = axis->effectiveSizeHint(Qt::MinimumSize); | |
@@ -153,6 +153,9 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch | |||||
153 | minBottom.setHeight(minBottom.height() + minSize.height()); |
|
153 | minBottom.setHeight(minBottom.height() + minSize.height()); | |
154 | bottomCount++; |
|
154 | bottomCount++; | |
155 | break; |
|
155 | break; | |
|
156 | default: | |||
|
157 | qWarning()<<"Axis is without alignment !"; | |||
|
158 | break; | |||
156 | } |
|
159 | } | |
157 | } |
|
160 | } | |
158 |
|
161 | |||
@@ -176,7 +179,10 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch | |||||
176 | qreal topOffset = 0; |
|
179 | qreal topOffset = 0; | |
177 | qreal bottomOffset = 0; |
|
180 | qreal bottomOffset = 0; | |
178 |
|
181 | |||
179 |
foreach(Chart |
|
182 | foreach(ChartElement *axisElement , axes) { | |
|
183 | ||||
|
184 | //TODO fixme | |||
|
185 | ChartAxis* axis = qobject_cast<ChartAxis*>(axisElement); | |||
180 |
|
186 | |||
181 | if (!axis->isVisible()) |
|
187 | if (!axis->isVisible()) | |
182 | continue; |
|
188 | continue; | |
@@ -217,7 +223,7 QRectF ChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<Char | |||||
217 | QSizeF bottom; |
|
223 | QSizeF bottom; | |
218 | QSizeF top; |
|
224 | QSizeF top; | |
219 |
|
225 | |||
220 |
foreach (ChartAxis *axis |
|
226 | foreach (ChartAxis *axis, axes) { | |
221 |
|
227 | |||
222 | QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); |
|
228 | QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); | |
223 |
|
229 | |||
@@ -287,15 +293,6 QRectF ChartLayout::calculateLegendGeometry(const QRectF &geometry, QLegend *leg | |||||
287 | return result; |
|
293 | return result; | |
288 | } |
|
294 | } | |
289 |
|
295 | |||
290 |
|
||||
291 | QRectF ChartLayout::calculateChartsGeometry(const QRectF &geometry, const QList<ChartElement *>& charts) const |
|
|||
292 | { |
|
|||
293 | Q_ASSERT(geometry.isValid()); |
|
|||
294 | foreach (ChartElement *chart, charts) |
|
|||
295 | chart->handleGeometryChanged(geometry); |
|
|||
296 | return geometry; |
|
|||
297 | } |
|
|||
298 |
|
||||
299 | QRectF ChartLayout::calculateLegendMinimum(const QRectF &geometry, QLegend *legend) const |
|
296 | QRectF ChartLayout::calculateLegendMinimum(const QRectF &geometry, QLegend *legend) const | |
300 | { |
|
297 | { | |
301 | QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)); |
|
298 | QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)); |
@@ -31,7 +31,6 class ChartTitle; | |||||
31 | class QLegend; |
|
31 | class QLegend; | |
32 | class ChartAxis; |
|
32 | class ChartAxis; | |
33 | class ChartBackground; |
|
33 | class ChartBackground; | |
34 | class ChartElement; |
|
|||
35 |
|
34 | |||
36 | class ChartLayout : public QGraphicsLayout |
|
35 | class ChartLayout : public QGraphicsLayout | |
37 | { |
|
36 | { | |
@@ -44,7 +43,6 public: | |||||
44 | QMargins margins() const; |
|
43 | QMargins margins() const; | |
45 |
|
44 | |||
46 | void setGeometry(const QRectF &rect); |
|
45 | void setGeometry(const QRectF &rect); | |
47 | QRectF chartsGeometry() const { return m_chartsRect;} |
|
|||
48 |
|
46 | |||
49 | protected: |
|
47 | protected: | |
50 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; |
|
48 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; | |
@@ -56,10 +54,8 private: | |||||
56 | QRectF calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const; |
|
54 | QRectF calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const; | |
57 | QRectF calculateContentGeometry(const QRectF &geometry) const; |
|
55 | QRectF calculateContentGeometry(const QRectF &geometry) const; | |
58 | QRectF calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const; |
|
56 | QRectF calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const; | |
59 | QRectF calculateChartGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const; |
|
|||
60 | QRectF calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const; |
|
57 | QRectF calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const; | |
61 | QRectF calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const; |
|
58 | QRectF calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const; | |
62 | QRectF calculateChartsGeometry(const QRectF &geometry, const QList<ChartElement *>& charts) const; |
|
|||
63 | QRectF calculateBackgroundMinimum(const QRectF &minimum) const; |
|
59 | QRectF calculateBackgroundMinimum(const QRectF &minimum) const; | |
64 | QRectF calculateContentMinimum(const QRectF &minimum) const; |
|
60 | QRectF calculateContentMinimum(const QRectF &minimum) const; | |
65 | QRectF calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const; |
|
61 | QRectF calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const; | |
@@ -71,7 +67,6 private: | |||||
71 | QMargins m_margins; |
|
67 | QMargins m_margins; | |
72 | QRectF m_minChartRect; |
|
68 | QRectF m_minChartRect; | |
73 | QRectF m_minAxisRect; |
|
69 | QRectF m_minAxisRect; | |
74 | QRectF m_chartsRect; |
|
|||
75 | }; |
|
70 | }; | |
76 |
|
71 | |||
77 | QTCOMMERCIALCHART_END_NAMESPACE |
|
72 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -19,11 +19,11 | |||||
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 "qchart_p.h" |
|
23 | #include "qchart_p.h" | |
23 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
24 | #include "qabstractaxis_p.h" |
|
25 | #include "qabstractaxis_p.h" | |
25 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
26 | #include "charttheme_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" | |
@@ -35,11 +35,9 | |||||
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
ChartPresenter::ChartPresenter(QChart *chart |
|
38 | ChartPresenter::ChartPresenter(QChart *chart) | |
39 | : QObject(chart), |
|
39 | : QObject(chart), | |
40 | m_chart(chart), |
|
40 | m_chart(chart), | |
41 | m_dataset(dataset), |
|
|||
42 | m_chartTheme(0), |
|
|||
43 | m_options(QChart::NoAnimation), |
|
41 | m_options(QChart::NoAnimation), | |
44 | m_state(ShowState), |
|
42 | m_state(ShowState), | |
45 | m_layout(new ChartLayout(this)), |
|
43 | m_layout(new ChartLayout(this)), | |
@@ -51,164 +49,97 ChartPresenter::ChartPresenter(QChart *chart, ChartDataSet *dataset) | |||||
51 |
|
49 | |||
52 | ChartPresenter::~ChartPresenter() |
|
50 | ChartPresenter::~ChartPresenter() | |
53 | { |
|
51 | { | |
54 | delete m_chartTheme; |
|
52 | ||
55 | } |
|
53 | } | |
56 |
|
54 | |||
57 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis, Domain *domain) |
|
55 | void ChartPresenter::setGeometry(const QRectF rect) | |
58 | { |
|
56 | { | |
59 | ChartAxis *item = axis->d_ptr->createGraphics(this); |
|
57 | if(m_rect != rect) { | |
60 | item->setDomain(domain); |
|
58 | m_rect=rect; | |
61 |
|
59 | foreach (ChartItem *chart, m_chartItems){ | ||
62 | if (m_options.testFlag(QChart::GridAxisAnimations)) |
|
60 | chart->domain()->setSize(rect.size()); | |
63 | item->setAnimation(new AxisAnimation(item)); |
|
61 | chart->setPos(rect.topLeft()); | |
64 |
|
62 | } | ||
65 | QObject::connect(domain, SIGNAL(updated()), item, SLOT(handleDomainUpdated())); |
|
63 | } | |
|
64 | } | |||
66 |
|
65 | |||
67 | //initialize |
|
66 | QRectF ChartPresenter::geometry() const | |
68 | domain->emitUpdated(); |
|
67 | { | |
69 | m_chartTheme->decorate(axis); |
|
68 | return m_rect; | |
70 | axis->d_ptr->setDirty(false); |
|
69 | } | |
71 | axis->d_ptr->emitUpdated(); |
|
|||
72 |
|
70 | |||
73 | m_axisItems.insert(axis, item); |
|
71 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) | |
|
72 | { | |||
|
73 | qDebug()<<__FUNCTION__; | |||
|
74 | axis->d_ptr->initializeGraphics(rootItem()); | |||
|
75 | axis->d_ptr->initializeAnimations(m_options); | |||
|
76 | ChartAxis *item = axis->d_ptr->axisItem(); | |||
|
77 | item->setPresenter(this); | |||
|
78 | item->setThemeManager(m_chart->d_ptr->m_themeManager); | |||
|
79 | m_axisItems<<item; | |||
|
80 | m_axes<<axis; | |||
74 | m_layout->invalidate(); |
|
81 | m_layout->invalidate(); | |
75 | } |
|
82 | } | |
76 |
|
83 | |||
77 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) |
|
84 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) | |
78 | { |
|
85 | { | |
79 | ChartAxis *item = m_axisItems.take(axis); |
|
86 | qDebug()<<__FUNCTION__; | |
80 | Q_ASSERT(item); |
|
87 | ChartAxis *item = axis->d_ptr->m_item.take(); | |
81 | item->hide(); |
|
88 | item->hide(); | |
82 | item->disconnect(); |
|
89 | item->disconnect(); | |
83 | QObject::disconnect(this, 0, item, 0); |
|
|||
84 | item->deleteLater(); |
|
90 | item->deleteLater(); | |
|
91 | m_axisItems.removeAll(item); | |||
|
92 | m_axes.removeAll(axis); | |||
85 | m_layout->invalidate(); |
|
93 | m_layout->invalidate(); | |
86 | } |
|
94 | } | |
87 |
|
95 | |||
88 |
|
96 | |||
89 |
void ChartPresenter::handleSeriesAdded(QAbstractSeries *series |
|
97 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) | |
90 | { |
|
98 | { | |
91 | ChartElement *item = series->d_ptr->createGraphics(this); |
|
99 | qDebug()<<__FUNCTION__; | |
92 | Q_ASSERT(item); |
|
100 | series->d_ptr->initializeGraphics(rootItem()); | |
93 | item->setDomain(domain); |
|
101 | series->d_ptr->initializeAnimations(m_options); | |
94 |
|
102 | ChartItem *chart = series->d_ptr->chartItem(); | ||
95 | QObject::connect(domain, SIGNAL(updated()), item, SLOT(handleDomainUpdated())); |
|
103 | chart->setPresenter(this); | |
96 | //initialize |
|
104 | chart->setThemeManager(m_chart->d_ptr->m_themeManager); | |
97 | item->handleDomainUpdated(); |
|
105 | chart->domain()->setSize(m_rect.size()); | |
98 |
|
106 | chart->setPos(m_rect.topLeft()); | ||
99 | m_chartItems.insert(series, item); |
|
107 | chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored | |
|
108 | m_chartItems<<chart; | |||
|
109 | m_series<<series; | |||
100 | m_layout->invalidate(); |
|
110 | m_layout->invalidate(); | |
101 | } |
|
111 | } | |
102 |
|
112 | |||
103 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) |
|
113 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) | |
104 | { |
|
114 | { | |
105 | ChartElement *item = m_chartItems.take(series); |
|
115 | qDebug()<<__FUNCTION__; | |
106 | Q_ASSERT(item); |
|
116 | ChartItem *chart = series->d_ptr->m_item.take(); | |
107 | item->deleteLater(); |
|
117 | chart->hide(); | |
108 | } |
|
118 | chart->disconnect(); | |
109 |
|
119 | chart->deleteLater(); | ||
110 | void ChartPresenter::setTheme(QChart::ChartTheme theme, bool force) |
|
120 | m_chartItems.removeAll(chart); | |
111 | { |
|
121 | m_series.removeAll(series); | |
112 | if (m_chartTheme && m_chartTheme->id() == theme) |
|
122 | m_layout->invalidate(); | |
113 | return; |
|
|||
114 | delete m_chartTheme; |
|
|||
115 | m_chartTheme = ChartTheme::createTheme(theme); |
|
|||
116 | m_chartTheme->setForced(force); |
|
|||
117 | m_chartTheme->decorate(m_chart); |
|
|||
118 | m_chartTheme->decorate(m_chart->legend()); |
|
|||
119 | resetAllElements(); |
|
|||
120 |
|
||||
121 | // We do not want "force" to stay on. |
|
|||
122 | // Bar/pie are calling decorate when adding/removing slices/bars which means |
|
|||
123 | // that to preserve users colors "force" must not be on. |
|
|||
124 | m_chartTheme->setForced(false); |
|
|||
125 | } |
|
|||
126 |
|
||||
127 | QChart::ChartTheme ChartPresenter::theme() |
|
|||
128 | { |
|
|||
129 | return m_chartTheme->id(); |
|
|||
130 | } |
|
123 | } | |
131 |
|
124 | |||
132 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
125 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
133 | { |
|
126 | { | |
134 | if (m_options != options) { |
|
127 | if (m_options != options) { | |
135 | m_options = options; |
|
128 | m_options = options; | |
136 | resetAllElements(); |
|
|||
137 | } |
|
|||
138 |
|
129 | |||
139 | } |
|
130 | foreach(QAbstractSeries* series, m_series){ | |
140 |
|
131 | series->d_ptr->initializeAnimations(m_options); | ||
141 | void ChartPresenter::resetAllElements() |
|
132 | } | |
142 | { |
|
133 | foreach(QAbstractAxis* axis, m_axes){ | |
143 | QMapIterator<QAbstractAxis *, ChartAxis *> i(m_axisItems); |
|
134 | axis->d_ptr->initializeAnimations(m_options); | |
144 | while (i.hasNext()) { |
|
135 | } | |
145 | i.next(); |
|
|||
146 | Domain *domain = i.value()->domain(); |
|
|||
147 | QAbstractAxis *axis = i.key(); |
|
|||
148 | handleAxisRemoved(axis); |
|
|||
149 | handleAxisAdded(axis, domain); |
|
|||
150 | } |
|
|||
151 |
|
||||
152 | QMapIterator<QAbstractSeries *, ChartElement *> j(m_chartItems); |
|
|||
153 | while (j.hasNext()) { |
|
|||
154 | j.next(); |
|
|||
155 | Domain *domain = j.value()->domain(); |
|
|||
156 | QAbstractSeries *series = j.key(); |
|
|||
157 | handleSeriesRemoved(series); |
|
|||
158 | handleSeriesAdded(series, domain); |
|
|||
159 | } |
|
136 | } | |
160 |
|
||||
161 | layout()->invalidate(); |
|
|||
162 | } |
|
137 | } | |
163 |
|
138 | |||
164 | void ChartPresenter::zoomIn(qreal factor) |
|
139 | void ChartPresenter::setState(State state,QPointF point) | |
165 | { |
|
140 | { | |
166 | QRectF rect = m_layout->chartsGeometry(); |
|
141 | m_state=state; | |
167 | rect.setWidth(rect.width() / factor); |
|
142 | m_statePoint=point; | |
168 | rect.setHeight(rect.height() / factor); |
|
|||
169 | rect.moveCenter(m_layout->chartsGeometry().center()); |
|
|||
170 | zoomIn(rect); |
|
|||
171 | } |
|
|||
172 |
|
||||
173 | void ChartPresenter::zoomIn(const QRectF &rect) |
|
|||
174 | { |
|
|||
175 | QRectF r = rect.normalized(); |
|
|||
176 | r.translate(-m_layout->chartsGeometry().topLeft()); |
|
|||
177 | if (!r.isValid()) |
|
|||
178 | return; |
|
|||
179 |
|
||||
180 | m_state = ZoomInState; |
|
|||
181 | m_statePoint = QPointF(r.center().x() / m_layout->chartsGeometry().width(), r.center().y() / m_layout->chartsGeometry().height()); |
|
|||
182 | m_dataset->zoomInDomain(r, m_layout->chartsGeometry().size()); |
|
|||
183 | m_state = ShowState; |
|
|||
184 | } |
|
|||
185 |
|
||||
186 | void ChartPresenter::zoomOut(qreal factor) |
|
|||
187 | { |
|
|||
188 | m_state = ZoomOutState; |
|
|||
189 |
|
||||
190 | QRectF chartRect; |
|
|||
191 | chartRect.setSize(m_layout->chartsGeometry().size()); |
|
|||
192 |
|
||||
193 | QRectF rect; |
|
|||
194 | rect.setSize(chartRect.size() / factor); |
|
|||
195 | rect.moveCenter(chartRect.center()); |
|
|||
196 | if (!rect.isValid()) |
|
|||
197 | return; |
|
|||
198 | m_statePoint = QPointF(rect.center().x() / m_layout->chartsGeometry().width(), rect.center().y() / m_layout->chartsGeometry().height()); |
|
|||
199 | m_dataset->zoomOutDomain(rect, chartRect.size()); |
|
|||
200 | m_state = ShowState; |
|
|||
201 | } |
|
|||
202 |
|
||||
203 | void ChartPresenter::scroll(qreal dx, qreal dy) |
|
|||
204 | { |
|
|||
205 | if (dx < 0) m_state = ScrollLeftState; |
|
|||
206 | if (dx > 0) m_state = ScrollRightState; |
|
|||
207 | if (dy < 0) m_state = ScrollUpState; |
|
|||
208 | if (dy > 0) m_state = ScrollDownState; |
|
|||
209 |
|
||||
210 | m_dataset->scrollDomain(dx, dy, m_layout->chartsGeometry().size()); |
|
|||
211 | m_state = ShowState; |
|
|||
212 | } |
|
143 | } | |
213 |
|
144 | |||
214 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
145 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
@@ -370,12 +301,12 ChartBackground *ChartPresenter::backgroundElement() | |||||
370 |
|
301 | |||
371 | QList<ChartAxis *> ChartPresenter::axisItems() const |
|
302 | QList<ChartAxis *> ChartPresenter::axisItems() const | |
372 | { |
|
303 | { | |
373 |
return m_axisItems |
|
304 | return m_axisItems; | |
374 | } |
|
305 | } | |
375 |
|
306 | |||
376 |
QList<Chart |
|
307 | QList<ChartItem *> ChartPresenter::chartItems() const | |
377 | { |
|
308 | { | |
378 |
return m_chartItems |
|
309 | return m_chartItems; | |
379 | } |
|
310 | } | |
380 |
|
311 | |||
381 | ChartTitle *ChartPresenter::titleElement() |
|
312 | ChartTitle *ChartPresenter::titleElement() |
@@ -37,12 +37,12 | |||||
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 |
class Chart |
|
40 | class ChartItem; | |
|
41 | class AxisItem; | |||
41 | class QAbstractSeries; |
|
42 | class QAbstractSeries; | |
42 | class ChartDataSet; |
|
43 | class ChartDataSet; | |
43 | class Domain; |
|
44 | class Domain; | |
44 | class ChartAxis; |
|
45 | class ChartAxis; | |
45 | class ChartTheme; |
|
|||
46 | class ChartAnimator; |
|
46 | class ChartAnimator; | |
47 | class ChartBackground; |
|
47 | class ChartBackground; | |
48 | class ChartTitle; |
|
48 | class ChartTitle; | |
@@ -78,16 +78,21 public: | |||||
78 | ZoomOutState |
|
78 | ZoomOutState | |
79 | }; |
|
79 | }; | |
80 |
|
80 | |||
81 |
ChartPresenter(QChart *chart |
|
81 | ChartPresenter(QChart *chart); | |
82 | virtual ~ChartPresenter(); |
|
82 | virtual ~ChartPresenter(); | |
83 |
|
83 | |||
84 | ChartTheme *chartTheme() const { return m_chartTheme; } |
|
84 | ||
85 | ChartDataSet *dataSet() const { return m_dataset; } |
|
85 | void setGeometry(QRectF rect); | |
86 | QGraphicsItem *rootItem() const { return m_chart; } |
|
86 | QRectF geometry() const; | |
|
87 | ||||
|
88 | QGraphicsItem *rootItem(){ return m_chart; } | |||
87 | ChartBackground *backgroundElement(); |
|
89 | ChartBackground *backgroundElement(); | |
88 | ChartTitle *titleElement(); |
|
90 | ChartTitle *titleElement(); | |
89 | QList<ChartAxis *> axisItems() const; |
|
91 | QList<ChartAxis *> axisItems() const; | |
90 |
QList<Chart |
|
92 | QList<ChartItem *> chartItems() const; | |
|
93 | ||||
|
94 | ChartItem* chartElement(QAbstractSeries* series) const; | |||
|
95 | ChartAxis* chartElement(QAbstractAxis* axis) const; | |||
91 |
|
96 | |||
92 | QLegend *legend(); |
|
97 | QLegend *legend(); | |
93 |
|
98 | |||
@@ -114,23 +119,15 public: | |||||
114 |
|
119 | |||
115 | void setVisible(bool visible); |
|
120 | void setVisible(bool visible); | |
116 |
|
121 | |||
117 | void setTheme(QChart::ChartTheme theme, bool force = true); |
|
|||
118 | QChart::ChartTheme theme(); |
|
|||
119 |
|
||||
120 | void setAnimationOptions(QChart::AnimationOptions options); |
|
122 | void setAnimationOptions(QChart::AnimationOptions options); | |
121 | QChart::AnimationOptions animationOptions() const; |
|
123 | QChart::AnimationOptions animationOptions() const; | |
122 |
|
124 | |||
123 | void zoomIn(qreal factor); |
|
|||
124 | void zoomIn(const QRectF &rect); |
|
|||
125 | void zoomOut(qreal factor); |
|
|||
126 | void scroll(qreal dx, qreal dy); |
|
|||
127 |
|
||||
128 | void startAnimation(ChartAnimation *animation); |
|
125 | void startAnimation(ChartAnimation *animation); | |
|
126 | ||||
|
127 | //TODO refactor | |||
|
128 | void setState(State state,QPointF point); | |||
129 | State state() const { return m_state; } |
|
129 | State state() const { return m_state; } | |
130 | QPointF statePoint() const { return m_statePoint; } |
|
130 | QPointF statePoint() const { return m_statePoint; } | |
131 |
|
||||
132 | void resetAllElements(); |
|
|||
133 |
|
||||
134 | ChartLayout *layout(); |
|
131 | ChartLayout *layout(); | |
135 |
|
132 | |||
136 | private: |
|
133 | private: | |
@@ -138,9 +135,9 private: | |||||
138 | void createTitleItem(); |
|
135 | void createTitleItem(); | |
139 |
|
136 | |||
140 | public Q_SLOTS: |
|
137 | public Q_SLOTS: | |
141 |
void handleSeriesAdded(QAbstractSeries *series |
|
138 | void handleSeriesAdded(QAbstractSeries *series); | |
142 | void handleSeriesRemoved(QAbstractSeries *series); |
|
139 | void handleSeriesRemoved(QAbstractSeries *series); | |
143 |
void handleAxisAdded(QAbstractAxis *axis |
|
140 | void handleAxisAdded(QAbstractAxis *axis); | |
144 | void handleAxisRemoved(QAbstractAxis *axis); |
|
141 | void handleAxisRemoved(QAbstractAxis *axis); | |
145 |
|
142 | |||
146 | private Q_SLOTS: |
|
143 | private Q_SLOTS: | |
@@ -151,10 +148,10 Q_SIGNALS: | |||||
151 |
|
148 | |||
152 | private: |
|
149 | private: | |
153 | QChart *m_chart; |
|
150 | QChart *m_chart; | |
154 | ChartDataSet *m_dataset; |
|
151 | QList<ChartItem *> m_chartItems; | |
155 | ChartTheme *m_chartTheme; |
|
152 | QList<ChartAxis *> m_axisItems; | |
156 |
Q |
|
153 | QList<QAbstractSeries *> m_series; | |
157 |
Q |
|
154 | QList<QAbstractAxis *> m_axes; | |
158 | QChart::AnimationOptions m_options; |
|
155 | QChart::AnimationOptions m_options; | |
159 | State m_state; |
|
156 | State m_state; | |
160 | QPointF m_statePoint; |
|
157 | QPointF m_statePoint; | |
@@ -162,6 +159,7 private: | |||||
162 | ChartLayout *m_layout; |
|
159 | ChartLayout *m_layout; | |
163 | ChartBackground *m_background; |
|
160 | ChartBackground *m_background; | |
164 | ChartTitle *m_title; |
|
161 | ChartTitle *m_title; | |
|
162 | QRectF m_rect; | |||
165 | }; |
|
163 | }; | |
166 |
|
164 | |||
167 | QTCOMMERCIALCHART_END_NAMESPACE |
|
165 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -20,6 +20,7 | |||||
20 |
|
20 | |||
21 | #include "domain_p.h" |
|
21 | #include "domain_p.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
|
23 | #include <qmath.h> | |||
23 |
|
24 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
26 | |||
@@ -28,7 +29,8 Domain::Domain(QObject *parent) | |||||
28 | m_minX(0), |
|
29 | m_minX(0), | |
29 | m_maxX(0), |
|
30 | m_maxX(0), | |
30 | m_minY(0), |
|
31 | m_minY(0), | |
31 | m_maxY(0) |
|
32 | m_maxY(0), | |
|
33 | m_axisSignalsBlocked(false) | |||
32 | { |
|
34 | { | |
33 | } |
|
35 | } | |
34 |
|
36 | |||
@@ -36,6 +38,20 Domain::~Domain() | |||||
36 | { |
|
38 | { | |
37 | } |
|
39 | } | |
38 |
|
40 | |||
|
41 | void Domain::setSize(const QSizeF& size) | |||
|
42 | { | |||
|
43 | if(m_size!=size) | |||
|
44 | { | |||
|
45 | m_size=size; | |||
|
46 | emit updated(); | |||
|
47 | } | |||
|
48 | } | |||
|
49 | ||||
|
50 | QSizeF Domain::size() const | |||
|
51 | { | |||
|
52 | return m_size; | |||
|
53 | } | |||
|
54 | ||||
39 | void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
55 | void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
40 | { |
|
56 | { | |
41 | bool axisXChanged = false; |
|
57 | bool axisXChanged = false; | |
@@ -45,14 +61,14 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||||
45 | m_minX = minX; |
|
61 | m_minX = minX; | |
46 | m_maxX = maxX; |
|
62 | m_maxX = maxX; | |
47 | axisXChanged = true; |
|
63 | axisXChanged = true; | |
48 |
emit range |
|
64 | emit rangeHorizontalChanged(m_minX, m_maxX); | |
49 | } |
|
65 | } | |
50 |
|
66 | |||
51 | if (!qFuzzyCompare(m_minY, minY) || !qFuzzyCompare(m_maxY, maxY)) { |
|
67 | if (!qFuzzyCompare(m_minY, minY) || !qFuzzyCompare(m_maxY, maxY)) { | |
52 | m_minY = minY; |
|
68 | m_minY = minY; | |
53 | m_maxY = maxY; |
|
69 | m_maxY = maxY; | |
54 | axisYChanged = true; |
|
70 | axisYChanged = true; | |
55 |
emit range |
|
71 | emit rangeVerticalChanged(m_minY, m_maxY); | |
56 | } |
|
72 | } | |
57 |
|
73 | |||
58 | if (axisXChanged || axisYChanged) |
|
74 | if (axisXChanged || axisYChanged) | |
@@ -103,13 +119,13 qreal Domain::spanY() const | |||||
103 |
|
119 | |||
104 | bool Domain::isEmpty() const |
|
120 | bool Domain::isEmpty() const | |
105 | { |
|
121 | { | |
106 |
return qFuzzyCompare(spanX(), |
|
122 | return qFuzzyCompare(spanX(),0) || qFuzzyCompare(spanY(),0) || m_size.isEmpty() ; | |
107 | } |
|
123 | } | |
108 |
|
124 | |||
109 |
void Domain::zoomIn(const QRectF &rect |
|
125 | void Domain::zoomIn(const QRectF &rect) | |
110 | { |
|
126 | { | |
111 | qreal dx = spanX() / size.width(); |
|
127 | qreal dx = spanX() / m_size.width(); | |
112 | qreal dy = spanY() / size.height(); |
|
128 | qreal dy = spanY() / m_size.height(); | |
113 |
|
129 | |||
114 | qreal maxX = m_maxX; |
|
130 | qreal maxX = m_maxX; | |
115 | qreal minX = m_minX; |
|
131 | qreal minX = m_minX; | |
@@ -124,7 +140,7 void Domain::zoomIn(const QRectF &rect, const QSizeF &size) | |||||
124 | setRange(minX, maxX, minY, maxY); |
|
140 | setRange(minX, maxX, minY, maxY); | |
125 | } |
|
141 | } | |
126 |
|
142 | |||
127 |
void Domain::zoomOut(const QRectF &rect |
|
143 | void Domain::zoomOut(const QRectF &rect) | |
128 | { |
|
144 | { | |
129 | qreal dx = spanX() / rect.width(); |
|
145 | qreal dx = spanX() / rect.width(); | |
130 | qreal dy = spanY() / rect.height(); |
|
146 | qreal dy = spanY() / rect.height(); | |
@@ -135,17 +151,17 void Domain::zoomOut(const QRectF &rect, const QSizeF &size) | |||||
135 | qreal maxY = m_maxY; |
|
151 | qreal maxY = m_maxY; | |
136 |
|
152 | |||
137 | minX = maxX - dx * rect.right(); |
|
153 | minX = maxX - dx * rect.right(); | |
138 | maxX = minX + dx * size.width(); |
|
154 | maxX = minX + dx * m_size.width(); | |
139 | maxY = minY + dy * rect.bottom(); |
|
155 | maxY = minY + dy * rect.bottom(); | |
140 | minY = maxY - dy * size.height(); |
|
156 | minY = maxY - dy * m_size.height(); | |
141 |
|
157 | |||
142 | setRange(minX, maxX, minY, maxY); |
|
158 | setRange(minX, maxX, minY, maxY); | |
143 | } |
|
159 | } | |
144 |
|
160 | |||
145 |
void Domain::move(qreal dx, qreal dy |
|
161 | void Domain::move(qreal dx, qreal dy) | |
146 | { |
|
162 | { | |
147 | qreal x = spanX() / size.width(); |
|
163 | qreal x = spanX() / m_size.width(); | |
148 | qreal y = spanY() / size.height(); |
|
164 | qreal y = spanY() / m_size.height(); | |
149 |
|
165 | |||
150 | qreal maxX = m_maxX; |
|
166 | qreal maxX = m_maxX; | |
151 | qreal minX = m_minX; |
|
167 | qreal minX = m_minX; | |
@@ -163,22 +179,97 void Domain::move(qreal dx, qreal dy, const QSizeF &size) | |||||
163 | setRange(minX, maxX, minY, maxY); |
|
179 | setRange(minX, maxX, minY, maxY); | |
164 | } |
|
180 | } | |
165 |
|
181 | |||
166 | void Domain::emitUpdated() |
|
182 | QPointF Domain::calculateGeometryPoint(const QPointF &point) const | |
167 | { |
|
183 | { | |
168 | emit updated(); |
|
184 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); | |
|
185 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); | |||
|
186 | qreal x = (point.x() - m_minX) * deltaX; | |||
|
187 | qreal y = (point.y() - m_minY) * -deltaY + m_size.height(); | |||
|
188 | return QPointF(x, y); | |||
169 | } |
|
189 | } | |
170 |
|
190 | |||
171 | void Domain::handleAxisUpdated() |
|
191 | QVector<QPointF> Domain::calculateGeometryPoints(const QList<QPointF>& vector) const | |
172 | { |
|
192 | { | |
173 | QAbstractAxisPrivate *axis = qobject_cast<QAbstractAxisPrivate *>(sender()); |
|
193 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); | |
174 | Q_ASSERT(axis); |
|
194 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); | |
175 | axis->setDirty(false); |
|
195 | ||
176 | if (axis->orientation() == Qt::Horizontal) |
|
196 | QVector<QPointF> result; | |
177 | setRangeX(axis->min(), axis->max()); |
|
197 | result.resize(vector.count()); | |
178 | else if (axis->orientation() == Qt::Vertical) |
|
198 | ||
179 | setRangeY(axis->min(), axis->max()); |
|
199 | for (int i = 0; i < vector.count(); ++i) { | |
|
200 | qreal x = (vector[i].x() - m_minX) * deltaX; | |||
|
201 | qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height(); | |||
|
202 | result[i].setX(x); | |||
|
203 | result[i].setY(y); | |||
|
204 | } | |||
|
205 | return result; | |||
180 | } |
|
206 | } | |
181 |
|
207 | |||
|
208 | QPointF Domain::calculateDomainPoint(const QPointF &point) const | |||
|
209 | { | |||
|
210 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); | |||
|
211 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); | |||
|
212 | qreal x = point.x() / deltaX + m_minX; | |||
|
213 | qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY; | |||
|
214 | return QPointF(x, y); | |||
|
215 | } | |||
|
216 | ||||
|
217 | // handlers | |||
|
218 | ||||
|
219 | void Domain::handleVerticalAxisRangeChanged(qreal min, qreal max) | |||
|
220 | { | |||
|
221 | if(!m_axisSignalsBlocked) | |||
|
222 | setRangeY(min, max); | |||
|
223 | } | |||
|
224 | ||||
|
225 | void Domain::handleHorizontalAxisRangeChanged(qreal min, qreal max) | |||
|
226 | { | |||
|
227 | if(!m_axisSignalsBlocked) | |||
|
228 | setRangeX(min, max); | |||
|
229 | } | |||
|
230 | ||||
|
231 | void Domain::blockAxisSignals(bool block) | |||
|
232 | { | |||
|
233 | m_axisSignalsBlocked=block; | |||
|
234 | } | |||
|
235 | ||||
|
236 | //algorithm defined by Paul S.Heckbert GraphicalGems I | |||
|
237 | ||||
|
238 | void Domain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) | |||
|
239 | { | |||
|
240 | qreal range = niceNumber(max - min, true); //range with ceiling | |||
|
241 | qreal step = niceNumber(range / (ticksCount - 1), false); | |||
|
242 | min = qFloor(min / step); | |||
|
243 | max = qCeil(max / step); | |||
|
244 | ticksCount = int(max - min) + 1; | |||
|
245 | min *= step; | |||
|
246 | max *= step; | |||
|
247 | } | |||
|
248 | ||||
|
249 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n | |||
|
250 | ||||
|
251 | qreal Domain::niceNumber(qreal x, bool ceiling) | |||
|
252 | { | |||
|
253 | qreal z = qPow(10, qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x | |||
|
254 | qreal q = x / z; //q<10 && q>=1; | |||
|
255 | ||||
|
256 | if (ceiling) { | |||
|
257 | if (q <= 1.0) q = 1; | |||
|
258 | else if (q <= 2.0) q = 2; | |||
|
259 | else if (q <= 5.0) q = 5; | |||
|
260 | else q = 10; | |||
|
261 | } else { | |||
|
262 | if (q < 1.5) q = 1; | |||
|
263 | else if (q < 3.0) q = 2; | |||
|
264 | else if (q < 7.0) q = 5; | |||
|
265 | else q = 10; | |||
|
266 | } | |||
|
267 | return q * z; | |||
|
268 | } | |||
|
269 | ||||
|
270 | ||||
|
271 | // operators | |||
|
272 | ||||
182 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2) |
|
273 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2) | |
183 | { |
|
274 | { | |
184 | return (qFuzzyCompare(domain1.m_maxX, domain2.m_maxX) && |
|
275 | return (qFuzzyCompare(domain1.m_maxX, domain2.m_maxX) && | |
@@ -196,7 +287,7 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const | |||||
196 |
|
287 | |||
197 | QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain) |
|
288 | QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain) | |
198 | { |
|
289 | { | |
199 | dbg.nospace() << "Domain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')'; |
|
290 | dbg.nospace() << "Domain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; | |
200 | return dbg.maybeSpace(); |
|
291 | return dbg.maybeSpace(); | |
201 | } |
|
292 | } | |
202 |
|
293 |
@@ -43,6 +43,9 public: | |||||
43 | explicit Domain(QObject *object = 0); |
|
43 | explicit Domain(QObject *object = 0); | |
44 | virtual ~Domain(); |
|
44 | virtual ~Domain(); | |
45 |
|
45 | |||
|
46 | void setSize(const QSizeF& size); | |||
|
47 | QSizeF size() const; | |||
|
48 | ||||
46 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
49 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
47 | void setRangeX(qreal min, qreal max); |
|
50 | void setRangeX(qreal min, qreal max); | |
48 | void setRangeY(qreal min, qreal max); |
|
51 | void setRangeY(qreal min, qreal max); | |
@@ -60,28 +63,40 public: | |||||
60 | qreal spanY() const; |
|
63 | qreal spanY() const; | |
61 | bool isEmpty() const; |
|
64 | bool isEmpty() const; | |
62 |
|
65 | |||
|
66 | void blockAxisSignals(bool block); | |||
|
67 | bool axisSignalsBlocked() const { return m_axisSignalsBlocked; } | |||
|
68 | ||||
63 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2); |
|
69 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2); | |
64 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2); |
|
70 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2); | |
65 | friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain); |
|
71 | friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain); | |
66 |
|
72 | |||
67 |
void zoomIn(const QRectF &rect |
|
73 | void zoomIn(const QRectF &rect); | |
68 |
void zoomOut(const QRectF &rect |
|
74 | void zoomOut(const QRectF &rect); | |
69 |
void move(qreal dx, qreal dy |
|
75 | void move(qreal dx, qreal dy); | |
70 | void emitUpdated(); |
|
76 | ||
|
77 | QPointF calculateGeometryPoint(const QPointF &point) const; | |||
|
78 | QPointF calculateDomainPoint(const QPointF &point) const; | |||
|
79 | QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const; | |||
|
80 | ||||
|
81 | static void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount); | |||
|
82 | static qreal niceNumber(qreal x, bool ceiling); | |||
71 |
|
83 | |||
72 | Q_SIGNALS: |
|
84 | Q_SIGNALS: | |
73 | void updated(); |
|
85 | void updated(); | |
74 |
void range |
|
86 | void rangeHorizontalChanged(qreal min, qreal max); | |
75 |
void range |
|
87 | void rangeVerticalChanged(qreal min, qreal max); | |
76 |
|
88 | |||
77 | public Q_SLOTS: |
|
89 | public Q_SLOTS: | |
78 | void handleAxisUpdated(); |
|
90 | void handleVerticalAxisRangeChanged(qreal min,qreal max); | |
|
91 | void handleHorizontalAxisRangeChanged(qreal min,qreal max); | |||
79 |
|
92 | |||
80 | private: |
|
93 | private: | |
81 | qreal m_minX; |
|
94 | qreal m_minX; | |
82 | qreal m_maxX; |
|
95 | qreal m_maxX; | |
83 | qreal m_minY; |
|
96 | qreal m_minY; | |
84 | qreal m_maxY; |
|
97 | qreal m_maxY; | |
|
98 | QSizeF m_size; | |||
|
99 | bool m_axisSignalsBlocked; | |||
85 | }; |
|
100 | }; | |
86 |
|
101 | |||
87 | QTCOMMERCIALCHART_END_NAMESPACE |
|
102 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -29,6 +29,7 | |||||
29 | #include "qlegendmarker.h" |
|
29 | #include "qlegendmarker.h" | |
30 | #include "qlegendmarker_p.h" |
|
30 | #include "qlegendmarker_p.h" | |
31 | #include "legendmarkeritem_p.h" |
|
31 | #include "legendmarkeritem_p.h" | |
|
32 | #include "chartdataset_p.h" | |||
32 | #include <QPainter> |
|
33 | #include <QPainter> | |
33 | #include <QPen> |
|
34 | #include <QPen> | |
34 | #include <QGraphicsItemGroup> |
|
35 | #include <QGraphicsItemGroup> | |
@@ -161,7 +162,7 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), | |||||
161 | { |
|
162 | { | |
162 | setZValue(ChartPresenter::LegendZValue); |
|
163 | setZValue(ChartPresenter::LegendZValue); | |
163 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
164 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
164 |
QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries |
|
165 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); | |
165 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
166 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
166 | setLayout(d_ptr->m_layout); |
|
167 | setLayout(d_ptr->m_layout); | |
167 | } |
|
168 | } | |
@@ -249,14 +250,14 QPen QLegend::pen() const | |||||
249 |
|
250 | |||
250 | void QLegend::setFont(const QFont &font) |
|
251 | void QLegend::setFont(const QFont &font) | |
251 | { |
|
252 | { | |
252 | if (d_ptr->m_font != font) |
|
253 | if (d_ptr->m_font != font) { | |
253 | d_ptr->m_font = font; |
|
254 | d_ptr->m_font = font; | |
254 |
|
255 | foreach (QLegendMarker *marker, d_ptr->markers()) { | ||
255 | foreach (QLegendMarker *marker, d_ptr->markers()) { |
|
256 | marker->setFont(d_ptr->m_font); | |
256 | marker->setFont(d_ptr->m_font); |
|
257 | } | |
|
258 | layout()->invalidate(); | |||
|
259 | emit fontChanged(font); | |||
257 | } |
|
260 | } | |
258 | layout()->invalidate(); |
|
|||
259 | emit fontChanged(font); |
|
|||
260 | } |
|
261 | } | |
261 |
|
262 | |||
262 | QFont QLegend::font() const |
|
263 | QFont QLegend::font() const |
@@ -22,6 +22,7 | |||||
22 | #include "qlineseries.h" |
|
22 | #include "qlineseries.h" | |
23 | #include "qlineseries_p.h" |
|
23 | #include "qlineseries_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
|
25 | #include "domain_p.h" | |||
25 | #include <QPainter> |
|
26 | #include <QPainter> | |
26 | #include <QGraphicsSceneMouseEvent> |
|
27 | #include <QGraphicsSceneMouseEvent> | |
27 |
|
28 | |||
@@ -29,9 +30,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
29 |
|
30 | |||
30 | const qreal mouseEventMinWidth(12); |
|
31 | const qreal mouseEventMinWidth(12); | |
31 |
|
32 | |||
32 |
LineChartItem::LineChartItem(QLineSeries *series, |
|
33 | LineChartItem::LineChartItem(QLineSeries *series,QGraphicsItem* item) | |
33 |
: XYChart(series, |
|
34 | : XYChart(series,item), | |
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
|||
35 | m_series(series), |
|
35 | m_series(series), | |
36 | m_pointsVisible(false) |
|
36 | m_pointsVisible(false) | |
37 | { |
|
37 | { | |
@@ -96,8 +96,6 void LineChartItem::updateGeometry() | |||||
96 |
|
96 | |||
97 | m_path = stroker.createStroke(linePath); |
|
97 | m_path = stroker.createStroke(linePath); | |
98 | m_rect = m_path.boundingRect(); |
|
98 | m_rect = m_path.boundingRect(); | |
99 |
|
||||
100 | setPos(origin()); |
|
|||
101 | } |
|
99 | } | |
102 |
|
100 | |||
103 | void LineChartItem::handleUpdated() |
|
101 | void LineChartItem::handleUpdated() | |
@@ -117,7 +115,7 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt | |||||
117 | painter->save(); |
|
115 | painter->save(); | |
118 | painter->setPen(m_linePen); |
|
116 | painter->setPen(m_linePen); | |
119 | painter->setBrush(m_linePen.color()); |
|
117 | painter->setBrush(m_linePen.color()); | |
120 |
painter->setClipRect( |
|
118 | painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); | |
121 |
|
119 | |||
122 | if (m_pointsVisible) { |
|
120 | if (m_pointsVisible) { | |
123 | painter->drawPath(m_linePath); |
|
121 | painter->drawPath(m_linePath); | |
@@ -130,22 +128,22 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt | |||||
130 |
|
128 | |||
131 | void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
129 | void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
132 | { |
|
130 | { | |
133 | emit XYChart::clicked(calculateDomainPoint(event->pos())); |
|
131 | emit XYChart::clicked(domain()->calculateDomainPoint(event->pos())); | |
134 | QGraphicsItem::mousePressEvent(event); |
|
132 | QGraphicsItem::mousePressEvent(event); | |
135 | } |
|
133 | } | |
136 |
|
134 | |||
137 | void LineChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
135 | void LineChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
138 | { |
|
136 | { | |
139 | emit XYChart::hovered(calculateDomainPoint(event->pos()), true); |
|
137 | emit XYChart::hovered(domain()->calculateDomainPoint(event->pos()), true); | |
140 | event->accept(); |
|
138 | event->accept(); | |
141 |
|
|
139 | //QGraphicsItem::hoverEnterEvent(event); | |
142 | } |
|
140 | } | |
143 |
|
141 | |||
144 | void LineChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
142 | void LineChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
145 | { |
|
143 | { | |
146 | emit XYChart::hovered(calculateDomainPoint(event->pos()), false); |
|
144 | emit XYChart::hovered(domain()->calculateDomainPoint(event->pos()), false); | |
147 | event->accept(); |
|
145 | event->accept(); | |
148 |
|
|
146 | //QGraphicsItem::hoverEnterEvent(event); | |
149 | } |
|
147 | } | |
150 |
|
148 | |||
151 | #include "moc_linechartitem_p.cpp" |
|
149 | #include "moc_linechartitem_p.cpp" |
@@ -39,12 +39,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
39 | class QLineSeries; |
|
39 | class QLineSeries; | |
40 | class ChartPresenter; |
|
40 | class ChartPresenter; | |
41 |
|
41 | |||
42 |
class LineChartItem : public XYChart |
|
42 | class LineChartItem : public XYChart | |
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 | Q_INTERFACES(QGraphicsItem) |
|
45 | Q_INTERFACES(QGraphicsItem) | |
46 | public: |
|
46 | public: | |
47 |
explicit LineChartItem(QLineSeries *series, |
|
47 | explicit LineChartItem(QLineSeries *series, QGraphicsItem* item = 0); | |
48 | ~LineChartItem() {} |
|
48 | ~LineChartItem() {} | |
49 |
|
49 | |||
50 | //from QGraphicsItem |
|
50 | //from QGraphicsItem |
@@ -119,8 +119,8 QLineSeries::QLineSeries(QLineSeriesPrivate &d, QObject *parent) | |||||
119 | QLineSeries::~QLineSeries() |
|
119 | QLineSeries::~QLineSeries() | |
120 | { |
|
120 | { | |
121 | Q_D(QLineSeries); |
|
121 | Q_D(QLineSeries); | |
122 |
if (d->m_ |
|
122 | if (d->m_chart) | |
123 |
d->m_ |
|
123 | d->m_chart->removeSeries(this); | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | QAbstractSeries::SeriesType QLineSeries::type() const |
|
126 | QAbstractSeries::SeriesType QLineSeries::type() const | |
@@ -148,14 +148,25 QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries *q) | |||||
148 |
|
148 | |||
149 | }; |
|
149 | }; | |
150 |
|
150 | |||
151 | ChartElement *QLineSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
151 | void QLineSeriesPrivate::initializeGraphics(QGraphicsItem *parent) | |
152 | { |
|
152 | { | |
153 | Q_Q(QLineSeries); |
|
153 | Q_Q(QLineSeries); | |
154 |
LineChartItem *line = new LineChartItem(q, |
|
154 | LineChartItem *line = new LineChartItem(q,parent); | |
155 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
155 | m_item.reset(line); | |
156 | line->setAnimation(new XYAnimation(line)); |
|
156 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
157 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
157 | } | |
158 | return line; |
|
158 | ||
|
159 | void QLineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |||
|
160 | { | |||
|
161 | Q_Q(QLineSeries); | |||
|
162 | const QList<QColor> colors = theme->seriesColors(); | |||
|
163 | ||||
|
164 | QPen pen; | |||
|
165 | if (forced || pen == m_pen) { | |||
|
166 | pen.setColor(colors.at(index % colors.size())); | |||
|
167 | pen.setWidthF(2); | |||
|
168 | q->setPen(pen); | |||
|
169 | } | |||
159 | } |
|
170 | } | |
160 |
|
171 | |||
161 | #include "moc_qlineseries.cpp" |
|
172 | #include "moc_qlineseries.cpp" |
@@ -39,7 +39,8 class QLineSeriesPrivate: public QXYSeriesPrivate | |||||
39 | { |
|
39 | { | |
40 | public: |
|
40 | public: | |
41 | QLineSeriesPrivate(QLineSeries *q); |
|
41 | QLineSeriesPrivate(QLineSeries *q); | |
42 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
42 | void initializeGraphics(QGraphicsItem* parent); | |
|
43 | void initializeTheme(int index, ChartTheme* theme, bool forced = false); | |||
43 |
|
44 | |||
44 | private: |
|
45 | private: | |
45 | Q_DECLARE_PUBLIC(QLineSeries); |
|
46 | Q_DECLARE_PUBLIC(QLineSeries); |
@@ -32,8 +32,8 | |||||
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 |
PieChartItem::PieChartItem(QPieSeries *series, |
|
35 | PieChartItem::PieChartItem(QPieSeries *series, QGraphicsItem* item) | |
36 |
: ChartItem( |
|
36 | : ChartItem(series->d_func(),item), | |
37 | m_series(series), |
|
37 | m_series(series), | |
38 | m_animation(0) |
|
38 | m_animation(0) | |
39 | { |
|
39 | { | |
@@ -70,46 +70,17 ChartAnimation *PieChartItem::animation() const | |||||
70 | return m_animation; |
|
70 | return m_animation; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void PieChartItem::handleGeometryChanged(const QRectF &rect) |
|
|||
74 | { |
|
|||
75 | prepareGeometryChange(); |
|
|||
76 | m_rect = rect; |
|
|||
77 | updateLayout(); |
|
|||
78 |
|
||||
79 | // This is for delayed initialization of the slice items during startup. |
|
|||
80 | // It ensures that startup animation originates from the correct position. |
|
|||
81 | if (m_sliceItems.isEmpty()) |
|
|||
82 | handleSlicesAdded(m_series->slices()); |
|
|||
83 | } |
|
|||
84 |
|
||||
85 | void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
|||
86 | { |
|
|||
87 | Q_UNUSED(minX); |
|
|||
88 | Q_UNUSED(maxX); |
|
|||
89 | Q_UNUSED(minY); |
|
|||
90 | Q_UNUSED(maxY); |
|
|||
91 | // does not apply to pie |
|
|||
92 | } |
|
|||
93 |
|
||||
94 | void PieChartItem::handleDomainUpdated() |
|
73 | void PieChartItem::handleDomainUpdated() | |
95 | { |
|
74 | { | |
96 | // does not apply to pie |
|
75 | QRectF rect(QPointF(0,0),domain()->size()); | |
97 | } |
|
76 | if(m_rect!=rect){ | |
98 |
|
77 | prepareGeometryChange(); | ||
99 | void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount) |
|
78 | m_rect = rect; | |
100 | { |
|
79 | updateLayout(); | |
101 | Q_UNUSED(min); |
|
|||
102 | Q_UNUSED(max); |
|
|||
103 | Q_UNUSED(tickXCount); |
|
|||
104 | // does not apply to pie |
|
|||
105 | } |
|
|||
106 |
|
80 | |||
107 | void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount) |
|
81 | if (m_sliceItems.isEmpty()) | |
108 | { |
|
82 | handleSlicesAdded(m_series->slices()); | |
109 | Q_UNUSED(min); |
|
83 | } | |
110 | Q_UNUSED(max); |
|
|||
111 | Q_UNUSED(tickYCount); |
|
|||
112 | // does not apply to pie |
|
|||
113 | } |
|
84 | } | |
114 |
|
85 | |||
115 | void PieChartItem::updateLayout() |
|
86 | void PieChartItem::updateLayout() | |
@@ -149,7 +120,7 void PieChartItem::handleSlicesAdded(QList<QPieSlice *> slices) | |||||
149 | if (!m_rect.isValid() && m_sliceItems.isEmpty()) |
|
120 | if (!m_rect.isValid() && m_sliceItems.isEmpty()) | |
150 | return; |
|
121 | return; | |
151 |
|
122 | |||
152 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
123 | themeManager()->updateSeries(m_series); | |
153 |
|
124 | |||
154 | bool startupAnimation = m_sliceItems.isEmpty(); |
|
125 | bool startupAnimation = m_sliceItems.isEmpty(); | |
155 |
|
126 | |||
@@ -185,7 +156,7 void PieChartItem::handleSlicesAdded(QList<QPieSlice *> slices) | |||||
185 |
|
156 | |||
186 | void PieChartItem::handleSlicesRemoved(QList<QPieSlice *> slices) |
|
157 | void PieChartItem::handleSlicesRemoved(QList<QPieSlice *> slices) | |
187 | { |
|
158 | { | |
188 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
159 | themeManager()->updateSeries(m_series); | |
189 |
|
160 | |||
190 | foreach (QPieSlice *slice, slices) { |
|
161 | foreach (QPieSlice *slice, slices) { | |
191 |
|
162 |
@@ -45,7 +45,7 class PieChartItem : public ChartItem | |||||
45 | Q_OBJECT |
|
45 | Q_OBJECT | |
46 |
|
46 | |||
47 | public: |
|
47 | public: | |
48 |
explicit PieChartItem(QPieSeries *series, |
|
48 | explicit PieChartItem(QPieSeries *series, QGraphicsItem* item = 0); | |
49 | ~PieChartItem(); |
|
49 | ~PieChartItem(); | |
50 |
|
50 | |||
51 | // from QGraphicsItem |
|
51 | // from QGraphicsItem | |
@@ -54,11 +54,7 public: | |||||
54 |
|
54 | |||
55 | public Q_SLOTS: |
|
55 | public Q_SLOTS: | |
56 | // from Chart |
|
56 | // from Chart | |
57 | virtual void handleGeometryChanged(const QRectF &rect); |
|
|||
58 | virtual void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
|||
59 | virtual void handleDomainUpdated(); |
|
57 | virtual void handleDomainUpdated(); | |
60 | virtual void rangeXChanged(qreal min, qreal max, int tickXCount); |
|
|||
61 | virtual void rangeYChanged(qreal min, qreal max, int tickYCount); |
|
|||
62 |
|
58 | |||
63 | void updateLayout(); |
|
59 | void updateLayout(); | |
64 | void handleSlicesAdded(QList<QPieSlice *> slices); |
|
60 | void handleSlicesAdded(QList<QPieSlice *> slices); |
@@ -834,20 +834,29 void QPieSeriesPrivate::sliceHovered(bool state) | |||||
834 | emit q->hovered(slice, state); |
|
834 | emit q->hovered(slice, state); | |
835 | } |
|
835 | } | |
836 |
|
836 | |||
837 |
void QPieSeriesPrivate:: |
|
837 | void QPieSeriesPrivate::initializeDomain() | |
838 | { |
|
838 | { | |
839 | Q_UNUSED(domain); |
|
|||
840 | // does not apply to pie |
|
839 | // does not apply to pie | |
841 | } |
|
840 | } | |
842 |
|
841 | |||
843 | ChartElement *QPieSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
842 | void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
844 | { |
|
843 | { | |
845 | Q_Q(QPieSeries); |
|
844 | Q_Q(QPieSeries); | |
846 |
PieChartItem *pie = new PieChartItem(q, |
|
845 | PieChartItem *pie = new PieChartItem(q,parent); | |
847 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
846 | m_item.reset(pie); | |
848 | pie->setAnimation(new PieAnimation(pie)); |
|
847 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
849 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
848 | } | |
850 | return pie; |
|
849 | ||
|
850 | void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |||
|
851 | { | |||
|
852 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); | |||
|
853 | Q_ASSERT(item); | |||
|
854 | if (options.testFlag(QChart::SeriesAnimations)) { | |||
|
855 | item->setAnimation(new PieAnimation(item)); | |||
|
856 | }else{ | |||
|
857 | item->setAnimation(0); | |||
|
858 | } | |||
|
859 | QAbstractSeriesPrivate::initializeAnimations(options); | |||
851 | } |
|
860 | } | |
852 |
|
861 | |||
853 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
862 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) | |
@@ -861,9 +870,9 QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) | |||||
861 | return markers; |
|
870 | return markers; | |
862 | } |
|
871 | } | |
863 |
|
872 | |||
864 |
void QPieSeriesPrivate::initializeAx |
|
873 | void QPieSeriesPrivate::initializeAxes() | |
865 | { |
|
874 | { | |
866 | Q_UNUSED(axis); |
|
875 | ||
867 | } |
|
876 | } | |
868 |
|
877 | |||
869 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
878 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
@@ -872,6 +881,44 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orien | |||||
872 | return QAbstractAxis::AxisTypeNoAxis; |
|
881 | return QAbstractAxis::AxisTypeNoAxis; | |
873 | } |
|
882 | } | |
874 |
|
883 | |||
|
884 | QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |||
|
885 | { | |||
|
886 | Q_UNUSED(orientation); | |||
|
887 | return 0; | |||
|
888 | } | |||
|
889 | ||||
|
890 | void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |||
|
891 | { | |||
|
892 | Q_Q(QPieSeries); | |||
|
893 | const QList<QColor>& colors = theme->seriesColors(); | |||
|
894 | const QList<QGradient>& gradients = theme->seriesGradients(); | |||
|
895 | ||||
|
896 | for (int i(0); i < m_slices.count(); i++) { | |||
|
897 | ||||
|
898 | QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); | |||
|
899 | ||||
|
900 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |||
|
901 | qreal pos = (qreal)(i + 1) / (qreal) m_slices.count(); | |||
|
902 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos); | |||
|
903 | ||||
|
904 | QPieSlice *s = m_slices.at(i); | |||
|
905 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |||
|
906 | ||||
|
907 | if (forced || d->m_data.m_slicePen.isThemed()) | |||
|
908 | d->setPen(penColor, true); | |||
|
909 | ||||
|
910 | if (forced || d->m_data.m_sliceBrush.isThemed()) | |||
|
911 | d->setBrush(brushColor, true); | |||
|
912 | ||||
|
913 | if (forced || d->m_data.m_labelBrush.isThemed()) | |||
|
914 | d->setLabelBrush(theme->labelBrush().color(), true); | |||
|
915 | ||||
|
916 | if (forced || d->m_data.m_labelFont.isThemed()) | |||
|
917 | d->setLabelFont(theme->labelFont(), true); | |||
|
918 | } | |||
|
919 | } | |||
|
920 | ||||
|
921 | ||||
875 | #include "moc_qpieseries.cpp" |
|
922 | #include "moc_qpieseries.cpp" | |
876 | #include "moc_qpieseries_p.cpp" |
|
923 | #include "moc_qpieseries_p.cpp" | |
877 |
|
924 |
@@ -95,6 +95,7 Q_SIGNALS: | |||||
95 | private: |
|
95 | private: | |
96 | Q_DECLARE_PRIVATE(QPieSeries) |
|
96 | Q_DECLARE_PRIVATE(QPieSeries) | |
97 | Q_DISABLE_COPY(QPieSeries) |
|
97 | Q_DISABLE_COPY(QPieSeries) | |
|
98 | friend class PieChartItem; | |||
98 | }; |
|
99 | }; | |
99 |
|
100 | |||
100 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -44,11 +44,16 public: | |||||
44 | QPieSeriesPrivate(QPieSeries *parent); |
|
44 | QPieSeriesPrivate(QPieSeries *parent); | |
45 | ~QPieSeriesPrivate(); |
|
45 | ~QPieSeriesPrivate(); | |
46 |
|
46 | |||
47 |
void |
|
47 | void initializeDomain(); | |
48 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
48 | void initializeAxes(); | |
|
49 | void initializeGraphics(QGraphicsItem* parent); | |||
|
50 | void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); | |||
|
51 | void initializeTheme(int index, ChartTheme* theme, bool forced = false); | |||
|
52 | ||||
49 | QList<QLegendMarker *> createLegendMarkers(QLegend *legend); |
|
53 | QList<QLegendMarker *> createLegendMarkers(QLegend *legend); | |
50 | void initializeAxis(QAbstractAxis *axis); |
|
54 | ||
51 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
55 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
|
56 | QAbstractAxis* createDefaultAxis(Qt::Orientation orientation) const; | |||
52 |
|
57 | |||
53 | void updateDerivativeData(); |
|
58 | void updateDerivativeData(); | |
54 | void setSizes(qreal innerSize, qreal outerSize); |
|
59 | void setSizes(qreal innerSize, qreal outerSize); | |
@@ -78,7 +83,7 private: | |||||
78 | qreal m_sum; |
|
83 | qreal m_sum; | |
79 | qreal m_holeRelativeSize; |
|
84 | qreal m_holeRelativeSize; | |
80 |
|
85 | |||
81 | private: |
|
86 | public: | |
82 | friend class QLegendPrivate; |
|
87 | friend class QLegendPrivate; | |
83 | Q_DECLARE_PUBLIC(QPieSeries) |
|
88 | Q_DECLARE_PUBLIC(QPieSeries) | |
84 | }; |
|
89 | }; |
@@ -65,7 +65,7 Q_SIGNALS: | |||||
65 | private: |
|
65 | private: | |
66 | friend class QPieSeries; |
|
66 | friend class QPieSeries; | |
67 | friend class QPieSeriesPrivate; |
|
67 | friend class QPieSeriesPrivate; | |
68 | friend class ChartTheme; |
|
68 | friend class ChartThemeManager; | |
69 | friend class PieChartItem; |
|
69 | friend class PieChartItem; | |
70 |
|
70 | |||
71 | QPieSlice * const q_ptr; |
|
71 | QPieSlice * const q_ptr; |
@@ -21,6 +21,9 | |||||
21 | #include "qabstractseries.h" |
|
21 | #include "qabstractseries.h" | |
22 | #include "qabstractseries_p.h" |
|
22 | #include "qabstractseries_p.h" | |
23 | #include "chartdataset_p.h" |
|
23 | #include "chartdataset_p.h" | |
|
24 | #include "qchart.h" | |||
|
25 | #include "qchart_p.h" | |||
|
26 | #include "chartitem_p.h" | |||
24 |
|
27 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
29 | |||
@@ -137,7 +140,7 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : | |||||
137 | */ |
|
140 | */ | |
138 | QAbstractSeries::~QAbstractSeries() |
|
141 | QAbstractSeries::~QAbstractSeries() | |
139 | { |
|
142 | { | |
140 |
if (d_ptr->m_ |
|
143 | if (d_ptr->m_chart) | |
141 | qFatal("Still binded series detected !"); |
|
144 | qFatal("Still binded series detected !"); | |
142 | } |
|
145 | } | |
143 |
|
146 | |||
@@ -222,12 +225,39 void QAbstractSeries::hide() | |||||
222 | setVisible(false); |
|
225 | setVisible(false); | |
223 | } |
|
226 | } | |
224 |
|
227 | |||
|
228 | bool QAbstractSeries::attachAxis(QAbstractAxis* axis) | |||
|
229 | { | |||
|
230 | if(d_ptr->m_chart) { | |||
|
231 | return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this,axis); | |||
|
232 | } else { | |||
|
233 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; | |||
|
234 | return false; | |||
|
235 | } | |||
|
236 | } | |||
|
237 | ||||
|
238 | bool QAbstractSeries::detachAxis(QAbstractAxis* axis) | |||
|
239 | { | |||
|
240 | if(d_ptr->m_chart) { | |||
|
241 | return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this,axis); | |||
|
242 | } | |||
|
243 | else { | |||
|
244 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; | |||
|
245 | return false; | |||
|
246 | } | |||
|
247 | } | |||
|
248 | ||||
|
249 | QList<QAbstractAxis*> QAbstractSeries::attachedAxes() | |||
|
250 | { | |||
|
251 | return d_ptr->m_axes; | |||
|
252 | } | |||
|
253 | ||||
225 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
254 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
226 |
|
255 | |||
227 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q) |
|
256 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q) | |
228 | : q_ptr(q), |
|
257 | : q_ptr(q), | |
229 | m_chart(0), |
|
258 | m_chart(0), | |
230 |
m_ |
|
259 | m_item(0), | |
|
260 | m_domain(new Domain()), | |||
231 | m_visible(true), |
|
261 | m_visible(true), | |
232 | m_opacity(1.0) |
|
262 | m_opacity(1.0) | |
233 | { |
|
263 | { | |
@@ -237,6 +267,31 QAbstractSeriesPrivate::~QAbstractSeriesPrivate() | |||||
237 | { |
|
267 | { | |
238 | } |
|
268 | } | |
239 |
|
269 | |||
|
270 | void QAbstractSeriesPrivate::setDomain(QSharedPointer<Domain> domain) | |||
|
271 | { | |||
|
272 | Q_ASSERT(!domain.isNull()); | |||
|
273 | if(m_domain!=domain) { | |||
|
274 | if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated())); | |||
|
275 | m_domain = domain; | |||
|
276 | if(!m_item.isNull()) { | |||
|
277 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); | |||
|
278 | m_item->handleDomainUpdated(); | |||
|
279 | } | |||
|
280 | } | |||
|
281 | } | |||
|
282 | ||||
|
283 | void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |||
|
284 | { | |||
|
285 | Q_ASSERT(!m_item.isNull()); | |||
|
286 | Q_UNUSED(parent); | |||
|
287 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); | |||
|
288 | } | |||
|
289 | ||||
|
290 | void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) | |||
|
291 | { | |||
|
292 | Q_UNUSED(options); | |||
|
293 | } | |||
|
294 | ||||
240 | #include "moc_qabstractseries.cpp" |
|
295 | #include "moc_qabstractseries.cpp" | |
241 | #include "moc_qabstractseries_p.cpp" |
|
296 | #include "moc_qabstractseries_p.cpp" | |
242 |
|
297 |
@@ -71,6 +71,10 public: | |||||
71 |
|
71 | |||
72 | QChart *chart() const; |
|
72 | QChart *chart() const; | |
73 |
|
73 | |||
|
74 | bool attachAxis(QAbstractAxis* axis); | |||
|
75 | bool detachAxis(QAbstractAxis* axis); | |||
|
76 | QList<QAbstractAxis*> attachedAxes(); | |||
|
77 | ||||
74 | void show(); |
|
78 | void show(); | |
75 | void hide(); |
|
79 | void hide(); | |
76 |
|
80 | |||
@@ -83,6 +87,7 protected: | |||||
83 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; |
|
87 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; | |
84 | friend class ChartDataSet; |
|
88 | friend class ChartDataSet; | |
85 | friend class ChartPresenter; |
|
89 | friend class ChartPresenter; | |
|
90 | friend class ChartThemeManager; | |||
86 | friend class QLegendPrivate; |
|
91 | friend class QLegendPrivate; | |
87 | friend class DeclarativeChart; |
|
92 | friend class DeclarativeChart; | |
88 | }; |
|
93 | }; |
@@ -31,10 +31,13 | |||||
31 | #define QABSTRACTSERIES_P_H |
|
31 | #define QABSTRACTSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries.h" |
|
33 | #include "qabstractseries.h" | |
|
34 | #include "qchart.h" | |||
|
35 | #include "domain_p.h" | |||
|
36 | ||||
|
37 | class QGraphicsItem; | |||
34 |
|
38 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
40 | |||
37 | class Domain; |
|
|||
38 | class ChartPresenter; |
|
41 | class ChartPresenter; | |
39 | class ChartElement; |
|
42 | class ChartElement; | |
40 | class LegendMarker; |
|
43 | class LegendMarker; | |
@@ -42,6 +45,9 class QLegend; | |||||
42 | class ChartDataSet; |
|
45 | class ChartDataSet; | |
43 | class QAbstractAxis; |
|
46 | class QAbstractAxis; | |
44 | class QLegendMarker; |
|
47 | class QLegendMarker; | |
|
48 | class ChartTheme; | |||
|
49 | class ChartAnimation; | |||
|
50 | class ChartItem; | |||
45 |
|
51 | |||
46 | class QAbstractSeriesPrivate : public QObject |
|
52 | class QAbstractSeriesPrivate : public QObject | |
47 | { |
|
53 | { | |
@@ -50,11 +56,23 public: | |||||
50 | QAbstractSeriesPrivate(QAbstractSeries *q); |
|
56 | QAbstractSeriesPrivate(QAbstractSeries *q); | |
51 | ~QAbstractSeriesPrivate(); |
|
57 | ~QAbstractSeriesPrivate(); | |
52 |
|
58 | |||
53 |
virtual void |
|
59 | virtual void initializeDomain() = 0; | |
54 | virtual ChartElement *createGraphics(ChartPresenter *presenter) = 0; |
|
60 | virtual void initializeAxes() = 0; | |
|
61 | virtual void initializeTheme(int index, ChartTheme* theme, bool forced = false) = 0; | |||
|
62 | virtual void initializeGraphics(QGraphicsItem* parent) = 0; | |||
|
63 | virtual void initializeAnimations(QChart::AnimationOptions options) = 0; | |||
|
64 | ||||
55 | virtual QList<QLegendMarker*> createLegendMarkers(QLegend* legend) = 0; |
|
65 | virtual QList<QLegendMarker*> createLegendMarkers(QLegend* legend) = 0; | |
56 | virtual void initializeAxis(QAbstractAxis *axis) = 0; |
|
66 | ||
57 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0; |
|
67 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0; | |
|
68 | virtual QAbstractAxis* createDefaultAxis(Qt::Orientation) const = 0; | |||
|
69 | ||||
|
70 | ChartItem* chartItem() { return m_item.data(); } | |||
|
71 | ||||
|
72 | virtual void setDomain(QSharedPointer<Domain> domain); | |||
|
73 | QSharedPointer<Domain> domain() { return m_domain; } | |||
|
74 | ||||
|
75 | QChart* chart() { return m_chart; } | |||
58 |
|
76 | |||
59 | Q_SIGNALS: |
|
77 | Q_SIGNALS: | |
60 | void countChanged(); |
|
78 | void countChanged(); | |
@@ -62,13 +80,17 Q_SIGNALS: | |||||
62 | protected: |
|
80 | protected: | |
63 | QAbstractSeries *q_ptr; |
|
81 | QAbstractSeries *q_ptr; | |
64 | QChart *m_chart; |
|
82 | QChart *m_chart; | |
65 | ChartDataSet *m_dataset; |
|
83 | QScopedPointer<ChartItem> m_item; | |
|
84 | QList<QAbstractAxis*> m_axes; | |||
|
85 | private: | |||
|
86 | QSharedPointer<Domain> m_domain; | |||
66 | QString m_name; |
|
87 | QString m_name; | |
67 | bool m_visible; |
|
88 | bool m_visible; | |
68 | qreal m_opacity; |
|
89 | qreal m_opacity; | |
69 |
|
90 | |||
70 | friend class QAbstractSeries; |
|
91 | friend class QAbstractSeries; | |
71 | friend class ChartDataSet; |
|
92 | friend class ChartDataSet; | |
|
93 | friend class ChartPresenter; | |||
72 | friend class QLegendPrivate; |
|
94 | friend class QLegendPrivate; | |
73 | }; |
|
95 | }; | |
74 |
|
96 |
@@ -25,6 +25,9 | |||||
25 | #include "chartbackground_p.h" |
|
25 | #include "chartbackground_p.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include "chartlayout_p.h" |
|
27 | #include "chartlayout_p.h" | |
|
28 | #include "charttheme_p.h" | |||
|
29 | #include "chartpresenter_p.h" | |||
|
30 | #include "chartdataset_p.h" | |||
28 | #include <QGraphicsScene> |
|
31 | #include <QGraphicsScene> | |
29 | #include <QGraphicsSceneResizeEvent> |
|
32 | #include <QGraphicsSceneResizeEvent> | |
30 |
|
33 | |||
@@ -106,13 +109,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
106 | */ |
|
109 | */ | |
107 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
110 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
108 | : QGraphicsWidget(parent, wFlags), |
|
111 | : QGraphicsWidget(parent, wFlags), | |
109 | d_ptr(new QChartPrivate()) |
|
112 | d_ptr(new QChartPrivate(this)) | |
110 | { |
|
113 | { | |
111 | d_ptr->m_dataset = new ChartDataSet(this); |
|
|||
112 | d_ptr->m_presenter = new ChartPresenter(this, d_ptr->m_dataset); |
|
|||
113 | d_ptr->createConnections(); |
|
|||
114 | d_ptr->m_legend = new LegendScroller(this); |
|
114 | d_ptr->m_legend = new LegendScroller(this); | |
115 |
|
|
115 | setTheme(QChart::ChartThemeLight); | |
|
116 | //TODO: what is that ? | |||
116 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); |
|
117 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); | |
117 | setLayout(d_ptr->m_presenter->layout()); |
|
118 | setLayout(d_ptr->m_presenter->layout()); | |
118 | } |
|
119 | } | |
@@ -122,10 +123,9 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |||||
122 | */ |
|
123 | */ | |
123 | QChart::~QChart() |
|
124 | QChart::~QChart() | |
124 | { |
|
125 | { | |
125 | //delete first presenter , since this is a root of all the graphical items |
|
126 | //start by deleting dataset, it will remove all series and axes | |
126 | setLayout(0); |
|
127 | delete d_ptr->m_dataset; | |
127 |
|
|
128 | d_ptr->m_dataset = 0; | |
128 | d_ptr->m_presenter = 0; |
|
|||
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
@@ -245,12 +245,12 QBrush QChart::titleBrush() const | |||||
245 |
|
245 | |||
246 | void QChart::setTheme(QChart::ChartTheme theme) |
|
246 | void QChart::setTheme(QChart::ChartTheme theme) | |
247 | { |
|
247 | { | |
248 |
d_ptr->m_ |
|
248 | d_ptr->m_themeManager->setTheme(theme); | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | QChart::ChartTheme QChart::theme() const |
|
251 | QChart::ChartTheme QChart::theme() const | |
252 | { |
|
252 | { | |
253 |
return d_ptr->m_ |
|
253 | return d_ptr->m_themeManager->theme()->id(); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | /*! |
|
256 | /*! | |
@@ -258,7 +258,7 QChart::ChartTheme QChart::theme() const | |||||
258 | */ |
|
258 | */ | |
259 | void QChart::zoomIn() |
|
259 | void QChart::zoomIn() | |
260 | { |
|
260 | { | |
261 |
d_ptr |
|
261 | d_ptr->zoomIn(2.0); | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | /*! |
|
264 | /*! | |
@@ -266,9 +266,7 void QChart::zoomIn() | |||||
266 | */ |
|
266 | */ | |
267 | void QChart::zoomIn(const QRectF &rect) |
|
267 | void QChart::zoomIn(const QRectF &rect) | |
268 | { |
|
268 | { | |
269 | if (!rect.isValid()) |
|
269 | d_ptr->zoomIn(rect); | |
270 | return; |
|
|||
271 | d_ptr->m_presenter->zoomIn(rect); |
|
|||
272 | } |
|
270 | } | |
273 |
|
271 | |||
274 | /*! |
|
272 | /*! | |
@@ -276,7 +274,7 void QChart::zoomIn(const QRectF &rect) | |||||
276 | */ |
|
274 | */ | |
277 | void QChart::zoomOut() |
|
275 | void QChart::zoomOut() | |
278 | { |
|
276 | { | |
279 |
d_ptr |
|
277 | d_ptr->zoomOut(2.0); | |
280 | } |
|
278 | } | |
281 |
|
279 | |||
282 | /*! |
|
280 | /*! | |
@@ -296,9 +294,9 void QChart::zoom(qreal factor) | |||||
296 | return; |
|
294 | return; | |
297 |
|
295 | |||
298 | if (factor > 1.0) |
|
296 | if (factor > 1.0) | |
299 |
d_ptr |
|
297 | d_ptr->zoomIn(factor); | |
300 | else |
|
298 | else | |
301 |
d_ptr |
|
299 | d_ptr->zoomOut(1.0 / factor); | |
302 | } |
|
300 | } | |
303 |
|
301 | |||
304 | /*! |
|
302 | /*! | |
@@ -307,7 +305,27 void QChart::zoom(qreal factor) | |||||
307 | */ |
|
305 | */ | |
308 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
306 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | |
309 | { |
|
307 | { | |
310 |
|
|
308 | if(!series && d_ptr->m_dataset->series().size()>0){ | |
|
309 | series = d_ptr->m_dataset->series().first(); | |||
|
310 | }else{ | |||
|
311 | return 0; | |||
|
312 | } | |||
|
313 | ||||
|
314 | QList<QAbstractAxis*> axes = series->attachedAxes(); | |||
|
315 | QAbstractAxis* bottom=0; | |||
|
316 | QAbstractAxis* top=0; | |||
|
317 | ||||
|
318 | foreach(QAbstractAxis* axis, axes){ | |||
|
319 | ||||
|
320 | if(axis->alignment()==Qt::AlignTop){ | |||
|
321 | top=axis; | |||
|
322 | } | |||
|
323 | ||||
|
324 | if(axis->alignment()==Qt::AlignBottom){ | |||
|
325 | bottom=axis; | |||
|
326 | } | |||
|
327 | } | |||
|
328 | return bottom?bottom:top; | |||
311 | } |
|
329 | } | |
312 |
|
330 | |||
313 | /*! |
|
331 | /*! | |
@@ -316,7 +334,42 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | |||||
316 | */ |
|
334 | */ | |
317 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
335 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const | |
318 | { |
|
336 | { | |
319 |
|
|
337 | if(!series && d_ptr->m_dataset->series().size()>0) { | |
|
338 | series = d_ptr->m_dataset->series().first(); | |||
|
339 | } else { | |||
|
340 | return 0; | |||
|
341 | } | |||
|
342 | ||||
|
343 | QList<QAbstractAxis*> axes = series->attachedAxes(); | |||
|
344 | ||||
|
345 | QAbstractAxis* left=0; | |||
|
346 | QAbstractAxis* right=0; | |||
|
347 | ||||
|
348 | foreach(QAbstractAxis* axis, axes){ | |||
|
349 | ||||
|
350 | if(axis->alignment()==Qt::AlignLeft){ | |||
|
351 | left=axis; | |||
|
352 | } | |||
|
353 | ||||
|
354 | if(axis->alignment()==Qt::AlignRight){ | |||
|
355 | right=axis; | |||
|
356 | } | |||
|
357 | } | |||
|
358 | ||||
|
359 | return left?left:right; | |||
|
360 | } | |||
|
361 | ||||
|
362 | ||||
|
363 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const | |||
|
364 | { | |||
|
365 | QList<QAbstractAxis *> result ; | |||
|
366 | ||||
|
367 | foreach(QAbstractAxis* axis,series->attachedAxes()){ | |||
|
368 | if(orientation.testFlag(axis->orientation())) | |||
|
369 | result << axis; | |||
|
370 | } | |||
|
371 | ||||
|
372 | return result; | |||
320 | } |
|
373 | } | |
321 |
|
374 | |||
322 | /*! |
|
375 | /*! | |
@@ -410,7 +463,7 QMargins QChart::margins() const | |||||
410 | */ |
|
463 | */ | |
411 | QRectF QChart::plotArea() const |
|
464 | QRectF QChart::plotArea() const | |
412 | { |
|
465 | { | |
413 |
return d_ptr->m_presenter-> |
|
466 | return d_ptr->m_presenter->geometry(); | |
414 | } |
|
467 | } | |
415 |
|
468 | |||
416 | ///*! |
|
469 | ///*! | |
@@ -440,7 +493,7 QChart::AnimationOptions QChart::animationOptions() const | |||||
440 | */ |
|
493 | */ | |
441 | void QChart::scroll(qreal dx, qreal dy) |
|
494 | void QChart::scroll(qreal dx, qreal dy) | |
442 | { |
|
495 | { | |
443 |
d_ptr |
|
496 | d_ptr->scroll(dx,dy); | |
444 | } |
|
497 | } | |
445 |
|
498 | |||
446 | void QChart::setBackgroundVisible(bool visible) |
|
499 | void QChart::setBackgroundVisible(bool visible) | |
@@ -480,9 +533,18 QList<QAbstractSeries *> QChart::series() const | |||||
480 | */ |
|
533 | */ | |
481 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) |
|
534 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) | |
482 | { |
|
535 | { | |
483 | if (axis->alignment() == Qt::AlignLeft || axis->alignment() == Qt::AlignRight) |
|
536 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); | |
484 | return; |
|
537 | ||
485 | d_ptr->m_dataset->setAxis(series, axis, Qt::Horizontal); |
|
538 | foreach(QAbstractAxis* a, list){ | |
|
539 | if(a->alignment()==axis->alignment()){ | |||
|
540 | d_ptr->m_dataset->removeAxis(a); | |||
|
541 | delete a; | |||
|
542 | } | |||
|
543 | } | |||
|
544 | ||||
|
545 | if(!d_ptr->m_dataset->axes().contains(axis)) | |||
|
546 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); | |||
|
547 | d_ptr->m_dataset->attachAxis(series,axis); | |||
486 | } |
|
548 | } | |
487 |
|
549 | |||
488 | /*! |
|
550 | /*! | |
@@ -492,19 +554,47 void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) | |||||
492 | */ |
|
554 | */ | |
493 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) |
|
555 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) | |
494 | { |
|
556 | { | |
495 | if (axis->alignment() == Qt::AlignTop || axis->alignment() == Qt::AlignBottom) |
|
557 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); | |
496 | return; |
|
558 | ||
497 | d_ptr->m_dataset->setAxis(series, axis, Qt::Vertical); |
|
559 | foreach(QAbstractAxis* a, list) { | |
|
560 | if(a->alignment()==axis->alignment()) { | |||
|
561 | d_ptr->m_dataset->removeAxis(a); | |||
|
562 | delete a; | |||
|
563 | } | |||
|
564 | } | |||
|
565 | ||||
|
566 | if(!d_ptr->m_dataset->axes().contains(axis)) | |||
|
567 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); | |||
|
568 | d_ptr->m_dataset->attachAxis(series,axis); | |||
|
569 | } | |||
|
570 | ||||
|
571 | void QChart::addAxis(QAbstractAxis *axis,Qt::Alignment aligment) | |||
|
572 | { | |||
|
573 | d_ptr->m_dataset->addAxis(axis,aligment); | |||
|
574 | } | |||
|
575 | ||||
|
576 | void QChart::removeAxis(QAbstractAxis *axis) | |||
|
577 | { | |||
|
578 | d_ptr->m_dataset->removeAxis(axis); | |||
498 | } |
|
579 | } | |
499 |
|
580 | |||
500 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
581 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
501 |
|
582 | |||
502 | QChartPrivate::QChartPrivate(): |
|
583 | QChartPrivate::QChartPrivate(QChart *q): | |
|
584 | q_ptr(q), | |||
503 | m_legend(0), |
|
585 | m_legend(0), | |
504 |
m_dataset( |
|
586 | m_dataset(new ChartDataSet(q)), | |
505 | m_presenter(0) |
|
587 | m_presenter(new ChartPresenter(q)), | |
|
588 | m_themeManager(new ChartThemeManager(q)) | |||
506 | { |
|
589 | { | |
507 |
|
590 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); | ||
|
591 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |||
|
592 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); | |||
|
593 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); | |||
|
594 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); | |||
|
595 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |||
|
596 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); | |||
|
597 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); | |||
508 | } |
|
598 | } | |
509 |
|
599 | |||
510 | QChartPrivate::~QChartPrivate() |
|
600 | QChartPrivate::~QChartPrivate() | |
@@ -512,13 +602,59 QChartPrivate::~QChartPrivate() | |||||
512 |
|
602 | |||
513 | } |
|
603 | } | |
514 |
|
604 | |||
515 |
void QChartPrivate:: |
|
605 | void QChartPrivate::zoomIn(qreal factor) | |
516 | { |
|
606 | { | |
517 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
607 | QRectF rect = m_presenter->geometry(); | |
518 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
608 | rect.setWidth(rect.width() / factor); | |
519 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*,Domain*))); |
|
609 | rect.setHeight(rect.height() / factor); | |
520 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
610 | rect.moveCenter(m_presenter->geometry().center()); | |
521 | //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF))); |
|
611 | zoomIn(rect); | |
|
612 | } | |||
|
613 | ||||
|
614 | void QChartPrivate::zoomIn(const QRectF &rect) | |||
|
615 | { | |||
|
616 | if (!rect.isValid()) | |||
|
617 | return; | |||
|
618 | ||||
|
619 | QRectF r = rect.normalized(); | |||
|
620 | const QRectF geometry = m_presenter->geometry(); | |||
|
621 | r.translate(-geometry.topLeft()); | |||
|
622 | ||||
|
623 | if (!r.isValid()) | |||
|
624 | return; | |||
|
625 | ||||
|
626 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |||
|
627 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); | |||
|
628 | m_dataset->zoomInDomain(r); | |||
|
629 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |||
|
630 | ||||
|
631 | } | |||
|
632 | ||||
|
633 | void QChartPrivate::zoomOut(qreal factor) | |||
|
634 | { | |||
|
635 | const QRectF geometry = m_presenter->geometry(); | |||
|
636 | ||||
|
637 | QRectF r; | |||
|
638 | r.setSize(geometry.size() / factor); | |||
|
639 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); | |||
|
640 | if (!r.isValid()) | |||
|
641 | return; | |||
|
642 | ||||
|
643 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |||
|
644 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); | |||
|
645 | m_dataset->zoomOutDomain(r); | |||
|
646 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |||
|
647 | } | |||
|
648 | ||||
|
649 | void QChartPrivate::scroll(qreal dx, qreal dy) | |||
|
650 | { | |||
|
651 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); | |||
|
652 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); | |||
|
653 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); | |||
|
654 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); | |||
|
655 | ||||
|
656 | m_dataset->scrollDomain(dx, dy); | |||
|
657 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |||
522 | } |
|
658 | } | |
523 |
|
659 | |||
524 | #include "moc_qchart.cpp" |
|
660 | #include "moc_qchart.cpp" |
@@ -76,11 +76,17 public: | |||||
76 | void removeAllSeries(); |
|
76 | void removeAllSeries(); | |
77 | QList<QAbstractSeries *> series() const; |
|
77 | QList<QAbstractSeries *> series() const; | |
78 |
|
78 | |||
|
79 | //depreciated shit//////////////////////////////////////////////////. | |||
79 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
80 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); | |
80 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
81 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); | |
81 |
|
82 | |||
82 | QAbstractAxis *axisX(QAbstractSeries *series = 0) const; |
|
83 | QAbstractAxis *axisX(QAbstractSeries *series = 0) const; | |
83 | QAbstractAxis *axisY(QAbstractSeries *series = 0) const; |
|
84 | QAbstractAxis *axisY(QAbstractSeries *series = 0) const; | |
|
85 | ///////////////////////////////////////////////////////////////////// | |||
|
86 | ||||
|
87 | void addAxis(QAbstractAxis *axis,Qt::Alignment aligment); | |||
|
88 | void removeAxis(QAbstractAxis *axis); | |||
|
89 | QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const; | |||
84 |
|
90 | |||
85 | void createDefaultAxes(); |
|
91 | void createDefaultAxes(); | |
86 |
|
92 | |||
@@ -107,9 +113,11 public: | |||||
107 | AnimationOptions animationOptions() const; |
|
113 | AnimationOptions animationOptions() const; | |
108 |
|
114 | |||
109 | void zoomIn(); |
|
115 | void zoomIn(); | |
110 | void zoomIn(const QRectF &rect); |
|
|||
111 | void zoomOut(); |
|
116 | void zoomOut(); | |
|
117 | ||||
|
118 | void zoomIn(const QRectF &rect); | |||
112 | void zoom(qreal factor); |
|
119 | void zoom(qreal factor); | |
|
120 | ||||
113 | void scroll(qreal dx, qreal dy); |
|
121 | void scroll(qreal dx, qreal dy); | |
114 |
|
122 | |||
115 | QLegend *legend() const; |
|
123 | QLegend *legend() const; | |
@@ -126,6 +134,10 protected: | |||||
126 | QScopedPointer<QChartPrivate> d_ptr; |
|
134 | QScopedPointer<QChartPrivate> d_ptr; | |
127 | friend class QLegend; |
|
135 | friend class QLegend; | |
128 | friend class DeclarativeChart; |
|
136 | friend class DeclarativeChart; | |
|
137 | friend class ChartDataSet; | |||
|
138 | friend class ChartPresenter; | |||
|
139 | friend class ChartThemeManager; | |||
|
140 | friend class QAbstractSeries; | |||
129 | Q_DISABLE_COPY(QChart) |
|
141 | Q_DISABLE_COPY(QChart) | |
130 | }; |
|
142 | }; | |
131 |
|
143 |
@@ -30,23 +30,32 | |||||
30 | #ifndef QCHART_P_H |
|
30 | #ifndef QCHART_P_H | |
31 | #define QCHART_P_H |
|
31 | #define QCHART_P_H | |
32 |
|
32 | |||
33 |
#include "q |
|
33 | #include "qchartglobal.h" | |
34 | #include "chartpresenter_p.h" |
|
|||
35 | #include "chartdataset_p.h" |
|
|||
36 |
|
34 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
36 | |||
39 | class QChart; |
|
37 | class QChart; | |
|
38 | class ChartThemeManager; | |||
|
39 | class ChartPresenter; | |||
|
40 | class QLegend; | |||
|
41 | class ChartDataSet; | |||
40 |
|
42 | |||
41 |
|
|
43 | class QChartPrivate | |
42 | { |
|
44 | { | |
43 | QChartPrivate(); |
|
45 | ||
|
46 | public: | |||
|
47 | QChartPrivate(QChart *q); | |||
44 | ~QChartPrivate(); |
|
48 | ~QChartPrivate(); | |
|
49 | QChart *q_ptr; | |||
45 | QLegend *m_legend; |
|
50 | QLegend *m_legend; | |
46 | ChartDataSet *m_dataset; |
|
51 | ChartDataSet *m_dataset; | |
47 | ChartPresenter *m_presenter; |
|
52 | ChartPresenter *m_presenter; | |
|
53 | ChartThemeManager *m_themeManager; | |||
48 |
|
54 | |||
49 | void createConnections(); |
|
55 | void zoomIn(qreal factor); | |
|
56 | void zoomOut(qreal factor); | |||
|
57 | void zoomIn(const QRectF &rect); | |||
|
58 | void scroll(qreal dx, qreal dy); | |||
50 | }; |
|
59 | }; | |
51 |
|
60 | |||
52 | QTCOMMERCIALCHART_END_NAMESPACE |
|
61 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -143,8 +143,8 QScatterSeries::QScatterSeries(QObject *parent) | |||||
143 | QScatterSeries::~QScatterSeries() |
|
143 | QScatterSeries::~QScatterSeries() | |
144 | { |
|
144 | { | |
145 | Q_D(QScatterSeries); |
|
145 | Q_D(QScatterSeries); | |
146 |
if (d->m_ |
|
146 | if (d->m_chart) | |
147 |
d->m_ |
|
147 | d->m_chart->removeSeries(this); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | QAbstractSeries::SeriesType QScatterSeries::type() const |
|
150 | QAbstractSeries::SeriesType QScatterSeries::type() const | |
@@ -254,14 +254,32 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q) | |||||
254 | { |
|
254 | { | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | ChartElement *QScatterSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
257 | void QScatterSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
258 | { |
|
258 | { | |
259 | Q_Q(QScatterSeries); |
|
259 | Q_Q(QScatterSeries); | |
260 |
ScatterChartItem *scatter = new ScatterChartItem(q, |
|
260 | ScatterChartItem *scatter = new ScatterChartItem(q,parent); | |
261 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
261 | m_item.reset(scatter); | |
262 | scatter->setAnimation(new XYAnimation(scatter)); |
|
262 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
263 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
263 | } | |
264 | return scatter; |
|
264 | ||
|
265 | void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |||
|
266 | { | |||
|
267 | Q_Q(QScatterSeries); | |||
|
268 | QPen pen; | |||
|
269 | QBrush brush; | |||
|
270 | const QList<QColor> colors = theme->seriesColors(); | |||
|
271 | const QList<QGradient> gradients = theme->seriesGradients(); | |||
|
272 | ||||
|
273 | if (forced || pen == m_pen) { | |||
|
274 | pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); | |||
|
275 | pen.setWidthF(2); | |||
|
276 | q->setPen(pen); | |||
|
277 | } | |||
|
278 | ||||
|
279 | if (forced || brush == m_brush) { | |||
|
280 | QBrush brush(colors.at(index % colors.size())); | |||
|
281 | q->setBrush(brush); | |||
|
282 | } | |||
265 | } |
|
283 | } | |
266 |
|
284 | |||
267 | #include "moc_qscatterseries.cpp" |
|
285 | #include "moc_qscatterseries.cpp" |
@@ -38,7 +38,8 class QScatterSeriesPrivate: public QXYSeriesPrivate | |||||
38 | { |
|
38 | { | |
39 | public: |
|
39 | public: | |
40 | QScatterSeriesPrivate(QScatterSeries *q); |
|
40 | QScatterSeriesPrivate(QScatterSeries *q); | |
41 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
41 | void initializeGraphics(QGraphicsItem* parent); | |
|
42 | void initializeTheme(int index, ChartTheme* theme, bool forced = false); | |||
42 |
|
43 | |||
43 | private: |
|
44 | private: | |
44 | QScatterSeries::MarkerShape m_shape; |
|
45 | QScatterSeries::MarkerShape m_shape; |
@@ -22,6 +22,7 | |||||
22 | #include "qscatterseries.h" |
|
22 | #include "qscatterseries.h" | |
23 | #include "qscatterseries_p.h" |
|
23 | #include "qscatterseries_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
|
25 | #include "domain_p.h" | |||
25 | #include <QPainter> |
|
26 | #include <QPainter> | |
26 | #include <QGraphicsScene> |
|
27 | #include <QGraphicsScene> | |
27 | #include <QDebug> |
|
28 | #include <QDebug> | |
@@ -29,9 +30,8 | |||||
29 |
|
30 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
32 | |||
32 |
ScatterChartItem::ScatterChartItem(QScatterSeries *series, |
|
33 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem* item) | |
33 |
: XYChart(series, |
|
34 | : XYChart(series,item), | |
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
|||
35 | m_series(series), |
|
35 | m_series(series), | |
36 | m_items(this), |
|
36 | m_items(this), | |
37 | m_visible(true), |
|
37 | m_visible(true), | |
@@ -93,12 +93,12 void ScatterChartItem::deletePoints(int count) | |||||
93 |
|
93 | |||
94 | void ScatterChartItem::markerSelected(QGraphicsItem *marker) |
|
94 | void ScatterChartItem::markerSelected(QGraphicsItem *marker) | |
95 | { |
|
95 | { | |
96 | emit XYChart::clicked(calculateDomainPoint(m_markerMap[marker])); |
|
96 | emit XYChart::clicked(domain()->calculateDomainPoint(m_markerMap[marker])); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void ScatterChartItem::markerHovered(QGraphicsItem *marker, bool state) |
|
99 | void ScatterChartItem::markerHovered(QGraphicsItem *marker, bool state) | |
100 | { |
|
100 | { | |
101 | emit XYChart::hovered(calculateDomainPoint(m_markerMap[marker]), state); |
|
101 | emit XYChart::hovered(domain()->calculateDomainPoint(m_markerMap[marker]), state); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void ScatterChartItem::updateGeometry() |
|
104 | void ScatterChartItem::updateGeometry() | |
@@ -123,21 +123,22 void ScatterChartItem::updateGeometry() | |||||
123 |
|
123 | |||
124 | QList<QGraphicsItem *> items = m_items.childItems(); |
|
124 | QList<QGraphicsItem *> items = m_items.childItems(); | |
125 |
|
125 | |||
|
126 | QRectF clipRect(QPointF(0,0),domain()->size()); | |||
|
127 | ||||
126 | for (int i = 0; i < points.size(); i++) { |
|
128 | for (int i = 0; i < points.size(); i++) { | |
127 | QGraphicsItem *item = items.at(i); |
|
129 | QGraphicsItem *item = items.at(i); | |
128 | const QPointF &point = points.at(i); |
|
130 | const QPointF &point = points.at(i); | |
129 | const QRectF &rect = item->boundingRect(); |
|
131 | const QRectF &rect = item->boundingRect(); | |
130 | m_markerMap[item] = point; |
|
132 | m_markerMap[item] = point; | |
131 | item->setPos(point.x() - rect.width() / 2, point.y() - rect.height() / 2); |
|
133 | item->setPos(point.x() - rect.width() / 2, point.y() - rect.height() / 2); | |
132 |
if (!m_visible || !clipRect |
|
134 | if (!m_visible || !clipRect.contains(point)) | |
133 | item->setVisible(false); |
|
135 | item->setVisible(false); | |
134 | else |
|
136 | else | |
135 | item->setVisible(true); |
|
137 | item->setVisible(true); | |
136 | } |
|
138 | } | |
137 |
|
139 | |||
138 | prepareGeometryChange(); |
|
140 | prepareGeometryChange(); | |
139 |
m_rect = clipRect |
|
141 | m_rect = clipRect; | |
140 | setPos(origin()); |
|
|||
141 | } |
|
142 | } | |
142 |
|
143 | |||
143 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
144 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
@@ -39,12 +39,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
39 |
|
39 | |||
40 | class QScatterSeries; |
|
40 | class QScatterSeries; | |
41 |
|
41 | |||
42 |
class ScatterChartItem : public XYChart |
|
42 | class ScatterChartItem : public XYChart | |
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 | Q_INTERFACES(QGraphicsItem) |
|
45 | Q_INTERFACES(QGraphicsItem) | |
46 | public: |
|
46 | public: | |
47 |
explicit ScatterChartItem(QScatterSeries *series, |
|
47 | explicit ScatterChartItem(QScatterSeries *series, QGraphicsItem* item = 0); | |
48 |
|
48 | |||
49 | public: |
|
49 | public: | |
50 | //from QGraphicsItem |
|
50 | //from QGraphicsItem |
@@ -114,8 +114,8 QSplineSeries::QSplineSeries(QObject *parent) | |||||
114 | QSplineSeries::~QSplineSeries() |
|
114 | QSplineSeries::~QSplineSeries() | |
115 | { |
|
115 | { | |
116 | Q_D(QSplineSeries); |
|
116 | Q_D(QSplineSeries); | |
117 |
if (d->m_ |
|
117 | if (d->m_chart) | |
118 |
d->m_ |
|
118 | d->m_chart->removeSeries(this); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | QAbstractSeries::SeriesType QSplineSeries::type() const |
|
121 | QAbstractSeries::SeriesType QSplineSeries::type() const | |
@@ -244,14 +244,38 void QSplineSeriesPrivate::updateControlPoints() | |||||
244 | } |
|
244 | } | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | ChartElement *QSplineSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
247 | void QSplineSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
248 | { |
|
248 | { | |
249 | Q_Q(QSplineSeries); |
|
249 | Q_Q(QSplineSeries); | |
250 |
SplineChartItem *spline = new SplineChartItem(q, |
|
250 | SplineChartItem *spline = new SplineChartItem(q,parent); | |
251 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
251 | m_item.reset(spline); | |
252 | spline->setAnimation(new SplineAnimation(spline)); |
|
252 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
253 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
253 | } | |
254 | return spline; |
|
254 | ||
|
255 | void QSplineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |||
|
256 | { | |||
|
257 | Q_Q(QSplineSeries); | |||
|
258 | const QList<QColor> colors = theme->seriesColors(); | |||
|
259 | ||||
|
260 | QPen pen; | |||
|
261 | if (forced || pen == m_pen) { | |||
|
262 | pen.setColor(colors.at(index % colors.size())); | |||
|
263 | pen.setWidthF(2); | |||
|
264 | q->setPen(pen); | |||
|
265 | } | |||
|
266 | } | |||
|
267 | ||||
|
268 | ||||
|
269 | void QSplineSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |||
|
270 | { | |||
|
271 | SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data()); | |||
|
272 | Q_ASSERT(item); | |||
|
273 | if (options.testFlag(QChart::SeriesAnimations)) { | |||
|
274 | item->setAnimation(new SplineAnimation(item)); | |||
|
275 | }else{ | |||
|
276 | item->setAnimation(0); | |||
|
277 | } | |||
|
278 | QAbstractSeriesPrivate::initializeAnimations(options); | |||
255 | } |
|
279 | } | |
256 |
|
280 | |||
257 | #include "moc_qsplineseries.cpp" |
|
281 | #include "moc_qsplineseries.cpp" |
@@ -39,9 +39,12 class QSplineSeriesPrivate: public QLineSeriesPrivate | |||||
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
|||
43 | QSplineSeriesPrivate(QSplineSeries *q); |
|
42 | QSplineSeriesPrivate(QSplineSeries *q); | |
44 |
|
43 | |||
|
44 | void initializeTheme(int index, ChartTheme* theme, bool forced = false); | |||
|
45 | void initializeGraphics(QGraphicsItem* parent); | |||
|
46 | void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); | |||
|
47 | ||||
45 | QPointF controlPoint(int index) const; |
|
48 | QPointF controlPoint(int index) const; | |
46 |
|
49 | |||
47 | public Q_SLOTS: |
|
50 | public Q_SLOTS: |
@@ -22,14 +22,14 | |||||
22 | #include "qsplineseries_p.h" |
|
22 | #include "qsplineseries_p.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "splineanimation_p.h" |
|
24 | #include "splineanimation_p.h" | |
|
25 | #include "domain_p.h" | |||
25 | #include <QPainter> |
|
26 | #include <QPainter> | |
26 | #include <QGraphicsSceneMouseEvent> |
|
27 | #include <QGraphicsSceneMouseEvent> | |
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
30 | |||
30 |
SplineChartItem::SplineChartItem(QSplineSeries *series, |
|
31 | SplineChartItem::SplineChartItem(QSplineSeries *series, QGraphicsItem* item) | |
31 |
: XYChart(series, |
|
32 | : XYChart(series,item), | |
32 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
|||
33 | m_series(series), |
|
33 | m_series(series), | |
34 | m_pointsVisible(false), |
|
34 | m_pointsVisible(false), | |
35 | m_animation(0) |
|
35 | m_animation(0) | |
@@ -101,7 +101,7 void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> | |||||
101 |
|
101 | |||
102 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const |
|
102 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const | |
103 | { |
|
103 | { | |
104 |
return |
|
104 | return domain()->calculateGeometryPoint(m_series->d_func()->controlPoint(index)); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void SplineChartItem::updateGeometry() |
|
107 | void SplineChartItem::updateGeometry() | |
@@ -131,7 +131,7 void SplineChartItem::updateGeometry() | |||||
131 | // m_path = stroker.createStroke(splinePath); |
|
131 | // m_path = stroker.createStroke(splinePath); | |
132 | m_path = splinePath; |
|
132 | m_path = splinePath; | |
133 | m_rect = splinePath.boundingRect(); |
|
133 | m_rect = splinePath.boundingRect(); | |
134 | setPos(origin()); |
|
134 | ||
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | //handlers |
|
137 | //handlers | |
@@ -155,9 +155,9 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o | |||||
155 | Q_UNUSED(option) |
|
155 | Q_UNUSED(option) | |
156 |
|
156 | |||
157 | painter->save(); |
|
157 | painter->save(); | |
|
158 | painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); | |||
158 | painter->setPen(m_linePen); |
|
159 | painter->setPen(m_linePen); | |
159 | // painter->setBrush(m_linePen.color()); |
|
160 | // painter->setBrush(m_linePen.color()); | |
160 | painter->setClipRect(clipRect()); |
|
|||
161 |
|
161 | |||
162 | painter->drawPath(m_path); |
|
162 | painter->drawPath(m_path); | |
163 | if (m_pointsVisible) { |
|
163 | if (m_pointsVisible) { | |
@@ -169,19 +169,19 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o | |||||
169 |
|
169 | |||
170 | void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
170 | void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
171 | { |
|
171 | { | |
172 | emit XYChart::clicked(calculateDomainPoint(event->pos())); |
|
172 | emit XYChart::clicked(domain()->calculateDomainPoint(event->pos())); | |
173 | QGraphicsItem::mousePressEvent(event); |
|
173 | QGraphicsItem::mousePressEvent(event); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void SplineChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
176 | void SplineChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
177 | { |
|
177 | { | |
178 | emit XYChart::hovered(calculateDomainPoint(event->pos()), true); |
|
178 | emit XYChart::hovered(domain()->calculateDomainPoint(event->pos()), true); | |
179 | event->accept(); |
|
179 | event->accept(); | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | void SplineChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
182 | void SplineChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
183 | { |
|
183 | { | |
184 | emit XYChart::hovered(calculateDomainPoint(event->pos()), false); |
|
184 | emit XYChart::hovered(domain()->calculateDomainPoint(event->pos()), false); | |
185 | event->accept(); |
|
185 | event->accept(); | |
186 | } |
|
186 | } | |
187 |
|
187 |
@@ -37,12 +37,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
37 |
|
37 | |||
38 | class SplineAnimation; |
|
38 | class SplineAnimation; | |
39 |
|
39 | |||
40 |
class SplineChartItem : public XYChart |
|
40 | class SplineChartItem : public XYChart | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 | Q_INTERFACES(QGraphicsItem) |
|
43 | Q_INTERFACES(QGraphicsItem) | |
44 | public: |
|
44 | public: | |
45 |
SplineChartItem(QSplineSeries *series, |
|
45 | SplineChartItem(QSplineSeries *series, QGraphicsItem* item = 0); | |
46 |
|
46 | |||
47 | //from QGraphicsItem |
|
47 | //from QGraphicsItem | |
48 | QRectF boundingRect() const; |
|
48 | QRectF boundingRect() const; |
@@ -31,13 +31,14 INCLUDEPATH += ../include . | |||||
31 | SOURCES += \ |
|
31 | SOURCES += \ | |
32 | $$PWD/chartdataset.cpp \ |
|
32 | $$PWD/chartdataset.cpp \ | |
33 | $$PWD/chartpresenter.cpp \ |
|
33 | $$PWD/chartpresenter.cpp \ | |
34 | $$PWD/charttheme.cpp \ |
|
34 | $$PWD/chartthememanager.cpp \ | |
35 | $$PWD/domain.cpp \ |
|
35 | $$PWD/domain.cpp \ | |
36 | $$PWD/qchart.cpp \ |
|
36 | $$PWD/qchart.cpp \ | |
37 | $$PWD/qchartview.cpp \ |
|
37 | $$PWD/qchartview.cpp \ | |
38 | $$PWD/qabstractseries.cpp \ |
|
38 | $$PWD/qabstractseries.cpp \ | |
39 | $$PWD/chartbackground.cpp \ |
|
39 | $$PWD/chartbackground.cpp \ | |
40 | $$PWD/chartelement.cpp \ |
|
40 | $$PWD/chartelement.cpp \ | |
|
41 | $$PWD/chartitem.cpp \ | |||
41 | $$PWD/scroller.cpp \ |
|
42 | $$PWD/scroller.cpp \ | |
42 | $$PWD/chartlayout.cpp \ |
|
43 | $$PWD/chartlayout.cpp \ | |
43 | $$PWD/charttitle.cpp |
|
44 | $$PWD/charttitle.cpp | |
@@ -45,7 +46,7 PRIVATE_HEADERS += \ | |||||
45 | $$PWD/chartdataset_p.h \ |
|
46 | $$PWD/chartdataset_p.h \ | |
46 | $$PWD/chartitem_p.h \ |
|
47 | $$PWD/chartitem_p.h \ | |
47 | $$PWD/chartpresenter_p.h \ |
|
48 | $$PWD/chartpresenter_p.h \ | |
48 | $$PWD/charttheme_p.h \ |
|
49 | $$PWD/chartthememanager_p.h \ | |
49 | $$PWD/domain_p.h \ |
|
50 | $$PWD/domain_p.h \ | |
50 | $$PWD/chartbackground_p.h \ |
|
51 | $$PWD/chartbackground_p.h \ | |
51 | $$PWD/chartelement_p.h \ |
|
52 | $$PWD/chartelement_p.h \ |
@@ -30,33 +30,15 | |||||
30 | #ifndef CHARTTHEME_H |
|
30 | #ifndef CHARTTHEME_H | |
31 | #define CHARTTHEME_H |
|
31 | #define CHARTTHEME_H | |
32 |
|
32 | |||
33 |
#include " |
|
33 | #include "chartthememanager_p.h" | |
34 | #include "qchart.h" |
|
|||
35 | #include <QColor> |
|
34 | #include <QColor> | |
36 | #include <QGradientStops> |
|
35 | #include <QGradientStops> | |
37 |
|
36 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
38 | |||
40 | class ChartItem; |
|
|||
41 | class LineChartItem; |
|
|||
42 | class QLineSeries; |
|
|||
43 | class AbstractBarChartItem; |
|
|||
44 | class QAbstractBarSeries; |
|
|||
45 | class StackedBarChartItem; |
|
|||
46 | class QStackedBarSeries; |
|
|||
47 | class QPercentBarSeries; |
|
|||
48 | class PercentBarChartItem; |
|
|||
49 | class QScatterSeries; |
|
|||
50 | class ScatterChartItem; |
|
|||
51 | class PieChartItem; |
|
|||
52 | class QPieSeries; |
|
|||
53 | class SplineChartItem; |
|
|||
54 | class QSplineSeries; |
|
|||
55 | class AreaChartItem; |
|
|||
56 | class QAreaSeries; |
|
|||
57 |
|
||||
58 | class ChartTheme |
|
39 | class ChartTheme | |
59 | { |
|
40 | { | |
|
41 | ||||
60 | public: |
|
42 | public: | |
61 | enum BackgroundShadesMode { |
|
43 | enum BackgroundShadesMode { | |
62 | BackgroundShadesNone = 0, |
|
44 | BackgroundShadesNone = 0, | |
@@ -66,26 +48,23 public: | |||||
66 | }; |
|
48 | }; | |
67 |
|
49 | |||
68 | protected: |
|
50 | protected: | |
69 |
explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight) |
|
51 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight):m_id(id), | |
|
52 | m_backgroundShades(BackgroundShadesNone), | |||
|
53 | m_backgroundDropShadowEnabled(false){}; | |||
70 | public: |
|
54 | public: | |
71 | static ChartTheme *createTheme(QChart::ChartTheme theme); |
|
|||
72 | QChart::ChartTheme id() const { return m_id; } |
|
55 | QChart::ChartTheme id() const { return m_id; } | |
73 | void decorate(QChart *chart); |
|
56 | QList<QGradient> seriesGradients() const { return m_seriesGradients; } | |
74 | void decorate(QLegend *legend); |
|
57 | QList<QColor> seriesColors() const { return m_seriesColors; } | |
75 | void decorate(QAbstractBarSeries *series, int index); |
|
58 | QLinearGradient chartBackgroundGradient() const { return m_chartBackgroundGradient; } | |
76 | void decorate(QLineSeries *series, int index); |
|
59 | QFont masterFont() const { return m_masterFont; } | |
77 | void decorate(QAreaSeries *series, int index); |
|
60 | QFont labelFont() const { return m_labelFont; } | |
78 | void decorate(QScatterSeries *series, int index); |
|
61 | QBrush labelBrush() const { return m_labelBrush; } | |
79 | void decorate(QPieSeries *series, int index); |
|
62 | QPen axisLinePen() const { return m_axisLinePen; } | |
80 | void decorate(QSplineSeries *series, int index); |
|
63 | QPen backgroundShadesPen() const { return m_backgroundShadesPen; } | |
81 | void decorate(QAbstractAxis *axis); |
|
64 | QBrush backgroundShadesBrush() const { return m_backgroundShadesBrush; } | |
82 | void setForced(bool enabled); |
|
65 | BackgroundShadesMode backgroundShades() const { return m_backgroundShades; } | |
83 | bool isForced() { return m_force; } |
|
66 | bool isBackgroundDropShadowEnabled() const { return m_backgroundDropShadowEnabled; } | |
84 |
|
67 | QPen girdLinePen() const { return m_gridLinePen; } | ||
85 | public: // utils |
|
|||
86 | void generateSeriesGradients(); |
|
|||
87 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); |
|
|||
88 | static QColor colorAt(const QGradient &gradient, qreal pos); |
|
|||
89 |
|
68 | |||
90 | protected: |
|
69 | protected: | |
91 | QChart::ChartTheme m_id; |
|
70 | QChart::ChartTheme m_id; | |
@@ -102,7 +81,7 protected: | |||||
102 | BackgroundShadesMode m_backgroundShades; |
|
81 | BackgroundShadesMode m_backgroundShades; | |
103 | bool m_backgroundDropShadowEnabled; |
|
82 | bool m_backgroundDropShadowEnabled; | |
104 | QPen m_gridLinePen; |
|
83 | QPen m_gridLinePen; | |
105 | bool m_force; |
|
84 | ||
106 | }; |
|
85 | }; | |
107 |
|
86 | |||
108 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -44,7 +44,7 public: | |||||
44 | m_seriesColors << QRgb(0x5cbf9b); |
|
44 | m_seriesColors << QRgb(0x5cbf9b); | |
45 | m_seriesColors << QRgb(0x009fbf); |
|
45 | m_seriesColors << QRgb(0x009fbf); | |
46 | m_seriesColors << QRgb(0xee7392); |
|
46 | m_seriesColors << QRgb(0xee7392); | |
47 | generateSeriesGradients(); |
|
47 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
48 |
|
48 | |||
49 | // Background |
|
49 | // Background | |
50 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
|
50 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
@@ -45,7 +45,7 public: | |||||
45 | m_seriesColors << QRgb(0x0c2673); |
|
45 | m_seriesColors << QRgb(0x0c2673); | |
46 | m_seriesColors << QRgb(0x5f3dba); |
|
46 | m_seriesColors << QRgb(0x5f3dba); | |
47 | m_seriesColors << QRgb(0x2fa3b4); |
|
47 | m_seriesColors << QRgb(0x2fa3b4); | |
48 | generateSeriesGradients(); |
|
48 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
|
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
@@ -45,7 +45,7 public: | |||||
45 | m_seriesColors << QRgb(0x88d41e); |
|
45 | m_seriesColors << QRgb(0x88d41e); | |
46 | m_seriesColors << QRgb(0xff8e1a); |
|
46 | m_seriesColors << QRgb(0xff8e1a); | |
47 | m_seriesColors << QRgb(0x398ca3); |
|
47 | m_seriesColors << QRgb(0x398ca3); | |
48 | generateSeriesGradients(); |
|
48 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient; |
|
51 | QLinearGradient backgroundGradient; |
@@ -45,7 +45,7 public: | |||||
45 | m_seriesColors << QRgb(0xc35660); |
|
45 | m_seriesColors << QRgb(0xc35660); | |
46 | m_seriesColors << QRgb(0x536780); |
|
46 | m_seriesColors << QRgb(0x536780); | |
47 | m_seriesColors << QRgb(0x494345); |
|
47 | m_seriesColors << QRgb(0x494345); | |
48 | generateSeriesGradients(); |
|
48 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient; |
|
51 | QLinearGradient backgroundGradient; |
@@ -45,7 +45,7 public: | |||||
45 | m_seriesColors << QRgb(0xeb8817); |
|
45 | m_seriesColors << QRgb(0xeb8817); | |
46 | m_seriesColors << QRgb(0x7b7f8c); |
|
46 | m_seriesColors << QRgb(0x7b7f8c); | |
47 | m_seriesColors << QRgb(0xbf593e); |
|
47 | m_seriesColors << QRgb(0xbf593e); | |
48 | generateSeriesGradients(); |
|
48 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
|
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
@@ -45,7 +45,7 public: | |||||
45 | m_seriesColors << QRgb(0xffab03); |
|
45 | m_seriesColors << QRgb(0xffab03); | |
46 | m_seriesColors << QRgb(0x038e9b); |
|
46 | m_seriesColors << QRgb(0x038e9b); | |
47 | m_seriesColors << QRgb(0xff4a41); |
|
47 | m_seriesColors << QRgb(0xff4a41); | |
48 | generateSeriesGradients(); |
|
48 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
|
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
@@ -45,7 +45,7 public: | |||||
45 | m_seriesColors << QRgb(0xf6a625); |
|
45 | m_seriesColors << QRgb(0xf6a625); | |
46 | m_seriesColors << QRgb(0x6d5fd5); |
|
46 | m_seriesColors << QRgb(0x6d5fd5); | |
47 | m_seriesColors << QRgb(0xbf593e); |
|
47 | m_seriesColors << QRgb(0xbf593e); | |
48 | generateSeriesGradients(); |
|
48 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient; |
|
51 | QLinearGradient backgroundGradient; |
@@ -106,7 +106,7 public: | |||||
106 | m_seriesColors << QRgb(0x92ca66); |
|
106 | m_seriesColors << QRgb(0x92ca66); | |
107 | m_seriesColors << QRgb(0xeba85f); |
|
107 | m_seriesColors << QRgb(0xeba85f); | |
108 | m_seriesColors << QRgb(0xfc5751); |
|
108 | m_seriesColors << QRgb(0xfc5751); | |
109 | generateSeriesGradients(); |
|
109 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
110 |
|
110 | |||
111 | // Background |
|
111 | // Background | |
112 | QLinearGradient backgroundGradient; |
|
112 | QLinearGradient backgroundGradient; | |
@@ -152,7 +152,7 public: | |||||
152 | m_seriesColors << QRgb(0x92ca66); |
|
152 | m_seriesColors << QRgb(0x92ca66); | |
153 | m_seriesColors << QRgb(0xeba85f); |
|
153 | m_seriesColors << QRgb(0xeba85f); | |
154 | m_seriesColors << QRgb(0xfc5751); |
|
154 | m_seriesColors << QRgb(0xfc5751); | |
155 | generateSeriesGradients(); |
|
155 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
156 |
|
156 | |||
157 | // Background |
|
157 | // Background | |
158 | QLinearGradient backgroundGradient; |
|
158 | QLinearGradient backgroundGradient; |
@@ -2,6 +2,7 INCLUDEPATH += $$PWD | |||||
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | THEMES += \ |
|
4 | THEMES += \ | |
|
5 | $$PWD/charttheme_p.h \ | |||
5 | $$PWD/chartthemesystem_p.h \ |
|
6 | $$PWD/chartthemesystem_p.h \ | |
6 | $$PWD/chartthemelight_p.h \ |
|
7 | $$PWD/chartthemelight_p.h \ | |
7 | $$PWD/chartthemebluecerulean_p.h \ |
|
8 | $$PWD/chartthemebluecerulean_p.h \ |
@@ -22,6 +22,7 | |||||
22 | #include "qxyseries_p.h" |
|
22 | #include "qxyseries_p.h" | |
23 | #include "domain_p.h" |
|
23 | #include "domain_p.h" | |
24 | #include "qvalueaxis.h" |
|
24 | #include "qvalueaxis.h" | |
|
25 | #include "xychart_p.h" | |||
25 |
|
26 | |||
26 | #include "qxylegendmarker.h" |
|
27 | #include "qxylegendmarker.h" | |
27 |
|
28 | |||
@@ -418,7 +419,7 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) | |||||
418 | { |
|
419 | { | |
419 | } |
|
420 | } | |
420 |
|
421 | |||
421 |
void QXYSeriesPrivate:: |
|
422 | void QXYSeriesPrivate::initializeDomain() | |
422 | { |
|
423 | { | |
423 | qreal minX(0); |
|
424 | qreal minX(0); | |
424 | qreal minY(0); |
|
425 | qreal minY(0); | |
@@ -445,7 +446,7 void QXYSeriesPrivate::scaleDomain(Domain &domain) | |||||
445 | } |
|
446 | } | |
446 | } |
|
447 | } | |
447 |
|
448 | |||
448 |
domain |
|
449 | domain()->setRange(minX, maxX, minY, maxY); | |
449 | } |
|
450 | } | |
450 |
|
451 | |||
451 | QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
452 | QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) | |
@@ -455,9 +456,9 QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) | |||||
455 | return list << new QXYLegendMarker(q,legend); |
|
456 | return list << new QXYLegendMarker(q,legend); | |
456 | } |
|
457 | } | |
457 |
|
458 | |||
458 |
void QXYSeriesPrivate::initializeAx |
|
459 | void QXYSeriesPrivate::initializeAxes() | |
459 | { |
|
460 | { | |
460 | Q_UNUSED(axis); |
|
461 | ||
461 | } |
|
462 | } | |
462 |
|
463 | |||
463 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
464 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
@@ -466,6 +467,24 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orient | |||||
466 | return QAbstractAxis::AxisTypeValue; |
|
467 | return QAbstractAxis::AxisTypeValue; | |
467 | } |
|
468 | } | |
468 |
|
469 | |||
|
470 | QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |||
|
471 | { | |||
|
472 | Q_UNUSED(orientation); | |||
|
473 | return 0; | |||
|
474 | } | |||
|
475 | ||||
|
476 | void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |||
|
477 | { | |||
|
478 | XYChart *item = static_cast<XYChart *>(m_item.data()); | |||
|
479 | Q_ASSERT(item); | |||
|
480 | if (options.testFlag(QChart::SeriesAnimations)) { | |||
|
481 | item->setAnimation(new XYAnimation(item)); | |||
|
482 | }else{ | |||
|
483 | item->setAnimation(0); | |||
|
484 | } | |||
|
485 | QAbstractSeriesPrivate::initializeAnimations(options); | |||
|
486 | } | |||
|
487 | ||||
469 | #include "moc_qxyseries.cpp" |
|
488 | #include "moc_qxyseries.cpp" | |
470 | #include "moc_qxyseries_p.cpp" |
|
489 | #include "moc_qxyseries_p.cpp" | |
471 |
|
490 |
@@ -44,11 +44,14 class QXYSeriesPrivate: public QAbstractSeriesPrivate | |||||
44 | public: |
|
44 | public: | |
45 | QXYSeriesPrivate(QXYSeries *q); |
|
45 | QXYSeriesPrivate(QXYSeries *q); | |
46 |
|
46 | |||
47 |
void |
|
47 | void initializeDomain(); | |
|
48 | void initializeAxes(); | |||
|
49 | void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); | |||
|
50 | ||||
48 | QList<QLegendMarker*> createLegendMarkers(QLegend* legend); |
|
51 | QList<QLegendMarker*> createLegendMarkers(QLegend* legend); | |
49 |
|
52 | |||
50 | void initializeAxis(QAbstractAxis *axis); |
|
|||
51 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
53 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
|
54 | QAbstractAxis* createDefaultAxis(Qt::Orientation orientation) const; | |||
52 |
|
55 | |||
53 | Q_SIGNALS: |
|
56 | Q_SIGNALS: | |
54 | void updated(); |
|
57 | void updated(); |
@@ -32,12 +32,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
32 |
|
32 | |||
33 | //TODO: optimize : remove points which are not visible |
|
33 | //TODO: optimize : remove points which are not visible | |
34 |
|
34 | |||
35 |
XYChart::XYChart(QXYSeries *series, |
|
35 | XYChart::XYChart(QXYSeries *series,QGraphicsItem* item): | |
36 |
|
|
36 | ChartItem(series->d_func(),item), | |
37 | m_minX(0), |
|
|||
38 | m_maxX(0), |
|
|||
39 | m_minY(0), |
|
|||
40 | m_maxY(0), |
|
|||
41 | m_series(series), |
|
37 | m_series(series), | |
42 | m_animation(0), |
|
38 | m_animation(0), | |
43 | m_dirty(true) |
|
39 | m_dirty(true) | |
@@ -55,11 +51,6 void XYChart::setGeometryPoints(const QVector<QPointF>& points) | |||||
55 | m_points = points; |
|
51 | m_points = points; | |
56 | } |
|
52 | } | |
57 |
|
53 | |||
58 | void XYChart::setClipRect(const QRectF &rect) |
|
|||
59 | { |
|
|||
60 | m_clipRect = rect; |
|
|||
61 | } |
|
|||
62 |
|
||||
63 | void XYChart::setAnimation(XYAnimation *animation) |
|
54 | void XYChart::setAnimation(XYAnimation *animation) | |
64 | { |
|
55 | { | |
65 | m_animation = animation; |
|
56 | m_animation = animation; | |
@@ -70,51 +61,6 void XYChart::setDirty(bool dirty) | |||||
70 | m_dirty = dirty; |
|
61 | m_dirty = dirty; | |
71 | } |
|
62 | } | |
72 |
|
63 | |||
73 | QPointF XYChart::calculateGeometryPoint(const QPointF &point) const |
|
|||
74 | { |
|
|||
75 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
|||
76 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
|||
77 | qreal x = (point.x() - m_minX) * deltaX; |
|
|||
78 | qreal y = (point.y() - m_minY) * -deltaY + m_size.height(); |
|
|||
79 | return QPointF(x, y); |
|
|||
80 | } |
|
|||
81 |
|
||||
82 | QPointF XYChart::calculateGeometryPoint(int index) const |
|
|||
83 | { |
|
|||
84 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
|||
85 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
|||
86 | const QList<QPointF>& vector = m_series->points(); |
|
|||
87 | qreal x = (vector[index].x() - m_minX) * deltaX; |
|
|||
88 | qreal y = (vector[index].y() - m_minY) * -deltaY + m_size.height(); |
|
|||
89 | return QPointF(x, y); |
|
|||
90 | } |
|
|||
91 |
|
||||
92 | QVector<QPointF> XYChart::calculateGeometryPoints() const |
|
|||
93 | { |
|
|||
94 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
|||
95 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
|||
96 |
|
||||
97 | QVector<QPointF> result; |
|
|||
98 | result.resize(m_series->count()); |
|
|||
99 | const QList<QPointF>& vector = m_series->points(); |
|
|||
100 | for (int i = 0; i < m_series->count(); ++i) { |
|
|||
101 | qreal x = (vector[i].x() - m_minX) * deltaX; |
|
|||
102 | qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height(); |
|
|||
103 | result[i].setX(x); |
|
|||
104 | result[i].setY(y); |
|
|||
105 | } |
|
|||
106 | return result; |
|
|||
107 | } |
|
|||
108 |
|
||||
109 | QPointF XYChart::calculateDomainPoint(const QPointF &point) const |
|
|||
110 | { |
|
|||
111 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
|||
112 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
|||
113 | qreal x = point.x() / deltaX + m_minX; |
|
|||
114 | qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY; |
|
|||
115 | return QPointF(x, y); |
|
|||
116 | } |
|
|||
117 |
|
||||
118 | void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index) |
|
64 | void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index) | |
119 | { |
|
65 | { | |
120 |
|
66 | |||
@@ -139,10 +85,10 void XYChart::handlePointAdded(int index) | |||||
139 | QVector<QPointF> points; |
|
85 | QVector<QPointF> points; | |
140 |
|
86 | |||
141 | if (m_dirty) { |
|
87 | if (m_dirty) { | |
142 | points = calculateGeometryPoints(); |
|
88 | points = domain()->calculateGeometryPoints(m_series->points()); | |
143 | } else { |
|
89 | } else { | |
144 | points = m_points; |
|
90 | points = m_points; | |
145 | QPointF point = calculateGeometryPoint(index); |
|
91 | QPointF point = domain()->calculateGeometryPoint(m_series->points()[index]); | |
146 | points.insert(index, point); |
|
92 | points.insert(index, point); | |
147 | } |
|
93 | } | |
148 |
|
94 | |||
@@ -157,7 +103,7 void XYChart::handlePointRemoved(int index) | |||||
157 | QVector<QPointF> points; |
|
103 | QVector<QPointF> points; | |
158 |
|
104 | |||
159 | if (m_dirty) { |
|
105 | if (m_dirty) { | |
160 | points = calculateGeometryPoints(); |
|
106 | points = domain()->calculateGeometryPoints(m_series->points()); | |
161 | } else { |
|
107 | } else { | |
162 | points = m_points; |
|
108 | points = m_points; | |
163 | points.remove(index); |
|
109 | points.remove(index); | |
@@ -174,9 +120,9 void XYChart::handlePointReplaced(int index) | |||||
174 | QVector<QPointF> points; |
|
120 | QVector<QPointF> points; | |
175 |
|
121 | |||
176 | if (m_dirty) { |
|
122 | if (m_dirty) { | |
177 | points = calculateGeometryPoints(); |
|
123 | points = domain()->calculateGeometryPoints(m_series->points()); | |
178 | } else { |
|
124 | } else { | |
179 | QPointF point = calculateGeometryPoint(index); |
|
125 | QPointF point = domain()->calculateGeometryPoint(m_series->points()[index]); | |
180 | points = m_points; |
|
126 | points = m_points; | |
181 | points.replace(index, point); |
|
127 | points.replace(index, point); | |
182 | } |
|
128 | } | |
@@ -187,40 +133,20 void XYChart::handlePointReplaced(int index) | |||||
187 | void XYChart::handlePointsReplaced() |
|
133 | void XYChart::handlePointsReplaced() | |
188 | { |
|
134 | { | |
189 | // All the points were replaced -> recalculate |
|
135 | // All the points were replaced -> recalculate | |
190 | QVector<QPointF> points = calculateGeometryPoints(); |
|
136 | QVector<QPointF> points = domain()->calculateGeometryPoints(m_series->points()); | |
191 | updateChart(m_points, points, -1); |
|
137 | updateChart(m_points, points, -1); | |
192 | } |
|
138 | } | |
193 |
|
139 | |||
194 | void XYChart::handleDomainUpdated() |
|
140 | void XYChart::handleDomainUpdated() | |
195 | { |
|
141 | { | |
196 | m_minX = domain()->minX(); |
|
|||
197 | m_maxX = domain()->maxX(); |
|
|||
198 | m_minY = domain()->minY(); |
|
|||
199 | m_maxY = domain()->maxY(); |
|
|||
200 | if (isEmpty()) return; |
|
142 | if (isEmpty()) return; | |
201 |
|
143 | QVector<QPointF> points = domain()->calculateGeometryPoints(m_series->points()); | ||
202 | QVector<QPointF> points = calculateGeometryPoints(); |
|
|||
203 |
|
||||
204 | updateChart(m_points, points); |
|
|||
205 | } |
|
|||
206 |
|
||||
207 | void XYChart::handleGeometryChanged(const QRectF &rect) |
|
|||
208 | { |
|
|||
209 | Q_ASSERT(rect.isValid()); |
|
|||
210 | m_size = rect.size(); |
|
|||
211 | m_clipRect = rect.translated(-rect.topLeft()); |
|
|||
212 | m_origin = rect.topLeft(); |
|
|||
213 |
|
||||
214 | if (isEmpty()) return; |
|
|||
215 |
|
||||
216 | QVector<QPointF> points = calculateGeometryPoints(); |
|
|||
217 |
|
||||
218 | updateChart(m_points, points); |
|
144 | updateChart(m_points, points); | |
219 | } |
|
145 | } | |
220 |
|
146 | |||
221 | bool XYChart::isEmpty() |
|
147 | bool XYChart::isEmpty() | |
222 | { |
|
148 | { | |
223 | return !m_clipRect.isValid() || qFuzzyCompare(m_maxX, m_minX) || qFuzzyCompare(m_maxY, m_minY) || m_series->points().isEmpty(); |
|
149 | return domain()->isEmpty() || m_series->points().isEmpty(); | |
224 | } |
|
150 | } | |
225 |
|
151 | |||
226 | #include "moc_xychart_p.cpp" |
|
152 | #include "moc_xychart_p.cpp" |
@@ -41,22 +41,16 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
41 | class ChartPresenter; |
|
41 | class ChartPresenter; | |
42 | class QXYSeries; |
|
42 | class QXYSeries; | |
43 |
|
43 | |||
44 |
class XYChart : public Chart |
|
44 | class XYChart : public ChartItem | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | public: |
|
47 | public: | |
48 |
explicit XYChart(QXYSeries *series, |
|
48 | explicit XYChart(QXYSeries *series,QGraphicsItem* item = 0); | |
49 | ~XYChart() {} |
|
49 | ~XYChart() {} | |
50 |
|
50 | |||
51 | void setGeometryPoints(const QVector<QPointF>& points); |
|
51 | void setGeometryPoints(const QVector<QPointF>& points); | |
52 | QVector<QPointF> geometryPoints() const { return m_points; } |
|
52 | QVector<QPointF> geometryPoints() const { return m_points; } | |
53 |
|
53 | |||
54 | void setClipRect(const QRectF &rect); |
|
|||
55 | QRectF clipRect() const { return m_clipRect; } |
|
|||
56 |
|
||||
57 | QSizeF size() const { return m_size; } |
|
|||
58 | QPointF origin() const { return m_origin; } |
|
|||
59 |
|
||||
60 | void setAnimation(XYAnimation *animation); |
|
54 | void setAnimation(XYAnimation *animation); | |
61 | ChartAnimation *animation() const { return m_animation; } |
|
55 | ChartAnimation *animation() const { return m_animation; } | |
62 | virtual void updateGeometry() = 0; |
|
56 | virtual void updateGeometry() = 0; | |
@@ -70,7 +64,6 public Q_SLOTS: | |||||
70 | void handlePointReplaced(int index); |
|
64 | void handlePointReplaced(int index); | |
71 | void handlePointsReplaced(); |
|
65 | void handlePointsReplaced(); | |
72 | void handleDomainUpdated(); |
|
66 | void handleDomainUpdated(); | |
73 | void handleGeometryChanged(const QRectF &size); |
|
|||
74 |
|
67 | |||
75 | Q_SIGNALS: |
|
68 | Q_SIGNALS: | |
76 | void clicked(const QPointF &point); |
|
69 | void clicked(const QPointF &point); | |
@@ -78,23 +71,12 Q_SIGNALS: | |||||
78 |
|
71 | |||
79 | protected: |
|
72 | protected: | |
80 | virtual void updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index = -1); |
|
73 | virtual void updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index = -1); | |
81 | QPointF calculateGeometryPoint(const QPointF &point) const; |
|
|||
82 | QPointF calculateGeometryPoint(int index) const; |
|
|||
83 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
|||
84 | QVector<QPointF> calculateGeometryPoints() const; |
|
|||
85 |
|
74 | |||
86 | private: |
|
75 | private: | |
87 | inline bool isEmpty(); |
|
76 | inline bool isEmpty(); | |
88 |
|
77 | |||
89 | protected: |
|
78 | protected: | |
90 | qreal m_minX; |
|
|||
91 | qreal m_maxX; |
|
|||
92 | qreal m_minY; |
|
|||
93 | qreal m_maxY; |
|
|||
94 | QXYSeries *m_series; |
|
79 | QXYSeries *m_series; | |
95 | QSizeF m_size; |
|
|||
96 | QPointF m_origin; |
|
|||
97 | QRectF m_clipRect; |
|
|||
98 | QVector<QPointF> m_points; |
|
80 | QVector<QPointF> m_points; | |
99 | XYAnimation *m_animation; |
|
81 | XYAnimation *m_animation; | |
100 | bool m_dirty; |
|
82 | bool m_dirty; |
This diff has been collapsed as it changes many lines, (544 lines changed) Show them Hide them | |||||
@@ -43,6 +43,8 QTEST_MAIN(tst_ChartDataSet) | |||||
43 | #include <qabstractaxis.h> |
|
43 | #include <qabstractaxis.h> | |
44 | #include <qvalueaxis.h> |
|
44 | #include <qvalueaxis.h> | |
45 | #include <qbarcategoryaxis.h> |
|
45 | #include <qbarcategoryaxis.h> | |
|
46 | #include <qcategoryaxis.h> | |||
|
47 | #include <qdatetimeaxis.h> | |||
46 | #include <qlineseries.h> |
|
48 | #include <qlineseries.h> | |
47 | #include <qareaseries.h> |
|
49 | #include <qareaseries.h> | |
48 | #include <qscatterseries.h> |
|
50 | #include <qscatterseries.h> | |
@@ -62,6 +64,8 Q_DECLARE_METATYPE(QAbstractAxis *) | |||||
62 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
64 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
63 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
65 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) | |
64 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
66 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) | |
|
67 | Q_DECLARE_METATYPE(Qt::Alignment) | |||
|
68 | Q_DECLARE_METATYPE(QList<Qt::Alignment>) | |||
65 | Q_DECLARE_METATYPE(QLineSeries *) |
|
69 | Q_DECLARE_METATYPE(QLineSeries *) | |
66 |
|
70 | |||
67 | class tst_ChartDataSet: public QObject { |
|
71 | class tst_ChartDataSet: public QObject { | |
@@ -79,26 +83,20 private Q_SLOTS: | |||||
79 | void chartdataset(); |
|
83 | void chartdataset(); | |
80 | void addSeries_data(); |
|
84 | void addSeries_data(); | |
81 | void addSeries(); |
|
85 | void addSeries(); | |
82 | void setAxisX_data(); |
|
|||
83 | void setAxisX(); |
|
|||
84 | void setAxisY_data(); |
|
|||
85 | void setAxisY(); |
|
|||
86 | void removeSeries_data(); |
|
86 | void removeSeries_data(); | |
87 | void removeSeries(); |
|
87 | void removeSeries(); | |
88 | void removeAllSeries_data(); |
|
88 | void removeAllSeries_data(); | |
89 | void removeAllSeries(); |
|
89 | void removeAllSeries(); | |
90 |
void |
|
90 | void addAxis_data(); | |
91 |
void |
|
91 | void addAxis(); | |
92 |
void |
|
92 | void removeAxis_data(); | |
93 | void seriesIndex(); |
|
93 | void removeAxis(); | |
94 |
void |
|
94 | void removeAllAxes_data(); | |
95 |
void |
|
95 | void removeAllAxes(); | |
96 |
void |
|
96 | void attachAxis_data(); | |
97 |
void |
|
97 | void attachAxis(); | |
98 |
void |
|
98 | void detachAxis_data(); | |
99 |
void |
|
99 | void detachAxis(); | |
100 | void scrollDomain_data(); |
|
|||
101 | void scrollDomain(); |
|
|||
102 |
|
100 | |||
103 | private: |
|
101 | private: | |
104 | ChartDataSet* m_dataset; |
|
102 | ChartDataSet* m_dataset; | |
@@ -117,7 +115,7 void tst_ChartDataSet::cleanupTestCase() | |||||
117 |
|
115 | |||
118 | void tst_ChartDataSet::init() |
|
116 | void tst_ChartDataSet::init() | |
119 | { |
|
117 | { | |
120 | m_dataset = new ChartDataSet(); |
|
118 | m_dataset = new ChartDataSet(0); | |
121 | } |
|
119 | } | |
122 |
|
120 | |||
123 |
|
121 | |||
@@ -136,14 +134,9 void tst_ChartDataSet::chartdataset_data() | |||||
136 |
|
134 | |||
137 | void tst_ChartDataSet::chartdataset() |
|
135 | void tst_ChartDataSet::chartdataset() | |
138 | { |
|
136 | { | |
139 |
|
|
137 | QVERIFY(m_dataset->axes().isEmpty()); | |
140 |
|
|
138 | QVERIFY(m_dataset->series().isEmpty()); | |
141 | QLineSeries* series = new QLineSeries(this); |
|
139 | m_dataset->createDefaultAxes(); | |
142 | QCOMPARE(m_dataset->seriesIndex(series),-1); |
|
|||
143 | QVERIFY(m_dataset->domain(series) == 0); |
|
|||
144 | QVERIFY(m_dataset->axisX(series) == 0); |
|
|||
145 | QVERIFY(m_dataset->axisY(series) == 0); |
|
|||
146 | m_dataset->createDefaultAxes(); |
|
|||
147 | } |
|
140 | } | |
148 |
|
141 | |||
149 |
|
142 | |||
@@ -172,143 +165,21 void tst_ChartDataSet::addSeries_data() | |||||
172 |
|
165 | |||
173 | void tst_ChartDataSet::addSeries() |
|
166 | void tst_ChartDataSet::addSeries() | |
174 | { |
|
167 | { | |
175 |
|
||||
176 | QFETCH(QAbstractSeries*, series); |
|
168 | QFETCH(QAbstractSeries*, series); | |
|
169 | QVERIFY(m_dataset->series().isEmpty()); | |||
177 |
|
170 | |||
178 |
QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis* |
|
171 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
179 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
172 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
180 |
QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries* |
|
173 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
181 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
174 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
182 |
|
175 | |||
183 | m_dataset->addSeries(series); |
|
176 | m_dataset->addSeries(series); | |
184 | m_dataset->createDefaultAxes(); |
|
|||
185 | if(series->type()==QAbstractSeries::SeriesTypePie){ |
|
|||
186 | TRY_COMPARE(spy0.count(), 0); |
|
|||
187 | }else{ |
|
|||
188 | TRY_COMPARE(spy0.count(), 2); |
|
|||
189 | } |
|
|||
190 | TRY_COMPARE(spy1.count(), 0); |
|
|||
191 | TRY_COMPARE(spy2.count(), 1); |
|
|||
192 | TRY_COMPARE(spy3.count(), 0); |
|
|||
193 | } |
|
|||
194 |
|
||||
195 |
|
||||
196 | void tst_ChartDataSet::setAxisX_data() |
|
|||
197 | { |
|
|||
198 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
|||
199 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
|||
200 | QTest::addColumn<int>("axisCount"); |
|
|||
201 |
|
||||
202 | QAbstractSeries* line = new QLineSeries(this); |
|
|||
203 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
|||
204 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
|||
205 | QAbstractSeries* spline = new QSplineSeries(this); |
|
|||
206 | /*QAbstractSeries* pie = */new QPieSeries(this); |
|
|||
207 | /*QAbstractSeries* bar = */new QBarSeries(this); |
|
|||
208 | /*QAbstractSeries* percent = */new QPercentBarSeries(this); |
|
|||
209 | /*QAbstractSeries* stacked = */new QStackedBarSeries(this); |
|
|||
210 |
|
||||
211 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
|||
212 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
|||
213 | << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this)) << 3; |
|
|||
214 |
|
||||
215 | QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area) |
|
|||
216 | << (QList<QAbstractAxis*>() << new QValueAxis(this)) << 1; |
|
|||
217 |
|
||||
218 | QList<QAbstractAxis*> axes0; |
|
|||
219 | axes0 << new QValueAxis(this) << new QValueAxis(this); |
|
|||
220 | axes0 << axes0.last(); |
|
|||
221 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1") |
|
|||
222 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
|||
223 | << axes0 << 2; |
|
|||
224 | //TODO: add more test cases |
|
|||
225 | } |
|
|||
226 |
|
||||
227 | void tst_ChartDataSet::setAxisX() |
|
|||
228 | { |
|
|||
229 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
|||
230 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
|||
231 | QFETCH(int, axisCount); |
|
|||
232 |
|
||||
233 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
|||
234 |
|
||||
235 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
|||
236 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
|||
237 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
|||
238 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
|||
239 |
|
||||
240 | foreach (QAbstractSeries* series, seriesList){ |
|
|||
241 | m_dataset->addSeries(series); |
|
|||
242 | } |
|
|||
243 |
|
177 | |||
|
178 | QCOMPARE(m_dataset->series().count(),1); | |||
244 | TRY_COMPARE(spy0.count(), 0); |
|
179 | TRY_COMPARE(spy0.count(), 0); | |
245 | TRY_COMPARE(spy1.count(), 0); |
|
180 | TRY_COMPARE(spy1.count(), 0); | |
246 |
TRY_COMPARE(spy2.count(), |
|
181 | TRY_COMPARE(spy2.count(), 1); | |
247 | TRY_COMPARE(spy3.count(), 0); |
|
|||
248 |
|
||||
249 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
|||
250 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
|||
251 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
|||
252 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
|||
253 |
|
||||
254 | for(int i=0 ; i < seriesList.count(); i++){ |
|
|||
255 | m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Horizontal); |
|
|||
256 | } |
|
|||
257 |
|
||||
258 | TRY_COMPARE(spy4.count(), axisCount); |
|
|||
259 | TRY_COMPARE(spy5.count(), 0); |
|
|||
260 | TRY_COMPARE(spy6.count(), 0); |
|
|||
261 | TRY_COMPARE(spy7.count(), 0); |
|
|||
262 |
|
||||
263 | for(int i=0 ; i < seriesList.count(); i++){ |
|
|||
264 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); |
|
|||
265 | } |
|
|||
266 | } |
|
|||
267 |
|
||||
268 | void tst_ChartDataSet::setAxisY_data() |
|
|||
269 | { |
|
|||
270 | setAxisX_data(); |
|
|||
271 | } |
|
|||
272 |
|
||||
273 | void tst_ChartDataSet::setAxisY() |
|
|||
274 | { |
|
|||
275 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
|||
276 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
|||
277 | QFETCH(int, axisCount); |
|
|||
278 |
|
||||
279 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
|||
280 |
|
||||
281 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
|||
282 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
|||
283 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
|||
284 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
|||
285 |
|
||||
286 | foreach (QAbstractSeries* series, seriesList){ |
|
|||
287 | m_dataset->addSeries(series); |
|
|||
288 | } |
|
|||
289 |
|
||||
290 | TRY_COMPARE(spy0.count(), 0); |
|
|||
291 | TRY_COMPARE(spy1.count(), 0); |
|
|||
292 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
|||
293 | TRY_COMPARE(spy3.count(), 0); |
|
182 | TRY_COMPARE(spy3.count(), 0); | |
294 |
|
||||
295 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
|||
296 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
|||
297 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
|||
298 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
|||
299 |
|
||||
300 | for(int i=0 ; i < seriesList.count(); i++){ |
|
|||
301 | m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Vertical); |
|
|||
302 | } |
|
|||
303 |
|
||||
304 | TRY_COMPARE(spy4.count(), axisCount); |
|
|||
305 | TRY_COMPARE(spy5.count(), 0); |
|
|||
306 | TRY_COMPARE(spy6.count(), 0); |
|
|||
307 | TRY_COMPARE(spy7.count(), 0); |
|
|||
308 |
|
||||
309 | for(int i=0 ; i < seriesList.count(); i++){ |
|
|||
310 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); |
|
|||
311 | } |
|
|||
312 | } |
|
183 | } | |
313 |
|
184 | |||
314 | void tst_ChartDataSet::removeSeries_data() |
|
185 | void tst_ChartDataSet::removeSeries_data() | |
@@ -319,24 +190,19 void tst_ChartDataSet::removeSeries_data() | |||||
319 | void tst_ChartDataSet::removeSeries() |
|
190 | void tst_ChartDataSet::removeSeries() | |
320 | { |
|
191 | { | |
321 | QFETCH(QAbstractSeries*, series); |
|
192 | QFETCH(QAbstractSeries*, series); | |
322 |
|
193 | QVERIFY(m_dataset->series().isEmpty()); | ||
323 | m_dataset->addSeries(series); |
|
194 | m_dataset->addSeries(series); | |
324 | m_dataset->createDefaultAxes(); |
|
|||
325 |
|
195 | |||
326 |
QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis* |
|
196 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
327 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
197 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
328 |
QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries* |
|
198 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
329 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
199 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
330 |
|
200 | |||
331 | m_dataset->removeSeries(series); |
|
201 | m_dataset->removeSeries(series); | |
332 |
|
202 | |||
|
203 | QCOMPARE(m_dataset->series().count(),0); | |||
333 | TRY_COMPARE(spy0.count(), 0); |
|
204 | TRY_COMPARE(spy0.count(), 0); | |
334 | if (series->type() == QAbstractSeries::SeriesTypePie) { |
|
205 | TRY_COMPARE(spy1.count(), 0); | |
335 | TRY_COMPARE(spy1.count(), 0); |
|
|||
336 | } |
|
|||
337 | else { |
|
|||
338 | TRY_COMPARE(spy1.count(), 2); |
|
|||
339 | } |
|
|||
340 | TRY_COMPARE(spy2.count(), 0); |
|
206 | TRY_COMPARE(spy2.count(), 0); | |
341 | TRY_COMPARE(spy3.count(), 1); |
|
207 | TRY_COMPARE(spy3.count(), 1); | |
342 | } |
|
208 | } | |
@@ -345,298 +211,270 void tst_ChartDataSet::removeAllSeries_data() | |||||
345 | { |
|
211 | { | |
346 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
212 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
347 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
213 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); | |
348 | QTest::addColumn<int>("axisCount"); |
|
214 | ||
349 |
|
215 | QList<QAbstractSeries*> series; | ||
350 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
216 | QList<QAbstractAxis*> axis; | |
351 | << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this) |
|
217 | ||
352 | << new QScatterSeries(this)) |
|
218 | series << new QLineSeries(this) << new QSplineSeries(this) << new QScatterSeries(this); | |
353 |
|
|
219 | axis << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this); | |
354 | << new QValueAxis(this)) << 3; |
|
220 | ||
355 | //TODO: |
|
221 | QTest::newRow("3 series , 3 axis") << series << axis; | |
356 | } |
|
222 | } | |
357 |
|
223 | |||
358 | void tst_ChartDataSet::removeAllSeries() |
|
224 | void tst_ChartDataSet::removeAllSeries() | |
359 | { |
|
225 | { | |
360 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
226 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
361 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
227 | QFETCH(QList<QAbstractAxis*>, axisList); | |
362 | QFETCH(int, axisCount); |
|
228 | ||
|
229 | QCOMPARE(m_dataset->series().count(),0); | |||
|
230 | QCOMPARE(m_dataset->axes().count(),0); | |||
363 |
|
231 | |||
364 | foreach (QAbstractSeries* series, seriesList) { |
|
232 | foreach (QAbstractSeries* series, seriesList) { | |
365 | m_dataset->addSeries(series); |
|
233 | m_dataset->addSeries(series); | |
366 | } |
|
234 | } | |
367 |
|
235 | |||
|
236 | foreach (QAbstractAxis* axis, axisList) { | |||
|
237 | m_dataset->addAxis(axis,Qt::AlignBottom); | |||
|
238 | } | |||
|
239 | ||||
368 | for (int i = 0; i < seriesList.count(); i++) { |
|
240 | for (int i = 0; i < seriesList.count(); i++) { | |
369 |
m_dataset-> |
|
241 | m_dataset->attachAxis(seriesList.at(i),axisList.at(i)); | |
370 | } |
|
242 | } | |
371 |
|
243 | |||
372 |
QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis* |
|
244 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
373 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
245 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
374 |
QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries* |
|
246 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
375 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
247 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
376 |
|
248 | |||
377 | m_dataset->removeAllSeries(); |
|
249 | m_dataset->removeAllSeries(); | |
378 |
|
250 | |||
379 | TRY_COMPARE(spy0.count(), 0); |
|
251 | TRY_COMPARE(spy0.count(), 0); | |
380 |
TRY_COMPARE(spy1.count(), |
|
252 | TRY_COMPARE(spy1.count(), 0); | |
381 | TRY_COMPARE(spy2.count(), 0); |
|
253 | TRY_COMPARE(spy2.count(), 0); | |
382 | TRY_COMPARE(spy3.count(), seriesList.count()); |
|
254 | TRY_COMPARE(spy3.count(), seriesList.count()); | |
383 | } |
|
|||
384 |
|
255 | |||
|
256 | QCOMPARE(m_dataset->series().count(),0); | |||
|
257 | QCOMPARE(m_dataset->axes().count(),axisList.count()); | |||
|
258 | } | |||
385 |
|
259 | |||
386 |
void tst_ChartDataSet:: |
|
260 | void tst_ChartDataSet::addAxis_data() | |
387 | { |
|
261 | { | |
388 |
QTest::addColumn< |
|
262 | QTest::addColumn<QAbstractAxis*>("axis"); | |
389 | QTest::addColumn<int>("seriesCount"); |
|
263 | QAbstractAxis* value = new QValueAxis(this); | |
390 |
|
264 | QAbstractAxis* category = new QCategoryAxis(this); | ||
391 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; |
|
265 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); | |
392 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; |
|
266 | QAbstractAxis* datetime = new QDateTimeAxis(this); | |
|
267 | ||||
|
268 | QTest::newRow("value") << value; | |||
|
269 | QTest::newRow("category") << category; | |||
|
270 | QTest::newRow("barcategory") << barcategory; | |||
|
271 | QTest::newRow("datetime") << datetime; | |||
393 | } |
|
272 | } | |
394 |
|
273 | |||
395 |
void tst_ChartDataSet:: |
|
274 | void tst_ChartDataSet::addAxis() | |
396 | { |
|
275 | { | |
397 |
QFETCH( |
|
276 | QFETCH(QAbstractAxis*, axis); | |
398 | QFETCH(int, seriesCount); |
|
277 | QVERIFY(m_dataset->axes().isEmpty()); | |
399 |
|
278 | |||
400 | foreach (QAbstractSeries* series, seriesList){ |
|
279 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
401 | m_dataset->addSeries(series); |
|
|||
402 | } |
|
|||
403 |
|
||||
404 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
|||
405 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
280 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
406 |
QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries* |
|
281 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
407 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
282 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
408 |
|
283 | |||
409 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); |
|
284 | m_dataset->addAxis(axis,Qt::AlignBottom); | |
410 | TRY_COMPARE(spy0.count(), 0); |
|
285 | ||
|
286 | QCOMPARE(m_dataset->axes().count(),1); | |||
|
287 | TRY_COMPARE(spy0.count(), 1); | |||
411 | TRY_COMPARE(spy1.count(), 0); |
|
288 | TRY_COMPARE(spy1.count(), 0); | |
412 | TRY_COMPARE(spy2.count(), 0); |
|
289 | TRY_COMPARE(spy2.count(), 0); | |
413 | TRY_COMPARE(spy3.count(), 0); |
|
290 | TRY_COMPARE(spy3.count(), 0); | |
414 | } |
|
291 | } | |
415 |
|
292 | |||
416 |
void tst_ChartDataSet:: |
|
293 | void tst_ChartDataSet::removeAxis_data() | |
417 | { |
|
294 | { | |
418 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
295 | addAxis_data(); | |
419 |
|
||||
420 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
|||
421 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); |
|
|||
422 | } |
|
296 | } | |
423 |
|
297 | |||
424 |
void tst_ChartDataSet:: |
|
298 | void tst_ChartDataSet::removeAxis() | |
425 | { |
|
299 | { | |
|
300 | QFETCH(QAbstractAxis*, axis); | |||
|
301 | QVERIFY(m_dataset->series().isEmpty()); | |||
|
302 | m_dataset->addAxis(axis,Qt::AlignBottom); | |||
426 |
|
303 | |||
427 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
304 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
428 |
|
||||
429 | foreach (QAbstractSeries* series, seriesList) { |
|
|||
430 | m_dataset->addSeries(series); |
|
|||
431 | } |
|
|||
432 |
|
||||
433 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
|||
434 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
305 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
435 |
QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries* |
|
306 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
436 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
307 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
437 |
|
308 | |||
438 | for (int i = 0; i < seriesList.count(); i++) { |
|
309 | m_dataset->removeAxis(axis); | |
439 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
|||
440 | } |
|
|||
441 |
|
310 | |||
|
311 | QCOMPARE(m_dataset->series().count(),0); | |||
442 | TRY_COMPARE(spy0.count(), 0); |
|
312 | TRY_COMPARE(spy0.count(), 0); | |
443 |
TRY_COMPARE(spy1.count(), |
|
313 | TRY_COMPARE(spy1.count(), 1); | |
444 | TRY_COMPARE(spy2.count(), 0); |
|
314 | TRY_COMPARE(spy2.count(), 0); | |
445 | TRY_COMPARE(spy3.count(), 0); |
|
315 | TRY_COMPARE(spy3.count(), 0); | |
|
316 | } | |||
446 |
|
317 | |||
447 | foreach (QAbstractSeries* series, seriesList) { |
|
318 | void tst_ChartDataSet::removeAllAxes_data() | |
448 | m_dataset->removeSeries(series); |
|
319 | { | |
449 | } |
|
320 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
450 |
|
321 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); | ||
451 | for (int i = 0; i < seriesList.count(); i++) { |
|
|||
452 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
|||
453 | } |
|
|||
454 |
|
||||
455 | foreach (QAbstractSeries* series, seriesList) { |
|
|||
456 | m_dataset->addSeries(series); |
|
|||
457 | } |
|
|||
458 |
|
||||
459 | for (int i = 0; i < seriesList.count(); i++) { |
|
|||
460 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
|||
461 | } |
|
|||
462 |
|
322 | |||
463 | m_dataset->removeSeries(seriesList.at(1)); |
|
323 | QList<QAbstractSeries*> series; | |
|
324 | QList<QAbstractAxis*> axis; | |||
464 |
|
325 | |||
465 | for (int i = 0; i < seriesList.count(); i++) { |
|
326 | series << new QLineSeries(this) << new QSplineSeries(this) << new QScatterSeries(this); | |
466 | if (i != 1) |
|
327 | axis << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this); | |
467 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
|||
468 | else |
|
|||
469 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
|||
470 | } |
|
|||
471 |
|
328 | |||
472 | m_dataset->addSeries(seriesList.at(1)); |
|
329 | QTest::newRow("3 series , 3 axis") << series << axis; | |
|
330 | } | |||
473 |
|
331 | |||
474 | for (int i = 0; i < seriesList.count(); i++) { |
|
332 | void tst_ChartDataSet::removeAllAxes() | |
475 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
333 | { | |
476 | } |
|
334 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
|
335 | QFETCH(QList<QAbstractAxis*>, axisList); | |||
477 |
|
336 | |||
478 |
m_dataset-> |
|
337 | QCOMPARE(m_dataset->series().count(),0); | |
|
338 | QCOMPARE(m_dataset->axes().count(),0); | |||
479 |
|
339 | |||
480 | for (int i = 0; i < seriesList.count(); i++) { |
|
340 | foreach (QAbstractSeries* series, seriesList) { | |
481 | if (i != 2) |
|
341 | m_dataset->addSeries(series); | |
482 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
|||
483 | else |
|
|||
484 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
|||
485 | } |
|
342 | } | |
486 |
|
343 | |||
487 | m_dataset->removeSeries(seriesList.at(0)); |
|
344 | foreach (QAbstractAxis* axis, axisList) { | |
488 |
|
345 | m_dataset->addAxis(axis,Qt::AlignBottom); | ||
489 | for (int i = 0; i < seriesList.count(); i++) { |
|
|||
490 | if (i != 2 && i != 0) |
|
|||
491 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
|||
492 | else |
|
|||
493 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
|||
494 | } |
|
346 | } | |
495 |
|
347 | |||
496 | m_dataset->addSeries(seriesList.at(2)); |
|
|||
497 | m_dataset->addSeries(seriesList.at(0)); |
|
|||
498 |
|
||||
499 | for (int i = 0; i < seriesList.count(); i++) { |
|
348 | for (int i = 0; i < seriesList.count(); i++) { | |
500 | if (i == 2) |
|
349 | m_dataset->attachAxis(seriesList.at(i),axisList.at(i)); | |
501 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); |
|
|||
502 | else if (i == 0) |
|
|||
503 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); |
|
|||
504 | else |
|
|||
505 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
|||
506 | } |
|
350 | } | |
507 |
|
351 | |||
508 | } |
|
352 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
509 |
|
||||
510 | void tst_ChartDataSet::domain_data() |
|
|||
511 | { |
|
|||
512 | addSeries_data(); |
|
|||
513 | } |
|
|||
514 |
|
||||
515 | void tst_ChartDataSet::domain() |
|
|||
516 | { |
|
|||
517 | QFETCH(QAbstractSeries*, series); |
|
|||
518 |
|
||||
519 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
|||
520 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
353 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
521 |
QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries* |
|
354 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
522 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
355 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
523 |
|
356 | |||
524 |
m_dataset-> |
|
357 | m_dataset->removeAllAxes(); | |
525 | QVERIFY(m_dataset->domain(series)); |
|
|||
526 |
|
||||
527 |
|
358 | |||
528 | TRY_COMPARE(spy0.count(), 0); |
|
359 | TRY_COMPARE(spy0.count(), 0); | |
529 |
TRY_COMPARE(spy1.count(), |
|
360 | TRY_COMPARE(spy1.count(), axisList.count()); | |
530 |
TRY_COMPARE(spy2.count(), |
|
361 | TRY_COMPARE(spy2.count(), 0); | |
531 |
|
||||
532 | QList<QVariant> arguments = spy2.takeFirst(); |
|
|||
533 | Domain *domain = (Domain *) arguments.at(1).value<Domain *>(); |
|
|||
534 | QVERIFY(m_dataset->domain(series) == domain); |
|
|||
535 |
|
||||
536 | TRY_COMPARE(spy3.count(), 0); |
|
362 | TRY_COMPARE(spy3.count(), 0); | |
537 |
|
363 | |||
|
364 | QCOMPARE(m_dataset->series().count(),seriesList.count()); | |||
|
365 | QCOMPARE(m_dataset->axes().count(),0); | |||
538 | } |
|
366 | } | |
539 |
|
367 | |||
540 |
void tst_ChartDataSet:: |
|
368 | void tst_ChartDataSet::attachAxis_data() | |
541 | { |
|
|||
542 | QTest::addColumn<bool >("sameAxis"); |
|
|||
543 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
|||
544 | QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
|||
545 | QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
|||
546 | } |
|
|||
547 |
|
||||
548 | void tst_ChartDataSet::zoomInDomain() |
|
|||
549 | { |
|
369 | { | |
550 | QFETCH(bool, sameAxis); |
|
370 | QTest::addColumn<QList<QAbstractSeries*> >("series"); | |
551 |
Q |
|
371 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); | |
552 |
|
372 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); | ||
553 | foreach (QAbstractSeries* series, seriesList) { |
|
373 | QTest::addColumn<QAbstractSeries*>("attachSeries"); | |
554 | m_dataset->addSeries(series); |
|
374 | QTest::addColumn<QAbstractAxis*>("attachAxis"); | |
555 | } |
|
375 | QTest::addColumn<bool>("success"); | |
556 |
|
||||
557 | if(sameAxis) m_dataset->createDefaultAxes(); |
|
|||
558 |
|
||||
559 | QList<QSignalSpy*> spyList; |
|
|||
560 |
|
||||
561 | foreach (QAbstractSeries* series, seriesList) { |
|
|||
562 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(updated())); |
|
|||
563 | } |
|
|||
564 |
|
376 | |||
565 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
377 | QList<QAbstractSeries*> series; | |
|
378 | QList<QAbstractAxis*> axes; | |||
|
379 | QList<Qt::Alignment> alignment; | |||
566 |
|
380 | |||
567 | foreach (QSignalSpy* spy, spyList) { |
|
381 | QAbstractSeries* line = new QLineSeries(this); | |
568 | TRY_COMPARE(spy->count(), 1); |
|
382 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
569 | } |
|
383 | QAbstractSeries* scatter = new QScatterSeries(this); | |
|
384 | QAbstractSeries* spline = new QSplineSeries(this); | |||
|
385 | QAbstractSeries* pie = new QPieSeries(this); | |||
|
386 | QAbstractSeries* bar = new QBarSeries(this); | |||
|
387 | QAbstractSeries* percent = new QPercentBarSeries(this); | |||
|
388 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |||
570 |
|
389 | |||
571 | qDeleteAll(spyList); |
|
390 | QAbstractAxis* value1 = new QValueAxis(this); | |
572 | } |
|
391 | QAbstractAxis* value2 = new QValueAxis(this); | |
|
392 | QAbstractAxis* category = new QCategoryAxis(this); | |||
|
393 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); | |||
|
394 | QAbstractAxis* datetime = new QDateTimeAxis(this); | |||
573 |
|
395 | |||
574 |
|
396 | |||
|
397 | series << line << 0; | |||
|
398 | axes << value1 << value2; | |||
|
399 | alignment << Qt::AlignBottom << Qt::AlignLeft; | |||
|
400 | QTest::newRow("line + two axes") << series << axes << alignment << line << value2 << true; | |||
575 |
|
401 | |||
576 | void tst_ChartDataSet::zoomOutDomain_data() |
|
|||
577 | { |
|
|||
578 | zoomInDomain_data(); |
|
|||
579 | } |
|
402 | } | |
580 |
|
403 | |||
581 |
void tst_ChartDataSet:: |
|
404 | void tst_ChartDataSet::attachAxis() | |
582 | { |
|
405 | { | |
583 | QFETCH(bool, sameAxis); |
|
406 | QFETCH(QList<QAbstractSeries*>, series); | |
584 |
QFETCH(QList<QAbstract |
|
407 | QFETCH(QList<QAbstractAxis*>, axis); | |
585 |
|
408 | QFETCH(QList<Qt::Alignment>, alignment); | ||
586 | foreach (QAbstractSeries* series, seriesList) { |
|
409 | QFETCH(QAbstractSeries*, attachSeries); | |
587 | m_dataset->addSeries(series); |
|
410 | QFETCH(QAbstractAxis*, attachAxis); | |
588 | } |
|
411 | QFETCH(bool, success); | |
589 |
|
412 | |||
590 | if (sameAxis) |
|
413 | Q_ASSERT(series.count() == axis.count()); | |
591 | m_dataset->createDefaultAxes(); |
|
414 | Q_ASSERT(series.count() == alignment.count()); | |
592 |
|
415 | |||
593 | QList<QSignalSpy*> spyList; |
|
416 | QVERIFY(m_dataset->series().isEmpty()); | |
|
417 | QVERIFY(m_dataset->axes().isEmpty()); | |||
594 |
|
418 | |||
595 | foreach (QAbstractSeries* series, seriesList) { |
|
419 | for(int i = 0 ; i < series.count() ; i++){ | |
596 | spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(updated())); |
|
420 | if(series[i]) m_dataset->addSeries(series[i]); | |
|
421 | if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]); | |||
|
422 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); | |||
597 | } |
|
423 | } | |
598 |
|
424 | |||
599 | m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
425 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
|
426 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |||
|
427 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |||
|
428 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |||
600 |
|
429 | |||
601 | foreach (QSignalSpy* spy, spyList) { |
|
430 | QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success); | |
602 | TRY_COMPARE(spy->count(), 1); |
|
|||
603 | } |
|
|||
604 |
|
431 | |||
605 | qDeleteAll (spyList); |
|
|||
606 | } |
|
432 | } | |
607 |
|
433 | |||
608 |
void tst_ChartDataSet:: |
|
434 | void tst_ChartDataSet::detachAxis_data() | |
609 | { |
|
435 | { | |
610 | zoomInDomain_data(); |
|
436 | QTest::addColumn<QList<QAbstractSeries*> >("series"); | |
611 | } |
|
437 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); | |
|
438 | QTest::addColumn<QAbstractSeries*>("detachSeries"); | |||
|
439 | QTest::addColumn<QAbstractAxis*>("detachAxis"); | |||
|
440 | QTest::addColumn<bool>("success"); | |||
612 |
|
441 | |||
613 | void tst_ChartDataSet::scrollDomain() |
|
442 | QList<QAbstractSeries*> series; | |
614 | { |
|
443 | QList<QAbstractAxis*> axes; | |
615 | QFETCH(bool, sameAxis); |
|
|||
616 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
|||
617 |
|
444 | |||
618 | foreach (QAbstractSeries* series, seriesList) { |
|
445 | QAbstractSeries* line = new QLineSeries(this); | |
619 | m_dataset->addSeries(series); |
|
446 | QAbstractAxis* value = new QValueAxis(this); | |
620 | } |
|
|||
621 |
|
447 | |||
622 | if (sameAxis) |
|
448 | series << line; | |
623 | m_dataset->createDefaultAxes(); |
|
449 | axes << value; | |
|
450 | QTest::newRow("line + axis") << series << axes << line << value << true; | |||
|
451 | } | |||
624 |
|
452 | |||
625 | QList<QSignalSpy*> spyList; |
|
453 | void tst_ChartDataSet::detachAxis() | |
|
454 | { | |||
|
455 | QFETCH(QList<QAbstractSeries*>, series); | |||
|
456 | QFETCH(QList<QAbstractAxis*>, axis); | |||
|
457 | QFETCH(QAbstractSeries*, detachSeries); | |||
|
458 | QFETCH(QAbstractAxis*, detachAxis); | |||
|
459 | QFETCH(bool, success); | |||
626 |
|
460 | |||
627 | foreach (QAbstractSeries* series, seriesList) { |
|
461 | Q_ASSERT(series.count() == axis.count()); | |
628 | spyList |
|
|||
629 | << new QSignalSpy(m_dataset->domain(series), |
|
|||
630 | SIGNAL(updated())); |
|
|||
631 | } |
|
|||
632 |
|
462 | |||
633 | m_dataset->scrollDomain(10, 10, QSize(1000, 1000)); |
|
463 | QVERIFY(m_dataset->series().isEmpty()); | |
|
464 | QVERIFY(m_dataset->axes().isEmpty()); | |||
634 |
|
465 | |||
635 | foreach (QSignalSpy* spy, spyList) { |
|
466 | for(int i = 0; i < series.count(); i++) { | |
636 | TRY_COMPARE(spy->count(), 1); |
|
467 | if(series[i]) m_dataset->addSeries(series[i]); | |
|
468 | if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom); | |||
|
469 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); | |||
637 | } |
|
470 | } | |
638 |
|
471 | |||
639 | qDeleteAll(spyList); |
|
472 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
|
473 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |||
|
474 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |||
|
475 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |||
|
476 | ||||
|
477 | QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success); | |||
640 | } |
|
478 | } | |
641 |
|
479 | |||
642 | QTEST_MAIN(tst_ChartDataSet) |
|
480 | QTEST_MAIN(tst_ChartDataSet) |
@@ -49,19 +49,19 QTCOMMERCIALCHART_USE_NAMESPACE | |||||
49 |
|
49 | |||
50 | Q_DECLARE_METATYPE(Domain*) |
|
50 | Q_DECLARE_METATYPE(Domain*) | |
51 | Q_DECLARE_METATYPE(QSizeF) |
|
51 | Q_DECLARE_METATYPE(QSizeF) | |
|
52 | Q_DECLARE_METATYPE(QMargins) | |||
52 |
|
53 | |||
53 |
|
54 | |||
54 | class AxisMock: public QAbstractAxisPrivate |
|
55 | class AxisMock: public QAbstractAxisPrivate | |
55 | { |
|
56 | { | |
56 | Q_OBJECT |
|
57 | Q_OBJECT | |
57 | public: |
|
58 | public: | |
58 |
AxisMock(Qt:: |
|
59 | AxisMock(Qt::Alignment alignment):QAbstractAxisPrivate(0){ setAlignment(alignment);}; | |
59 | ChartAxis* createGraphics(ChartPresenter* presenter) |
|
60 | void initializeGraphics(QGraphicsItem* item) | |
60 | { |
|
61 | { | |
61 |
Q_UNUSED( |
|
62 | Q_UNUSED(item); | |
62 | return 0; |
|
|||
63 | }; |
|
63 | }; | |
64 | void intializeDomain(Domain* domain) |
|
64 | void initializeDomain(Domain* domain) | |
65 | { |
|
65 | { | |
66 | Q_UNUSED(domain); |
|
66 | Q_UNUSED(domain); | |
67 | }; |
|
67 | }; | |
@@ -81,6 +81,13 public: | |||||
81 | Q_UNUSED(max); |
|
81 | Q_UNUSED(max); | |
82 | }; |
|
82 | }; | |
83 |
|
83 | |||
|
84 | void setRange(qreal min, qreal max) | |||
|
85 | { | |||
|
86 | m_min=min; | |||
|
87 | m_max=max; | |||
|
88 | emit rangeChanged(min,max); | |||
|
89 | }; | |||
|
90 | ||||
84 | int count () const { return m_count; } |
|
91 | int count () const { return m_count; } | |
85 |
|
92 | |||
86 | void handleDomainUpdated(){}; |
|
93 | void handleDomainUpdated(){}; | |
@@ -102,10 +109,10 public Q_SLOTS: | |||||
102 |
|
109 | |||
103 | private Q_SLOTS: |
|
110 | private Q_SLOTS: | |
104 | void domain(); |
|
111 | void domain(); | |
105 |
void handle |
|
112 | void handleHorizontalAxisRangeChanged_data(); | |
106 |
void handle |
|
113 | void handleHorizontalAxisRangeChanged(); | |
107 |
void handle |
|
114 | void handleVerticalAxisRangeChanged_data(); | |
108 |
void handle |
|
115 | void handleVerticalAxisRangeChanged(); | |
109 | void isEmpty_data(); |
|
116 | void isEmpty_data(); | |
110 | void isEmpty(); |
|
117 | void isEmpty(); | |
111 | void maxX_data(); |
|
118 | void maxX_data(); | |
@@ -128,8 +135,10 private Q_SLOTS: | |||||
128 | void spanX(); |
|
135 | void spanX(); | |
129 | void spanY_data(); |
|
136 | void spanY_data(); | |
130 | void spanY(); |
|
137 | void spanY(); | |
131 | void zoom_data(); |
|
138 | void zoomIn_data(); | |
132 | void zoom(); |
|
139 | void zoomIn(); | |
|
140 | void zoomOut_data(); | |||
|
141 | void zoomOut(); | |||
133 | void move_data(); |
|
142 | void move_data(); | |
134 | void move(); |
|
143 | void move(); | |
135 | }; |
|
144 | }; | |
@@ -161,7 +170,7 void tst_Domain::domain() | |||||
161 | QCOMPARE(domain.minY(), 0.0); |
|
170 | QCOMPARE(domain.minY(), 0.0); | |
162 | } |
|
171 | } | |
163 |
|
172 | |||
164 |
void tst_Domain::handle |
|
173 | void tst_Domain::handleHorizontalAxisRangeChanged_data() | |
165 | { |
|
174 | { | |
166 | QTest::addColumn<qreal>("min"); |
|
175 | QTest::addColumn<qreal>("min"); | |
167 | QTest::addColumn<qreal>("max"); |
|
176 | QTest::addColumn<qreal>("max"); | |
@@ -170,7 +179,7 void tst_Domain::handleAxisUpdatedX_data() | |||||
170 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
179 | QTest::newRow("-1 0") << -1.0 << 0.0; | |
171 | } |
|
180 | } | |
172 |
|
181 | |||
173 |
void tst_Domain::handle |
|
182 | void tst_Domain::handleHorizontalAxisRangeChanged() | |
174 | { |
|
183 | { | |
175 | QFETCH(qreal, min); |
|
184 | QFETCH(qreal, min); | |
176 | QFETCH(qreal, max); |
|
185 | QFETCH(qreal, max); | |
@@ -178,14 +187,12 void tst_Domain::handleAxisUpdatedX() | |||||
178 | Domain domain; |
|
187 | Domain domain; | |
179 |
|
188 | |||
180 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
189 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
181 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
190 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
182 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
191 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
183 |
|
192 | |||
184 |
AxisMock axis(Qt:: |
|
193 | AxisMock axis(Qt::AlignBottom); | |
185 |
QObject::connect(&axis,SIGNAL( |
|
194 | QObject::connect(&axis,SIGNAL(rangeChanged(qreal,qreal)),&domain,SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); | |
186 |
axis. |
|
195 | axis.setRange(min,max); | |
187 | axis.m_max=max; |
|
|||
188 | axis.emitUpdated(); |
|
|||
189 |
|
196 | |||
190 | QVERIFY(qFuzzyCompare(domain.minX(), min)); |
|
197 | QVERIFY(qFuzzyCompare(domain.minX(), min)); | |
191 | QVERIFY(qFuzzyCompare(domain.maxX(), max)); |
|
198 | QVERIFY(qFuzzyCompare(domain.maxX(), max)); | |
@@ -200,7 +207,7 void tst_Domain::handleAxisUpdatedX() | |||||
200 |
|
207 | |||
201 | } |
|
208 | } | |
202 |
|
209 | |||
203 |
void tst_Domain::handle |
|
210 | void tst_Domain::handleVerticalAxisRangeChanged_data() | |
204 | { |
|
211 | { | |
205 | QTest::addColumn<qreal>("min"); |
|
212 | QTest::addColumn<qreal>("min"); | |
206 | QTest::addColumn<qreal>("max"); |
|
213 | QTest::addColumn<qreal>("max"); | |
@@ -209,7 +216,7 void tst_Domain::handleAxisUpdatedY_data() | |||||
209 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
216 | QTest::newRow("-1 0") << -1.0 << 0.0; | |
210 | } |
|
217 | } | |
211 |
|
218 | |||
212 |
void tst_Domain::handle |
|
219 | void tst_Domain::handleVerticalAxisRangeChanged() | |
213 | { |
|
220 | { | |
214 | QFETCH(qreal, min); |
|
221 | QFETCH(qreal, min); | |
215 | QFETCH(qreal, max); |
|
222 | QFETCH(qreal, max); | |
@@ -217,14 +224,12 void tst_Domain::handleAxisUpdatedY() | |||||
217 | Domain domain; |
|
224 | Domain domain; | |
218 |
|
225 | |||
219 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
226 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
220 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
227 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
221 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
228 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
222 |
|
229 | |||
223 |
AxisMock axis(Qt:: |
|
230 | AxisMock axis(Qt::AlignLeft); | |
224 |
QObject::connect(&axis, SIGNAL( |
|
231 | QObject::connect(&axis, SIGNAL(rangeChanged(qreal,qreal)), &domain, SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); | |
225 | axis.m_min = min; |
|
232 | axis.setRange(min,max); | |
226 | axis.m_max = max; |
|
|||
227 | axis.emitUpdated(); |
|
|||
228 |
|
233 | |||
229 | QVERIFY(qFuzzyCompare(domain.minY(), min)); |
|
234 | QVERIFY(qFuzzyCompare(domain.minY(), min)); | |
230 | QVERIFY(qFuzzyCompare(domain.maxY(), max)); |
|
235 | QVERIFY(qFuzzyCompare(domain.maxY(), max)); | |
@@ -244,11 +249,13 void tst_Domain::isEmpty_data() | |||||
244 | QTest::addColumn<qreal>("maxX"); |
|
249 | QTest::addColumn<qreal>("maxX"); | |
245 | QTest::addColumn<qreal>("minY"); |
|
250 | QTest::addColumn<qreal>("minY"); | |
246 | QTest::addColumn<qreal>("maxY"); |
|
251 | QTest::addColumn<qreal>("maxY"); | |
|
252 | QTest::addColumn<QSizeF>("size"); | |||
247 | QTest::addColumn<bool>("isEmpty"); |
|
253 | QTest::addColumn<bool>("isEmpty"); | |
248 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true; |
|
254 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << QSizeF(1,1) << true; | |
249 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
255 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << QSizeF(1,1) << true; | |
250 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
256 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << QSizeF(1,1) << true; | |
251 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false; |
|
257 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << QSizeF(1,1) << false; | |
|
258 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << QSizeF(-11,1) << true; | |||
252 | } |
|
259 | } | |
253 |
|
260 | |||
254 | void tst_Domain::isEmpty() |
|
261 | void tst_Domain::isEmpty() | |
@@ -257,10 +264,12 void tst_Domain::isEmpty() | |||||
257 | QFETCH(qreal, maxX); |
|
264 | QFETCH(qreal, maxX); | |
258 | QFETCH(qreal, minY); |
|
265 | QFETCH(qreal, minY); | |
259 | QFETCH(qreal, maxY); |
|
266 | QFETCH(qreal, maxY); | |
|
267 | QFETCH(QSizeF, size); | |||
260 | QFETCH(bool, isEmpty); |
|
268 | QFETCH(bool, isEmpty); | |
261 |
|
269 | |||
262 | Domain domain; |
|
270 | Domain domain; | |
263 | domain.setRange(minX, maxX, minY, maxY); |
|
271 | domain.setRange(minX, maxX, minY, maxY); | |
|
272 | domain.setSize(size); | |||
264 | QCOMPARE(domain.isEmpty(), isEmpty); |
|
273 | QCOMPARE(domain.isEmpty(), isEmpty); | |
265 | } |
|
274 | } | |
266 |
|
275 | |||
@@ -283,8 +292,8 void tst_Domain::maxX() | |||||
283 | Domain domain; |
|
292 | Domain domain; | |
284 |
|
293 | |||
285 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
294 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
286 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
295 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
287 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
296 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
288 |
|
297 | |||
289 | domain.setMaxX(maxX1); |
|
298 | domain.setMaxX(maxX1); | |
290 | QCOMPARE(domain.maxX(), maxX1); |
|
299 | QCOMPARE(domain.maxX(), maxX1); | |
@@ -316,8 +325,8 void tst_Domain::maxY() | |||||
316 | Domain domain; |
|
325 | Domain domain; | |
317 |
|
326 | |||
318 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
327 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
319 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
328 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
320 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
329 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
321 |
|
330 | |||
322 | domain.setMaxY(maxY1); |
|
331 | domain.setMaxY(maxY1); | |
323 | QCOMPARE(domain.maxY(), maxY1); |
|
332 | QCOMPARE(domain.maxY(), maxY1); | |
@@ -348,8 +357,8 void tst_Domain::minX() | |||||
348 | Domain domain; |
|
357 | Domain domain; | |
349 |
|
358 | |||
350 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
359 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
351 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
360 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
352 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
361 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
353 |
|
362 | |||
354 | domain.setMinX(minX1); |
|
363 | domain.setMinX(minX1); | |
355 | QCOMPARE(domain.minX(), minX1); |
|
364 | QCOMPARE(domain.minX(), minX1); | |
@@ -380,8 +389,8 void tst_Domain::minY() | |||||
380 | Domain domain; |
|
389 | Domain domain; | |
381 |
|
390 | |||
382 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
391 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
383 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
392 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
384 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
393 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
385 |
|
394 | |||
386 | domain.setMinY(minY1); |
|
395 | domain.setMinY(minY1); | |
387 | QCOMPARE(domain.minY(), minY1); |
|
396 | QCOMPARE(domain.minY(), minY1); | |
@@ -430,8 +439,8 void tst_Domain::operatorEquals() | |||||
430 | Domain domain; |
|
439 | Domain domain; | |
431 |
|
440 | |||
432 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
441 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
433 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
442 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
434 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
443 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
435 |
|
444 | |||
436 | QCOMPARE(*domain1==*domain2, equals); |
|
445 | QCOMPARE(*domain1==*domain2, equals); | |
437 | QCOMPARE(*domain1!=*domain2, notEquals); |
|
446 | QCOMPARE(*domain1!=*domain2, notEquals); | |
@@ -462,8 +471,8 void tst_Domain::setRange() | |||||
462 | Domain domain; |
|
471 | Domain domain; | |
463 |
|
472 | |||
464 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
473 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
465 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
474 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
466 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
475 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
467 |
|
476 | |||
468 | domain.setRange(minX, maxX, minY, maxY); |
|
477 | domain.setRange(minX, maxX, minY, maxY); | |
469 |
|
478 | |||
@@ -495,8 +504,8 void tst_Domain::setRangeX() | |||||
495 | Domain domain; |
|
504 | Domain domain; | |
496 |
|
505 | |||
497 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
506 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
498 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
507 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
499 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
508 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
500 |
|
509 | |||
501 | domain.setRangeX(min, max); |
|
510 | domain.setRangeX(min, max); | |
502 |
|
511 | |||
@@ -529,8 +538,8 void tst_Domain::setRangeY() | |||||
529 | Domain domain; |
|
538 | Domain domain; | |
530 |
|
539 | |||
531 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
540 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
532 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
541 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
533 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
542 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
534 |
|
543 | |||
535 | domain.setRangeY(min, max); |
|
544 | domain.setRangeY(min, max); | |
536 |
|
545 | |||
@@ -566,8 +575,8 void tst_Domain::spanX() | |||||
566 | domain.setRangeX(minX, maxX); |
|
575 | domain.setRangeX(minX, maxX); | |
567 |
|
576 | |||
568 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
577 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
569 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
578 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
570 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
579 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
571 |
|
580 | |||
572 | QCOMPARE(domain.spanX(), spanX); |
|
581 | QCOMPARE(domain.spanX(), spanX); | |
573 |
|
582 | |||
@@ -596,8 +605,8 void tst_Domain::spanY() | |||||
596 | domain.setRangeY(minY, maxY); |
|
605 | domain.setRangeY(minY, maxY); | |
597 |
|
606 | |||
598 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
607 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
599 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
608 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
600 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
609 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
601 |
|
610 | |||
602 | QCOMPARE(domain.spanY(), spanY); |
|
611 | QCOMPARE(domain.spanY(), spanY); | |
603 |
|
612 | |||
@@ -606,93 +615,123 void tst_Domain::spanY() | |||||
606 | TRY_COMPARE(spy2.count(), 0); |
|
615 | TRY_COMPARE(spy2.count(), 0); | |
607 | } |
|
616 | } | |
608 |
|
617 | |||
609 | void tst_Domain::zoom_data() |
|
618 | void tst_Domain::zoomIn_data() | |
610 | { |
|
619 | { | |
611 |
QTest::addColumn<Q |
|
620 | QTest::addColumn<QMargins>("range"); | |
612 |
QTest::addColumn<QSizeF>("size |
|
621 | QTest::addColumn<QSizeF>("size"); | |
613 |
QTest::addColumn<Q |
|
622 | QTest::addColumn<QMargins>("zoom"); | |
614 |
QTest::addColumn<Q |
|
623 | QTest::addColumn<QMargins>("result"); | |
615 | QTest::addColumn<QRectF>("rect2"); |
|
624 | ||
616 | QTest::addColumn<QSizeF>("size2"); |
|
625 | QTest::newRow("first") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) << | |
617 | QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000) |
|
626 | QMargins(100, 100, 900, 900) << QMargins(100,100,900,900); | |
618 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) |
|
627 | QTest::newRow("second") << QMargins(0,0,2000,2000) << QSizeF(1000, 1000) << | |
619 | << QSizeF(1000, 1000); |
|
628 | QMargins(100, 100, 900, 900) << QMargins(200,200,1800,1800); | |
620 | QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000) |
|
|||
621 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) |
|
|||
622 | << QSizeF(1000, 1000); |
|
|||
623 | QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20) |
|
|||
624 | << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100); |
|
|||
625 | } |
|
629 | } | |
626 |
|
630 | |||
627 | void tst_Domain::zoom() |
|
631 | void tst_Domain::zoomIn() | |
628 | { |
|
632 | { | |
629 |
QFETCH(Q |
|
633 | QFETCH(QMargins, range); | |
630 |
QFETCH(QSizeF, size |
|
634 | QFETCH(QSizeF, size); | |
631 |
QFETCH(Q |
|
635 | QFETCH(QMargins, zoom); | |
632 |
QFETCH(Q |
|
636 | QFETCH(QMargins, result); | |
633 | QFETCH(QRectF, rect2); |
|
|||
634 | QFETCH(QSizeF, size2); |
|
|||
635 |
|
637 | |||
636 | Domain domain; |
|
638 | Domain domain; | |
|
639 | domain.setRange(range.left(), range.right(), range.top(),range.bottom()); | |||
|
640 | domain.setSize(size); | |||
|
641 | ||||
|
642 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |||
|
643 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |||
|
644 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |||
|
645 | ||||
|
646 | domain.zoomIn(QRectF(zoom.left(),zoom.top(),zoom.right()-zoom.left(),zoom.bottom()-zoom.top())); | |||
|
647 | ||||
|
648 | QCOMPARE(domain.minX(),qreal(result.left())); | |||
|
649 | QCOMPARE(domain.maxX(),qreal(result.right())); | |||
|
650 | QCOMPARE(domain.minY(),qreal(result.top())); | |||
|
651 | QCOMPARE(domain.maxY(),qreal(result.bottom())); | |||
|
652 | ||||
|
653 | TRY_COMPARE(spy0.count(), 1); | |||
|
654 | TRY_COMPARE(spy1.count(), 1); | |||
|
655 | TRY_COMPARE(spy2.count(), 1); | |||
|
656 | } | |||
|
657 | ||||
|
658 | void tst_Domain::zoomOut_data() | |||
|
659 | { | |||
|
660 | QTest::addColumn<QMargins>("range"); | |||
|
661 | QTest::addColumn<QSizeF>("size"); | |||
|
662 | QTest::addColumn<QMargins>("zoom"); | |||
|
663 | QTest::addColumn<QMargins>("result"); | |||
|
664 | ||||
|
665 | QTest::newRow("first") << QMargins(100,100,900,900) << QSizeF(1000, 1000) << | |||
|
666 | QMargins(100, 100, 900, 900) << QMargins(0,0,1000,1000); | |||
|
667 | QTest::newRow("second") << QMargins(200,200,1800,1800) << QSizeF(1000, 1000) << | |||
|
668 | QMargins(100, 100, 900, 900) << QMargins(0,0,2000,2000); | |||
|
669 | } | |||
|
670 | ||||
|
671 | void tst_Domain::zoomOut() | |||
|
672 | { | |||
|
673 | QFETCH(QMargins, range); | |||
|
674 | QFETCH(QSizeF, size); | |||
|
675 | QFETCH(QMargins, zoom); | |||
|
676 | QFETCH(QMargins, result); | |||
637 |
|
677 | |||
638 | domain.setRange(0, 1000, 0, 1000); |
|
678 | Domain domain; | |
|
679 | domain.setRange(range.left(), range.right(), range.top(),range.bottom()); | |||
|
680 | domain.setSize(size); | |||
639 |
|
681 | |||
640 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
682 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
641 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
683 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
642 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
684 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
643 |
|
685 | |||
644 | Domain domain0; |
|
686 | domain.zoomOut(QRectF(zoom.left(),zoom.top(),zoom.right()-zoom.left(),zoom.bottom()-zoom.top())); | |
645 | domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
687 | ||
646 | domain.zoomIn(rect0, size0); |
|
688 | QCOMPARE(domain.minX(),qreal(result.left())); | |
647 | Domain domain1; |
|
689 | QCOMPARE(domain.maxX(),qreal(result.right())); | |
648 | domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
690 | QCOMPARE(domain.minY(),qreal(result.top())); | |
649 | domain.zoomIn(rect1, size1); |
|
691 | QCOMPARE(domain.maxY(),qreal(result.bottom())); | |
650 | Domain domain2; |
|
692 | ||
651 | domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
693 | TRY_COMPARE(spy0.count(), 1); | |
652 | domain.zoomIn(rect2, size2); |
|
694 | TRY_COMPARE(spy1.count(), 1); | |
653 | domain.zoomOut(rect2, size2); |
|
695 | TRY_COMPARE(spy2.count(), 1); | |
654 | QCOMPARE(domain == domain2, true); |
|
|||
655 | domain.zoomOut(rect1, size1); |
|
|||
656 | QCOMPARE(domain == domain1, true); |
|
|||
657 | domain.zoomOut(rect0, size0); |
|
|||
658 | QCOMPARE(domain == domain0, true); |
|
|||
659 | TRY_COMPARE(spy0.count(), 6); |
|
|||
660 | TRY_COMPARE(spy1.count(), 6); |
|
|||
661 | TRY_COMPARE(spy2.count(), 6); |
|
|||
662 | } |
|
696 | } | |
663 |
|
697 | |||
664 | void tst_Domain::move_data() |
|
698 | void tst_Domain::move_data() | |
665 | { |
|
699 | { | |
|
700 | QTest::addColumn<QMargins>("range"); | |||
|
701 | QTest::addColumn<QSizeF>("size"); | |||
666 | QTest::addColumn<int>("dx"); |
|
702 | QTest::addColumn<int>("dx"); | |
667 | QTest::addColumn<int>("dy"); |
|
703 | QTest::addColumn<int>("dy"); | |
668 |
QTest::addColumn<Q |
|
704 | QTest::addColumn<QMargins>("result"); | |
669 | QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000); |
|
705 | ||
670 |
QTest::newRow(" |
|
706 | QTest::newRow("first") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) << | |
671 | QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000); |
|
707 | 10 << 10 << QMargins(10,10,1010,1010); | |
672 |
QTest::newRow(" |
|
708 | QTest::newRow("second") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) << | |
673 | QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000); |
|
709 | -10 << -10 << QMargins(-10,-10,990,990); | |
674 | QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000); |
|
|||
675 | } |
|
710 | } | |
676 |
|
711 | |||
677 | void tst_Domain::move() |
|
712 | void tst_Domain::move() | |
678 | { |
|
713 | { | |
|
714 | QFETCH(QMargins, range); | |||
|
715 | QFETCH(QSizeF, size); | |||
679 | QFETCH(int, dx); |
|
716 | QFETCH(int, dx); | |
680 | QFETCH(int, dy); |
|
717 | QFETCH(int, dy); | |
681 |
QFETCH(Q |
|
718 | QFETCH(QMargins, result); | |
682 | Domain domain; |
|
|||
683 |
|
719 | |||
684 | domain.setRange(0, size.width(), 0, size.height()); |
|
720 | Domain domain; | |
|
721 | domain.setRange(range.left(), range.right(), range.top(),range.bottom()); | |||
|
722 | domain.setSize(size); | |||
685 |
|
723 | |||
686 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
724 | QSignalSpy spy0(&domain, SIGNAL(updated())); | |
687 |
QSignalSpy spy1(&domain, SIGNAL(range |
|
725 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | |
688 |
QSignalSpy spy2(&domain, SIGNAL(range |
|
726 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | |
689 |
|
727 | |||
690 |
domain.move(dx, dy |
|
728 | domain.move(dx, dy); | |
691 |
|
729 | |||
692 | Domain result; |
|
730 | QCOMPARE(domain.minX(),qreal(result.left())); | |
693 | result.setRange(dx, size.width() + dx, dy, size.height() + dy); |
|
731 | QCOMPARE(domain.maxX(),qreal(result.right())); | |
|
732 | QCOMPARE(domain.minY(),qreal(result.top())); | |||
|
733 | QCOMPARE(domain.maxY(),qreal(result.bottom())); | |||
694 |
|
734 | |||
695 | QCOMPARE(domain == result, true); |
|
|||
696 | TRY_COMPARE(spy0.count(), 1); |
|
735 | TRY_COMPARE(spy0.count(), 1); | |
697 | TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0)); |
|
736 | TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0)); | |
698 | TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0)); |
|
737 | TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0)); |
@@ -106,7 +106,7 void tst_QAbstractAxis::axisPen() | |||||
106 |
|
106 | |||
107 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
107 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
108 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
108 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
109 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
109 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
110 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
110 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
111 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
111 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
112 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
112 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -159,7 +159,7 void tst_QAbstractAxis::gridLinePen() | |||||
159 |
|
159 | |||
160 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
160 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
161 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
161 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
162 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
162 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
163 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
163 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
164 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
164 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
165 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
165 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -201,7 +201,7 void tst_QAbstractAxis::lineVisible() | |||||
201 |
|
201 | |||
202 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
202 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
203 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
203 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
204 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
204 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
205 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
205 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
206 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
206 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
207 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
207 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -243,7 +243,7 void tst_QAbstractAxis::gridLineVisible() | |||||
243 |
|
243 | |||
244 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
244 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
245 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
245 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
246 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
246 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
247 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
247 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
248 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
248 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
249 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
249 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -286,7 +286,7 void tst_QAbstractAxis::visible() | |||||
286 |
|
286 | |||
287 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
287 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
288 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
288 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
289 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
289 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
290 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
290 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
291 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
291 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
292 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
292 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -327,7 +327,7 void tst_QAbstractAxis::labelsAngle() | |||||
327 |
|
327 | |||
328 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
328 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
329 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
329 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
330 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
330 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
331 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
331 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
332 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
332 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
333 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
333 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -370,7 +370,7 void tst_QAbstractAxis::labelsBrush() | |||||
370 |
|
370 | |||
371 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
371 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
372 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
372 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
373 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
373 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
374 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
374 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
375 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
375 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
376 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
376 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -421,7 +421,7 void tst_QAbstractAxis::labelsFont() | |||||
421 |
|
421 | |||
422 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
422 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
423 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
423 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
424 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
424 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
425 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
425 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
426 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
426 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
427 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
427 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -463,7 +463,7 void tst_QAbstractAxis::labelsPen() | |||||
463 |
|
463 | |||
464 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
464 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
465 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
465 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
466 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
466 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
467 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
467 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
468 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
468 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
469 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
469 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -505,7 +505,7 void tst_QAbstractAxis::labelsVisible() | |||||
505 |
|
505 | |||
506 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
506 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
507 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
507 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
508 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
508 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
509 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
509 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
510 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
510 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
511 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
511 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -545,7 +545,7 void tst_QAbstractAxis::orientation() | |||||
545 |
|
545 | |||
546 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
546 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
547 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
547 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
548 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
548 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
549 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
549 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
550 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
550 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
551 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
551 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -646,7 +646,7 void tst_QAbstractAxis::shadesBrush() | |||||
646 |
|
646 | |||
647 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
647 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
648 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
648 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
649 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
649 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
650 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
650 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
651 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
651 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
652 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
652 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -697,7 +697,7 void tst_QAbstractAxis::shadesPen() | |||||
697 |
|
697 | |||
698 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
698 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
699 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
699 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
700 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
700 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
701 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
701 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
702 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
702 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
703 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
703 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -739,7 +739,7 void tst_QAbstractAxis::shadesVisible() | |||||
739 |
|
739 | |||
740 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
740 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
741 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
741 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
742 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
742 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
743 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
743 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
744 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
744 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
745 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
745 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -778,7 +778,7 void tst_QAbstractAxis::show() | |||||
778 |
|
778 | |||
779 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
779 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
780 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
780 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
781 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
781 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
782 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
782 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
783 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
783 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
784 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
784 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
@@ -812,7 +812,7 void tst_QAbstractAxis::hide() | |||||
812 |
|
812 | |||
813 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
813 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
814 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
814 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
815 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
815 | QSignalSpy spy2(m_axis, SIGNAL(gridLineVisibleChanged(bool))); | |
816 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
816 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
817 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
817 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
818 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
818 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
@@ -47,8 +47,8 private slots: | |||||
47 | void min(); |
|
47 | void min(); | |
48 | void min_animation_data(); |
|
48 | void min_animation_data(); | |
49 | void min_animation(); |
|
49 | void min_animation(); | |
50 |
void |
|
50 | void applyNiceNumbers_data(); | |
51 |
void |
|
51 | void applyNiceNumbers(); | |
52 | void range_raw_data(); |
|
52 | void range_raw_data(); | |
53 | void range_raw(); |
|
53 | void range_raw(); | |
54 | void range_data(); |
|
54 | void range_data(); | |
@@ -215,7 +215,7 void tst_QValueAxis::min_animation() | |||||
215 | min(); |
|
215 | min(); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 |
void tst_QValueAxis:: |
|
218 | void tst_QValueAxis::applyNiceNumbers_data() | |
219 | { |
|
219 | { | |
220 | QTest::addColumn<bool>("niceNumbersEnabled"); |
|
220 | QTest::addColumn<bool>("niceNumbersEnabled"); | |
221 | QTest::addColumn<qreal>("min"); |
|
221 | QTest::addColumn<qreal>("min"); | |
@@ -232,7 +232,7 void tst_QValueAxis::niceNumbersEnabled_data() | |||||
232 | QTest::newRow("true 5, 93.5 , 5") << true << (qreal)5.0 << (qreal)93.5 << 5 << (qreal)0.0 << (qreal)100.0 << 6; |
|
232 | QTest::newRow("true 5, 93.5 , 5") << true << (qreal)5.0 << (qreal)93.5 << 5 << (qreal)0.0 << (qreal)100.0 << 6; | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 |
void tst_QValueAxis:: |
|
235 | void tst_QValueAxis::applyNiceNumbers() | |
236 | { |
|
236 | { | |
237 | QFETCH(bool, niceNumbersEnabled); |
|
237 | QFETCH(bool, niceNumbersEnabled); | |
238 | QFETCH(qreal, min); |
|
238 | QFETCH(qreal, min); | |
@@ -252,8 +252,7 void tst_QValueAxis::niceNumbersEnabled() | |||||
252 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); |
|
252 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | |
253 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal))); |
|
253 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal))); | |
254 |
|
254 | |||
255 | m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled); |
|
255 | if(niceNumbersEnabled) m_valuesaxis->applyNiceNumbers(); | |
256 | QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled); |
|
|||
257 |
|
256 | |||
258 | if(!qFuzzyCompare(expectedMin, min)) |
|
257 | if(!qFuzzyCompare(expectedMin, min)) | |
259 | QCOMPARE(spy1.count(), 1); |
|
258 | QCOMPARE(spy1.count(), 1); |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now