@@ -1,373 +1,371 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "themewidget.h" |
|
21 | #include "themewidget.h" | |
22 |
|
22 | |||
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QPieSeries> |
|
24 | #include <QPieSeries> | |
25 | #include <QPieSlice> |
|
25 | #include <QPieSlice> | |
26 | #include <QBarSeries> |
|
26 | #include <QBarSeries> | |
27 | #include <QPercentBarSeries> |
|
27 | #include <QPercentBarSeries> | |
28 | #include <QStackedBarSeries> |
|
28 | #include <QStackedBarSeries> | |
29 | #include <QBarSet> |
|
29 | #include <QBarSet> | |
30 | #include <QLineSeries> |
|
30 | #include <QLineSeries> | |
31 | #include <QSplineSeries> |
|
31 | #include <QSplineSeries> | |
32 | #include <QScatterSeries> |
|
32 | #include <QScatterSeries> | |
33 | #include <QAreaSeries> |
|
33 | #include <QAreaSeries> | |
34 | #include <QLegend> |
|
34 | #include <QLegend> | |
35 | #include <QGridLayout> |
|
35 | #include <QGridLayout> | |
36 | #include <QFormLayout> |
|
36 | #include <QFormLayout> | |
37 | #include <QComboBox> |
|
37 | #include <QComboBox> | |
38 | #include <QSpinBox> |
|
38 | #include <QSpinBox> | |
39 | #include <QCheckBox> |
|
39 | #include <QCheckBox> | |
40 | #include <QGroupBox> |
|
40 | #include <QGroupBox> | |
41 | #include <QLabel> |
|
41 | #include <QLabel> | |
42 | #include <QTime> |
|
42 | #include <QTime> | |
43 |
|
43 | |||
44 | ThemeWidget::ThemeWidget(QWidget* parent) : |
|
44 | ThemeWidget::ThemeWidget(QWidget* parent) : | |
45 | QWidget(parent), |
|
45 | QWidget(parent), | |
46 | m_listCount(3), |
|
46 | m_listCount(3), | |
47 | m_valueMax(10), |
|
47 | m_valueMax(10), | |
48 | m_valueCount(7), |
|
48 | m_valueCount(7), | |
49 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
49 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), | |
50 | m_themeComboBox(createThemeBox()), |
|
50 | m_themeComboBox(createThemeBox()), | |
51 |
m_antialiasCheckBox(new QCheckBox("Anti |
|
51 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), | |
52 | m_animatedComboBox(createAnimationBox()), |
|
52 | m_animatedComboBox(createAnimationBox()), | |
53 | m_legendComboBox(createLegendBox()) |
|
53 | m_legendComboBox(createLegendBox()) | |
54 |
|
||||
55 | { |
|
54 | { | |
56 | connectSignals(); |
|
55 | connectSignals(); | |
57 | // create layout |
|
56 | // create layout | |
58 | QGridLayout* baseLayout = new QGridLayout(); |
|
57 | QGridLayout* baseLayout = new QGridLayout(); | |
59 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
58 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
60 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
59 | settingsLayout->addWidget(new QLabel("Theme:")); | |
61 | settingsLayout->addWidget(m_themeComboBox); |
|
60 | settingsLayout->addWidget(m_themeComboBox); | |
62 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
61 | settingsLayout->addWidget(new QLabel("Animation:")); | |
63 | settingsLayout->addWidget(m_animatedComboBox); |
|
62 | settingsLayout->addWidget(m_animatedComboBox); | |
64 | settingsLayout->addWidget(m_legendComboBox); |
|
63 | settingsLayout->addWidget(m_legendComboBox); | |
65 | settingsLayout->addWidget(m_antialiasCheckBox); |
|
64 | settingsLayout->addWidget(m_antialiasCheckBox); | |
66 | settingsLayout->addStretch(); |
|
65 | settingsLayout->addStretch(); | |
67 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
66 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); | |
68 |
|
67 | |||
69 | //create charts |
|
68 | //create charts | |
70 |
|
69 | |||
71 | QChartView *chartView; |
|
70 | QChartView *chartView; | |
72 |
|
71 | |||
73 | chartView = new QChartView(createAreaChart()); |
|
72 | chartView = new QChartView(createAreaChart()); | |
74 | baseLayout->addWidget(chartView, 1, 0); |
|
73 | baseLayout->addWidget(chartView, 1, 0); | |
75 | m_charts << chartView; |
|
74 | m_charts << chartView; | |
76 |
|
75 | |||
77 | chartView = new QChartView(createBarChart(m_valueCount)); |
|
76 | chartView = new QChartView(createBarChart(m_valueCount)); | |
78 | baseLayout->addWidget(chartView, 1, 1); |
|
77 | baseLayout->addWidget(chartView, 1, 1); | |
79 | m_charts << chartView; |
|
78 | m_charts << chartView; | |
80 |
|
79 | |||
81 | chartView = new QChartView(createLineChart()); |
|
80 | chartView = new QChartView(createLineChart()); | |
82 | baseLayout->addWidget(chartView, 1, 2); |
|
81 | baseLayout->addWidget(chartView, 1, 2); | |
83 | m_charts << chartView; |
|
82 | m_charts << chartView; | |
84 |
|
83 | |||
85 | chartView = new QChartView(createPieChart()); |
|
84 | chartView = new QChartView(createPieChart()); | |
86 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... |
|
85 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... | |
87 | baseLayout->addWidget(chartView, 2, 0); |
|
86 | baseLayout->addWidget(chartView, 2, 0); | |
88 | m_charts << chartView; |
|
87 | m_charts << chartView; | |
89 |
|
88 | |||
90 | chartView = new QChartView(createSplineChart()); |
|
89 | chartView = new QChartView(createSplineChart()); | |
91 | baseLayout->addWidget(chartView, 2, 1); |
|
90 | baseLayout->addWidget(chartView, 2, 1); | |
92 | m_charts << chartView; |
|
91 | m_charts << chartView; | |
93 |
|
92 | |||
94 | chartView = new QChartView(createScatterChart()); |
|
93 | chartView = new QChartView(createScatterChart()); | |
95 | baseLayout->addWidget(chartView, 2, 2); |
|
94 | baseLayout->addWidget(chartView, 2, 2); | |
96 | m_charts << chartView; |
|
95 | m_charts << chartView; | |
97 |
|
96 | |||
98 | setLayout(baseLayout); |
|
97 | setLayout(baseLayout); | |
99 |
|
98 | |||
100 | // Set defaults |
|
99 | // Set defaults | |
101 | m_antialiasCheckBox->setChecked(true); |
|
100 | m_antialiasCheckBox->setChecked(true); | |
102 | } |
|
101 | } | |
103 |
|
102 | |||
104 | ThemeWidget::~ThemeWidget() |
|
103 | ThemeWidget::~ThemeWidget() | |
105 | { |
|
104 | { | |
106 | } |
|
105 | } | |
107 |
|
106 | |||
108 | void ThemeWidget::connectSignals() |
|
107 | void ThemeWidget::connectSignals() | |
109 | { |
|
108 | { | |
110 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
109 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
111 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
110 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
112 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
111 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
113 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
112 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
114 | } |
|
113 | } | |
115 |
|
114 | |||
116 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
115 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const | |
117 | { |
|
116 | { | |
118 | DataTable dataTable; |
|
117 | DataTable dataTable; | |
119 |
|
118 | |||
120 | // set seed for random stuff |
|
119 | // set seed for random stuff | |
121 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
120 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
122 |
|
121 | |||
123 | // generate random data |
|
122 | // generate random data | |
124 | for (int i(0); i < listCount; i++) { |
|
123 | for (int i(0); i < listCount; i++) { | |
125 | DataList dataList; |
|
124 | DataList dataList; | |
126 | qreal yValue(0); |
|
125 | qreal yValue(0); | |
127 | for (int j(0); j < valueCount; j++) { |
|
126 | for (int j(0); j < valueCount; j++) { | |
128 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; |
|
127 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; | |
129 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), |
|
128 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), | |
130 | yValue); |
|
129 | yValue); | |
131 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); |
|
130 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); | |
132 | dataList << Data(value, label); |
|
131 | dataList << Data(value, label); | |
133 | } |
|
132 | } | |
134 | dataTable << dataList; |
|
133 | dataTable << dataList; | |
135 | } |
|
134 | } | |
136 |
|
135 | |||
137 | return dataTable; |
|
136 | return dataTable; | |
138 | } |
|
137 | } | |
139 |
|
138 | |||
140 | QComboBox* ThemeWidget::createThemeBox() const |
|
139 | QComboBox* ThemeWidget::createThemeBox() const | |
141 | { |
|
140 | { | |
142 | // settings layout |
|
141 | // settings layout | |
143 | QComboBox* themeComboBox = new QComboBox(); |
|
142 | QComboBox* themeComboBox = new QComboBox(); | |
144 | themeComboBox->addItem("Default", QChart::ChartThemeDefault); |
|
|||
145 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
143 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
146 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
144 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
147 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
145 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
148 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
146 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
149 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
147 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
150 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
148 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
151 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
149 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
152 | return themeComboBox; |
|
150 | return themeComboBox; | |
153 | } |
|
151 | } | |
154 |
|
152 | |||
155 | QComboBox* ThemeWidget::createAnimationBox() const |
|
153 | QComboBox* ThemeWidget::createAnimationBox() const | |
156 | { |
|
154 | { | |
157 | // settings layout |
|
155 | // settings layout | |
158 | QComboBox* animationComboBox = new QComboBox(); |
|
156 | QComboBox* animationComboBox = new QComboBox(); | |
159 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
157 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
160 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
158 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
161 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
159 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
162 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
160 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
163 | return animationComboBox; |
|
161 | return animationComboBox; | |
164 | } |
|
162 | } | |
165 |
|
163 | |||
166 | QComboBox* ThemeWidget::createLegendBox() const |
|
164 | QComboBox* ThemeWidget::createLegendBox() const | |
167 | { |
|
165 | { | |
168 | QComboBox* legendComboBox = new QComboBox(); |
|
166 | QComboBox* legendComboBox = new QComboBox(); | |
169 | legendComboBox->addItem("Legend None", -1); |
|
167 | legendComboBox->addItem("Legend None", -1); | |
170 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); |
|
168 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); | |
171 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); |
|
169 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); | |
172 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); |
|
170 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); | |
173 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); |
|
171 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); | |
174 | return legendComboBox; |
|
172 | return legendComboBox; | |
175 | } |
|
173 | } | |
176 |
|
174 | |||
177 | QChart* ThemeWidget::createAreaChart() const |
|
175 | QChart* ThemeWidget::createAreaChart() const | |
178 | { |
|
176 | { | |
179 | // area chart |
|
177 | // area chart | |
180 | QChart *chart = new QChart(); |
|
178 | QChart *chart = new QChart(); | |
181 | chart->axisX()->setNiceNumbers(true); |
|
179 | chart->axisX()->setNiceNumbers(true); | |
182 | chart->axisY()->setNiceNumbers(true); |
|
180 | chart->axisY()->setNiceNumbers(true); | |
183 | chart->setTitle("Area chart"); |
|
181 | chart->setTitle("Area chart"); | |
184 | QString name("Series "); |
|
182 | QString name("Series "); | |
185 | int nameIndex = 0; |
|
183 | int nameIndex = 0; | |
186 |
|
184 | |||
187 | // The lower series initialized to zero values |
|
185 | // The lower series initialized to zero values | |
188 | QLineSeries *lowerSeries = 0; |
|
186 | QLineSeries *lowerSeries = 0; | |
189 | for (int i(0); i < m_dataTable.count(); i++) { |
|
187 | for (int i(0); i < m_dataTable.count(); i++) { | |
190 | QLineSeries *upperSeries = new QLineSeries(chart); |
|
188 | QLineSeries *upperSeries = new QLineSeries(chart); | |
191 | for (int j(0); j < m_dataTable[i].count(); j++) { |
|
189 | for (int j(0); j < m_dataTable[i].count(); j++) { | |
192 | Data data = m_dataTable[i].at(j); |
|
190 | Data data = m_dataTable[i].at(j); | |
193 | if (lowerSeries) |
|
191 | if (lowerSeries) | |
194 | upperSeries->append(QPointF(j, lowerSeries->y(i) + data.first.y())); |
|
192 | upperSeries->append(QPointF(j, lowerSeries->y(i) + data.first.y())); | |
195 | else |
|
193 | else | |
196 | upperSeries->append(QPointF(j, data.first.y())); |
|
194 | upperSeries->append(QPointF(j, data.first.y())); | |
197 | } |
|
195 | } | |
198 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
196 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); | |
199 | area->setName(name + QString::number(nameIndex)); |
|
197 | area->setName(name + QString::number(nameIndex)); | |
200 | nameIndex++; |
|
198 | nameIndex++; | |
201 | chart->addSeries(area); |
|
199 | chart->addSeries(area); | |
202 | lowerSeries = upperSeries; |
|
200 | lowerSeries = upperSeries; | |
203 | } |
|
201 | } | |
204 | return chart; |
|
202 | return chart; | |
205 | } |
|
203 | } | |
206 |
|
204 | |||
207 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
205 | QChart* ThemeWidget::createBarChart(int valueCount) const | |
208 | { |
|
206 | { | |
209 | // bar chart |
|
207 | // bar chart | |
210 | QChart* chart = new QChart(); |
|
208 | QChart* chart = new QChart(); | |
211 | chart->axisX()->setNiceNumbers(true); |
|
209 | chart->axisX()->setNiceNumbers(true); | |
212 | chart->axisY()->setNiceNumbers(true); |
|
210 | chart->axisY()->setNiceNumbers(true); | |
213 | chart->setTitle("Bar chart"); |
|
211 | chart->setTitle("Bar chart"); | |
214 | QBarCategories categories; |
|
212 | QBarCategories categories; | |
215 | // TODO: categories |
|
213 | // TODO: categories | |
216 | for (int i(0); i < valueCount; i++) |
|
214 | for (int i(0); i < valueCount; i++) | |
217 | categories << QString::number(i); |
|
215 | categories << QString::number(i); | |
218 | // QBarSeries* series = new QBarSeries(categories, chart); |
|
216 | // QBarSeries* series = new QBarSeries(categories, chart); | |
219 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); |
|
217 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); | |
220 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); |
|
218 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); | |
221 | for (int i(0); i < m_dataTable.count(); i++) { |
|
219 | for (int i(0); i < m_dataTable.count(); i++) { | |
222 | QBarSet *set = new QBarSet("Set" + QString::number(i)); |
|
220 | QBarSet *set = new QBarSet("Set" + QString::number(i)); | |
223 | foreach (Data data, m_dataTable[i]) |
|
221 | foreach (Data data, m_dataTable[i]) | |
224 | *set << data.first.y(); |
|
222 | *set << data.first.y(); | |
225 | series->appendBarSet(set); |
|
223 | series->appendBarSet(set); | |
226 | } |
|
224 | } | |
227 | chart->addSeries(series); |
|
225 | chart->addSeries(series); | |
228 | return chart; |
|
226 | return chart; | |
229 | } |
|
227 | } | |
230 |
|
228 | |||
231 | QChart* ThemeWidget::createLineChart() const |
|
229 | QChart* ThemeWidget::createLineChart() const | |
232 | { |
|
230 | { | |
233 | // line chart |
|
231 | // line chart | |
234 | QChart* chart = new QChart(); |
|
232 | QChart* chart = new QChart(); | |
235 | chart->axisX()->setNiceNumbers(true); |
|
233 | chart->axisX()->setNiceNumbers(true); | |
236 | chart->axisY()->setNiceNumbers(true); |
|
234 | chart->axisY()->setNiceNumbers(true); | |
237 | chart->setTitle("Line chart"); |
|
235 | chart->setTitle("Line chart"); | |
238 | QString name("Series "); |
|
236 | QString name("Series "); | |
239 | int nameIndex = 0; |
|
237 | int nameIndex = 0; | |
240 | foreach (DataList list, m_dataTable) { |
|
238 | foreach (DataList list, m_dataTable) { | |
241 | QLineSeries *series = new QLineSeries(chart); |
|
239 | QLineSeries *series = new QLineSeries(chart); | |
242 | foreach (Data data, list) |
|
240 | foreach (Data data, list) | |
243 | series->append(data.first); |
|
241 | series->append(data.first); | |
244 | series->setName(name + QString::number(nameIndex)); |
|
242 | series->setName(name + QString::number(nameIndex)); | |
245 | nameIndex++; |
|
243 | nameIndex++; | |
246 | chart->addSeries(series); |
|
244 | chart->addSeries(series); | |
247 | } |
|
245 | } | |
248 | return chart; |
|
246 | return chart; | |
249 | } |
|
247 | } | |
250 |
|
248 | |||
251 | QChart* ThemeWidget::createPieChart() const |
|
249 | QChart* ThemeWidget::createPieChart() const | |
252 | { |
|
250 | { | |
253 | // pie chart |
|
251 | // pie chart | |
254 | QChart* chart = new QChart(); |
|
252 | QChart* chart = new QChart(); | |
255 | chart->setTitle("Pie chart"); |
|
253 | chart->setTitle("Pie chart"); | |
256 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
254 | qreal pieSize = 1.0 / m_dataTable.count(); | |
257 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
255 | for (int i = 0; i < m_dataTable.count(); i++) { | |
258 | QPieSeries *series = new QPieSeries(chart); |
|
256 | QPieSeries *series = new QPieSeries(chart); | |
259 | foreach (Data data, m_dataTable[i]) { |
|
257 | foreach (Data data, m_dataTable[i]) { | |
260 | QPieSlice *slice = series->append(data.first.y(), data.second); |
|
258 | QPieSlice *slice = series->append(data.first.y(), data.second); | |
261 | if (data == m_dataTable[i].first()) { |
|
259 | if (data == m_dataTable[i].first()) { | |
262 | slice->setLabelVisible(); |
|
260 | slice->setLabelVisible(); | |
263 | slice->setExploded(); |
|
261 | slice->setExploded(); | |
264 | } |
|
262 | } | |
265 | } |
|
263 | } | |
266 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
264 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
267 | series->setPieSize(pieSize); |
|
265 | series->setPieSize(pieSize); | |
268 | series->setPiePosition(hPos, 0.5); |
|
266 | series->setPiePosition(hPos, 0.5); | |
269 | chart->addSeries(series); |
|
267 | chart->addSeries(series); | |
270 | } |
|
268 | } | |
271 |
|
269 | |||
272 | return chart; |
|
270 | return chart; | |
273 | } |
|
271 | } | |
274 |
|
272 | |||
275 | QChart* ThemeWidget::createSplineChart() const |
|
273 | QChart* ThemeWidget::createSplineChart() const | |
276 | { // spine chart |
|
274 | { // spine chart | |
277 | QChart* chart = new QChart(); |
|
275 | QChart* chart = new QChart(); | |
278 | chart->axisX()->setNiceNumbers(true); |
|
276 | chart->axisX()->setNiceNumbers(true); | |
279 | chart->axisY()->setNiceNumbers(true); |
|
277 | chart->axisY()->setNiceNumbers(true); | |
280 | chart->setTitle("Spline chart"); |
|
278 | chart->setTitle("Spline chart"); | |
281 | QString name("Series "); |
|
279 | QString name("Series "); | |
282 | int nameIndex = 0; |
|
280 | int nameIndex = 0; | |
283 | foreach (DataList list, m_dataTable) { |
|
281 | foreach (DataList list, m_dataTable) { | |
284 | QSplineSeries *series = new QSplineSeries(chart); |
|
282 | QSplineSeries *series = new QSplineSeries(chart); | |
285 | foreach (Data data, list) |
|
283 | foreach (Data data, list) | |
286 | series->append(data.first); |
|
284 | series->append(data.first); | |
287 | series->setName(name + QString::number(nameIndex)); |
|
285 | series->setName(name + QString::number(nameIndex)); | |
288 | nameIndex++; |
|
286 | nameIndex++; | |
289 | chart->addSeries(series); |
|
287 | chart->addSeries(series); | |
290 | } |
|
288 | } | |
291 | return chart; |
|
289 | return chart; | |
292 | } |
|
290 | } | |
293 |
|
291 | |||
294 | QChart* ThemeWidget::createScatterChart() const |
|
292 | QChart* ThemeWidget::createScatterChart() const | |
295 | { // scatter chart |
|
293 | { // scatter chart | |
296 | QChart* chart = new QChart(); |
|
294 | QChart* chart = new QChart(); | |
297 | chart->axisX()->setNiceNumbers(true); |
|
295 | chart->axisX()->setNiceNumbers(true); | |
298 | chart->axisY()->setNiceNumbers(true); |
|
296 | chart->axisY()->setNiceNumbers(true); | |
299 | chart->setTitle("Scatter chart"); |
|
297 | chart->setTitle("Scatter chart"); | |
300 | QString name("Series "); |
|
298 | QString name("Series "); | |
301 | int nameIndex = 0; |
|
299 | int nameIndex = 0; | |
302 | foreach (DataList list, m_dataTable) { |
|
300 | foreach (DataList list, m_dataTable) { | |
303 | QScatterSeries *series = new QScatterSeries(chart); |
|
301 | QScatterSeries *series = new QScatterSeries(chart); | |
304 | foreach (Data data, list) |
|
302 | foreach (Data data, list) | |
305 | series->append(data.first); |
|
303 | series->append(data.first); | |
306 | series->setName(name + QString::number(nameIndex)); |
|
304 | series->setName(name + QString::number(nameIndex)); | |
307 | nameIndex++; |
|
305 | nameIndex++; | |
308 | chart->addSeries(series); |
|
306 | chart->addSeries(series); | |
309 | } |
|
307 | } | |
310 | return chart; |
|
308 | return chart; | |
311 | } |
|
309 | } | |
312 |
|
310 | |||
313 | void ThemeWidget::updateUI() |
|
311 | void ThemeWidget::updateUI() | |
314 | { |
|
312 | { | |
315 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
313 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
316 |
|
314 | |||
317 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
315 | if (m_charts.at(0)->chart()->theme() != theme) { | |
318 | foreach (QChartView *chartView, m_charts) |
|
316 | foreach (QChartView *chartView, m_charts) | |
319 | chartView->chart()->setTheme(theme); |
|
317 | chartView->chart()->setTheme(theme); | |
320 |
|
318 | |||
321 | QPalette pal = window()->palette(); |
|
319 | QPalette pal = window()->palette(); | |
322 | if (theme == QChart::ChartThemeLight) { |
|
320 | if (theme == QChart::ChartThemeLight) { | |
323 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
321 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
324 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
322 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
325 | } else if (theme == QChart::ChartThemeDark) { |
|
323 | } else if (theme == QChart::ChartThemeDark) { | |
326 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
324 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
327 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
325 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
328 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
326 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
329 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
327 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
330 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
328 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
331 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
329 | } else if (theme == QChart::ChartThemeBrownSand) { | |
332 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
330 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
333 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
331 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
334 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
332 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
335 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
333 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
336 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
334 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
337 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
335 | } else if (theme == QChart::ChartThemeHighContrast) { | |
338 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
336 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
339 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
337 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
340 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
338 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
341 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
339 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
342 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
340 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
343 | } else { |
|
341 | } else { | |
344 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
342 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
345 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
343 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
346 | } |
|
344 | } | |
347 | window()->setPalette(pal); |
|
345 | window()->setPalette(pal); | |
348 | } |
|
346 | } | |
349 |
|
347 | |||
350 | bool checked = m_antialiasCheckBox->isChecked(); |
|
348 | bool checked = m_antialiasCheckBox->isChecked(); | |
351 | foreach (QChartView *chart, m_charts) |
|
349 | foreach (QChartView *chart, m_charts) | |
352 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
350 | chart->setRenderHint(QPainter::Antialiasing, checked); | |
353 |
|
351 | |||
354 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
352 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
355 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
353 | if (m_charts.at(0)->chart()->animationOptions() != options) { | |
356 | foreach (QChartView *chartView, m_charts) |
|
354 | foreach (QChartView *chartView, m_charts) | |
357 | chartView->chart()->setAnimationOptions(options); |
|
355 | chartView->chart()->setAnimationOptions(options); | |
358 | } |
|
356 | } | |
359 |
|
357 | |||
360 | int alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
358 | int alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
361 | if (alignment == -1) { |
|
359 | if (alignment == -1) { | |
362 | foreach (QChartView *chartView, m_charts) { |
|
360 | foreach (QChartView *chartView, m_charts) { | |
363 | chartView->chart()->legend()->setVisible(false); |
|
361 | chartView->chart()->legend()->setVisible(false); | |
364 | } |
|
362 | } | |
365 | } else { |
|
363 | } else { | |
366 | QLegend::Alignments legendAlignment(alignment); |
|
364 | QLegend::Alignments legendAlignment(alignment); | |
367 | foreach (QChartView *chartView, m_charts) { |
|
365 | foreach (QChartView *chartView, m_charts) { | |
368 | chartView->chart()->legend()->setAlignmnent(legendAlignment); |
|
366 | chartView->chart()->legend()->setAlignmnent(legendAlignment); | |
369 | chartView->chart()->legend()->setVisible(true); |
|
367 | chartView->chart()->legend()->setVisible(true); | |
370 | } |
|
368 | } | |
371 | } |
|
369 | } | |
372 | } |
|
370 | } | |
373 |
|
371 |
@@ -1,322 +1,321 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 | #include "mainwidget.h" |
|
20 | #include "mainwidget.h" | |
21 | #include "customslice.h" |
|
21 | #include "customslice.h" | |
22 | #include "pentool.h" |
|
22 | #include "pentool.h" | |
23 | #include "brushtool.h" |
|
23 | #include "brushtool.h" | |
24 | #include <QPushButton> |
|
24 | #include <QPushButton> | |
25 | #include <QComboBox> |
|
25 | #include <QComboBox> | |
26 | #include <QCheckBox> |
|
26 | #include <QCheckBox> | |
27 | #include <QLabel> |
|
27 | #include <QLabel> | |
28 | #include <QGroupBox> |
|
28 | #include <QGroupBox> | |
29 | #include <QDoubleSpinBox> |
|
29 | #include <QDoubleSpinBox> | |
30 | #include <QFormLayout> |
|
30 | #include <QFormLayout> | |
31 | #include <QFontDialog> |
|
31 | #include <QFontDialog> | |
32 | #include <QChartView> |
|
32 | #include <QChartView> | |
33 | #include <QPieSeries> |
|
33 | #include <QPieSeries> | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
35 | QTCOMMERCIALCHART_USE_NAMESPACE | |
36 |
|
36 | |||
37 | MainWidget::MainWidget(QWidget* parent) |
|
37 | MainWidget::MainWidget(QWidget* parent) | |
38 | :QWidget(parent), |
|
38 | :QWidget(parent), | |
39 | m_slice(0) |
|
39 | m_slice(0) | |
40 | { |
|
40 | { | |
41 | // create chart |
|
41 | // create chart | |
42 | QChart *chart = new QChart; |
|
42 | QChart *chart = new QChart; | |
43 | chart->setTitle("Piechart customization"); |
|
43 | chart->setTitle("Piechart customization"); | |
44 | chart->setAnimationOptions(QChart::AllAnimations); |
|
44 | chart->setAnimationOptions(QChart::AllAnimations); | |
45 |
|
45 | |||
46 | // create series |
|
46 | // create series | |
47 | m_series = new QPieSeries(); |
|
47 | m_series = new QPieSeries(); | |
48 | *m_series << new CustomSlice(10.0, "Slice 1"); |
|
48 | *m_series << new CustomSlice(10.0, "Slice 1"); | |
49 | *m_series << new CustomSlice(20.0, "Slice 2"); |
|
49 | *m_series << new CustomSlice(20.0, "Slice 2"); | |
50 | *m_series << new CustomSlice(30.0, "Slice 3"); |
|
50 | *m_series << new CustomSlice(30.0, "Slice 3"); | |
51 | *m_series << new CustomSlice(40.0, "Slice 4"); |
|
51 | *m_series << new CustomSlice(40.0, "Slice 4"); | |
52 | *m_series << new CustomSlice(50.0, "Slice 5"); |
|
52 | *m_series << new CustomSlice(50.0, "Slice 5"); | |
53 | m_series->setLabelsVisible(); |
|
53 | m_series->setLabelsVisible(); | |
54 | chart->addSeries(m_series); |
|
54 | chart->addSeries(m_series); | |
55 |
|
55 | |||
56 | connect(m_series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), this, SLOT(handleSliceClicked(QPieSlice*, Qt::MouseButtons))); |
|
56 | connect(m_series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), this, SLOT(handleSliceClicked(QPieSlice*, Qt::MouseButtons))); | |
57 |
|
57 | |||
58 | // chart settings |
|
58 | // chart settings | |
59 | m_themeComboBox = new QComboBox(); |
|
59 | m_themeComboBox = new QComboBox(); | |
60 | m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); |
|
|||
61 | m_themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
60 | m_themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
62 | m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean); |
|
61 | m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean); | |
63 | m_themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
62 | m_themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
64 | m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand); |
|
63 | m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand); | |
65 | m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs); |
|
64 | m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs); | |
66 | m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
65 | m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
67 | m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
66 | m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
68 |
|
67 | |||
69 | m_aaCheckBox = new QCheckBox(); |
|
68 | m_aaCheckBox = new QCheckBox(); | |
70 | m_animationsCheckBox = new QCheckBox(); |
|
69 | m_animationsCheckBox = new QCheckBox(); | |
71 | m_animationsCheckBox->setCheckState(Qt::Checked); |
|
70 | m_animationsCheckBox->setCheckState(Qt::Checked); | |
72 |
|
71 | |||
73 | QFormLayout* chartSettingsLayout = new QFormLayout(); |
|
72 | QFormLayout* chartSettingsLayout = new QFormLayout(); | |
74 | chartSettingsLayout->addRow("Theme", m_themeComboBox); |
|
73 | chartSettingsLayout->addRow("Theme", m_themeComboBox); | |
75 | chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox); |
|
74 | chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox); | |
76 | chartSettingsLayout->addRow("Animations", m_animationsCheckBox); |
|
75 | chartSettingsLayout->addRow("Animations", m_animationsCheckBox); | |
77 | QGroupBox* chartSettings = new QGroupBox("Chart"); |
|
76 | QGroupBox* chartSettings = new QGroupBox("Chart"); | |
78 | chartSettings->setLayout(chartSettingsLayout); |
|
77 | chartSettings->setLayout(chartSettingsLayout); | |
79 |
|
78 | |||
80 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings())); |
|
79 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings())); | |
81 | connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); |
|
80 | connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); | |
82 | connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); |
|
81 | connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); | |
83 |
|
82 | |||
84 | // series settings |
|
83 | // series settings | |
85 | m_hPosition = new QDoubleSpinBox(); |
|
84 | m_hPosition = new QDoubleSpinBox(); | |
86 | m_hPosition->setMinimum(0.0); |
|
85 | m_hPosition->setMinimum(0.0); | |
87 | m_hPosition->setMaximum(1.0); |
|
86 | m_hPosition->setMaximum(1.0); | |
88 | m_hPosition->setSingleStep(0.1); |
|
87 | m_hPosition->setSingleStep(0.1); | |
89 | m_hPosition->setValue(m_series->pieHorizontalPosition()); |
|
88 | m_hPosition->setValue(m_series->pieHorizontalPosition()); | |
90 |
|
89 | |||
91 | m_vPosition = new QDoubleSpinBox(); |
|
90 | m_vPosition = new QDoubleSpinBox(); | |
92 | m_vPosition->setMinimum(0.0); |
|
91 | m_vPosition->setMinimum(0.0); | |
93 | m_vPosition->setMaximum(1.0); |
|
92 | m_vPosition->setMaximum(1.0); | |
94 | m_vPosition->setSingleStep(0.1); |
|
93 | m_vPosition->setSingleStep(0.1); | |
95 | m_vPosition->setValue(m_series->pieVerticalPosition()); |
|
94 | m_vPosition->setValue(m_series->pieVerticalPosition()); | |
96 |
|
95 | |||
97 | m_sizeFactor = new QDoubleSpinBox(); |
|
96 | m_sizeFactor = new QDoubleSpinBox(); | |
98 | m_sizeFactor->setMinimum(0.0); |
|
97 | m_sizeFactor->setMinimum(0.0); | |
99 | m_sizeFactor->setMaximum(1.0); |
|
98 | m_sizeFactor->setMaximum(1.0); | |
100 | m_sizeFactor->setSingleStep(0.1); |
|
99 | m_sizeFactor->setSingleStep(0.1); | |
101 | m_sizeFactor->setValue(m_series->pieSize()); |
|
100 | m_sizeFactor->setValue(m_series->pieSize()); | |
102 |
|
101 | |||
103 | m_startAngle = new QDoubleSpinBox(); |
|
102 | m_startAngle = new QDoubleSpinBox(); | |
104 | m_startAngle->setMinimum(0.0); |
|
103 | m_startAngle->setMinimum(0.0); | |
105 | m_startAngle->setMaximum(360); |
|
104 | m_startAngle->setMaximum(360); | |
106 | m_startAngle->setValue(m_series->pieStartAngle()); |
|
105 | m_startAngle->setValue(m_series->pieStartAngle()); | |
107 | m_startAngle->setSingleStep(1); |
|
106 | m_startAngle->setSingleStep(1); | |
108 |
|
107 | |||
109 | m_endAngle = new QDoubleSpinBox(); |
|
108 | m_endAngle = new QDoubleSpinBox(); | |
110 | m_endAngle->setMinimum(0.0); |
|
109 | m_endAngle->setMinimum(0.0); | |
111 | m_endAngle->setMaximum(360); |
|
110 | m_endAngle->setMaximum(360); | |
112 | m_endAngle->setValue(m_series->pieEndAngle()); |
|
111 | m_endAngle->setValue(m_series->pieEndAngle()); | |
113 | m_endAngle->setSingleStep(1); |
|
112 | m_endAngle->setSingleStep(1); | |
114 |
|
113 | |||
115 | QPushButton *addSlice = new QPushButton("Add slice"); |
|
114 | QPushButton *addSlice = new QPushButton("Add slice"); | |
116 | QPushButton *insertSlice = new QPushButton("Insert slice"); |
|
115 | QPushButton *insertSlice = new QPushButton("Insert slice"); | |
117 |
|
116 | |||
118 | QFormLayout* seriesSettingsLayout = new QFormLayout(); |
|
117 | QFormLayout* seriesSettingsLayout = new QFormLayout(); | |
119 | seriesSettingsLayout->addRow("Horizontal position", m_hPosition); |
|
118 | seriesSettingsLayout->addRow("Horizontal position", m_hPosition); | |
120 | seriesSettingsLayout->addRow("Vertical position", m_vPosition); |
|
119 | seriesSettingsLayout->addRow("Vertical position", m_vPosition); | |
121 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); |
|
120 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); | |
122 | seriesSettingsLayout->addRow("Start angle", m_startAngle); |
|
121 | seriesSettingsLayout->addRow("Start angle", m_startAngle); | |
123 | seriesSettingsLayout->addRow("End angle", m_endAngle); |
|
122 | seriesSettingsLayout->addRow("End angle", m_endAngle); | |
124 | seriesSettingsLayout->addRow(addSlice); |
|
123 | seriesSettingsLayout->addRow(addSlice); | |
125 | seriesSettingsLayout->addRow(insertSlice); |
|
124 | seriesSettingsLayout->addRow(insertSlice); | |
126 | QGroupBox* seriesSettings = new QGroupBox("Series"); |
|
125 | QGroupBox* seriesSettings = new QGroupBox("Series"); | |
127 | seriesSettings->setLayout(seriesSettingsLayout); |
|
126 | seriesSettings->setLayout(seriesSettingsLayout); | |
128 |
|
127 | |||
129 | connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
128 | connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
130 | connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
129 | connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
131 | connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
130 | connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
132 | connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
131 | connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
133 | connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
132 | connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
134 | connect(addSlice, SIGNAL(clicked()), this, SLOT(addSlice())); |
|
133 | connect(addSlice, SIGNAL(clicked()), this, SLOT(addSlice())); | |
135 | connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); |
|
134 | connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); | |
136 |
|
135 | |||
137 | // slice settings |
|
136 | // slice settings | |
138 | m_sliceName = new QLabel("<click a slice>"); |
|
137 | m_sliceName = new QLabel("<click a slice>"); | |
139 | m_sliceValue = new QDoubleSpinBox(); |
|
138 | m_sliceValue = new QDoubleSpinBox(); | |
140 | m_sliceValue->setMaximum(1000); |
|
139 | m_sliceValue->setMaximum(1000); | |
141 | m_sliceLabelVisible = new QCheckBox(); |
|
140 | m_sliceLabelVisible = new QCheckBox(); | |
142 | m_sliceLabelArmFactor = new QDoubleSpinBox(); |
|
141 | m_sliceLabelArmFactor = new QDoubleSpinBox(); | |
143 | m_sliceLabelArmFactor->setSingleStep(0.01); |
|
142 | m_sliceLabelArmFactor->setSingleStep(0.01); | |
144 | m_sliceExploded = new QCheckBox(); |
|
143 | m_sliceExploded = new QCheckBox(); | |
145 | m_sliceExplodedFactor = new QDoubleSpinBox(); |
|
144 | m_sliceExplodedFactor = new QDoubleSpinBox(); | |
146 | m_sliceExplodedFactor->setSingleStep(0.01); |
|
145 | m_sliceExplodedFactor->setSingleStep(0.01); | |
147 | m_pen = new QPushButton(); |
|
146 | m_pen = new QPushButton(); | |
148 | m_penTool = new PenTool("Slice pen", this); |
|
147 | m_penTool = new PenTool("Slice pen", this); | |
149 | m_brush = new QPushButton(); |
|
148 | m_brush = new QPushButton(); | |
150 | m_brushTool = new BrushTool("Slice brush", this); |
|
149 | m_brushTool = new BrushTool("Slice brush", this); | |
151 | m_font = new QPushButton(); |
|
150 | m_font = new QPushButton(); | |
152 | m_labelPen = new QPushButton(); |
|
151 | m_labelPen = new QPushButton(); | |
153 | m_labelPenTool = new PenTool("Label pen", this); |
|
152 | m_labelPenTool = new PenTool("Label pen", this); | |
154 | QPushButton *removeSlice = new QPushButton("Remove slice"); |
|
153 | QPushButton *removeSlice = new QPushButton("Remove slice"); | |
155 |
|
154 | |||
156 | QFormLayout* sliceSettingsLayout = new QFormLayout(); |
|
155 | QFormLayout* sliceSettingsLayout = new QFormLayout(); | |
157 | sliceSettingsLayout->addRow("Selected", m_sliceName); |
|
156 | sliceSettingsLayout->addRow("Selected", m_sliceName); | |
158 | sliceSettingsLayout->addRow("Value", m_sliceValue); |
|
157 | sliceSettingsLayout->addRow("Value", m_sliceValue); | |
159 | sliceSettingsLayout->addRow("Pen", m_pen); |
|
158 | sliceSettingsLayout->addRow("Pen", m_pen); | |
160 | sliceSettingsLayout->addRow("Brush", m_brush); |
|
159 | sliceSettingsLayout->addRow("Brush", m_brush); | |
161 | sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); |
|
160 | sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); | |
162 | sliceSettingsLayout->addRow("Label font", m_font); |
|
161 | sliceSettingsLayout->addRow("Label font", m_font); | |
163 | sliceSettingsLayout->addRow("Label pen", m_labelPen); |
|
162 | sliceSettingsLayout->addRow("Label pen", m_labelPen); | |
164 | sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); |
|
163 | sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); | |
165 | sliceSettingsLayout->addRow("Exploded", m_sliceExploded); |
|
164 | sliceSettingsLayout->addRow("Exploded", m_sliceExploded); | |
166 | sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); |
|
165 | sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); | |
167 | sliceSettingsLayout->addRow(removeSlice); |
|
166 | sliceSettingsLayout->addRow(removeSlice); | |
168 | QGroupBox* sliceSettings = new QGroupBox("Slice"); |
|
167 | QGroupBox* sliceSettings = new QGroupBox("Slice"); | |
169 | sliceSettings->setLayout(sliceSettingsLayout); |
|
168 | sliceSettings->setLayout(sliceSettingsLayout); | |
170 |
|
169 | |||
171 | connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
170 | connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | |
172 | connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show())); |
|
171 | connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show())); | |
173 | connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
172 | connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | |
174 | connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); |
|
173 | connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); | |
175 | connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
174 | connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | |
176 | connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); |
|
175 | connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); | |
177 | connect(m_labelPen, SIGNAL(clicked()), m_labelPenTool, SLOT(show())); |
|
176 | connect(m_labelPen, SIGNAL(clicked()), m_labelPenTool, SLOT(show())); | |
178 | connect(m_labelPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
177 | connect(m_labelPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | |
179 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
178 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | |
180 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
179 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | |
181 | connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
180 | connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | |
182 | connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
181 | connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | |
183 | connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
182 | connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | |
184 | connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice())); |
|
183 | connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice())); | |
185 |
|
184 | |||
186 | // create chart view |
|
185 | // create chart view | |
187 | m_chartView = new QChartView(chart); |
|
186 | m_chartView = new QChartView(chart); | |
188 |
|
187 | |||
189 | // create main layout |
|
188 | // create main layout | |
190 | QVBoxLayout *settingsLayout = new QVBoxLayout(); |
|
189 | QVBoxLayout *settingsLayout = new QVBoxLayout(); | |
191 | settingsLayout->addWidget(chartSettings); |
|
190 | settingsLayout->addWidget(chartSettings); | |
192 | settingsLayout->addWidget(seriesSettings); |
|
191 | settingsLayout->addWidget(seriesSettings); | |
193 | settingsLayout->addWidget(sliceSettings); |
|
192 | settingsLayout->addWidget(sliceSettings); | |
194 | settingsLayout->addStretch(); |
|
193 | settingsLayout->addStretch(); | |
195 |
|
194 | |||
196 | QGridLayout* baseLayout = new QGridLayout(); |
|
195 | QGridLayout* baseLayout = new QGridLayout(); | |
197 | baseLayout->addLayout(settingsLayout, 0, 0); |
|
196 | baseLayout->addLayout(settingsLayout, 0, 0); | |
198 | baseLayout->addWidget(m_chartView, 0, 1); |
|
197 | baseLayout->addWidget(m_chartView, 0, 1); | |
199 | setLayout(baseLayout); |
|
198 | setLayout(baseLayout); | |
200 |
|
199 | |||
201 | updateSerieSettings(); |
|
200 | updateSerieSettings(); | |
202 | } |
|
201 | } | |
203 |
|
202 | |||
204 |
|
203 | |||
205 | void MainWidget::updateChartSettings() |
|
204 | void MainWidget::updateChartSettings() | |
206 | { |
|
205 | { | |
207 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
206 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
208 | m_chartView->chart()->setTheme(theme); |
|
207 | m_chartView->chart()->setTheme(theme); | |
209 | m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); |
|
208 | m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); | |
210 |
|
209 | |||
211 | if (m_animationsCheckBox->checkState() == Qt::Checked) |
|
210 | if (m_animationsCheckBox->checkState() == Qt::Checked) | |
212 | m_chartView->chart()->setAnimationOptions(QChart::AllAnimations); |
|
211 | m_chartView->chart()->setAnimationOptions(QChart::AllAnimations); | |
213 | else |
|
212 | else | |
214 | m_chartView->chart()->setAnimationOptions(QChart::NoAnimation); |
|
213 | m_chartView->chart()->setAnimationOptions(QChart::NoAnimation); | |
215 | } |
|
214 | } | |
216 |
|
215 | |||
217 | void MainWidget::updateSerieSettings() |
|
216 | void MainWidget::updateSerieSettings() | |
218 | { |
|
217 | { | |
219 | m_series->setPiePosition(m_hPosition->value(), m_vPosition->value()); |
|
218 | m_series->setPiePosition(m_hPosition->value(), m_vPosition->value()); | |
220 | m_series->setPieSize(m_sizeFactor->value()); |
|
219 | m_series->setPieSize(m_sizeFactor->value()); | |
221 | m_series->setPieStartAngle(m_startAngle->value()); |
|
220 | m_series->setPieStartAngle(m_startAngle->value()); | |
222 | m_series->setPieEndAngle(m_endAngle->value()); |
|
221 | m_series->setPieEndAngle(m_endAngle->value()); | |
223 | } |
|
222 | } | |
224 |
|
223 | |||
225 | void MainWidget::updateSliceSettings() |
|
224 | void MainWidget::updateSliceSettings() | |
226 | { |
|
225 | { | |
227 | if (!m_slice) |
|
226 | if (!m_slice) | |
228 | return; |
|
227 | return; | |
229 |
|
228 | |||
230 | m_slice->setValue(m_sliceValue->value()); |
|
229 | m_slice->setValue(m_sliceValue->value()); | |
231 |
|
230 | |||
232 | m_slice->setPen(m_penTool->pen()); |
|
231 | m_slice->setPen(m_penTool->pen()); | |
233 | m_slice->setBrush(m_brushTool->brush()); |
|
232 | m_slice->setBrush(m_brushTool->brush()); | |
234 |
|
233 | |||
235 | m_slice->setLabelPen(m_labelPenTool->pen()); |
|
234 | m_slice->setLabelPen(m_labelPenTool->pen()); | |
236 | m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); |
|
235 | m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); | |
237 | m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); |
|
236 | m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); | |
238 |
|
237 | |||
239 | m_slice->setExploded(m_sliceExploded->isChecked()); |
|
238 | m_slice->setExploded(m_sliceExploded->isChecked()); | |
240 | m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); |
|
239 | m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); | |
241 | } |
|
240 | } | |
242 |
|
241 | |||
243 | void MainWidget::handleSliceClicked(QPieSlice* slice, Qt::MouseButtons buttons) |
|
242 | void MainWidget::handleSliceClicked(QPieSlice* slice, Qt::MouseButtons buttons) | |
244 | { |
|
243 | { | |
245 | Q_UNUSED(buttons); |
|
244 | Q_UNUSED(buttons); | |
246 |
|
245 | |||
247 | m_slice = static_cast<CustomSlice*>(slice); |
|
246 | m_slice = static_cast<CustomSlice*>(slice); | |
248 |
|
247 | |||
249 | // name |
|
248 | // name | |
250 | m_sliceName->setText(slice->label()); |
|
249 | m_sliceName->setText(slice->label()); | |
251 |
|
250 | |||
252 | // value |
|
251 | // value | |
253 | m_sliceValue->blockSignals(true); |
|
252 | m_sliceValue->blockSignals(true); | |
254 | m_sliceValue->setValue(slice->value()); |
|
253 | m_sliceValue->setValue(slice->value()); | |
255 | m_sliceValue->blockSignals(false); |
|
254 | m_sliceValue->blockSignals(false); | |
256 |
|
255 | |||
257 | // pen |
|
256 | // pen | |
258 | m_pen->setText(PenTool::name(m_slice->pen())); |
|
257 | m_pen->setText(PenTool::name(m_slice->pen())); | |
259 | m_penTool->setPen(m_slice->pen()); |
|
258 | m_penTool->setPen(m_slice->pen()); | |
260 |
|
259 | |||
261 | // brush |
|
260 | // brush | |
262 | m_brush->setText(m_slice->originalBrush().color().name()); |
|
261 | m_brush->setText(m_slice->originalBrush().color().name()); | |
263 | m_brushTool->setBrush(m_slice->originalBrush()); |
|
262 | m_brushTool->setBrush(m_slice->originalBrush()); | |
264 |
|
263 | |||
265 | // label |
|
264 | // label | |
266 | m_labelPen->setText(PenTool::name(m_slice->labelPen())); |
|
265 | m_labelPen->setText(PenTool::name(m_slice->labelPen())); | |
267 | m_labelPenTool->setPen(m_slice->labelPen()); |
|
266 | m_labelPenTool->setPen(m_slice->labelPen()); | |
268 | m_font->setText(slice->labelFont().toString()); |
|
267 | m_font->setText(slice->labelFont().toString()); | |
269 | m_sliceLabelVisible->blockSignals(true); |
|
268 | m_sliceLabelVisible->blockSignals(true); | |
270 | m_sliceLabelVisible->setChecked(slice->isLabelVisible()); |
|
269 | m_sliceLabelVisible->setChecked(slice->isLabelVisible()); | |
271 | m_sliceLabelVisible->blockSignals(false); |
|
270 | m_sliceLabelVisible->blockSignals(false); | |
272 | m_sliceLabelArmFactor->blockSignals(true); |
|
271 | m_sliceLabelArmFactor->blockSignals(true); | |
273 | m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor()); |
|
272 | m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor()); | |
274 | m_sliceLabelArmFactor->blockSignals(false); |
|
273 | m_sliceLabelArmFactor->blockSignals(false); | |
275 |
|
274 | |||
276 | // exploded |
|
275 | // exploded | |
277 | m_sliceExploded->blockSignals(true); |
|
276 | m_sliceExploded->blockSignals(true); | |
278 | m_sliceExploded->setChecked(slice->isExploded()); |
|
277 | m_sliceExploded->setChecked(slice->isExploded()); | |
279 | m_sliceExploded->blockSignals(false); |
|
278 | m_sliceExploded->blockSignals(false); | |
280 | m_sliceExplodedFactor->blockSignals(true); |
|
279 | m_sliceExplodedFactor->blockSignals(true); | |
281 | m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor()); |
|
280 | m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor()); | |
282 | m_sliceExplodedFactor->blockSignals(false); |
|
281 | m_sliceExplodedFactor->blockSignals(false); | |
283 | } |
|
282 | } | |
284 |
|
283 | |||
285 | void MainWidget::showFontDialog() |
|
284 | void MainWidget::showFontDialog() | |
286 | { |
|
285 | { | |
287 | if (!m_slice) |
|
286 | if (!m_slice) | |
288 | return; |
|
287 | return; | |
289 |
|
288 | |||
290 | QFontDialog dialog(m_slice->labelFont()); |
|
289 | QFontDialog dialog(m_slice->labelFont()); | |
291 | dialog.show(); |
|
290 | dialog.show(); | |
292 | dialog.exec(); |
|
291 | dialog.exec(); | |
293 |
|
292 | |||
294 | m_slice->setLabelFont(dialog.currentFont()); |
|
293 | m_slice->setLabelFont(dialog.currentFont()); | |
295 | m_font->setText(dialog.currentFont().toString()); |
|
294 | m_font->setText(dialog.currentFont().toString()); | |
296 | } |
|
295 | } | |
297 |
|
296 | |||
298 | void MainWidget::addSlice() |
|
297 | void MainWidget::addSlice() | |
299 | { |
|
298 | { | |
300 | *m_series << new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1)); |
|
299 | *m_series << new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1)); | |
301 | } |
|
300 | } | |
302 |
|
301 | |||
303 | void MainWidget::insertSlice() |
|
302 | void MainWidget::insertSlice() | |
304 | { |
|
303 | { | |
305 | if (!m_slice) |
|
304 | if (!m_slice) | |
306 | return; |
|
305 | return; | |
307 |
|
306 | |||
308 | int i = m_series->slices().indexOf(m_slice); |
|
307 | int i = m_series->slices().indexOf(m_slice); | |
309 |
|
308 | |||
310 | m_series->insert(i, new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1))); |
|
309 | m_series->insert(i, new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1))); | |
311 | } |
|
310 | } | |
312 |
|
311 | |||
313 | void MainWidget::removeSlice() |
|
312 | void MainWidget::removeSlice() | |
314 | { |
|
313 | { | |
315 | if (!m_slice) |
|
314 | if (!m_slice) | |
316 | return; |
|
315 | return; | |
317 |
|
316 | |||
318 | m_series->remove(m_slice); |
|
317 | m_series->remove(m_slice); | |
319 | m_slice = 0; |
|
318 | m_slice = 0; | |
320 | } |
|
319 | } | |
321 |
|
320 | |||
322 | #include "moc_mainwidget.cpp" |
|
321 | #include "moc_mainwidget.cpp" |
@@ -1,401 +1,401 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchartaxis.h" |
|
22 | #include "qchartaxis.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 | //series |
|
27 | //series | |
28 | #include "qbarseries.h" |
|
28 | #include "qbarseries.h" | |
29 | #include "qstackedbarseries.h" |
|
29 | #include "qstackedbarseries.h" | |
30 | #include "qpercentbarseries.h" |
|
30 | #include "qpercentbarseries.h" | |
31 | #include "qlineseries.h" |
|
31 | #include "qlineseries.h" | |
32 | #include "qareaseries.h" |
|
32 | #include "qareaseries.h" | |
33 | #include "qpieseries.h" |
|
33 | #include "qpieseries.h" | |
34 | #include "qscatterseries.h" |
|
34 | #include "qscatterseries.h" | |
35 | #include "qsplineseries.h" |
|
35 | #include "qsplineseries.h" | |
36 | //items |
|
36 | //items | |
37 | #include "axisitem_p.h" |
|
37 | #include "axisitem_p.h" | |
38 | #include "areachartitem_p.h" |
|
38 | #include "areachartitem_p.h" | |
39 | #include "barchartitem_p.h" |
|
39 | #include "barchartitem_p.h" | |
40 | #include "stackedbarchartitem_p.h" |
|
40 | #include "stackedbarchartitem_p.h" | |
41 | #include "percentbarchartitem_p.h" |
|
41 | #include "percentbarchartitem_p.h" | |
42 | #include "linechartitem_p.h" |
|
42 | #include "linechartitem_p.h" | |
43 | #include "piechartitem_p.h" |
|
43 | #include "piechartitem_p.h" | |
44 | #include "scatterchartitem_p.h" |
|
44 | #include "scatterchartitem_p.h" | |
45 | #include "splinechartitem_p.h" |
|
45 | #include "splinechartitem_p.h" | |
46 |
|
46 | |||
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
48 |
|
48 | |||
49 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
49 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
50 | m_chart(chart), |
|
50 | m_chart(chart), | |
51 | m_animator(0), |
|
51 | m_animator(0), | |
52 | m_dataset(dataset), |
|
52 | m_dataset(dataset), | |
53 | m_chartTheme(0), |
|
53 | m_chartTheme(0), | |
54 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
54 | m_rect(QRectF(QPoint(0,0),m_chart->size())), | |
55 | m_options(QChart::NoAnimation), |
|
55 | m_options(QChart::NoAnimation), | |
56 | m_themeForce(false), |
|
56 | m_themeForce(false), | |
57 | m_backgroundPadding(10) |
|
57 | m_backgroundPadding(10) | |
58 | { |
|
58 | { | |
59 | createConnections(); |
|
59 | createConnections(); | |
60 |
setTheme(QChart::ChartTheme |
|
60 | setTheme(QChart::ChartThemeLight, false); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | ChartPresenter::~ChartPresenter() |
|
63 | ChartPresenter::~ChartPresenter() | |
64 | { |
|
64 | { | |
65 | delete m_chartTheme; |
|
65 | delete m_chartTheme; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void ChartPresenter::createConnections() |
|
68 | void ChartPresenter::createConnections() | |
69 | { |
|
69 | { | |
70 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
70 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
71 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
71 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
72 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); |
|
72 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); | |
73 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); |
|
73 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); | |
74 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
74 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void ChartPresenter::handleGeometryChanged() |
|
77 | void ChartPresenter::handleGeometryChanged() | |
78 | { |
|
78 | { | |
79 | QRectF rect(QPoint(0,0),m_chart->size()); |
|
79 | QRectF rect(QPoint(0,0),m_chart->size()); | |
80 | QRectF padding = m_chart->padding(); |
|
80 | QRectF padding = m_chart->padding(); | |
81 | rect.adjust(padding.left(), padding.top(), -padding.right(), -padding.bottom()); |
|
81 | rect.adjust(padding.left(), padding.top(), -padding.right(), -padding.bottom()); | |
82 |
|
82 | |||
83 | //rewrite zoom stack |
|
83 | //rewrite zoom stack | |
84 | /* |
|
84 | /* | |
85 | for(int i=0;i<m_zoomStack.count();i++){ |
|
85 | for(int i=0;i<m_zoomStack.count();i++){ | |
86 | QRectF r = m_zoomStack[i]; |
|
86 | QRectF r = m_zoomStack[i]; | |
87 | qreal w = rect.width()/m_rect.width(); |
|
87 | qreal w = rect.width()/m_rect.width(); | |
88 | qreal h = rect.height()/m_rect.height(); |
|
88 | qreal h = rect.height()/m_rect.height(); | |
89 | QPointF tl = r.topLeft(); |
|
89 | QPointF tl = r.topLeft(); | |
90 | tl.setX(tl.x()*w); |
|
90 | tl.setX(tl.x()*w); | |
91 | tl.setY(tl.y()*h); |
|
91 | tl.setY(tl.y()*h); | |
92 | QPointF br = r.bottomRight(); |
|
92 | QPointF br = r.bottomRight(); | |
93 | br.setX(br.x()*w); |
|
93 | br.setX(br.x()*w); | |
94 | br.setY(br.y()*h); |
|
94 | br.setY(br.y()*h); | |
95 | r.setTopLeft(tl); |
|
95 | r.setTopLeft(tl); | |
96 | r.setBottomRight(br); |
|
96 | r.setBottomRight(br); | |
97 | m_zoomStack[i]=r; |
|
97 | m_zoomStack[i]=r; | |
98 | } |
|
98 | } | |
99 | */ |
|
99 | */ | |
100 | m_rect = rect; |
|
100 | m_rect = rect; | |
101 | Q_ASSERT(m_rect.isValid()); |
|
101 | Q_ASSERT(m_rect.isValid()); | |
102 | emit geometryChanged(m_rect); |
|
102 | emit geometryChanged(m_rect); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) |
|
105 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) | |
106 | { |
|
106 | { | |
107 | Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS); |
|
107 | Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS); | |
108 |
|
108 | |||
109 | if(m_options.testFlag(QChart::GridAxisAnimations)){ |
|
109 | if(m_options.testFlag(QChart::GridAxisAnimations)){ | |
110 | m_animator->addAnimation(item); |
|
110 | m_animator->addAnimation(item); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | if(axis==m_dataset->axisX()){ |
|
113 | if(axis==m_dataset->axisX()){ | |
114 | m_chartTheme->decorate(axis,true,m_themeForce); |
|
114 | m_chartTheme->decorate(axis,true,m_themeForce); | |
115 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
115 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
116 | //initialize |
|
116 | //initialize | |
117 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); |
|
117 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); | |
118 |
|
118 | |||
119 | } |
|
119 | } | |
120 | else{ |
|
120 | else{ | |
121 | m_chartTheme->decorate(axis,false,m_themeForce); |
|
121 | m_chartTheme->decorate(axis,false,m_themeForce); | |
122 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
122 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
123 | //initialize |
|
123 | //initialize | |
124 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); |
|
124 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
127 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
128 | //initialize |
|
128 | //initialize | |
129 | item->handleGeometryChanged(m_rect); |
|
129 | item->handleGeometryChanged(m_rect); | |
130 | m_axisItems.insert(axis, item); |
|
130 | m_axisItems.insert(axis, item); | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
133 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
134 | { |
|
134 | { | |
135 | Axis* item = m_axisItems.take(axis); |
|
135 | Axis* item = m_axisItems.take(axis); | |
136 | Q_ASSERT(item); |
|
136 | Q_ASSERT(item); | |
137 | if(m_animator) m_animator->removeAnimation(item); |
|
137 | if(m_animator) m_animator->removeAnimation(item); | |
138 | delete item; |
|
138 | delete item; | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 |
|
141 | |||
142 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) |
|
142 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |
143 | { |
|
143 | { | |
144 | Chart *item = 0 ; |
|
144 | Chart *item = 0 ; | |
145 |
|
145 | |||
146 | switch(series->type()) |
|
146 | switch(series->type()) | |
147 | { |
|
147 | { | |
148 | case QSeries::SeriesTypeLine: { |
|
148 | case QSeries::SeriesTypeLine: { | |
149 |
|
149 | |||
150 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
150 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
151 | LineChartItem* line = new LineChartItem(lineSeries,this); |
|
151 | LineChartItem* line = new LineChartItem(lineSeries,this); | |
152 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
152 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
153 | m_animator->addAnimation(line); |
|
153 | m_animator->addAnimation(line); | |
154 | } |
|
154 | } | |
155 | m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
155 | m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce); | |
156 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); |
|
156 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); | |
157 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
157 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
158 | item = line; |
|
158 | item = line; | |
159 | break; |
|
159 | break; | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | case QSeries::SeriesTypeArea: { |
|
162 | case QSeries::SeriesTypeArea: { | |
163 |
|
163 | |||
164 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
164 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
165 | AreaChartItem* area = new AreaChartItem(areaSeries,this); |
|
165 | AreaChartItem* area = new AreaChartItem(areaSeries,this); | |
166 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
166 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
167 | m_animator->addAnimation(area->upperLineItem()); |
|
167 | m_animator->addAnimation(area->upperLineItem()); | |
168 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); |
|
168 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); | |
169 | } |
|
169 | } | |
170 | m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
170 | m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce); | |
171 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); |
|
171 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); | |
172 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
172 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
173 | item=area; |
|
173 | item=area; | |
174 | break; |
|
174 | break; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | case QSeries::SeriesTypeBar: { |
|
177 | case QSeries::SeriesTypeBar: { | |
178 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
178 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
179 | BarChartItem* bar = new BarChartItem(barSeries,this); |
|
179 | BarChartItem* bar = new BarChartItem(barSeries,this); | |
180 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
180 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
181 | m_animator->addAnimation(bar); |
|
181 | m_animator->addAnimation(bar); | |
182 | } |
|
182 | } | |
183 | m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce); |
|
183 | m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce); | |
184 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
184 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
185 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
185 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
186 | item=bar; |
|
186 | item=bar; | |
187 | break; |
|
187 | break; | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | case QSeries::SeriesTypeStackedBar: { |
|
190 | case QSeries::SeriesTypeStackedBar: { | |
191 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
191 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
192 | StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,this); |
|
192 | StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,this); | |
193 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
193 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
194 | m_animator->addAnimation(bar); |
|
194 | m_animator->addAnimation(bar); | |
195 | } |
|
195 | } | |
196 | m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce); |
|
196 | m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce); | |
197 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
197 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
198 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
198 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
199 | item=bar; |
|
199 | item=bar; | |
200 | break; |
|
200 | break; | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | case QSeries::SeriesTypePercentBar: { |
|
203 | case QSeries::SeriesTypePercentBar: { | |
204 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
204 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
205 | PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,this); |
|
205 | PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,this); | |
206 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
206 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
207 | m_animator->addAnimation(bar); |
|
207 | m_animator->addAnimation(bar); | |
208 | } |
|
208 | } | |
209 | m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce); |
|
209 | m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce); | |
210 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
210 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
211 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
211 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
212 | item=bar; |
|
212 | item=bar; | |
213 | break; |
|
213 | break; | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | case QSeries::SeriesTypeScatter: { |
|
216 | case QSeries::SeriesTypeScatter: { | |
217 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
217 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); | |
218 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries,this); |
|
218 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries,this); | |
219 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
219 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
220 | m_animator->addAnimation(scatter); |
|
220 | m_animator->addAnimation(scatter); | |
221 | } |
|
221 | } | |
222 | m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
222 | m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce); | |
223 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); |
|
223 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); | |
224 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
224 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
225 | item = scatter; |
|
225 | item = scatter; | |
226 | break; |
|
226 | break; | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | case QSeries::SeriesTypePie: { |
|
229 | case QSeries::SeriesTypePie: { | |
230 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
230 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
231 | PieChartItem* pie = new PieChartItem(pieSeries, this); |
|
231 | PieChartItem* pie = new PieChartItem(pieSeries, this); | |
232 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
232 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
233 | m_animator->addAnimation(pie); |
|
233 | m_animator->addAnimation(pie); | |
234 | } |
|
234 | } | |
235 | m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
235 | m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce); | |
236 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); |
|
236 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); | |
237 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
237 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
238 | // Hide all from background when there is only piechart |
|
238 | // Hide all from background when there is only piechart | |
239 | // TODO: refactor this ugly code... should be one setting for this |
|
239 | // TODO: refactor this ugly code... should be one setting for this | |
240 | if (m_chartItems.count() == 0) { |
|
240 | if (m_chartItems.count() == 0) { | |
241 | m_chart->axisX()->hide(); |
|
241 | m_chart->axisX()->hide(); | |
242 | m_chart->axisY()->hide(); |
|
242 | m_chart->axisY()->hide(); | |
243 | } |
|
243 | } | |
244 | item=pie; |
|
244 | item=pie; | |
245 | break; |
|
245 | break; | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | case QSeries::SeriesTypeSpline: { |
|
248 | case QSeries::SeriesTypeSpline: { | |
249 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); |
|
249 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); | |
250 | SplineChartItem* spline = new SplineChartItem(splineSeries, this); |
|
250 | SplineChartItem* spline = new SplineChartItem(splineSeries, this); | |
251 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
251 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
252 | m_animator->addAnimation(spline); |
|
252 | m_animator->addAnimation(spline); | |
253 | } |
|
253 | } | |
254 | m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
254 | m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce); | |
255 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); |
|
255 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); | |
256 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
256 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
257 | item=spline; |
|
257 | item=spline; | |
258 | break; |
|
258 | break; | |
259 | } |
|
259 | } | |
260 | default: { |
|
260 | default: { | |
261 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
261 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
262 | break; |
|
262 | break; | |
263 | } |
|
263 | } | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | //initialize |
|
266 | //initialize | |
267 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
267 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
268 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
268 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
269 | m_chartItems.insert(series,item); |
|
269 | m_chartItems.insert(series,item); | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
|
272 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
273 | { |
|
273 | { | |
274 | Chart* item = m_chartItems.take(series); |
|
274 | Chart* item = m_chartItems.take(series); | |
275 | Q_ASSERT(item); |
|
275 | Q_ASSERT(item); | |
276 | if(m_animator) { |
|
276 | if(m_animator) { | |
277 | //small hack to handle area animations |
|
277 | //small hack to handle area animations | |
278 | if(series->type()==QSeries::SeriesTypeArea){ |
|
278 | if(series->type()==QSeries::SeriesTypeArea){ | |
279 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
279 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
280 | AreaChartItem* area = static_cast<AreaChartItem*>(item); |
|
280 | AreaChartItem* area = static_cast<AreaChartItem*>(item); | |
281 | m_animator->removeAnimation(area->upperLineItem()); |
|
281 | m_animator->removeAnimation(area->upperLineItem()); | |
282 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); |
|
282 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); | |
283 | }else |
|
283 | }else | |
284 | m_animator->removeAnimation(item); |
|
284 | m_animator->removeAnimation(item); | |
285 | } |
|
285 | } | |
286 | delete item; |
|
286 | delete item; | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) |
|
289 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) | |
290 | { |
|
290 | { | |
291 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
291 | if(m_chartTheme && m_chartTheme->id() == theme) return; | |
292 | delete m_chartTheme; |
|
292 | delete m_chartTheme; | |
293 | m_themeForce = force; |
|
293 | m_themeForce = force; | |
294 | m_chartTheme = ChartTheme::createTheme(theme); |
|
294 | m_chartTheme = ChartTheme::createTheme(theme); | |
295 | m_chartTheme->decorate(m_chart,m_themeForce); |
|
295 | m_chartTheme->decorate(m_chart,m_themeForce); | |
296 | m_chartTheme->decorate(m_chart->legend(),m_themeForce); |
|
296 | m_chartTheme->decorate(m_chart->legend(),m_themeForce); | |
297 | resetAllElements(); |
|
297 | resetAllElements(); | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | QChart::ChartTheme ChartPresenter::theme() |
|
300 | QChart::ChartTheme ChartPresenter::theme() | |
301 | { |
|
301 | { | |
302 | return m_chartTheme->id(); |
|
302 | return m_chartTheme->id(); | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
305 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
306 | { |
|
306 | { | |
307 | if(m_options!=options) { |
|
307 | if(m_options!=options) { | |
308 |
|
308 | |||
309 | m_options=options; |
|
309 | m_options=options; | |
310 |
|
310 | |||
311 | if(m_options!=QChart::NoAnimation && !m_animator) { |
|
311 | if(m_options!=QChart::NoAnimation && !m_animator) { | |
312 | m_animator= new ChartAnimator(this); |
|
312 | m_animator= new ChartAnimator(this); | |
313 |
|
313 | |||
314 | } |
|
314 | } | |
315 | resetAllElements(); |
|
315 | resetAllElements(); | |
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | void ChartPresenter::resetAllElements() |
|
320 | void ChartPresenter::resetAllElements() | |
321 | { |
|
321 | { | |
322 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
322 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
323 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
323 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
324 |
|
324 | |||
325 | foreach(QChartAxis* axis, axisList) { |
|
325 | foreach(QChartAxis* axis, axisList) { | |
326 | handleAxisRemoved(axis); |
|
326 | handleAxisRemoved(axis); | |
327 | handleAxisAdded(axis,m_dataset->domain(axis)); |
|
327 | handleAxisAdded(axis,m_dataset->domain(axis)); | |
328 | } |
|
328 | } | |
329 | foreach(QSeries* series, seriesList) { |
|
329 | foreach(QSeries* series, seriesList) { | |
330 | handleSeriesRemoved(series); |
|
330 | handleSeriesRemoved(series); | |
331 | handleSeriesAdded(series,m_dataset->domain(series)); |
|
331 | handleSeriesAdded(series,m_dataset->domain(series)); | |
332 | } |
|
332 | } | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | void ChartPresenter::zoomIn() |
|
335 | void ChartPresenter::zoomIn() | |
336 | { |
|
336 | { | |
337 | QRectF rect = geometry(); |
|
337 | QRectF rect = geometry(); | |
338 | rect.setWidth(rect.width()/2); |
|
338 | rect.setWidth(rect.width()/2); | |
339 | rect.setHeight(rect.height()/2); |
|
339 | rect.setHeight(rect.height()/2); | |
340 | rect.moveCenter(geometry().center()); |
|
340 | rect.moveCenter(geometry().center()); | |
341 | zoomIn(rect); |
|
341 | zoomIn(rect); | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
344 | void ChartPresenter::zoomIn(const QRectF& rect) | |
345 | { |
|
345 | { | |
346 | QRectF r = rect.normalized(); |
|
346 | QRectF r = rect.normalized(); | |
347 | r.translate(-m_chart->padding().topLeft()); |
|
347 | r.translate(-m_chart->padding().topLeft()); | |
348 | if(m_animator) { |
|
348 | if(m_animator) { | |
349 |
|
349 | |||
350 | QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height()); |
|
350 | QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height()); | |
351 | m_animator->setState(ChartAnimator::ZoomInState,point); |
|
351 | m_animator->setState(ChartAnimator::ZoomInState,point); | |
352 | } |
|
352 | } | |
353 | m_dataset->zoomInDomain(r,geometry().size()); |
|
353 | m_dataset->zoomInDomain(r,geometry().size()); | |
354 | if(m_animator) { |
|
354 | if(m_animator) { | |
355 | m_animator->setState(ChartAnimator::ShowState); |
|
355 | m_animator->setState(ChartAnimator::ShowState); | |
356 | } |
|
356 | } | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | void ChartPresenter::zoomOut() |
|
359 | void ChartPresenter::zoomOut() | |
360 | { |
|
360 | { | |
361 | if(m_animator) |
|
361 | if(m_animator) | |
362 | { |
|
362 | { | |
363 | m_animator->setState(ChartAnimator::ZoomOutState); |
|
363 | m_animator->setState(ChartAnimator::ZoomOutState); | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | QSizeF size = geometry().size(); |
|
366 | QSizeF size = geometry().size(); | |
367 | QRectF rect = geometry(); |
|
367 | QRectF rect = geometry(); | |
368 | rect.translate(-m_chart->padding().topLeft()); |
|
368 | rect.translate(-m_chart->padding().topLeft()); | |
369 | m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size); |
|
369 | m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size); | |
370 | //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); |
|
370 | //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); | |
371 |
|
371 | |||
372 | if(m_animator){ |
|
372 | if(m_animator){ | |
373 | m_animator->setState(ChartAnimator::ShowState); |
|
373 | m_animator->setState(ChartAnimator::ShowState); | |
374 | } |
|
374 | } | |
375 | } |
|
375 | } | |
376 |
|
376 | |||
377 | void ChartPresenter::scroll(int dx,int dy) |
|
377 | void ChartPresenter::scroll(int dx,int dy) | |
378 | { |
|
378 | { | |
379 | if(m_animator){ |
|
379 | if(m_animator){ | |
380 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); |
|
380 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); | |
381 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); |
|
381 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); | |
382 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); |
|
382 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); | |
383 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); |
|
383 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | m_dataset->scrollDomain(dx,dy,geometry().size()); |
|
386 | m_dataset->scrollDomain(dx,dy,geometry().size()); | |
387 |
|
387 | |||
388 | if(m_animator){ |
|
388 | if(m_animator){ | |
389 | m_animator->setState(ChartAnimator::ShowState); |
|
389 | m_animator->setState(ChartAnimator::ShowState); | |
390 | } |
|
390 | } | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
393 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
394 | { |
|
394 | { | |
395 | return m_options; |
|
395 | return m_options; | |
396 | } |
|
396 | } | |
397 |
|
397 | |||
398 |
|
398 | |||
399 | #include "moc_chartpresenter_p.cpp" |
|
399 | #include "moc_chartpresenter_p.cpp" | |
400 |
|
400 | |||
401 | QTCOMMERCIALCHART_END_NAMESPACE |
|
401 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,393 +1,393 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "charttheme_p.h" |
|
21 | #include "charttheme_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qchartview.h" |
|
23 | #include "qchartview.h" | |
24 | #include "qlegend.h" |
|
24 | #include "qlegend.h" | |
25 | #include "qchartaxis.h" |
|
25 | #include "qchartaxis.h" | |
26 | #include <QTime> |
|
26 | #include <QTime> | |
27 |
|
27 | |||
28 | //series |
|
28 | //series | |
29 | #include "qbarset.h" |
|
29 | #include "qbarset.h" | |
30 | #include "qbarseries.h" |
|
30 | #include "qbarseries.h" | |
31 | #include "qstackedbarseries.h" |
|
31 | #include "qstackedbarseries.h" | |
32 | #include "qpercentbarseries.h" |
|
32 | #include "qpercentbarseries.h" | |
33 | #include "qlineseries.h" |
|
33 | #include "qlineseries.h" | |
34 | #include "qareaseries.h" |
|
34 | #include "qareaseries.h" | |
35 | #include "qscatterseries.h" |
|
35 | #include "qscatterseries.h" | |
36 | #include "qpieseries.h" |
|
36 | #include "qpieseries.h" | |
37 | #include "qpieslice.h" |
|
37 | #include "qpieslice.h" | |
38 | #include "qsplineseries.h" |
|
38 | #include "qsplineseries.h" | |
39 |
|
39 | |||
40 | //items |
|
40 | //items | |
41 | #include "axisitem_p.h" |
|
41 | #include "axisitem_p.h" | |
42 | #include "barchartitem_p.h" |
|
42 | #include "barchartitem_p.h" | |
43 | #include "stackedbarchartitem_p.h" |
|
43 | #include "stackedbarchartitem_p.h" | |
44 | #include "percentbarchartitem_p.h" |
|
44 | #include "percentbarchartitem_p.h" | |
45 | #include "linechartitem_p.h" |
|
45 | #include "linechartitem_p.h" | |
46 | #include "areachartitem_p.h" |
|
46 | #include "areachartitem_p.h" | |
47 | #include "scatterchartitem_p.h" |
|
47 | #include "scatterchartitem_p.h" | |
48 | #include "piechartitem_p.h" |
|
48 | #include "piechartitem_p.h" | |
49 | #include "splinechartitem_p.h" |
|
49 | #include "splinechartitem_p.h" | |
50 |
|
50 | |||
51 | //themes |
|
51 | //themes | |
52 |
#include "charttheme |
|
52 | #include "chartthemesystem_p.h" | |
53 | #include "chartthemelight_p.h" |
|
53 | #include "chartthemelight_p.h" | |
54 | #include "chartthemebluecerulean_p.h" |
|
54 | #include "chartthemebluecerulean_p.h" | |
55 | #include "chartthemedark_p.h" |
|
55 | #include "chartthemedark_p.h" | |
56 | #include "chartthemebrownsand_p.h" |
|
56 | #include "chartthemebrownsand_p.h" | |
57 | #include "chartthemebluencs_p.h" |
|
57 | #include "chartthemebluencs_p.h" | |
58 | #include "chartthemehighcontrast_p.h" |
|
58 | #include "chartthemehighcontrast_p.h" | |
59 | #include "chartthemeblueicy_p.h" |
|
59 | #include "chartthemeblueicy_p.h" | |
60 |
|
60 | |||
61 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
61 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
62 |
|
62 | |||
63 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
63 | ChartTheme::ChartTheme(QChart::ChartTheme id) : | |
64 |
m_masterFont(QFont("arial", 1 |
|
64 | m_masterFont(QFont("arial", 14)), | |
65 | m_labelFont(QFont("arial", 10)), |
|
65 | m_labelFont(QFont("arial", 10)), | |
66 | m_titleBrush(QColor(QRgb(0x000000))), |
|
66 | m_titleBrush(QColor(QRgb(0x000000))), | |
67 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
67 | m_axisLinePen(QPen(QRgb(0x000000))), | |
68 | m_axisLabelBrush(QColor(QRgb(0x000000))), |
|
68 | m_axisLabelBrush(QColor(QRgb(0x000000))), | |
69 | m_backgroundShadesPen(Qt::NoPen), |
|
69 | m_backgroundShadesPen(Qt::NoPen), | |
70 | m_backgroundShadesBrush(Qt::NoBrush), |
|
70 | m_backgroundShadesBrush(Qt::NoBrush), | |
71 | m_backgroundShades(BackgroundShadesNone), |
|
71 | m_backgroundShades(BackgroundShadesNone), | |
72 | m_gridLinePen(QPen(QRgb(0x000000))) |
|
72 | m_gridLinePen(QPen(QRgb(0x000000))) | |
73 | { |
|
73 | { | |
74 | m_id = id; |
|
74 | m_id = id; | |
75 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
75 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 |
|
78 | |||
79 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
79 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
80 | { |
|
80 | { | |
81 | switch(theme) { |
|
81 | switch(theme) { | |
82 | case QChart::ChartThemeLight: |
|
82 | case QChart::ChartThemeLight: | |
83 | return new ChartThemeLight(); |
|
83 | return new ChartThemeLight(); | |
84 | case QChart::ChartThemeBlueCerulean: |
|
84 | case QChart::ChartThemeBlueCerulean: | |
85 | return new ChartThemeBlueCerulean(); |
|
85 | return new ChartThemeBlueCerulean(); | |
86 | case QChart::ChartThemeDark: |
|
86 | case QChart::ChartThemeDark: | |
87 | return new ChartThemeDark(); |
|
87 | return new ChartThemeDark(); | |
88 | case QChart::ChartThemeBrownSand: |
|
88 | case QChart::ChartThemeBrownSand: | |
89 | return new ChartThemeBrownSand(); |
|
89 | return new ChartThemeBrownSand(); | |
90 | case QChart::ChartThemeBlueNcs: |
|
90 | case QChart::ChartThemeBlueNcs: | |
91 | return new ChartThemeBlueNcs(); |
|
91 | return new ChartThemeBlueNcs(); | |
92 | case QChart::ChartThemeHighContrast: |
|
92 | case QChart::ChartThemeHighContrast: | |
93 | return new ChartThemeHighContrast(); |
|
93 | return new ChartThemeHighContrast(); | |
94 | case QChart::ChartThemeBlueIcy: |
|
94 | case QChart::ChartThemeBlueIcy: | |
95 | return new ChartThemeBlueIcy(); |
|
95 | return new ChartThemeBlueIcy(); | |
96 | default: |
|
96 | default: | |
97 |
return new ChartTheme |
|
97 | return new ChartThemeSystem(); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void ChartTheme::decorate(QChart* chart,bool force) |
|
101 | void ChartTheme::decorate(QChart* chart,bool force) | |
102 | { |
|
102 | { | |
103 | QBrush brush; |
|
103 | QBrush brush; | |
104 |
|
104 | |||
105 | if(brush == chart->backgroundBrush() || force) |
|
105 | if(brush == chart->backgroundBrush() || force) | |
106 | chart->setBackgroundBrush(m_chartBackgroundGradient); |
|
106 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
107 | chart->setTitleFont(m_masterFont); |
|
107 | chart->setTitleFont(m_masterFont); | |
108 | chart->setTitleBrush(m_titleBrush); |
|
108 | chart->setTitleBrush(m_titleBrush); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void ChartTheme::decorate(QLegend* legend,bool force) |
|
111 | void ChartTheme::decorate(QLegend* legend,bool force) | |
112 | { |
|
112 | { | |
113 | QPen pen; |
|
113 | QPen pen; | |
114 | QBrush brush; |
|
114 | QBrush brush; | |
115 |
|
115 | |||
116 | if (pen == legend->pen() || force){ |
|
116 | if (pen == legend->pen() || force){ | |
117 | legend->setPen(Qt::NoPen); |
|
117 | legend->setPen(Qt::NoPen); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 |
|
120 | |||
121 | if (brush == legend->brush() || force) { |
|
121 | if (brush == legend->brush() || force) { | |
122 | legend->setBrush(m_chartBackgroundGradient); |
|
122 | legend->setBrush(m_chartBackgroundGradient); | |
123 | } |
|
123 | } | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) |
|
126 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) | |
127 | { |
|
127 | { | |
128 | QPen pen; |
|
128 | QPen pen; | |
129 | QBrush brush; |
|
129 | QBrush brush; | |
130 |
|
130 | |||
131 | if (pen == series->pen() || force){ |
|
131 | if (pen == series->pen() || force){ | |
132 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
132 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
133 | pen.setWidthF(2); |
|
133 | pen.setWidthF(2); | |
134 | series->setPen(pen); |
|
134 | series->setPen(pen); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | if (brush == series->brush() || force) { |
|
137 | if (brush == series->brush() || force) { | |
138 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
138 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
139 | series->setBrush(brush); |
|
139 | series->setBrush(brush); | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 |
|
143 | |||
144 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) |
|
144 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) | |
145 | { |
|
145 | { | |
146 | QPen pen; |
|
146 | QPen pen; | |
147 | if(pen == series->pen() || force ){ |
|
147 | if(pen == series->pen() || force ){ | |
148 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
148 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
149 | pen.setWidthF(2); |
|
149 | pen.setWidthF(2); | |
150 | series->setPen(pen); |
|
150 | series->setPen(pen); | |
151 | } |
|
151 | } | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | void ChartTheme::decorate(QBarSeries* series, int index, bool force) |
|
154 | void ChartTheme::decorate(QBarSeries* series, int index, bool force) | |
155 | { |
|
155 | { | |
156 | QBrush brush; |
|
156 | QBrush brush; | |
157 | QPen pen; |
|
157 | QPen pen; | |
158 | QList<QBarSet*> sets = series->barSets(); |
|
158 | QList<QBarSet*> sets = series->barSets(); | |
159 |
|
159 | |||
160 | qreal takeAtPos = 0.5; |
|
160 | qreal takeAtPos = 0.5; | |
161 | qreal step = 0.2; |
|
161 | qreal step = 0.2; | |
162 | if (sets.count() > 1 ) { |
|
162 | if (sets.count() > 1 ) { | |
163 | step = 1.0 / (qreal) sets.count(); |
|
163 | step = 1.0 / (qreal) sets.count(); | |
164 | if (sets.count() % m_seriesGradients.count()) |
|
164 | if (sets.count() % m_seriesGradients.count()) | |
165 | step *= m_seriesGradients.count(); |
|
165 | step *= m_seriesGradients.count(); | |
166 | else |
|
166 | else | |
167 | step *= (m_seriesGradients.count() - 1); |
|
167 | step *= (m_seriesGradients.count() - 1); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | for (int i(0); i < sets.count(); i++) { |
|
170 | for (int i(0); i < sets.count(); i++) { | |
171 | int colorIndex = (index + i) % m_seriesGradients.count(); |
|
171 | int colorIndex = (index + i) % m_seriesGradients.count(); | |
172 | if (i > 0 && i % m_seriesGradients.count() == 0) { |
|
172 | if (i > 0 && i % m_seriesGradients.count() == 0) { | |
173 | // There is no dedicated base color for each sets, generate more colors |
|
173 | // There is no dedicated base color for each sets, generate more colors | |
174 | takeAtPos += step; |
|
174 | takeAtPos += step; | |
175 | if (takeAtPos == 1.0) |
|
175 | if (takeAtPos == 1.0) | |
176 | takeAtPos += step; |
|
176 | takeAtPos += step; | |
177 | takeAtPos -= (int) takeAtPos; |
|
177 | takeAtPos -= (int) takeAtPos; | |
178 | } |
|
178 | } | |
179 | qDebug() << "pos:" << takeAtPos; |
|
179 | qDebug() << "pos:" << takeAtPos; | |
180 | if (brush == sets.at(i)->brush() || force ) |
|
180 | if (brush == sets.at(i)->brush() || force ) | |
181 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); |
|
181 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); | |
182 |
|
182 | |||
183 | // Pick label color from the opposite end of the gradient. |
|
183 | // Pick label color from the opposite end of the gradient. | |
184 | // 0.3 as a boundary seems to work well. |
|
184 | // 0.3 as a boundary seems to work well. | |
185 | if (takeAtPos < 0.3) |
|
185 | if (takeAtPos < 0.3) | |
186 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); |
|
186 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
187 | else |
|
187 | else | |
188 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); |
|
188 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
189 |
|
189 | |||
190 | if (pen == sets.at(i)->pen() || force) { |
|
190 | if (pen == sets.at(i)->pen() || force) { | |
191 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
191 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
192 | sets.at(i)->setPen(c); |
|
192 | sets.at(i)->setPen(c); | |
193 | } |
|
193 | } | |
194 | } |
|
194 | } | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) |
|
197 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) | |
198 | { |
|
198 | { | |
199 | QPen pen; |
|
199 | QPen pen; | |
200 | QBrush brush; |
|
200 | QBrush brush; | |
201 |
|
201 | |||
202 | if (pen == series->pen() || force) { |
|
202 | if (pen == series->pen() || force) { | |
203 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
203 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
204 | pen.setWidthF(2); |
|
204 | pen.setWidthF(2); | |
205 | series->setPen(pen); |
|
205 | series->setPen(pen); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | if (brush == series->brush() || force) { |
|
208 | if (brush == series->brush() || force) { | |
209 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
209 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
210 | series->setBrush(brush); |
|
210 | series->setBrush(brush); | |
211 | } |
|
211 | } | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) |
|
214 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) | |
215 | { |
|
215 | { | |
216 |
|
216 | |||
217 | for (int i(0); i < series->slices().count(); i++) { |
|
217 | for (int i(0); i < series->slices().count(); i++) { | |
218 |
|
218 | |||
219 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
219 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
220 |
|
220 | |||
221 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
221 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
222 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
222 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); | |
223 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
223 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
224 |
|
224 | |||
225 | QPieSlice *s = series->slices().at(i); |
|
225 | QPieSlice *s = series->slices().at(i); | |
226 | PieSliceData data = PieSliceData::data(s); |
|
226 | PieSliceData data = PieSliceData::data(s); | |
227 |
|
227 | |||
228 | if (data.m_slicePen.isThemed() || force) { |
|
228 | if (data.m_slicePen.isThemed() || force) { | |
229 | data.m_slicePen = penColor; |
|
229 | data.m_slicePen = penColor; | |
230 | data.m_slicePen.setThemed(true); |
|
230 | data.m_slicePen.setThemed(true); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | if (data.m_sliceBrush.isThemed() || force) { |
|
233 | if (data.m_sliceBrush.isThemed() || force) { | |
234 | data.m_sliceBrush = brushColor; |
|
234 | data.m_sliceBrush = brushColor; | |
235 | data.m_sliceBrush.setThemed(true); |
|
235 | data.m_sliceBrush.setThemed(true); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | if (data.m_labelPen.isThemed() || force) { |
|
238 | if (data.m_labelPen.isThemed() || force) { | |
239 | data.m_labelPen = QPen(m_titleBrush.color()); |
|
239 | data.m_labelPen = QPen(m_titleBrush.color()); | |
240 | data.m_labelPen.setThemed(true); |
|
240 | data.m_labelPen.setThemed(true); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | if (data.m_labelFont.isThemed() || force) { |
|
243 | if (data.m_labelFont.isThemed() || force) { | |
244 | data.m_labelFont = m_labelFont; |
|
244 | data.m_labelFont = m_labelFont; | |
245 | data.m_labelFont.setThemed(true); |
|
245 | data.m_labelFont.setThemed(true); | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | if (PieSliceData::data(s) != data) { |
|
248 | if (PieSliceData::data(s) != data) { | |
249 | PieSliceData::data(s) = data; |
|
249 | PieSliceData::data(s) = data; | |
250 | emit PieSliceData::data(s).emitChangedSignal(s); |
|
250 | emit PieSliceData::data(s).emitChangedSignal(s); | |
251 | } |
|
251 | } | |
252 | } |
|
252 | } | |
253 | } |
|
253 | } | |
254 |
|
254 | |||
255 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) |
|
255 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) | |
256 | { |
|
256 | { | |
257 | QPen pen; |
|
257 | QPen pen; | |
258 | if(pen == series->pen() || force){ |
|
258 | if(pen == series->pen() || force){ | |
259 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
259 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
260 | pen.setWidthF(2); |
|
260 | pen.setWidthF(2); | |
261 | series->setPen(pen); |
|
261 | series->setPen(pen); | |
262 | } |
|
262 | } | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) |
|
265 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) | |
266 | { |
|
266 | { | |
267 | QPen pen; |
|
267 | QPen pen; | |
268 | QBrush brush; |
|
268 | QBrush brush; | |
269 | QFont font; |
|
269 | QFont font; | |
270 |
|
270 | |||
271 | if (axis->isAxisVisible()) { |
|
271 | if (axis->isAxisVisible()) { | |
272 |
|
272 | |||
273 | if(brush == axis->labelsBrush() || force){ |
|
273 | if(brush == axis->labelsBrush() || force){ | |
274 | axis->setLabelsBrush(m_axisLabelBrush); |
|
274 | axis->setLabelsBrush(m_axisLabelBrush); | |
275 | } |
|
275 | } | |
276 | if(pen == axis->labelsPen() || force){ |
|
276 | if(pen == axis->labelsPen() || force){ | |
277 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
277 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 |
|
280 | |||
281 | if (axis->shadesVisible() || force) { |
|
281 | if (axis->shadesVisible() || force) { | |
282 |
|
282 | |||
283 | if(brush == axis->shadesBrush() || force){ |
|
283 | if(brush == axis->shadesBrush() || force){ | |
284 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
284 | axis->setShadesBrush(m_backgroundShadesBrush); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | if(pen == axis->shadesPen() || force){ |
|
287 | if(pen == axis->shadesPen() || force){ | |
288 | axis->setShadesPen(m_backgroundShadesPen); |
|
288 | axis->setShadesPen(m_backgroundShadesPen); | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | if(force && (m_backgroundShades == BackgroundShadesBoth |
|
291 | if(force && (m_backgroundShades == BackgroundShadesBoth | |
292 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
292 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
293 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ |
|
293 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ | |
294 | axis->setShadesVisible(true); |
|
294 | axis->setShadesVisible(true); | |
295 |
|
295 | |||
296 | } |
|
296 | } | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | if(pen == axis->axisPen() || force){ |
|
299 | if(pen == axis->axisPen() || force){ | |
300 | axis->setAxisPen(m_axisLinePen); |
|
300 | axis->setAxisPen(m_axisLinePen); | |
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | if(pen == axis->gridLinePen() || force){ |
|
303 | if(pen == axis->gridLinePen() || force){ | |
304 | axis->setGridLinePen(m_gridLinePen); |
|
304 | axis->setGridLinePen(m_gridLinePen); | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | if(font == axis->labelsFont() || force){ |
|
307 | if(font == axis->labelsFont() || force){ | |
308 | axis->setLabelsFont(m_labelFont); |
|
308 | axis->setLabelsFont(m_labelFont); | |
309 | } |
|
309 | } | |
310 | } |
|
310 | } | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | void ChartTheme::generateSeriesGradients() |
|
313 | void ChartTheme::generateSeriesGradients() | |
314 | { |
|
314 | { | |
315 | // Generate gradients in HSV color space |
|
315 | // Generate gradients in HSV color space | |
316 | foreach (QColor color, m_seriesColors) { |
|
316 | foreach (QColor color, m_seriesColors) { | |
317 | QLinearGradient g; |
|
317 | QLinearGradient g; | |
318 | qreal h = color.hsvHueF(); |
|
318 | qreal h = color.hsvHueF(); | |
319 | qreal s = color.hsvSaturationF(); |
|
319 | qreal s = color.hsvSaturationF(); | |
320 |
|
320 | |||
321 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
321 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
322 | // most themes. The rest of the gradients we can define manually in theme specific |
|
322 | // most themes. The rest of the gradients we can define manually in theme specific | |
323 | // implementation. |
|
323 | // implementation. | |
324 | QColor start = color; |
|
324 | QColor start = color; | |
325 | start.setHsvF(h, 0.0, 1.0); |
|
325 | start.setHsvF(h, 0.0, 1.0); | |
326 | g.setColorAt(0.0, start); |
|
326 | g.setColorAt(0.0, start); | |
327 |
|
327 | |||
328 | g.setColorAt(0.5, color); |
|
328 | g.setColorAt(0.5, color); | |
329 |
|
329 | |||
330 | QColor end = color; |
|
330 | QColor end = color; | |
331 | end.setHsvF(h, s, 0.25); |
|
331 | end.setHsvF(h, s, 0.25); | |
332 | g.setColorAt(1.0, end); |
|
332 | g.setColorAt(1.0, end); | |
333 |
|
333 | |||
334 | m_seriesGradients << g; |
|
334 | m_seriesGradients << g; | |
335 | } |
|
335 | } | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 |
|
338 | |||
339 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
339 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
340 | { |
|
340 | { | |
341 | Q_ASSERT(pos >=0.0 && pos <= 1.0); |
|
341 | Q_ASSERT(pos >=0.0 && pos <= 1.0); | |
342 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
342 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
343 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
343 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
344 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
344 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
345 | QColor c; |
|
345 | QColor c; | |
346 | c.setRgbF(r, g, b); |
|
346 | c.setRgbF(r, g, b); | |
347 | return c; |
|
347 | return c; | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
350 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
351 | { |
|
351 | { | |
352 | Q_ASSERT(pos >=0 && pos <= 1.0); |
|
352 | Q_ASSERT(pos >=0 && pos <= 1.0); | |
353 |
|
353 | |||
354 | // another possibility: |
|
354 | // another possibility: | |
355 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
355 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient | |
356 |
|
356 | |||
357 | QGradientStops stops = gradient.stops(); |
|
357 | QGradientStops stops = gradient.stops(); | |
358 | int count = stops.count(); |
|
358 | int count = stops.count(); | |
359 |
|
359 | |||
360 | // find previous stop relative to position |
|
360 | // find previous stop relative to position | |
361 | QGradientStop prev = stops.first(); |
|
361 | QGradientStop prev = stops.first(); | |
362 | for (int i=0; i<count; i++) { |
|
362 | for (int i=0; i<count; i++) { | |
363 | QGradientStop stop = stops.at(i); |
|
363 | QGradientStop stop = stops.at(i); | |
364 | if (pos > stop.first) |
|
364 | if (pos > stop.first) | |
365 | prev = stop; |
|
365 | prev = stop; | |
366 |
|
366 | |||
367 | // given position is actually a stop position? |
|
367 | // given position is actually a stop position? | |
368 | if (pos == stop.first) { |
|
368 | if (pos == stop.first) { | |
369 | //qDebug() << "stop color" << pos; |
|
369 | //qDebug() << "stop color" << pos; | |
370 | return stop.second; |
|
370 | return stop.second; | |
371 | } |
|
371 | } | |
372 | } |
|
372 | } | |
373 |
|
373 | |||
374 | // find next stop relative to position |
|
374 | // find next stop relative to position | |
375 | QGradientStop next = stops.last(); |
|
375 | QGradientStop next = stops.last(); | |
376 | for (int i=count-1; i>=0; i--) { |
|
376 | for (int i=count-1; i>=0; i--) { | |
377 | QGradientStop stop = stops.at(i); |
|
377 | QGradientStop stop = stops.at(i); | |
378 | if (pos < stop.first) |
|
378 | if (pos < stop.first) | |
379 | next = stop; |
|
379 | next = stop; | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
382 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
383 |
|
383 | |||
384 | qreal range = next.first - prev.first; |
|
384 | qreal range = next.first - prev.first; | |
385 | qreal posDelta = pos - prev.first; |
|
385 | qreal posDelta = pos - prev.first; | |
386 | qreal relativePos = posDelta / range; |
|
386 | qreal relativePos = posDelta / range; | |
387 |
|
387 | |||
388 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
388 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
389 |
|
389 | |||
390 | return colorAt(prev.second, next.second, relativePos); |
|
390 | return colorAt(prev.second, next.second, relativePos); | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | QTCOMMERCIALCHART_END_NAMESPACE |
|
393 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,99 +1,99 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef CHARTTHEME_H |
|
21 | #ifndef CHARTTHEME_H | |
22 | #define CHARTTHEME_H |
|
22 | #define CHARTTHEME_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qchart.h" |
|
25 | #include "qchart.h" | |
26 | #include <QColor> |
|
26 | #include <QColor> | |
27 | #include <QGradientStops> |
|
27 | #include <QGradientStops> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class ChartItem; |
|
31 | class ChartItem; | |
32 | class QSeries; |
|
32 | class QSeries; | |
33 | class LineChartItem; |
|
33 | class LineChartItem; | |
34 | class QLineSeries; |
|
34 | class QLineSeries; | |
35 | class BarChartItem; |
|
35 | class BarChartItem; | |
36 | class QBarSeries; |
|
36 | class QBarSeries; | |
37 | class StackedBarChartItem; |
|
37 | class StackedBarChartItem; | |
38 | class QStackedBarSeries; |
|
38 | class QStackedBarSeries; | |
39 | class QPercentBarSeries; |
|
39 | class QPercentBarSeries; | |
40 | class PercentBarChartItem; |
|
40 | class PercentBarChartItem; | |
41 | class QScatterSeries; |
|
41 | class QScatterSeries; | |
42 | class ScatterChartItem; |
|
42 | class ScatterChartItem; | |
43 | class PieChartItem; |
|
43 | class PieChartItem; | |
44 | class QPieSeries; |
|
44 | class QPieSeries; | |
45 | class SplineChartItem; |
|
45 | class SplineChartItem; | |
46 | class QSplineSeries; |
|
46 | class QSplineSeries; | |
47 | class AreaChartItem; |
|
47 | class AreaChartItem; | |
48 | class QAreaSeries; |
|
48 | class QAreaSeries; | |
49 |
|
49 | |||
50 | class ChartTheme |
|
50 | class ChartTheme | |
51 | { |
|
51 | { | |
52 | public: |
|
52 | public: | |
53 | enum BackgroundShadesMode { |
|
53 | enum BackgroundShadesMode { | |
54 | BackgroundShadesNone = 0, |
|
54 | BackgroundShadesNone = 0, | |
55 | BackgroundShadesVertical, |
|
55 | BackgroundShadesVertical, | |
56 | BackgroundShadesHorizontal, |
|
56 | BackgroundShadesHorizontal, | |
57 | BackgroundShadesBoth |
|
57 | BackgroundShadesBoth | |
58 | }; |
|
58 | }; | |
59 |
|
59 | |||
60 | protected: |
|
60 | protected: | |
61 |
explicit ChartTheme(QChart::ChartTheme id = |
|
61 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight); | |
62 | public: |
|
62 | public: | |
63 | static ChartTheme* createTheme(QChart::ChartTheme theme); |
|
63 | static ChartTheme* createTheme(QChart::ChartTheme theme); | |
64 | QChart::ChartTheme id() const {return m_id;} |
|
64 | QChart::ChartTheme id() const {return m_id;} | |
65 | void decorate(QChart* chart,bool force = true); |
|
65 | void decorate(QChart* chart,bool force = true); | |
66 | void decorate(QLegend* legend,bool force = true); |
|
66 | void decorate(QLegend* legend,bool force = true); | |
67 | void decorate(QBarSeries* series, int index,bool force = true); |
|
67 | void decorate(QBarSeries* series, int index,bool force = true); | |
68 | void decorate(QLineSeries* series, int index,bool force = true); |
|
68 | void decorate(QLineSeries* series, int index,bool force = true); | |
69 | void decorate(QAreaSeries* series, int index,bool force = true); |
|
69 | void decorate(QAreaSeries* series, int index,bool force = true); | |
70 | void decorate(QScatterSeries* series, int index,bool force = true); |
|
70 | void decorate(QScatterSeries* series, int index,bool force = true); | |
71 | void decorate(QPieSeries* series, int index,bool force = true); |
|
71 | void decorate(QPieSeries* series, int index,bool force = true); | |
72 | void decorate(QSplineSeries* series, int index,bool force = true); |
|
72 | void decorate(QSplineSeries* series, int index,bool force = true); | |
73 | void decorate(QChartAxis* axis, bool axisX,bool force = true); |
|
73 | void decorate(QChartAxis* axis, bool axisX,bool force = true); | |
74 |
|
74 | |||
75 | public: // utils |
|
75 | public: // utils | |
76 | void generateSeriesGradients(); |
|
76 | void generateSeriesGradients(); | |
77 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); |
|
77 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); | |
78 | static QColor colorAt(const QGradient &gradient, qreal pos); |
|
78 | static QColor colorAt(const QGradient &gradient, qreal pos); | |
79 |
|
79 | |||
80 | protected: |
|
80 | protected: | |
81 | QChart::ChartTheme m_id; |
|
81 | QChart::ChartTheme m_id; | |
82 | QList<QColor> m_seriesColors; |
|
82 | QList<QColor> m_seriesColors; | |
83 | QList<QGradient> m_seriesGradients; |
|
83 | QList<QGradient> m_seriesGradients; | |
84 | QLinearGradient m_chartBackgroundGradient; |
|
84 | QLinearGradient m_chartBackgroundGradient; | |
85 |
|
85 | |||
86 | QFont m_masterFont; |
|
86 | QFont m_masterFont; | |
87 | QFont m_labelFont; |
|
87 | QFont m_labelFont; | |
88 | QBrush m_titleBrush; |
|
88 | QBrush m_titleBrush; | |
89 | QPen m_axisLinePen; |
|
89 | QPen m_axisLinePen; | |
90 | QBrush m_axisLabelBrush; |
|
90 | QBrush m_axisLabelBrush; | |
91 | QPen m_backgroundShadesPen; |
|
91 | QPen m_backgroundShadesPen; | |
92 | QBrush m_backgroundShadesBrush; |
|
92 | QBrush m_backgroundShadesBrush; | |
93 | BackgroundShadesMode m_backgroundShades; |
|
93 | BackgroundShadesMode m_backgroundShades; | |
94 | QPen m_gridLinePen; |
|
94 | QPen m_gridLinePen; | |
95 | }; |
|
95 | }; | |
96 |
|
96 | |||
97 | QTCOMMERCIALCHART_END_NAMESPACE |
|
97 | QTCOMMERCIALCHART_END_NAMESPACE | |
98 |
|
98 | |||
99 | #endif // CHARTTHEME_H |
|
99 | #endif // CHARTTHEME_H |
@@ -1,501 +1,500 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include <QGraphicsScene> |
|
23 | #include <QGraphicsScene> | |
24 | #include <QGraphicsSceneResizeEvent> |
|
24 | #include <QGraphicsSceneResizeEvent> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \enum QChart::ChartTheme |
|
29 | \enum QChart::ChartTheme | |
30 |
|
30 | |||
31 | This enum describes the theme used by the chart. |
|
31 | This enum describes the theme used by the chart. | |
32 |
|
32 | |||
33 | \value ChartThemeDefault Follows the GUI style of the Operating System |
|
33 | \value ChartThemeLight The default theme | |
34 | \value ChartThemeLight |
|
|||
35 | \value ChartThemeBlueCerulean |
|
34 | \value ChartThemeBlueCerulean | |
36 | \value ChartThemeDark |
|
35 | \value ChartThemeDark | |
37 | \value ChartThemeBrownSand |
|
36 | \value ChartThemeBrownSand | |
38 | \value ChartThemeBlueNcs |
|
37 | \value ChartThemeBlueNcs | |
39 | \value ChartThemeHighContrast |
|
38 | \value ChartThemeHighContrast | |
40 | \value ChartThemeBlueIcy |
|
39 | \value ChartThemeBlueIcy | |
41 | \value ChartThemeCount Not really a theme; the total count of themes. |
|
40 | \value ChartThemeCount Not really a theme; the total count of themes. | |
42 | */ |
|
41 | */ | |
43 |
|
42 | |||
44 | /*! |
|
43 | /*! | |
45 | \enum QChart::AnimationOption |
|
44 | \enum QChart::AnimationOption | |
46 |
|
45 | |||
47 | For enabling/disabling animations. Defaults to NoAnimation. |
|
46 | For enabling/disabling animations. Defaults to NoAnimation. | |
48 |
|
47 | |||
49 | \value NoAnimation |
|
48 | \value NoAnimation | |
50 | \value GridAxisAnimations |
|
49 | \value GridAxisAnimations | |
51 | \value SeriesAnimations |
|
50 | \value SeriesAnimations | |
52 | \value AllAnimations |
|
51 | \value AllAnimations | |
53 | */ |
|
52 | */ | |
54 |
|
53 | |||
55 | /*! |
|
54 | /*! | |
56 | \class QChart |
|
55 | \class QChart | |
57 | \brief QtCommercial chart API. |
|
56 | \brief QtCommercial chart API. | |
58 |
|
57 | |||
59 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
58 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
60 | representation of different types of QChartSeries and other chart related objects like |
|
59 | representation of different types of QChartSeries and other chart related objects like | |
61 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
60 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
62 | convenience class QChartView instead of QChart. |
|
61 | convenience class QChartView instead of QChart. | |
63 | \sa QChartView |
|
62 | \sa QChartView | |
64 | */ |
|
63 | */ | |
65 |
|
64 | |||
66 | /*! |
|
65 | /*! | |
67 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
66 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
68 | */ |
|
67 | */ | |
69 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
68 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
70 | d_ptr(new QChartPrivate(this)) |
|
69 | d_ptr(new QChartPrivate(this)) | |
71 | { |
|
70 | { | |
72 | //setMinimumSize(200,200); |
|
71 | //setMinimumSize(200,200); | |
73 | d_ptr->m_legend = new QLegend(this); |
|
72 | d_ptr->m_legend = new QLegend(this); | |
74 | d_ptr->m_dataset = new ChartDataSet(this); |
|
73 | d_ptr->m_dataset = new ChartDataSet(this); | |
75 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
74 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
76 | setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); |
|
75 | setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); | |
77 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
76 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
78 | connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
77 | connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
79 | } |
|
78 | } | |
80 |
|
79 | |||
81 | /*! |
|
80 | /*! | |
82 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
81 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
83 | */ |
|
82 | */ | |
84 | QChart::~QChart() |
|
83 | QChart::~QChart() | |
85 | { |
|
84 | { | |
86 | //delete first presenter , since this is a root of all the graphical items |
|
85 | //delete first presenter , since this is a root of all the graphical items | |
87 | delete d_ptr->m_presenter; |
|
86 | delete d_ptr->m_presenter; | |
88 | d_ptr->m_presenter=0; |
|
87 | d_ptr->m_presenter=0; | |
89 | } |
|
88 | } | |
90 |
|
89 | |||
91 | /*! |
|
90 | /*! | |
92 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
91 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
93 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
92 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
94 | the y axis). |
|
93 | the y axis). | |
95 | */ |
|
94 | */ | |
96 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
95 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
97 | { |
|
96 | { | |
98 | d_ptr->m_dataset->addSeries(series, axisY); |
|
97 | d_ptr->m_dataset->addSeries(series, axisY); | |
99 | } |
|
98 | } | |
100 |
|
99 | |||
101 | /*! |
|
100 | /*! | |
102 | Removes the \a series specified in a perameter from the QChartView. |
|
101 | Removes the \a series specified in a perameter from the QChartView. | |
103 | It releses its ownership of the specified QChartSeries object. |
|
102 | It releses its ownership of the specified QChartSeries object. | |
104 | It does not delete the pointed QChartSeries data object |
|
103 | It does not delete the pointed QChartSeries data object | |
105 | \sa addSeries(), removeAllSeries() |
|
104 | \sa addSeries(), removeAllSeries() | |
106 | */ |
|
105 | */ | |
107 | void QChart::removeSeries(QSeries* series) |
|
106 | void QChart::removeSeries(QSeries* series) | |
108 | { |
|
107 | { | |
109 | d_ptr->m_dataset->removeSeries(series); |
|
108 | d_ptr->m_dataset->removeSeries(series); | |
110 | } |
|
109 | } | |
111 |
|
110 | |||
112 | /*! |
|
111 | /*! | |
113 | Removes all the QChartSeries that have been added to the QChartView |
|
112 | Removes all the QChartSeries that have been added to the QChartView | |
114 | It also deletes the pointed QChartSeries data objects |
|
113 | It also deletes the pointed QChartSeries data objects | |
115 | \sa addSeries(), removeSeries() |
|
114 | \sa addSeries(), removeSeries() | |
116 | */ |
|
115 | */ | |
117 | void QChart::removeAllSeries() |
|
116 | void QChart::removeAllSeries() | |
118 | { |
|
117 | { | |
119 | d_ptr->m_dataset->removeAllSeries(); |
|
118 | d_ptr->m_dataset->removeAllSeries(); | |
120 | } |
|
119 | } | |
121 |
|
120 | |||
122 | /*! |
|
121 | /*! | |
123 | Sets the \a brush that is used for painting the background of the chart area. |
|
122 | Sets the \a brush that is used for painting the background of the chart area. | |
124 | */ |
|
123 | */ | |
125 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
124 | void QChart::setBackgroundBrush(const QBrush& brush) | |
126 | { |
|
125 | { | |
127 | d_ptr->createChartBackgroundItem(); |
|
126 | d_ptr->createChartBackgroundItem(); | |
128 | d_ptr->m_backgroundItem->setBrush(brush); |
|
127 | d_ptr->m_backgroundItem->setBrush(brush); | |
129 | d_ptr->m_backgroundItem->update(); |
|
128 | d_ptr->m_backgroundItem->update(); | |
130 | } |
|
129 | } | |
131 |
|
130 | |||
132 | QBrush QChart::backgroundBrush() const |
|
131 | QBrush QChart::backgroundBrush() const | |
133 | { |
|
132 | { | |
134 | if (!d_ptr->m_backgroundItem) return QBrush(); |
|
133 | if (!d_ptr->m_backgroundItem) return QBrush(); | |
135 | return (d_ptr->m_backgroundItem)->brush(); |
|
134 | return (d_ptr->m_backgroundItem)->brush(); | |
136 | } |
|
135 | } | |
137 |
|
136 | |||
138 | /*! |
|
137 | /*! | |
139 | Sets the \a pen that is used for painting the background of the chart area. |
|
138 | Sets the \a pen that is used for painting the background of the chart area. | |
140 | */ |
|
139 | */ | |
141 | void QChart::setBackgroundPen(const QPen& pen) |
|
140 | void QChart::setBackgroundPen(const QPen& pen) | |
142 | { |
|
141 | { | |
143 | d_ptr->createChartBackgroundItem(); |
|
142 | d_ptr->createChartBackgroundItem(); | |
144 | d_ptr->m_backgroundItem->setPen(pen); |
|
143 | d_ptr->m_backgroundItem->setPen(pen); | |
145 | d_ptr->m_backgroundItem->update(); |
|
144 | d_ptr->m_backgroundItem->update(); | |
146 | } |
|
145 | } | |
147 |
|
146 | |||
148 | QPen QChart::backgroundPen() const |
|
147 | QPen QChart::backgroundPen() const | |
149 | { |
|
148 | { | |
150 | if (!d_ptr->m_backgroundItem) return QPen(); |
|
149 | if (!d_ptr->m_backgroundItem) return QPen(); | |
151 | return d_ptr->m_backgroundItem->pen(); |
|
150 | return d_ptr->m_backgroundItem->pen(); | |
152 | } |
|
151 | } | |
153 |
|
152 | |||
154 | /*! |
|
153 | /*! | |
155 | Sets the chart \a title. The description text that is drawn above the chart. |
|
154 | Sets the chart \a title. The description text that is drawn above the chart. | |
156 | */ |
|
155 | */ | |
157 | void QChart::setTitle(const QString& title) |
|
156 | void QChart::setTitle(const QString& title) | |
158 | { |
|
157 | { | |
159 | d_ptr->createChartTitleItem(); |
|
158 | d_ptr->createChartTitleItem(); | |
160 | d_ptr->m_titleItem->setText(title); |
|
159 | d_ptr->m_titleItem->setText(title); | |
161 | d_ptr->updateLayout(); |
|
160 | d_ptr->updateLayout(); | |
162 | } |
|
161 | } | |
163 |
|
162 | |||
164 | /*! |
|
163 | /*! | |
165 | Returns the chart title. The description text that is drawn above the chart. |
|
164 | Returns the chart title. The description text that is drawn above the chart. | |
166 | */ |
|
165 | */ | |
167 | QString QChart::title() const |
|
166 | QString QChart::title() const | |
168 | { |
|
167 | { | |
169 | if (d_ptr->m_titleItem) |
|
168 | if (d_ptr->m_titleItem) | |
170 | return d_ptr->m_titleItem->text(); |
|
169 | return d_ptr->m_titleItem->text(); | |
171 | else |
|
170 | else | |
172 | return QString(); |
|
171 | return QString(); | |
173 | } |
|
172 | } | |
174 |
|
173 | |||
175 | /*! |
|
174 | /*! | |
176 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
175 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
177 | */ |
|
176 | */ | |
178 | void QChart::setTitleFont(const QFont& font) |
|
177 | void QChart::setTitleFont(const QFont& font) | |
179 | { |
|
178 | { | |
180 | d_ptr->createChartTitleItem(); |
|
179 | d_ptr->createChartTitleItem(); | |
181 | d_ptr->m_titleItem->setFont(font); |
|
180 | d_ptr->m_titleItem->setFont(font); | |
182 | d_ptr->updateLayout(); |
|
181 | d_ptr->updateLayout(); | |
183 | } |
|
182 | } | |
184 |
|
183 | |||
185 | /*! |
|
184 | /*! | |
186 | Sets the \a brush used for rendering the title text. |
|
185 | Sets the \a brush used for rendering the title text. | |
187 | */ |
|
186 | */ | |
188 | void QChart::setTitleBrush(const QBrush &brush) |
|
187 | void QChart::setTitleBrush(const QBrush &brush) | |
189 | { |
|
188 | { | |
190 | d_ptr->createChartTitleItem(); |
|
189 | d_ptr->createChartTitleItem(); | |
191 | d_ptr->m_titleItem->setBrush(brush); |
|
190 | d_ptr->m_titleItem->setBrush(brush); | |
192 | d_ptr->updateLayout(); |
|
191 | d_ptr->updateLayout(); | |
193 | } |
|
192 | } | |
194 |
|
193 | |||
195 | /*! |
|
194 | /*! | |
196 | Returns the brush used for rendering the title text. |
|
195 | Returns the brush used for rendering the title text. | |
197 | */ |
|
196 | */ | |
198 | QBrush QChart::titleBrush() const |
|
197 | QBrush QChart::titleBrush() const | |
199 | { |
|
198 | { | |
200 | if (!d_ptr->m_titleItem) return QBrush(); |
|
199 | if (!d_ptr->m_titleItem) return QBrush(); | |
201 | return d_ptr->m_titleItem->brush(); |
|
200 | return d_ptr->m_titleItem->brush(); | |
202 | } |
|
201 | } | |
203 |
|
202 | |||
204 | /*! |
|
203 | /*! | |
205 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
204 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
206 | \sa ChartTheme, chartTheme() |
|
205 | \sa ChartTheme, chartTheme() | |
207 | */ |
|
206 | */ | |
208 | void QChart::setTheme(QChart::ChartTheme theme) |
|
207 | void QChart::setTheme(QChart::ChartTheme theme) | |
209 | { |
|
208 | { | |
210 | d_ptr->m_presenter->setTheme(theme); |
|
209 | d_ptr->m_presenter->setTheme(theme); | |
211 | } |
|
210 | } | |
212 |
|
211 | |||
213 | /*! |
|
212 | /*! | |
214 | Returns the theme enum used by the chart. |
|
213 | Returns the theme enum used by the chart. | |
215 | \sa ChartTheme, setChartTheme() |
|
214 | \sa ChartTheme, setChartTheme() | |
216 | */ |
|
215 | */ | |
217 | QChart::ChartTheme QChart::theme() const |
|
216 | QChart::ChartTheme QChart::theme() const | |
218 | { |
|
217 | { | |
219 | return d_ptr->m_presenter->theme(); |
|
218 | return d_ptr->m_presenter->theme(); | |
220 | } |
|
219 | } | |
221 |
|
220 | |||
222 | /*! |
|
221 | /*! | |
223 | Zooms in the view by a factor of 2 |
|
222 | Zooms in the view by a factor of 2 | |
224 | */ |
|
223 | */ | |
225 | void QChart::zoomIn() |
|
224 | void QChart::zoomIn() | |
226 | { |
|
225 | { | |
227 | d_ptr->m_presenter->zoomIn(); |
|
226 | d_ptr->m_presenter->zoomIn(); | |
228 | } |
|
227 | } | |
229 |
|
228 | |||
230 | /*! |
|
229 | /*! | |
231 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
230 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
232 | */ |
|
231 | */ | |
233 | void QChart::zoomIn(const QRectF& rect) |
|
232 | void QChart::zoomIn(const QRectF& rect) | |
234 | { |
|
233 | { | |
235 | if (!rect.isValid()) return; |
|
234 | if (!rect.isValid()) return; | |
236 | d_ptr->m_presenter->zoomIn(rect); |
|
235 | d_ptr->m_presenter->zoomIn(rect); | |
237 | } |
|
236 | } | |
238 |
|
237 | |||
239 | /*! |
|
238 | /*! | |
240 | Restores the view zoom level to the previous one. |
|
239 | Restores the view zoom level to the previous one. | |
241 | */ |
|
240 | */ | |
242 | void QChart::zoomOut() |
|
241 | void QChart::zoomOut() | |
243 | { |
|
242 | { | |
244 | d_ptr->m_presenter->zoomOut(); |
|
243 | d_ptr->m_presenter->zoomOut(); | |
245 | } |
|
244 | } | |
246 |
|
245 | |||
247 | /*! |
|
246 | /*! | |
248 | Returns the pointer to the x axis object of the chart |
|
247 | Returns the pointer to the x axis object of the chart | |
249 | */ |
|
248 | */ | |
250 | QChartAxis* QChart::axisX() const |
|
249 | QChartAxis* QChart::axisX() const | |
251 | { |
|
250 | { | |
252 | return d_ptr->m_dataset->axisX(); |
|
251 | return d_ptr->m_dataset->axisX(); | |
253 | } |
|
252 | } | |
254 |
|
253 | |||
255 | /*! |
|
254 | /*! | |
256 | Returns the pointer to the y axis object of the chart |
|
255 | Returns the pointer to the y axis object of the chart | |
257 | */ |
|
256 | */ | |
258 | QChartAxis* QChart::axisY() const |
|
257 | QChartAxis* QChart::axisY() const | |
259 | { |
|
258 | { | |
260 | return d_ptr->m_dataset->axisY(); |
|
259 | return d_ptr->m_dataset->axisY(); | |
261 | } |
|
260 | } | |
262 |
|
261 | |||
263 | /*! |
|
262 | /*! | |
264 | Returns the legend object of the chart. Ownership stays in chart. |
|
263 | Returns the legend object of the chart. Ownership stays in chart. | |
265 | */ |
|
264 | */ | |
266 | QLegend* QChart::legend() const |
|
265 | QLegend* QChart::legend() const | |
267 | { |
|
266 | { | |
268 | return d_ptr->m_legend; |
|
267 | return d_ptr->m_legend; | |
269 | } |
|
268 | } | |
270 |
|
269 | |||
271 | QRect QChart::padding() const |
|
270 | QRect QChart::padding() const | |
272 | { |
|
271 | { | |
273 | return d_ptr->m_padding; |
|
272 | return d_ptr->m_padding; | |
274 | } |
|
273 | } | |
275 |
|
274 | |||
276 |
|
275 | |||
277 | /*! |
|
276 | /*! | |
278 | Resizes and updates the chart area using the \a event data |
|
277 | Resizes and updates the chart area using the \a event data | |
279 | */ |
|
278 | */ | |
280 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
279 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
281 | { |
|
280 | { | |
282 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
281 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
283 | d_ptr->updateLayout(); |
|
282 | d_ptr->updateLayout(); | |
284 | QGraphicsWidget::resizeEvent(event); |
|
283 | QGraphicsWidget::resizeEvent(event); | |
285 | update(); |
|
284 | update(); | |
286 | } |
|
285 | } | |
287 |
|
286 | |||
288 | /*! |
|
287 | /*! | |
289 | Sets animation \a options for the chart |
|
288 | Sets animation \a options for the chart | |
290 | */ |
|
289 | */ | |
291 | void QChart::setAnimationOptions(AnimationOptions options) |
|
290 | void QChart::setAnimationOptions(AnimationOptions options) | |
292 | { |
|
291 | { | |
293 | d_ptr->m_presenter->setAnimationOptions(options); |
|
292 | d_ptr->m_presenter->setAnimationOptions(options); | |
294 | } |
|
293 | } | |
295 |
|
294 | |||
296 | /*! |
|
295 | /*! | |
297 | Returns animation options for the chart |
|
296 | Returns animation options for the chart | |
298 | */ |
|
297 | */ | |
299 | QChart::AnimationOptions QChart::animationOptions() const |
|
298 | QChart::AnimationOptions QChart::animationOptions() const | |
300 | { |
|
299 | { | |
301 | return d_ptr->m_presenter->animationOptions(); |
|
300 | return d_ptr->m_presenter->animationOptions(); | |
302 | } |
|
301 | } | |
303 |
|
302 | |||
304 | void QChart::scrollLeft() |
|
303 | void QChart::scrollLeft() | |
305 | { |
|
304 | { | |
306 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
305 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); | |
307 | } |
|
306 | } | |
308 |
|
307 | |||
309 | void QChart::scrollRight() |
|
308 | void QChart::scrollRight() | |
310 | { |
|
309 | { | |
311 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
310 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); | |
312 | } |
|
311 | } | |
313 |
|
312 | |||
314 | void QChart::scrollUp() |
|
313 | void QChart::scrollUp() | |
315 | { |
|
314 | { | |
316 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
315 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1)); | |
317 | } |
|
316 | } | |
318 |
|
317 | |||
319 | void QChart::scrollDown() |
|
318 | void QChart::scrollDown() | |
320 | { |
|
319 | { | |
321 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
320 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1)); | |
322 | } |
|
321 | } | |
323 |
|
322 | |||
324 | void QChart::setBackgroundVisible(bool visible) |
|
323 | void QChart::setBackgroundVisible(bool visible) | |
325 | { |
|
324 | { | |
326 | d_ptr->createChartBackgroundItem(); |
|
325 | d_ptr->createChartBackgroundItem(); | |
327 | d_ptr->m_backgroundItem->setVisible(visible); |
|
326 | d_ptr->m_backgroundItem->setVisible(visible); | |
328 | } |
|
327 | } | |
329 |
|
328 | |||
330 | bool QChart::isBackgroundVisible() const |
|
329 | bool QChart::isBackgroundVisible() const | |
331 | { |
|
330 | { | |
332 | if (!d_ptr->m_backgroundItem) return false; |
|
331 | if (!d_ptr->m_backgroundItem) return false; | |
333 | return d_ptr->m_backgroundItem->isVisible(); |
|
332 | return d_ptr->m_backgroundItem->isVisible(); | |
334 | } |
|
333 | } | |
335 |
|
334 | |||
336 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
335 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
337 |
|
336 | |||
338 | QChartPrivate::QChartPrivate(QChart *parent): |
|
337 | QChartPrivate::QChartPrivate(QChart *parent): | |
339 | q_ptr(parent), |
|
338 | q_ptr(parent), | |
340 | m_backgroundItem(0), |
|
339 | m_backgroundItem(0), | |
341 | m_titleItem(0), |
|
340 | m_titleItem(0), | |
342 | m_legend(0), |
|
341 | m_legend(0), | |
343 | m_dataset(0), |
|
342 | m_dataset(0), | |
344 | m_presenter(0), |
|
343 | m_presenter(0), | |
345 | m_padding(QRect(50,50,0,0)) |
|
344 | m_padding(QRect(50,50,0,0)) | |
346 | { |
|
345 | { | |
347 |
|
346 | |||
348 | } |
|
347 | } | |
349 |
|
348 | |||
350 | QChartPrivate::~QChartPrivate() |
|
349 | QChartPrivate::~QChartPrivate() | |
351 | { |
|
350 | { | |
352 |
|
351 | |||
353 | } |
|
352 | } | |
354 |
|
353 | |||
355 | void QChartPrivate::createChartBackgroundItem() |
|
354 | void QChartPrivate::createChartBackgroundItem() | |
356 | { |
|
355 | { | |
357 | if (!m_backgroundItem) { |
|
356 | if (!m_backgroundItem) { | |
358 | m_backgroundItem = new ChartBackground(q_ptr); |
|
357 | m_backgroundItem = new ChartBackground(q_ptr); | |
359 | m_backgroundItem->setPen(Qt::NoPen); |
|
358 | m_backgroundItem->setPen(Qt::NoPen); | |
360 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
359 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
361 | } |
|
360 | } | |
362 | } |
|
361 | } | |
363 |
|
362 | |||
364 | void QChartPrivate::createChartTitleItem() |
|
363 | void QChartPrivate::createChartTitleItem() | |
365 | { |
|
364 | { | |
366 | if (!m_titleItem) { |
|
365 | if (!m_titleItem) { | |
367 | m_titleItem = new QGraphicsSimpleTextItem(q_ptr); |
|
366 | m_titleItem = new QGraphicsSimpleTextItem(q_ptr); | |
368 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
367 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
369 | } |
|
368 | } | |
370 | } |
|
369 | } | |
371 |
|
370 | |||
372 | void QChartPrivate::updateLegendLayout() |
|
371 | void QChartPrivate::updateLegendLayout() | |
373 | { |
|
372 | { | |
374 | //int legendPadding = m_chart->legend()->padding(); |
|
373 | //int legendPadding = m_chart->legend()->padding(); | |
375 | int legendPadding = 30; |
|
374 | int legendPadding = 30; | |
376 | QRectF rect = m_rect; |
|
375 | QRectF rect = m_rect; | |
377 |
|
376 | |||
378 | if ((m_legend->attachedToChart()) && (m_legend->isVisible())) { |
|
377 | if ((m_legend->attachedToChart()) && (m_legend->isVisible())) { | |
379 |
|
378 | |||
380 | // Reserve some space for legend |
|
379 | // Reserve some space for legend | |
381 | switch (m_legend->alignment()) { |
|
380 | switch (m_legend->alignment()) { | |
382 | case QLegend::AlignmentTop: { |
|
381 | case QLegend::AlignmentTop: { | |
383 | rect.adjust(m_padding.left(), |
|
382 | rect.adjust(m_padding.left(), | |
384 | m_padding.top() + legendPadding, |
|
383 | m_padding.top() + legendPadding, | |
385 | -m_padding.right(), |
|
384 | -m_padding.right(), | |
386 | -m_padding.bottom()); |
|
385 | -m_padding.bottom()); | |
387 | break; |
|
386 | break; | |
388 | } |
|
387 | } | |
389 | case QLegend::AlignmentBottom: { |
|
388 | case QLegend::AlignmentBottom: { | |
390 | rect.adjust(m_padding.left(), |
|
389 | rect.adjust(m_padding.left(), | |
391 | m_padding.top(), |
|
390 | m_padding.top(), | |
392 | -m_padding.right(), |
|
391 | -m_padding.right(), | |
393 | -m_padding.bottom() - legendPadding); |
|
392 | -m_padding.bottom() - legendPadding); | |
394 | break; |
|
393 | break; | |
395 | } |
|
394 | } | |
396 | case QLegend::AlignmentLeft: { |
|
395 | case QLegend::AlignmentLeft: { | |
397 | rect.adjust(m_padding.left() + legendPadding, |
|
396 | rect.adjust(m_padding.left() + legendPadding, | |
398 | m_padding.top(), |
|
397 | m_padding.top(), | |
399 | -m_padding.right(), |
|
398 | -m_padding.right(), | |
400 | -m_padding.bottom()); |
|
399 | -m_padding.bottom()); | |
401 | break; |
|
400 | break; | |
402 | } |
|
401 | } | |
403 | case QLegend::AlignmentRight: { |
|
402 | case QLegend::AlignmentRight: { | |
404 | rect.adjust(m_padding.left(), |
|
403 | rect.adjust(m_padding.left(), | |
405 | m_padding.top(), |
|
404 | m_padding.top(), | |
406 | -m_padding.right() - legendPadding, |
|
405 | -m_padding.right() - legendPadding, | |
407 | -m_padding.bottom()); |
|
406 | -m_padding.bottom()); | |
408 | break; |
|
407 | break; | |
409 | } |
|
408 | } | |
410 | default: { |
|
409 | default: { | |
411 | rect.adjust(m_padding.left(), |
|
410 | rect.adjust(m_padding.left(), | |
412 | m_padding.top(), |
|
411 | m_padding.top(), | |
413 | -m_padding.right(), |
|
412 | -m_padding.right(), | |
414 | -m_padding.bottom()); |
|
413 | -m_padding.bottom()); | |
415 | break; |
|
414 | break; | |
416 | } |
|
415 | } | |
417 | } |
|
416 | } | |
418 | } else { |
|
417 | } else { | |
419 |
|
418 | |||
420 | rect.adjust(m_padding.left(), |
|
419 | rect.adjust(m_padding.left(), | |
421 | m_padding.top(), |
|
420 | m_padding.top(), | |
422 | -m_padding.right(), |
|
421 | -m_padding.right(), | |
423 | -m_padding.bottom()); |
|
422 | -m_padding.bottom()); | |
424 | } |
|
423 | } | |
425 |
|
424 | |||
426 | QRectF plotRect = m_rect.adjusted(m_padding.left() |
|
425 | QRectF plotRect = m_rect.adjusted(m_padding.left() | |
427 | ,m_padding.top() |
|
426 | ,m_padding.top() | |
428 | ,-m_padding.right() |
|
427 | ,-m_padding.right() | |
429 | ,-m_padding.bottom()); |
|
428 | ,-m_padding.bottom()); | |
430 | QRectF legendRect; |
|
429 | QRectF legendRect; | |
431 |
|
430 | |||
432 | int padding = 0; // TODO: fix this |
|
431 | int padding = 0; // TODO: fix this | |
433 | switch (m_legend->alignment()) |
|
432 | switch (m_legend->alignment()) | |
434 | { |
|
433 | { | |
435 | case QLegend::AlignmentTop: { |
|
434 | case QLegend::AlignmentTop: { | |
436 | legendRect = m_rect.adjusted(0,padding,0,-padding - plotRect.height()); |
|
435 | legendRect = m_rect.adjusted(0,padding,0,-padding - plotRect.height()); | |
437 | break; |
|
436 | break; | |
438 | } |
|
437 | } | |
439 | case QLegend::AlignmentBottom: { |
|
438 | case QLegend::AlignmentBottom: { | |
440 | legendRect = m_rect.adjusted(padding,padding + plotRect.height(),-padding,0); |
|
439 | legendRect = m_rect.adjusted(padding,padding + plotRect.height(),-padding,0); | |
441 | break; |
|
440 | break; | |
442 | } |
|
441 | } | |
443 | case QLegend::AlignmentLeft: { |
|
442 | case QLegend::AlignmentLeft: { | |
444 | legendRect = m_rect.adjusted(0,padding,-padding - plotRect.width(),-padding); |
|
443 | legendRect = m_rect.adjusted(0,padding,-padding - plotRect.width(),-padding); | |
445 | break; |
|
444 | break; | |
446 | } |
|
445 | } | |
447 | case QLegend::AlignmentRight: { |
|
446 | case QLegend::AlignmentRight: { | |
448 | legendRect = m_rect.adjusted(padding + plotRect.width(),padding,0,-padding); |
|
447 | legendRect = m_rect.adjusted(padding + plotRect.width(),padding,0,-padding); | |
449 | break; |
|
448 | break; | |
450 | } |
|
449 | } | |
451 | default: { |
|
450 | default: { | |
452 | legendRect = plotRect; |
|
451 | legendRect = plotRect; | |
453 | break; |
|
452 | break; | |
454 | } |
|
453 | } | |
455 | } |
|
454 | } | |
456 |
|
455 | |||
457 | m_legend->setMaximumSize(legendRect.size()); |
|
456 | m_legend->setMaximumSize(legendRect.size()); | |
458 |
|
457 | |||
459 | qreal width = legendRect.width() - m_legend->size().width(); |
|
458 | qreal width = legendRect.width() - m_legend->size().width(); | |
460 | qreal height = legendRect.height() - m_legend->size().height(); |
|
459 | qreal height = legendRect.height() - m_legend->size().height(); | |
461 |
|
460 | |||
462 | QPointF pos = legendRect.topLeft(); |
|
461 | QPointF pos = legendRect.topLeft(); | |
463 | if (width > 0) { |
|
462 | if (width > 0) { | |
464 | pos.setX(pos.x() + width/2); |
|
463 | pos.setX(pos.x() + width/2); | |
465 | } |
|
464 | } | |
466 | if (height > 0) { |
|
465 | if (height > 0) { | |
467 | pos.setY(pos.y() + height/2); |
|
466 | pos.setY(pos.y() + height/2); | |
468 | } |
|
467 | } | |
469 |
|
468 | |||
470 | m_legend->setPos(pos); |
|
469 | m_legend->setPos(pos); | |
471 | } |
|
470 | } | |
472 |
|
471 | |||
473 | void QChartPrivate::updateLayout() |
|
472 | void QChartPrivate::updateLayout() | |
474 | { |
|
473 | { | |
475 | if (!m_rect.isValid()) return; |
|
474 | if (!m_rect.isValid()) return; | |
476 |
|
475 | |||
477 | int padding = m_padding.top(); |
|
476 | int padding = m_padding.top(); | |
478 | int backgroundPadding = m_presenter->backgroundPadding(); |
|
477 | int backgroundPadding = m_presenter->backgroundPadding(); | |
479 |
|
478 | |||
480 | // recalculate title position |
|
479 | // recalculate title position | |
481 | if (m_titleItem) { |
|
480 | if (m_titleItem) { | |
482 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
481 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
483 | m_titleItem->setPos(center.x(),m_rect.top()/2 + padding/2); |
|
482 | m_titleItem->setPos(center.x(),m_rect.top()/2 + padding/2); | |
484 | } |
|
483 | } | |
485 |
|
484 | |||
486 | //recalculate background gradient |
|
485 | //recalculate background gradient | |
487 | if (m_backgroundItem) { |
|
486 | if (m_backgroundItem) { | |
488 | m_backgroundItem->setRect(m_rect.adjusted(backgroundPadding,backgroundPadding, -backgroundPadding, -backgroundPadding)); |
|
487 | m_backgroundItem->setRect(m_rect.adjusted(backgroundPadding,backgroundPadding, -backgroundPadding, -backgroundPadding)); | |
489 | } |
|
488 | } | |
490 |
|
489 | |||
491 | // recalculate legend position |
|
490 | // recalculate legend position | |
492 | if (m_legend) { |
|
491 | if (m_legend) { | |
493 | if ((m_legend->attachedToChart()) && (m_legend->parentObject() == q_ptr)) { |
|
492 | if ((m_legend->attachedToChart()) && (m_legend->parentObject() == q_ptr)) { | |
494 | updateLegendLayout(); |
|
493 | updateLegendLayout(); | |
495 | } |
|
494 | } | |
496 | } |
|
495 | } | |
497 | } |
|
496 | } | |
498 |
|
497 | |||
499 | #include "moc_qchart.cpp" |
|
498 | #include "moc_qchart.cpp" | |
500 |
|
499 | |||
501 | QTCOMMERCIALCHART_END_NAMESPACE |
|
500 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,119 +1,118 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QCHART_H |
|
21 | #ifndef QCHART_H | |
22 | #define QCHART_H |
|
22 | #define QCHART_H | |
23 |
|
23 | |||
24 | #include <QSeries> |
|
24 | #include <QSeries> | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 |
|
26 | |||
27 | class QGraphicsSceneResizeEvent; |
|
27 | class QGraphicsSceneResizeEvent; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QSeries; |
|
31 | class QSeries; | |
32 | class QChartAxis; |
|
32 | class QChartAxis; | |
33 | class QLegend; |
|
33 | class QLegend; | |
34 | struct QChartPrivate; |
|
34 | struct QChartPrivate; | |
35 |
|
35 | |||
36 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
36 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | Q_ENUMS(ChartTheme) |
|
39 | Q_ENUMS(ChartTheme) | |
40 |
|
40 | |||
41 | public: |
|
41 | public: | |
42 | enum ChartTheme { |
|
42 | enum ChartTheme { | |
43 |
ChartTheme |
|
43 | ChartThemeLight = 0, | |
44 | ChartThemeLight, |
|
|||
45 | ChartThemeBlueCerulean, |
|
44 | ChartThemeBlueCerulean, | |
46 | ChartThemeDark, |
|
45 | ChartThemeDark, | |
47 | ChartThemeBrownSand, |
|
46 | ChartThemeBrownSand, | |
48 | ChartThemeBlueNcs, |
|
47 | ChartThemeBlueNcs, | |
49 | ChartThemeHighContrast, |
|
48 | ChartThemeHighContrast, | |
50 | ChartThemeBlueIcy, |
|
49 | ChartThemeBlueIcy, | |
51 | ChartThemeCount |
|
50 | ChartThemeCount | |
52 | }; |
|
51 | }; | |
53 |
|
52 | |||
54 | enum AnimationOption { |
|
53 | enum AnimationOption { | |
55 | NoAnimation = 0x0, |
|
54 | NoAnimation = 0x0, | |
56 | GridAxisAnimations = 0x1, |
|
55 | GridAxisAnimations = 0x1, | |
57 | SeriesAnimations =0x2, |
|
56 | SeriesAnimations =0x2, | |
58 | AllAnimations = 0x3 |
|
57 | AllAnimations = 0x3 | |
59 | }; |
|
58 | }; | |
60 |
|
59 | |||
61 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
60 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
62 |
|
61 | |||
63 | public: |
|
62 | public: | |
64 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
63 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
65 | ~QChart(); |
|
64 | ~QChart(); | |
66 |
|
65 | |||
67 | void addSeries(QSeries *series, QChartAxis *axisY = 0); |
|
66 | void addSeries(QSeries *series, QChartAxis *axisY = 0); | |
68 | void removeSeries(QSeries *series); |
|
67 | void removeSeries(QSeries *series); | |
69 | void removeAllSeries(); |
|
68 | void removeAllSeries(); | |
70 |
|
69 | |||
71 | void setTheme(QChart::ChartTheme theme); |
|
70 | void setTheme(QChart::ChartTheme theme); | |
72 | QChart::ChartTheme theme() const; |
|
71 | QChart::ChartTheme theme() const; | |
73 |
|
72 | |||
74 | void setTitle(const QString& title); |
|
73 | void setTitle(const QString& title); | |
75 | QString title() const; |
|
74 | QString title() const; | |
76 | void setTitleFont(const QFont& font); |
|
75 | void setTitleFont(const QFont& font); | |
77 | QFont titleFont() const; |
|
76 | QFont titleFont() const; | |
78 | void setTitleBrush(const QBrush &brush); |
|
77 | void setTitleBrush(const QBrush &brush); | |
79 | QBrush titleBrush() const; |
|
78 | QBrush titleBrush() const; | |
80 | void setBackgroundBrush(const QBrush &brush); |
|
79 | void setBackgroundBrush(const QBrush &brush); | |
81 | QBrush backgroundBrush() const; |
|
80 | QBrush backgroundBrush() const; | |
82 | void setBackgroundPen(const QPen &pen); |
|
81 | void setBackgroundPen(const QPen &pen); | |
83 | QPen backgroundPen() const; |
|
82 | QPen backgroundPen() const; | |
84 |
|
83 | |||
85 | void setBackgroundVisible(bool visible); |
|
84 | void setBackgroundVisible(bool visible); | |
86 | bool isBackgroundVisible() const; |
|
85 | bool isBackgroundVisible() const; | |
87 |
|
86 | |||
88 | void setAnimationOptions(AnimationOptions options); |
|
87 | void setAnimationOptions(AnimationOptions options); | |
89 | AnimationOptions animationOptions() const; |
|
88 | AnimationOptions animationOptions() const; | |
90 |
|
89 | |||
91 | void zoomIn(); |
|
90 | void zoomIn(); | |
92 | void zoomIn(const QRectF &rect); |
|
91 | void zoomIn(const QRectF &rect); | |
93 | void zoomOut(); |
|
92 | void zoomOut(); | |
94 | void scrollLeft(); |
|
93 | void scrollLeft(); | |
95 | void scrollRight(); |
|
94 | void scrollRight(); | |
96 | void scrollUp(); |
|
95 | void scrollUp(); | |
97 | void scrollDown(); |
|
96 | void scrollDown(); | |
98 |
|
97 | |||
99 | QChartAxis* axisX() const; |
|
98 | QChartAxis* axisX() const; | |
100 | QChartAxis* axisY() const; |
|
99 | QChartAxis* axisY() const; | |
101 |
|
100 | |||
102 | QLegend* legend() const; |
|
101 | QLegend* legend() const; | |
103 |
|
102 | |||
104 | QRect padding() const; |
|
103 | QRect padding() const; | |
105 |
|
104 | |||
106 | protected: |
|
105 | protected: | |
107 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
106 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
108 |
|
107 | |||
109 | protected: |
|
108 | protected: | |
110 | QScopedPointer<QChartPrivate> d_ptr; |
|
109 | QScopedPointer<QChartPrivate> d_ptr; | |
111 | friend class QLegend; |
|
110 | friend class QLegend; | |
112 | Q_DISABLE_COPY(QChart) |
|
111 | Q_DISABLE_COPY(QChart) | |
113 | }; |
|
112 | }; | |
114 |
|
113 | |||
115 | QTCOMMERCIALCHART_END_NAMESPACE |
|
114 | QTCOMMERCIALCHART_END_NAMESPACE | |
116 |
|
115 | |||
117 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
116 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
118 |
|
117 | |||
119 | #endif |
|
118 | #endif |
@@ -1,12 +1,12 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | THEMES += \ |
|
4 | THEMES += \ | |
5 |
$$PWD/charttheme |
|
5 | $$PWD/chartthemesystem_p.h \ | |
6 | $$PWD/chartthemelight_p.h \ |
|
6 | $$PWD/chartthemelight_p.h \ | |
7 | $$PWD/chartthemebluecerulean_p.h \ |
|
7 | $$PWD/chartthemebluecerulean_p.h \ | |
8 | $$PWD/chartthemedark_p.h \ |
|
8 | $$PWD/chartthemedark_p.h \ | |
9 | $$PWD/chartthemebrownsand_p.h \ |
|
9 | $$PWD/chartthemebrownsand_p.h \ | |
10 | $$PWD/chartthemebluencs_p.h \ |
|
10 | $$PWD/chartthemebluencs_p.h \ | |
11 | $$PWD/chartthemehighcontrast_p.h \ |
|
11 | $$PWD/chartthemehighcontrast_p.h \ | |
12 | $$PWD/chartthemeblueicy_p.h |
|
12 | $$PWD/chartthemeblueicy_p.h |
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