@@ -1,374 +1,374 | |||||
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-aliasing")), |
|
51 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), | |
52 | m_animatedComboBox(createAnimationBox()), |
|
52 | m_animatedComboBox(createAnimationBox()), | |
53 | m_legendComboBox(createLegendBox()) |
|
53 | m_legendComboBox(createLegendBox()) | |
54 | { |
|
54 | { | |
55 | connectSignals(); |
|
55 | connectSignals(); | |
56 | // create layout |
|
56 | // create layout | |
57 | QGridLayout* baseLayout = new QGridLayout(); |
|
57 | QGridLayout* baseLayout = new QGridLayout(); | |
58 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
58 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
59 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
59 | settingsLayout->addWidget(new QLabel("Theme:")); | |
60 | settingsLayout->addWidget(m_themeComboBox); |
|
60 | settingsLayout->addWidget(m_themeComboBox); | |
61 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
61 | settingsLayout->addWidget(new QLabel("Animation:")); | |
62 | settingsLayout->addWidget(m_animatedComboBox); |
|
62 | settingsLayout->addWidget(m_animatedComboBox); | |
63 | settingsLayout->addWidget(new QLabel("Legend:")); |
|
63 | settingsLayout->addWidget(new QLabel("Legend:")); | |
64 | settingsLayout->addWidget(m_legendComboBox); |
|
64 | settingsLayout->addWidget(m_legendComboBox); | |
65 | settingsLayout->addWidget(m_antialiasCheckBox); |
|
65 | settingsLayout->addWidget(m_antialiasCheckBox); | |
66 | settingsLayout->addStretch(); |
|
66 | settingsLayout->addStretch(); | |
67 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
67 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); | |
68 |
|
68 | |||
69 | //create charts |
|
69 | //create charts | |
70 |
|
70 | |||
71 | QChartView *chartView; |
|
71 | QChartView *chartView; | |
72 |
|
72 | |||
73 | chartView = new QChartView(createAreaChart()); |
|
73 | chartView = new QChartView(createAreaChart()); | |
74 | baseLayout->addWidget(chartView, 1, 0); |
|
74 | baseLayout->addWidget(chartView, 1, 0); | |
75 | m_charts << chartView; |
|
75 | m_charts << chartView; | |
76 |
|
76 | |||
77 | chartView = new QChartView(createBarChart(m_valueCount)); |
|
77 | chartView = new QChartView(createBarChart(m_valueCount)); | |
78 | baseLayout->addWidget(chartView, 1, 1); |
|
78 | baseLayout->addWidget(chartView, 1, 1); | |
79 | m_charts << chartView; |
|
79 | m_charts << chartView; | |
80 |
|
80 | |||
81 | chartView = new QChartView(createLineChart()); |
|
81 | chartView = new QChartView(createLineChart()); | |
82 | baseLayout->addWidget(chartView, 1, 2); |
|
82 | baseLayout->addWidget(chartView, 1, 2); | |
83 | m_charts << chartView; |
|
83 | m_charts << chartView; | |
84 |
|
84 | |||
85 | chartView = new QChartView(createPieChart()); |
|
85 | chartView = new QChartView(createPieChart()); | |
86 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... |
|
86 | 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); |
|
87 | baseLayout->addWidget(chartView, 2, 0); | |
88 | m_charts << chartView; |
|
88 | m_charts << chartView; | |
89 |
|
89 | |||
90 | chartView = new QChartView(createSplineChart()); |
|
90 | chartView = new QChartView(createSplineChart()); | |
91 | baseLayout->addWidget(chartView, 2, 1); |
|
91 | baseLayout->addWidget(chartView, 2, 1); | |
92 | m_charts << chartView; |
|
92 | m_charts << chartView; | |
93 |
|
93 | |||
94 | chartView = new QChartView(createScatterChart()); |
|
94 | chartView = new QChartView(createScatterChart()); | |
95 | baseLayout->addWidget(chartView, 2, 2); |
|
95 | baseLayout->addWidget(chartView, 2, 2); | |
96 | m_charts << chartView; |
|
96 | m_charts << chartView; | |
97 |
|
97 | |||
98 | setLayout(baseLayout); |
|
98 | setLayout(baseLayout); | |
99 |
|
99 | |||
100 | // Set defaults |
|
100 | // Set defaults | |
101 | m_antialiasCheckBox->setChecked(true); |
|
101 | m_antialiasCheckBox->setChecked(true); | |
102 | updateUI(); |
|
102 | updateUI(); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | ThemeWidget::~ThemeWidget() |
|
105 | ThemeWidget::~ThemeWidget() | |
106 | { |
|
106 | { | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void ThemeWidget::connectSignals() |
|
109 | void ThemeWidget::connectSignals() | |
110 | { |
|
110 | { | |
111 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
111 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
112 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
112 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
113 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
113 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
114 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
114 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
117 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const | |
118 | { |
|
118 | { | |
119 | DataTable dataTable; |
|
119 | DataTable dataTable; | |
120 |
|
120 | |||
121 | // set seed for random stuff |
|
121 | // set seed for random stuff | |
122 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
122 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
123 |
|
123 | |||
124 | // generate random data |
|
124 | // generate random data | |
125 | for (int i(0); i < listCount; i++) { |
|
125 | for (int i(0); i < listCount; i++) { | |
126 | DataList dataList; |
|
126 | DataList dataList; | |
127 | qreal yValue(0); |
|
127 | qreal yValue(0); | |
128 | for (int j(0); j < valueCount; j++) { |
|
128 | for (int j(0); j < valueCount; j++) { | |
129 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; |
|
129 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; | |
130 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), |
|
130 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), | |
131 | yValue); |
|
131 | yValue); | |
132 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); |
|
132 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); | |
133 | dataList << Data(value, label); |
|
133 | dataList << Data(value, label); | |
134 | } |
|
134 | } | |
135 | dataTable << dataList; |
|
135 | dataTable << dataList; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | return dataTable; |
|
138 | return dataTable; | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | QComboBox* ThemeWidget::createThemeBox() const |
|
141 | QComboBox* ThemeWidget::createThemeBox() const | |
142 | { |
|
142 | { | |
143 | // settings layout |
|
143 | // settings layout | |
144 | QComboBox* themeComboBox = new QComboBox(); |
|
144 | QComboBox* themeComboBox = new QComboBox(); | |
145 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
145 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
146 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
146 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
147 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
147 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
148 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
148 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
149 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
149 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
150 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
150 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
151 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
151 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
152 | return themeComboBox; |
|
152 | return themeComboBox; | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | QComboBox* ThemeWidget::createAnimationBox() const |
|
155 | QComboBox* ThemeWidget::createAnimationBox() const | |
156 | { |
|
156 | { | |
157 | // settings layout |
|
157 | // settings layout | |
158 | QComboBox* animationComboBox = new QComboBox(); |
|
158 | QComboBox* animationComboBox = new QComboBox(); | |
159 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
159 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
160 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
160 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
161 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
161 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
162 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
162 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
163 | return animationComboBox; |
|
163 | return animationComboBox; | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | QComboBox* ThemeWidget::createLegendBox() const |
|
166 | QComboBox* ThemeWidget::createLegendBox() const | |
167 | { |
|
167 | { | |
168 | QComboBox* legendComboBox = new QComboBox(); |
|
168 | QComboBox* legendComboBox = new QComboBox(); | |
169 | legendComboBox->addItem("No Legend ", 0); |
|
169 | legendComboBox->addItem("No Legend ", 0); | |
170 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); |
|
170 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); | |
171 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); |
|
171 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); | |
172 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); |
|
172 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); | |
173 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); |
|
173 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); | |
174 | return legendComboBox; |
|
174 | return legendComboBox; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | QChart* ThemeWidget::createAreaChart() const |
|
177 | QChart* ThemeWidget::createAreaChart() const | |
178 | { |
|
178 | { | |
179 | // area chart |
|
179 | // area chart | |
180 | QChart *chart = new QChart(); |
|
180 | QChart *chart = new QChart(); | |
181 | chart->axisX()->setNiceNumbers(true); |
|
181 | chart->axisX()->setNiceNumbers(true); | |
182 | chart->axisY()->setNiceNumbers(true); |
|
182 | chart->axisY()->setNiceNumbers(true); | |
183 | chart->setTitle("Area chart"); |
|
183 | chart->setTitle("Area chart"); | |
184 | QString name("Series "); |
|
184 | QString name("Series "); | |
185 | int nameIndex = 0; |
|
185 | int nameIndex = 0; | |
186 |
|
186 | |||
187 | // The lower series initialized to zero values |
|
187 | // The lower series initialized to zero values | |
188 | QLineSeries *lowerSeries = 0; |
|
188 | QLineSeries *lowerSeries = 0; | |
189 | for (int i(0); i < m_dataTable.count(); i++) { |
|
189 | for (int i(0); i < m_dataTable.count(); i++) { | |
190 | QLineSeries *upperSeries = new QLineSeries(chart); |
|
190 | QLineSeries *upperSeries = new QLineSeries(chart); | |
191 | for (int j(0); j < m_dataTable[i].count(); j++) { |
|
191 | for (int j(0); j < m_dataTable[i].count(); j++) { | |
192 | Data data = m_dataTable[i].at(j); |
|
192 | Data data = m_dataTable[i].at(j); | |
193 | if (lowerSeries) |
|
193 | if (lowerSeries) | |
194 | upperSeries->append(QPointF(j, lowerSeries->y(i) + data.first.y())); |
|
194 | upperSeries->append(QPointF(j, lowerSeries->y(i) + data.first.y())); | |
195 | else |
|
195 | else | |
196 | upperSeries->append(QPointF(j, data.first.y())); |
|
196 | upperSeries->append(QPointF(j, data.first.y())); | |
197 | } |
|
197 | } | |
198 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
198 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); | |
199 | area->setName(name + QString::number(nameIndex)); |
|
199 | area->setName(name + QString::number(nameIndex)); | |
200 | nameIndex++; |
|
200 | nameIndex++; | |
201 | chart->addSeries(area); |
|
201 | chart->addSeries(area); | |
202 | lowerSeries = upperSeries; |
|
202 | lowerSeries = upperSeries; | |
203 | } |
|
203 | } | |
204 | return chart; |
|
204 | return chart; | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
207 | QChart* ThemeWidget::createBarChart(int valueCount) const | |
208 | { |
|
208 | { | |
209 | // bar chart |
|
209 | // bar chart | |
210 | QChart* chart = new QChart(); |
|
210 | QChart* chart = new QChart(); | |
211 | chart->axisX()->setNiceNumbers(true); |
|
211 | chart->axisX()->setNiceNumbers(true); | |
212 | chart->axisY()->setNiceNumbers(true); |
|
212 | chart->axisY()->setNiceNumbers(true); | |
213 | chart->setTitle("Bar chart"); |
|
213 | chart->setTitle("Bar chart"); | |
214 | QBarCategories categories; |
|
214 | QBarCategories categories; | |
215 | // TODO: categories |
|
215 | // TODO: categories | |
216 | for (int i(0); i < valueCount; i++) |
|
216 | for (int i(0); i < valueCount; i++) | |
217 | categories << QString::number(i); |
|
217 | categories << QString::number(i); | |
218 | // QBarSeries* series = new QBarSeries(categories, chart); |
|
218 | // QBarSeries* series = new QBarSeries(categories, chart); | |
219 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); |
|
219 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); | |
220 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); |
|
220 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); | |
221 | for (int i(0); i < m_dataTable.count(); i++) { |
|
221 | for (int i(0); i < m_dataTable.count(); i++) { | |
222 | QBarSet *set = new QBarSet("Set" + QString::number(i)); |
|
222 | QBarSet *set = new QBarSet("Set" + QString::number(i)); | |
223 | foreach (Data data, m_dataTable[i]) |
|
223 | foreach (Data data, m_dataTable[i]) | |
224 | *set << data.first.y(); |
|
224 | *set << data.first.y(); | |
225 | series->appendBarSet(set); |
|
225 | series->appendBarSet(set); | |
226 | } |
|
226 | } | |
227 | chart->addSeries(series); |
|
227 | chart->addSeries(series); | |
228 | return chart; |
|
228 | return chart; | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | QChart* ThemeWidget::createLineChart() const |
|
231 | QChart* ThemeWidget::createLineChart() const | |
232 | { |
|
232 | { | |
233 | // line chart |
|
233 | // line chart | |
234 | QChart* chart = new QChart(); |
|
234 | QChart* chart = new QChart(); | |
235 | chart->axisX()->setNiceNumbers(true); |
|
235 | chart->axisX()->setNiceNumbers(true); | |
236 | chart->axisY()->setNiceNumbers(true); |
|
236 | chart->axisY()->setNiceNumbers(true); | |
237 | chart->setTitle("Line chart"); |
|
237 | chart->setTitle("Line chart"); | |
238 | QString name("Series "); |
|
238 | QString name("Series "); | |
239 | int nameIndex = 0; |
|
239 | int nameIndex = 0; | |
240 | foreach (DataList list, m_dataTable) { |
|
240 | foreach (DataList list, m_dataTable) { | |
241 | QLineSeries *series = new QLineSeries(chart); |
|
241 | QLineSeries *series = new QLineSeries(chart); | |
242 | foreach (Data data, list) |
|
242 | foreach (Data data, list) | |
243 | series->append(data.first); |
|
243 | series->append(data.first); | |
244 | series->setName(name + QString::number(nameIndex)); |
|
244 | series->setName(name + QString::number(nameIndex)); | |
245 | nameIndex++; |
|
245 | nameIndex++; | |
246 | chart->addSeries(series); |
|
246 | chart->addSeries(series); | |
247 | } |
|
247 | } | |
248 | return chart; |
|
248 | return chart; | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | QChart* ThemeWidget::createPieChart() const |
|
251 | QChart* ThemeWidget::createPieChart() const | |
252 | { |
|
252 | { | |
253 | // pie chart |
|
253 | // pie chart | |
254 | QChart* chart = new QChart(); |
|
254 | QChart* chart = new QChart(); | |
255 | chart->setTitle("Pie chart"); |
|
255 | chart->setTitle("Pie chart"); | |
256 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
256 | qreal pieSize = 1.0 / m_dataTable.count(); | |
257 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
257 | for (int i = 0; i < m_dataTable.count(); i++) { | |
258 | QPieSeries *series = new QPieSeries(chart); |
|
258 | QPieSeries *series = new QPieSeries(chart); | |
259 | foreach (Data data, m_dataTable[i]) { |
|
259 | foreach (Data data, m_dataTable[i]) { | |
260 | QPieSlice *slice = series->append(data.first.y(), data.second); |
|
260 | QPieSlice *slice = series->append(data.first.y(), data.second); | |
261 | if (data == m_dataTable[i].first()) { |
|
261 | if (data == m_dataTable[i].first()) { | |
262 | slice->setLabelVisible(); |
|
262 | slice->setLabelVisible(); | |
263 | slice->setExploded(); |
|
263 | slice->setExploded(); | |
264 | } |
|
264 | } | |
265 | } |
|
265 | } | |
266 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
266 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
267 | series->setPieSize(pieSize); |
|
267 | series->setPieSize(pieSize); | |
268 | series->setHorizontalPosition(hPos); |
|
268 | series->setHorizontalPosition(hPos); | |
269 | series->setVerticalPosition(0.5); |
|
269 | series->setVerticalPosition(0.5); | |
270 | chart->addSeries(series); |
|
270 | chart->addSeries(series); | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | return chart; |
|
273 | return chart; | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | QChart* ThemeWidget::createSplineChart() const |
|
276 | QChart* ThemeWidget::createSplineChart() const | |
277 | { // spine chart |
|
277 | { // spine chart | |
278 | QChart* chart = new QChart(); |
|
278 | QChart* chart = new QChart(); | |
279 | chart->axisX()->setNiceNumbers(true); |
|
279 | chart->axisX()->setNiceNumbers(true); | |
280 | chart->axisY()->setNiceNumbers(true); |
|
280 | chart->axisY()->setNiceNumbers(true); | |
281 | chart->setTitle("Spline chart"); |
|
281 | chart->setTitle("Spline chart"); | |
282 | QString name("Series "); |
|
282 | QString name("Series "); | |
283 | int nameIndex = 0; |
|
283 | int nameIndex = 0; | |
284 | foreach (DataList list, m_dataTable) { |
|
284 | foreach (DataList list, m_dataTable) { | |
285 | QSplineSeries *series = new QSplineSeries(chart); |
|
285 | QSplineSeries *series = new QSplineSeries(chart); | |
286 | foreach (Data data, list) |
|
286 | foreach (Data data, list) | |
287 | series->append(data.first); |
|
287 | series->append(data.first); | |
288 | series->setName(name + QString::number(nameIndex)); |
|
288 | series->setName(name + QString::number(nameIndex)); | |
289 | nameIndex++; |
|
289 | nameIndex++; | |
290 | chart->addSeries(series); |
|
290 | chart->addSeries(series); | |
291 | } |
|
291 | } | |
292 | return chart; |
|
292 | return chart; | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | QChart* ThemeWidget::createScatterChart() const |
|
295 | QChart* ThemeWidget::createScatterChart() const | |
296 | { // scatter chart |
|
296 | { // scatter chart | |
297 | QChart* chart = new QChart(); |
|
297 | QChart* chart = new QChart(); | |
298 | chart->axisX()->setNiceNumbers(true); |
|
298 | chart->axisX()->setNiceNumbers(true); | |
299 | chart->axisY()->setNiceNumbers(true); |
|
299 | chart->axisY()->setNiceNumbers(true); | |
300 | chart->setTitle("Scatter chart"); |
|
300 | chart->setTitle("Scatter chart"); | |
301 | QString name("Series "); |
|
301 | QString name("Series "); | |
302 | int nameIndex = 0; |
|
302 | int nameIndex = 0; | |
303 | foreach (DataList list, m_dataTable) { |
|
303 | foreach (DataList list, m_dataTable) { | |
304 | QScatterSeries *series = new QScatterSeries(chart); |
|
304 | QScatterSeries *series = new QScatterSeries(chart); | |
305 | foreach (Data data, list) |
|
305 | foreach (Data data, list) | |
306 | series->append(data.first); |
|
306 | series->append(data.first); | |
307 | series->setName(name + QString::number(nameIndex)); |
|
307 | series->setName(name + QString::number(nameIndex)); | |
308 | nameIndex++; |
|
308 | nameIndex++; | |
309 | chart->addSeries(series); |
|
309 | chart->addSeries(series); | |
310 | } |
|
310 | } | |
311 | return chart; |
|
311 | return chart; | |
312 | } |
|
312 | } | |
313 |
|
313 | |||
314 | void ThemeWidget::updateUI() |
|
314 | void ThemeWidget::updateUI() | |
315 | { |
|
315 | { | |
316 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
316 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
317 |
|
317 | |||
318 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
318 | if (m_charts.at(0)->chart()->theme() != theme) { | |
319 | foreach (QChartView *chartView, m_charts) |
|
319 | foreach (QChartView *chartView, m_charts) | |
320 | chartView->chart()->setTheme(theme); |
|
320 | chartView->chart()->setTheme(theme); | |
321 |
|
321 | |||
322 | QPalette pal = window()->palette(); |
|
322 | QPalette pal = window()->palette(); | |
323 | if (theme == QChart::ChartThemeLight) { |
|
323 | if (theme == QChart::ChartThemeLight) { | |
324 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
324 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
325 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
325 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
326 | } else if (theme == QChart::ChartThemeDark) { |
|
326 | } else if (theme == QChart::ChartThemeDark) { | |
327 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
327 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
328 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
328 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
329 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
329 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
330 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
330 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
331 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
331 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
332 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
332 | } else if (theme == QChart::ChartThemeBrownSand) { | |
333 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
333 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
334 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
334 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
335 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
335 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
336 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
336 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
337 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
337 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
338 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
338 | } else if (theme == QChart::ChartThemeHighContrast) { | |
339 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
339 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
340 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
340 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
341 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
341 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
342 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
342 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
343 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
343 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
344 | } else { |
|
344 | } else { | |
345 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
345 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
346 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
346 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
347 | } |
|
347 | } | |
348 | window()->setPalette(pal); |
|
348 | window()->setPalette(pal); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | bool checked = m_antialiasCheckBox->isChecked(); |
|
351 | bool checked = m_antialiasCheckBox->isChecked(); | |
352 | foreach (QChartView *chart, m_charts) |
|
352 | foreach (QChartView *chart, m_charts) | |
353 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
353 | chart->setRenderHint(QPainter::Antialiasing, checked); | |
354 |
|
354 | |||
355 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
355 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
356 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
356 | if (m_charts.at(0)->chart()->animationOptions() != options) { | |
357 | foreach (QChartView *chartView, m_charts) |
|
357 | foreach (QChartView *chartView, m_charts) | |
358 | chartView->chart()->setAnimationOptions(options); |
|
358 | chartView->chart()->setAnimationOptions(options); | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
361 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
362 |
|
362 | |||
363 | if (!alignment) { |
|
363 | if (!alignment) { | |
364 | foreach (QChartView *chartView, m_charts) { |
|
364 | foreach (QChartView *chartView, m_charts) { | |
365 | chartView->chart()->legend()->hide(); |
|
365 | chartView->chart()->legend()->hide(); | |
366 | } |
|
366 | } | |
367 | } |
|
367 | } | |
368 | else |
|
368 | else | |
369 | foreach (QChartView *chartView, m_charts) { |
|
369 | foreach (QChartView *chartView, m_charts) { | |
370 |
chartView->chart()->legend()->setAlignm |
|
370 | chartView->chart()->legend()->setAlignment(alignment); | |
371 | chartView->chart()->legend()->show(); |
|
371 | chartView->chart()->legend()->show(); | |
372 | } |
|
372 | } | |
373 | } |
|
373 | } | |
374 |
|
374 |
@@ -1,87 +1,87 | |||||
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 <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QBarSeries> |
|
24 | #include <QBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarCategories categories; |
|
35 | QBarCategories categories; | |
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
37 | //![1] |
|
37 | //![1] | |
38 |
|
38 | |||
39 | //![2] |
|
39 | //![2] | |
40 | QBarSet *set0 = new QBarSet("Jane"); |
|
40 | QBarSet *set0 = new QBarSet("Jane"); | |
41 | QBarSet *set1 = new QBarSet("John"); |
|
41 | QBarSet *set1 = new QBarSet("John"); | |
42 | QBarSet *set2 = new QBarSet("Axel"); |
|
42 | QBarSet *set2 = new QBarSet("Axel"); | |
43 | QBarSet *set3 = new QBarSet("Mary"); |
|
43 | QBarSet *set3 = new QBarSet("Mary"); | |
44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
44 | QBarSet *set4 = new QBarSet("Samantha"); | |
45 |
|
45 | |||
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
51 | //![2] |
|
51 | //![2] | |
52 |
|
52 | |||
53 | //![3] |
|
53 | //![3] | |
54 | QBarSeries* series = new QBarSeries(categories); |
|
54 | QBarSeries* series = new QBarSeries(categories); | |
55 | series->appendBarSet(set0); |
|
55 | series->appendBarSet(set0); | |
56 | series->appendBarSet(set1); |
|
56 | series->appendBarSet(set1); | |
57 | series->appendBarSet(set2); |
|
57 | series->appendBarSet(set2); | |
58 | series->appendBarSet(set3); |
|
58 | series->appendBarSet(set3); | |
59 | series->appendBarSet(set4); |
|
59 | series->appendBarSet(set4); | |
60 | //![3] |
|
60 | //![3] | |
61 |
|
61 | |||
62 | //![4] |
|
62 | //![4] | |
63 | QChart* chart = new QChart(); |
|
63 | QChart* chart = new QChart(); | |
64 | chart->addSeries(series); |
|
64 | chart->addSeries(series); | |
65 | chart->setTitle("Simple barchart example"); |
|
65 | chart->setTitle("Simple barchart example"); | |
66 | //![4] |
|
66 | //![4] | |
67 |
|
67 | |||
68 | //![5] |
|
68 | //![5] | |
69 | chart->legend()->setVisible(true); |
|
69 | chart->legend()->setVisible(true); | |
70 |
chart->legend()->setAlignm |
|
70 | chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
71 | chart->axisY()->setNiceNumbers(true); |
|
71 | chart->axisY()->setNiceNumbers(true); | |
72 | //![5] |
|
72 | //![5] | |
73 |
|
73 | |||
74 | //![6] |
|
74 | //![6] | |
75 | QChartView* chartView = new QChartView(chart); |
|
75 | QChartView* chartView = new QChartView(chart); | |
76 | chartView->setRenderHint(QPainter::Antialiasing); |
|
76 | chartView->setRenderHint(QPainter::Antialiasing); | |
77 | //![6] |
|
77 | //![6] | |
78 |
|
78 | |||
79 | //![7] |
|
79 | //![7] | |
80 | QMainWindow window; |
|
80 | QMainWindow window; | |
81 | window.setCentralWidget(chartView); |
|
81 | window.setCentralWidget(chartView); | |
82 | window.resize(400, 300); |
|
82 | window.resize(400, 300); | |
83 | window.show(); |
|
83 | window.show(); | |
84 | //![7] |
|
84 | //![7] | |
85 |
|
85 | |||
86 | return a.exec(); |
|
86 | return a.exec(); | |
87 | } |
|
87 | } |
@@ -1,87 +1,87 | |||||
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 <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QPercentBarSeries> |
|
24 | #include <QPercentBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarCategories categories; |
|
35 | QBarCategories categories; | |
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
37 | //![1] |
|
37 | //![1] | |
38 |
|
38 | |||
39 | //![2] |
|
39 | //![2] | |
40 | QBarSet *set0 = new QBarSet("Jane"); |
|
40 | QBarSet *set0 = new QBarSet("Jane"); | |
41 | QBarSet *set1 = new QBarSet("John"); |
|
41 | QBarSet *set1 = new QBarSet("John"); | |
42 | QBarSet *set2 = new QBarSet("Axel"); |
|
42 | QBarSet *set2 = new QBarSet("Axel"); | |
43 | QBarSet *set3 = new QBarSet("Mary"); |
|
43 | QBarSet *set3 = new QBarSet("Mary"); | |
44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
44 | QBarSet *set4 = new QBarSet("Samantha"); | |
45 |
|
45 | |||
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
51 | //![2] |
|
51 | //![2] | |
52 |
|
52 | |||
53 | //![3] |
|
53 | //![3] | |
54 | QPercentBarSeries* series = new QPercentBarSeries(categories); |
|
54 | QPercentBarSeries* series = new QPercentBarSeries(categories); | |
55 | series->appendBarSet(set0); |
|
55 | series->appendBarSet(set0); | |
56 | series->appendBarSet(set1); |
|
56 | series->appendBarSet(set1); | |
57 | series->appendBarSet(set2); |
|
57 | series->appendBarSet(set2); | |
58 | series->appendBarSet(set3); |
|
58 | series->appendBarSet(set3); | |
59 | series->appendBarSet(set4); |
|
59 | series->appendBarSet(set4); | |
60 | //![3] |
|
60 | //![3] | |
61 |
|
61 | |||
62 | //![4] |
|
62 | //![4] | |
63 | QChart* chart = new QChart(); |
|
63 | QChart* chart = new QChart(); | |
64 | chart->addSeries(series); |
|
64 | chart->addSeries(series); | |
65 | chart->setTitle("Simple precentbarchart example"); |
|
65 | chart->setTitle("Simple precentbarchart example"); | |
66 | //![4] |
|
66 | //![4] | |
67 |
|
67 | |||
68 | //![5] |
|
68 | //![5] | |
69 | chart->legend()->setVisible(true); |
|
69 | chart->legend()->setVisible(true); | |
70 |
chart->legend()->setAlignm |
|
70 | chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
71 | //![5] |
|
71 | //![5] | |
72 |
|
72 | |||
73 | //![6] |
|
73 | //![6] | |
74 | QChartView* chartView = new QChartView(chart); |
|
74 | QChartView* chartView = new QChartView(chart); | |
75 | chartView->setRenderHint(QPainter::Antialiasing); |
|
75 | chartView->setRenderHint(QPainter::Antialiasing); | |
76 | //![6] |
|
76 | //![6] | |
77 |
|
77 | |||
78 | //![7] |
|
78 | //![7] | |
79 | QMainWindow window; |
|
79 | QMainWindow window; | |
80 | window.setCentralWidget(chartView); |
|
80 | window.setCentralWidget(chartView); | |
81 | window.resize(400, 300); |
|
81 | window.resize(400, 300); | |
82 | window.show(); |
|
82 | window.show(); | |
83 | //![7] |
|
83 | //![7] | |
84 |
|
84 | |||
85 | return a.exec(); |
|
85 | return a.exec(); | |
86 | } |
|
86 | } | |
87 |
|
87 |
@@ -1,77 +1,77 | |||||
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 "drilldownchart.h" |
|
21 | #include "drilldownchart.h" | |
22 | #include "drilldownslice.h" |
|
22 | #include "drilldownslice.h" | |
23 | #include <QtGui/QApplication> |
|
23 | #include <QtGui/QApplication> | |
24 | #include <QMainWindow> |
|
24 | #include <QMainWindow> | |
25 | #include <QTime> |
|
25 | #include <QTime> | |
26 | #include <QChartView> |
|
26 | #include <QChartView> | |
27 | #include <QLegend> |
|
27 | #include <QLegend> | |
28 | #include <QPieSeries> |
|
28 | #include <QPieSeries> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
31 |
|
31 | |||
32 | int main(int argc, char *argv[]) |
|
32 | int main(int argc, char *argv[]) | |
33 | { |
|
33 | { | |
34 | QApplication a(argc, argv); |
|
34 | QApplication a(argc, argv); | |
35 |
|
35 | |||
36 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
36 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
37 |
|
37 | |||
38 | QMainWindow window; |
|
38 | QMainWindow window; | |
39 |
|
39 | |||
40 | DrilldownChart* chart = new DrilldownChart(); |
|
40 | DrilldownChart* chart = new DrilldownChart(); | |
41 | chart->setTheme(QChart::ChartThemeLight); |
|
41 | chart->setTheme(QChart::ChartThemeLight); | |
42 | chart->setAnimationOptions(QChart::AllAnimations); |
|
42 | chart->setAnimationOptions(QChart::AllAnimations); | |
43 | chart->legend()->setVisible(true); |
|
43 | chart->legend()->setVisible(true); | |
44 |
chart->legend()->setAlignm |
|
44 | chart->legend()->setAlignment(QLegend::AlignmentRight); | |
45 |
|
45 | |||
46 | QPieSeries* yearSeries = new QPieSeries(&window); |
|
46 | QPieSeries* yearSeries = new QPieSeries(&window); | |
47 | yearSeries->setName("Sales by year - All"); |
|
47 | yearSeries->setName("Sales by year - All"); | |
48 |
|
48 | |||
49 | QList<QString> months; |
|
49 | QList<QString> months; | |
50 | months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
50 | months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
51 | QList<QString> names; |
|
51 | QList<QString> names; | |
52 | names << "Jane" << "John" << "Axel" << "Mary" << "Susan" << "Bob"; |
|
52 | names << "Jane" << "John" << "Axel" << "Mary" << "Susan" << "Bob"; | |
53 |
|
53 | |||
54 | foreach (QString name, names) { |
|
54 | foreach (QString name, names) { | |
55 | QPieSeries* series = new QPieSeries(&window); |
|
55 | QPieSeries* series = new QPieSeries(&window); | |
56 | series->setName("Sales by month - " + name); |
|
56 | series->setName("Sales by month - " + name); | |
57 |
|
57 | |||
58 | foreach (QString month, months) |
|
58 | foreach (QString month, months) | |
59 | *series << new DrilldownSlice(qrand() % 1000, month, yearSeries); |
|
59 | *series << new DrilldownSlice(qrand() % 1000, month, yearSeries); | |
60 |
|
60 | |||
61 | QObject::connect(series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), chart, SLOT(handleSliceClicked(QPieSlice*))); |
|
61 | QObject::connect(series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), chart, SLOT(handleSliceClicked(QPieSlice*))); | |
62 |
|
62 | |||
63 | *yearSeries << new DrilldownSlice(series->total(), name, series); |
|
63 | *yearSeries << new DrilldownSlice(series->total(), name, series); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), chart, SLOT(handleSliceClicked(QPieSlice*))); |
|
66 | QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), chart, SLOT(handleSliceClicked(QPieSlice*))); | |
67 |
|
67 | |||
68 | chart->changeSeries(yearSeries); |
|
68 | chart->changeSeries(yearSeries); | |
69 |
|
69 | |||
70 | QChartView* chartView = new QChartView(chart); |
|
70 | QChartView* chartView = new QChartView(chart); | |
71 | chartView->setRenderHint(QPainter::Antialiasing); |
|
71 | chartView->setRenderHint(QPainter::Antialiasing); | |
72 | window.setCentralWidget(chartView); |
|
72 | window.setCentralWidget(chartView); | |
73 | window.resize(800, 500); |
|
73 | window.resize(800, 500); | |
74 | window.show(); |
|
74 | window.show(); | |
75 |
|
75 | |||
76 | return a.exec(); |
|
76 | return a.exec(); | |
77 | } |
|
77 | } |
@@ -1,88 +1,88 | |||||
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 <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QStackedBarSeries> |
|
24 | #include <QStackedBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarCategories categories; |
|
35 | QBarCategories categories; | |
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
37 | //![1] |
|
37 | //![1] | |
38 |
|
38 | |||
39 | //![2] |
|
39 | //![2] | |
40 | QBarSet *set0 = new QBarSet("Jane"); |
|
40 | QBarSet *set0 = new QBarSet("Jane"); | |
41 | QBarSet *set1 = new QBarSet("John"); |
|
41 | QBarSet *set1 = new QBarSet("John"); | |
42 | QBarSet *set2 = new QBarSet("Axel"); |
|
42 | QBarSet *set2 = new QBarSet("Axel"); | |
43 | QBarSet *set3 = new QBarSet("Mary"); |
|
43 | QBarSet *set3 = new QBarSet("Mary"); | |
44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
44 | QBarSet *set4 = new QBarSet("Samantha"); | |
45 |
|
45 | |||
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
51 | //![2] |
|
51 | //![2] | |
52 |
|
52 | |||
53 | //![3] |
|
53 | //![3] | |
54 | QStackedBarSeries* series = new QStackedBarSeries(categories); |
|
54 | QStackedBarSeries* series = new QStackedBarSeries(categories); | |
55 | series->appendBarSet(set0); |
|
55 | series->appendBarSet(set0); | |
56 | series->appendBarSet(set1); |
|
56 | series->appendBarSet(set1); | |
57 | series->appendBarSet(set2); |
|
57 | series->appendBarSet(set2); | |
58 | series->appendBarSet(set3); |
|
58 | series->appendBarSet(set3); | |
59 | series->appendBarSet(set4); |
|
59 | series->appendBarSet(set4); | |
60 | //![3] |
|
60 | //![3] | |
61 |
|
61 | |||
62 | //![4] |
|
62 | //![4] | |
63 | QChart* chart = new QChart(); |
|
63 | QChart* chart = new QChart(); | |
64 | chart->addSeries(series); |
|
64 | chart->addSeries(series); | |
65 | chart->setTitle("Simple stackedbarchart example"); |
|
65 | chart->setTitle("Simple stackedbarchart example"); | |
66 | //![4] |
|
66 | //![4] | |
67 |
|
67 | |||
68 | //![5] |
|
68 | //![5] | |
69 | chart->legend()->setVisible(true); |
|
69 | chart->legend()->setVisible(true); | |
70 |
chart->legend()->setAlignm |
|
70 | chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
71 | chart->axisY()->setNiceNumbers(true); |
|
71 | chart->axisY()->setNiceNumbers(true); | |
72 | //![5] |
|
72 | //![5] | |
73 |
|
73 | |||
74 | //![6] |
|
74 | //![6] | |
75 | QChartView* chartView = new QChartView(chart); |
|
75 | QChartView* chartView = new QChartView(chart); | |
76 | chartView->setRenderHint(QPainter::Antialiasing); |
|
76 | chartView->setRenderHint(QPainter::Antialiasing); | |
77 | //![6] |
|
77 | //![6] | |
78 |
|
78 | |||
79 | //![7] |
|
79 | //![7] | |
80 | QMainWindow window; |
|
80 | QMainWindow window; | |
81 | window.setCentralWidget(chartView); |
|
81 | window.setCentralWidget(chartView); | |
82 | window.resize(400, 300); |
|
82 | window.resize(400, 300); | |
83 | window.show(); |
|
83 | window.show(); | |
84 | //![7] |
|
84 | //![7] | |
85 |
|
85 | |||
86 | return a.exec(); |
|
86 | return a.exec(); | |
87 | } |
|
87 | } | |
88 |
|
88 |
@@ -1,113 +1,113 | |||||
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 <QtGui/QApplication> |
|
21 | #include <QtGui/QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QBarSet> |
|
24 | #include <QBarSet> | |
25 | #include <QLegend> |
|
25 | #include <QLegend> | |
26 | #include "drilldownseries.h" |
|
26 | #include "drilldownseries.h" | |
27 | #include "drilldownchart.h" |
|
27 | #include "drilldownchart.h" | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
30 |
|
30 | |||
31 | int main(int argc, char *argv[]) |
|
31 | int main(int argc, char *argv[]) | |
32 | { |
|
32 | { | |
33 | QApplication a(argc, argv); |
|
33 | QApplication a(argc, argv); | |
34 | QMainWindow window; |
|
34 | QMainWindow window; | |
35 |
|
35 | |||
36 | DrilldownChart* drilldownChart = new DrilldownChart(); |
|
36 | DrilldownChart* drilldownChart = new DrilldownChart(); | |
37 | drilldownChart->setTheme(QChart::ChartThemeBlueIcy); |
|
37 | drilldownChart->setTheme(QChart::ChartThemeBlueIcy); | |
38 | drilldownChart->setAnimationOptions(QChart::SeriesAnimations); |
|
38 | drilldownChart->setAnimationOptions(QChart::SeriesAnimations); | |
39 |
|
39 | |||
40 | //! [3] |
|
40 | //! [3] | |
41 | // Define categories |
|
41 | // Define categories | |
42 | QStringList months; |
|
42 | QStringList months; | |
43 | months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; |
|
43 | months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; | |
44 | QStringList weeks; |
|
44 | QStringList weeks; | |
45 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; |
|
45 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; | |
46 | QStringList plants; |
|
46 | QStringList plants; | |
47 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; |
|
47 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; | |
48 | //! [3] |
|
48 | //! [3] | |
49 |
|
49 | |||
50 | //! [4] |
|
50 | //! [4] | |
51 | // Create drilldown structure |
|
51 | // Create drilldown structure | |
52 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); |
|
52 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); | |
53 | seasonSeries->setName("Crop by month - Season"); |
|
53 | seasonSeries->setName("Crop by month - Season"); | |
54 |
|
54 | |||
55 | // Each month in season series has drilldown series for weekly data |
|
55 | // Each month in season series has drilldown series for weekly data | |
56 | foreach (QString month, months) { |
|
56 | foreach (QString month, months) { | |
57 |
|
57 | |||
58 | // Create drilldown series for every week |
|
58 | // Create drilldown series for every week | |
59 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); |
|
59 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); | |
60 | seasonSeries->mapDrilldownSeries(month, weeklySeries); |
|
60 | seasonSeries->mapDrilldownSeries(month, weeklySeries); | |
61 |
|
61 | |||
62 | // Drilling down from weekly data brings us back to season data. |
|
62 | // Drilling down from weekly data brings us back to season data. | |
63 | foreach (QString week, weeks) { |
|
63 | foreach (QString week, weeks) { | |
64 | weeklySeries->mapDrilldownSeries(week, seasonSeries); |
|
64 | weeklySeries->mapDrilldownSeries(week, seasonSeries); | |
65 | weeklySeries->setName(QString("Crop by week - " + month)); |
|
65 | weeklySeries->setName(QString("Crop by week - " + month)); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | // Use right click signal to implement drilldown |
|
68 | // Use right click signal to implement drilldown | |
69 | QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons))); |
|
69 | QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons))); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | // Enable drilldown from season series using right click. |
|
72 | // Enable drilldown from season series using right click. | |
73 | QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons))); |
|
73 | QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons))); | |
74 | //! [4] |
|
74 | //! [4] | |
75 |
|
75 | |||
76 | //! [5] |
|
76 | //! [5] | |
77 | // Fill monthly and weekly series with data |
|
77 | // Fill monthly and weekly series with data | |
78 | foreach (QString plant, plants) { |
|
78 | foreach (QString plant, plants) { | |
79 | QBarSet* monthlyCrop = new QBarSet(plant); |
|
79 | QBarSet* monthlyCrop = new QBarSet(plant); | |
80 | foreach (QString month, months) { |
|
80 | foreach (QString month, months) { | |
81 | QBarSet* weeklyCrop = new QBarSet(plant); |
|
81 | QBarSet* weeklyCrop = new QBarSet(plant); | |
82 | foreach (QString week, weeks ) |
|
82 | foreach (QString week, weeks ) | |
83 | *weeklyCrop << (qrand() % 20); |
|
83 | *weeklyCrop << (qrand() % 20); | |
84 | // Get the drilldown series from season series and add crop to it. |
|
84 | // Get the drilldown series from season series and add crop to it. | |
85 | seasonSeries->drilldownSeries(month)->appendBarSet(weeklyCrop); |
|
85 | seasonSeries->drilldownSeries(month)->appendBarSet(weeklyCrop); | |
86 | seasonSeries->drilldownSeries(month)->setToolTipEnabled(true); |
|
86 | seasonSeries->drilldownSeries(month)->setToolTipEnabled(true); | |
87 | *monthlyCrop << weeklyCrop->total(); |
|
87 | *monthlyCrop << weeklyCrop->total(); | |
88 | } |
|
88 | } | |
89 | seasonSeries->appendBarSet(monthlyCrop); |
|
89 | seasonSeries->appendBarSet(monthlyCrop); | |
90 | } |
|
90 | } | |
91 | //! [5] |
|
91 | //! [5] | |
92 |
|
92 | |||
93 | //! [6] |
|
93 | //! [6] | |
94 | // Show season series in initial view |
|
94 | // Show season series in initial view | |
95 | drilldownChart->changeSeries(seasonSeries); |
|
95 | drilldownChart->changeSeries(seasonSeries); | |
96 | drilldownChart->setTitle(seasonSeries->name()); |
|
96 | drilldownChart->setTitle(seasonSeries->name()); | |
97 | //! [6] |
|
97 | //! [6] | |
98 |
|
98 | |||
99 | //! [7] |
|
99 | //! [7] | |
100 | drilldownChart->axisX()->setGridLineVisible(false); |
|
100 | drilldownChart->axisX()->setGridLineVisible(false); | |
101 | drilldownChart->axisY()->setNiceNumbers(true); |
|
101 | drilldownChart->axisY()->setNiceNumbers(true); | |
102 | drilldownChart->legend()->setVisible(true); |
|
102 | drilldownChart->legend()->setVisible(true); | |
103 |
drilldownChart->legend()->setAlignm |
|
103 | drilldownChart->legend()->setAlignment(QLegend::AlignmentBottom); | |
104 | //! [7] |
|
104 | //! [7] | |
105 |
|
105 | |||
106 | QChartView *chartView = new QChartView(drilldownChart); |
|
106 | QChartView *chartView = new QChartView(drilldownChart); | |
107 | window.setCentralWidget(chartView); |
|
107 | window.setCentralWidget(chartView); | |
108 | window.resize(400, 300); |
|
108 | window.resize(400, 300); | |
109 | window.show(); |
|
109 | window.show(); | |
110 |
|
110 | |||
111 | return a.exec(); |
|
111 | return a.exec(); | |
112 | } |
|
112 | } | |
113 |
|
113 |
@@ -1,533 +1,533 | |||||
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 "qlegend.h" |
|
21 | #include "qlegend.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "qseries.h" |
|
23 | #include "qseries.h" | |
24 | #include "legendmarker_p.h" |
|
24 | #include "legendmarker_p.h" | |
25 | #include "qxyseries.h" |
|
25 | #include "qxyseries.h" | |
26 | #include "qlineseries.h" |
|
26 | #include "qlineseries.h" | |
27 | #include "qareaseries.h" |
|
27 | #include "qareaseries.h" | |
28 | #include "qscatterseries.h" |
|
28 | #include "qscatterseries.h" | |
29 | #include "qsplineseries.h" |
|
29 | #include "qsplineseries.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 "qbarset.h" |
|
33 | #include "qbarset.h" | |
34 | #include "qpieseries.h" |
|
34 | #include "qpieseries.h" | |
35 | #include "qpieslice.h" |
|
35 | #include "qpieslice.h" | |
36 | #include "chartpresenter_p.h" |
|
36 | #include "chartpresenter_p.h" | |
37 | #include <QPainter> |
|
37 | #include <QPainter> | |
38 | #include <QPen> |
|
38 | #include <QPen> | |
39 | #include <QTimer> |
|
39 | #include <QTimer> | |
40 |
|
40 | |||
41 | #include <QGraphicsSceneEvent> |
|
41 | #include <QGraphicsSceneEvent> | |
42 |
|
42 | |||
43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \class QLegend |
|
46 | \class QLegend | |
47 | \brief part of QtCommercial chart API. |
|
47 | \brief part of QtCommercial chart API. | |
48 |
|
48 | |||
49 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
49 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
50 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
50 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
51 | handle the drawing manually. |
|
51 | handle the drawing manually. | |
52 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
52 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
53 |
|
53 | |||
54 | \mainclass |
|
54 | \mainclass | |
55 |
|
55 | |||
56 | \sa QChart, QSeries |
|
56 | \sa QChart, QSeries | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \enum QLegend::Alignment |
|
60 | \enum QLegend::Alignment | |
61 |
|
61 | |||
62 | This enum describes the possible position for legend inside chart. |
|
62 | This enum describes the possible position for legend inside chart. | |
63 |
|
63 | |||
64 | \value AlignmentTop |
|
64 | \value AlignmentTop | |
65 | \value AlignmentBottom |
|
65 | \value AlignmentBottom | |
66 | \value AlignmentLeft |
|
66 | \value AlignmentLeft | |
67 | \value AlignmentRight |
|
67 | \value AlignmentRight | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | \fn qreal QLegend::minWidth() const |
|
71 | \fn qreal QLegend::minWidth() const | |
72 | Returns minimum width of the legend |
|
72 | Returns minimum width of the legend | |
73 | */ |
|
73 | */ | |
74 |
|
74 | |||
75 | /*! |
|
75 | /*! | |
76 | \fn qreal QLegend::minHeight() const |
|
76 | \fn qreal QLegend::minHeight() const | |
77 | Returns minimum height of the legend |
|
77 | Returns minimum height of the legend | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | Constructs the legend object and sets the parent to \a parent |
|
81 | Constructs the legend object and sets the parent to \a parent | |
82 | */ |
|
82 | */ | |
83 |
|
83 | |||
84 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), |
|
84 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), | |
85 | m_margin(5), |
|
85 | m_margin(5), | |
86 | m_offsetX(0), |
|
86 | m_offsetX(0), | |
87 | m_offsetY(0), |
|
87 | m_offsetY(0), | |
88 | m_brush(Qt::darkGray), // TODO: default should come from theme |
|
88 | m_brush(Qt::darkGray), // TODO: default should come from theme | |
89 | m_alignment(QLegend::AlignmentTop), |
|
89 | m_alignment(QLegend::AlignmentTop), | |
90 | m_markers(new QGraphicsItemGroup(this)), |
|
90 | m_markers(new QGraphicsItemGroup(this)), | |
91 | m_attachedToChart(true), |
|
91 | m_attachedToChart(true), | |
92 | m_chart(chart), |
|
92 | m_chart(chart), | |
93 | m_minWidth(0), |
|
93 | m_minWidth(0), | |
94 | m_minHeight(0), |
|
94 | m_minHeight(0), | |
95 | m_width(0), |
|
95 | m_width(0), | |
96 | m_height(0), |
|
96 | m_height(0), | |
97 | m_backgroundVisible(false) |
|
97 | m_backgroundVisible(false) | |
98 | { |
|
98 | { | |
99 | setZValue(ChartPresenter::LegendZValue); |
|
99 | setZValue(ChartPresenter::LegendZValue); | |
100 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
100 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
101 | setVisible(false); // By default legend is invisible |
|
101 | setVisible(false); // By default legend is invisible | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | Paints the legend to given \a painter. Paremeters \a option and \a widget arent used. |
|
105 | Paints the legend to given \a painter. Paremeters \a option and \a widget arent used. | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
108 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
109 | { |
|
109 | { | |
110 | Q_UNUSED(option) |
|
110 | Q_UNUSED(option) | |
111 | Q_UNUSED(widget) |
|
111 | Q_UNUSED(widget) | |
112 | if(!m_backgroundVisible) return; |
|
112 | if(!m_backgroundVisible) return; | |
113 |
|
113 | |||
114 | painter->setOpacity(opacity()); |
|
114 | painter->setOpacity(opacity()); | |
115 | painter->setPen(m_pen); |
|
115 | painter->setPen(m_pen); | |
116 | painter->setBrush(m_brush); |
|
116 | painter->setBrush(m_brush); | |
117 | painter->drawRect(boundingRect()); |
|
117 | painter->drawRect(boundingRect()); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | Bounding rect of legend. |
|
121 | Bounding rect of legend. | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | QRectF QLegend::boundingRect() const |
|
124 | QRectF QLegend::boundingRect() const | |
125 | { |
|
125 | { | |
126 | return m_rect; |
|
126 | return m_rect; | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | Sets the \a brush of legend. Brush affects the background of legend. |
|
130 | Sets the \a brush of legend. Brush affects the background of legend. | |
131 | */ |
|
131 | */ | |
132 | void QLegend::setBrush(const QBrush &brush) |
|
132 | void QLegend::setBrush(const QBrush &brush) | |
133 | { |
|
133 | { | |
134 | if (m_brush != brush) { |
|
134 | if (m_brush != brush) { | |
135 | m_brush = brush; |
|
135 | m_brush = brush; | |
136 | update(); |
|
136 | update(); | |
137 | } |
|
137 | } | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | Returns the brush used by legend. |
|
141 | Returns the brush used by legend. | |
142 | */ |
|
142 | */ | |
143 | QBrush QLegend::brush() const |
|
143 | QBrush QLegend::brush() const | |
144 | { |
|
144 | { | |
145 | return m_brush; |
|
145 | return m_brush; | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | Sets the \a pen of legend. Pen affects the legend borders. |
|
149 | Sets the \a pen of legend. Pen affects the legend borders. | |
150 | */ |
|
150 | */ | |
151 | void QLegend::setPen(const QPen &pen) |
|
151 | void QLegend::setPen(const QPen &pen) | |
152 | { |
|
152 | { | |
153 | if (m_pen != pen) { |
|
153 | if (m_pen != pen) { | |
154 | m_pen = pen; |
|
154 | m_pen = pen; | |
155 | update(); |
|
155 | update(); | |
156 | } |
|
156 | } | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | Returns the pen used by legend |
|
160 | Returns the pen used by legend | |
161 | */ |
|
161 | */ | |
162 |
|
162 | |||
163 | QPen QLegend::pen() const |
|
163 | QPen QLegend::pen() const | |
164 | { |
|
164 | { | |
165 | return m_pen; |
|
165 | return m_pen; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | /*! |
|
168 | /*! | |
169 | Sets the \a alignment for legend. Legend tries to paint itself on the defined position in chart. |
|
169 | Sets the \a alignment for legend. Legend tries to paint itself on the defined position in chart. | |
170 | \sa QLegend::Alignment |
|
170 | \sa QLegend::Alignment | |
171 | */ |
|
171 | */ | |
172 |
void QLegend::setAlignm |
|
172 | void QLegend::setAlignment(QLegend::Alignments alignment) | |
173 | { |
|
173 | { | |
174 | if(m_alignment!=alignment && m_attachedToChart) { |
|
174 | if(m_alignment!=alignment && m_attachedToChart) { | |
175 | m_alignment = alignment; |
|
175 | m_alignment = alignment; | |
176 | updateLayout(); |
|
176 | updateLayout(); | |
177 | } |
|
177 | } | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | Returns the preferred layout for legend |
|
181 | Returns the preferred layout for legend | |
182 | */ |
|
182 | */ | |
183 | QLegend::Alignments QLegend::alignment() const |
|
183 | QLegend::Alignments QLegend::alignment() const | |
184 | { |
|
184 | { | |
185 | return m_alignment; |
|
185 | return m_alignment; | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | \internal \a series \a domain Should be called when series is added to chart. |
|
189 | \internal \a series \a domain Should be called when series is added to chart. | |
190 | */ |
|
190 | */ | |
191 | void QLegend::handleSeriesAdded(QSeries *series, Domain *domain) |
|
191 | void QLegend::handleSeriesAdded(QSeries *series, Domain *domain) | |
192 | { |
|
192 | { | |
193 | Q_UNUSED(domain) |
|
193 | Q_UNUSED(domain) | |
194 |
|
194 | |||
195 | switch (series->type()) |
|
195 | switch (series->type()) | |
196 | { |
|
196 | { | |
197 | case QSeries::SeriesTypeLine: { |
|
197 | case QSeries::SeriesTypeLine: { | |
198 | QLineSeries *lineSeries = static_cast<QLineSeries *>(series); |
|
198 | QLineSeries *lineSeries = static_cast<QLineSeries *>(series); | |
199 | appendMarkers(lineSeries); |
|
199 | appendMarkers(lineSeries); | |
200 | break; |
|
200 | break; | |
201 | } |
|
201 | } | |
202 | case QSeries::SeriesTypeArea: { |
|
202 | case QSeries::SeriesTypeArea: { | |
203 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); |
|
203 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); | |
204 | appendMarkers(areaSeries); |
|
204 | appendMarkers(areaSeries); | |
205 | break; |
|
205 | break; | |
206 | } |
|
206 | } | |
207 | case QSeries::SeriesTypeBar: { |
|
207 | case QSeries::SeriesTypeBar: { | |
208 | QBarSeries *barSeries = static_cast<QBarSeries *>(series); |
|
208 | QBarSeries *barSeries = static_cast<QBarSeries *>(series); | |
209 | appendMarkers(barSeries); |
|
209 | appendMarkers(barSeries); | |
210 | break; |
|
210 | break; | |
211 | } |
|
211 | } | |
212 | case QSeries::SeriesTypeStackedBar: { |
|
212 | case QSeries::SeriesTypeStackedBar: { | |
213 | QStackedBarSeries *stackedBarSeries = static_cast<QStackedBarSeries *>(series); |
|
213 | QStackedBarSeries *stackedBarSeries = static_cast<QStackedBarSeries *>(series); | |
214 | appendMarkers(stackedBarSeries); |
|
214 | appendMarkers(stackedBarSeries); | |
215 | break; |
|
215 | break; | |
216 | } |
|
216 | } | |
217 | case QSeries::SeriesTypePercentBar: { |
|
217 | case QSeries::SeriesTypePercentBar: { | |
218 | QPercentBarSeries *percentBarSeries = static_cast<QPercentBarSeries *>(series); |
|
218 | QPercentBarSeries *percentBarSeries = static_cast<QPercentBarSeries *>(series); | |
219 | appendMarkers(percentBarSeries); |
|
219 | appendMarkers(percentBarSeries); | |
220 | break; |
|
220 | break; | |
221 | } |
|
221 | } | |
222 | case QSeries::SeriesTypeScatter: { |
|
222 | case QSeries::SeriesTypeScatter: { | |
223 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
223 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); | |
224 | appendMarkers(scatterSeries); |
|
224 | appendMarkers(scatterSeries); | |
225 | break; |
|
225 | break; | |
226 | } |
|
226 | } | |
227 | case QSeries::SeriesTypePie: { |
|
227 | case QSeries::SeriesTypePie: { | |
228 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
228 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
229 | appendMarkers(pieSeries); |
|
229 | appendMarkers(pieSeries); | |
230 | connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>))); |
|
230 | connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>))); | |
231 | break; |
|
231 | break; | |
232 | } |
|
232 | } | |
233 | case QSeries::SeriesTypeSpline: { |
|
233 | case QSeries::SeriesTypeSpline: { | |
234 | QSplineSeries *splineSeries = static_cast<QSplineSeries *>(series); |
|
234 | QSplineSeries *splineSeries = static_cast<QSplineSeries *>(series); | |
235 | appendMarkers(splineSeries); |
|
235 | appendMarkers(splineSeries); | |
236 | break; |
|
236 | break; | |
237 | } |
|
237 | } | |
238 | default: { |
|
238 | default: { | |
239 | qWarning()<< "QLegend::handleSeriesAdded" << series->type() << "unknown series type."; |
|
239 | qWarning()<< "QLegend::handleSeriesAdded" << series->type() << "unknown series type."; | |
240 | break; |
|
240 | break; | |
241 | } |
|
241 | } | |
242 | } |
|
242 | } | |
243 |
|
243 | |||
244 | updateLayout(); |
|
244 | updateLayout(); | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | /*! |
|
247 | /*! | |
248 | \internal \a series Should be called when series is removed from chart. |
|
248 | \internal \a series Should be called when series is removed from chart. | |
249 | */ |
|
249 | */ | |
250 | void QLegend::handleSeriesRemoved(QSeries *series) |
|
250 | void QLegend::handleSeriesRemoved(QSeries *series) | |
251 | { |
|
251 | { | |
252 | switch (series->type()) |
|
252 | switch (series->type()) | |
253 | { |
|
253 | { | |
254 | case QSeries::SeriesTypeArea: { |
|
254 | case QSeries::SeriesTypeArea: { | |
255 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); |
|
255 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); | |
256 | deleteMarkers(areaSeries); |
|
256 | deleteMarkers(areaSeries); | |
257 | break; |
|
257 | break; | |
258 | } |
|
258 | } | |
259 | case QSeries::SeriesTypePie: { |
|
259 | case QSeries::SeriesTypePie: { | |
260 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
260 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
261 | disconnect(pieSeries, SIGNAL(added(QList<QPieSlice *>)), this, SLOT(handleAdded(QList<QPieSlice *>))); |
|
261 | disconnect(pieSeries, SIGNAL(added(QList<QPieSlice *>)), this, SLOT(handleAdded(QList<QPieSlice *>))); | |
262 | deleteMarkers(series); |
|
262 | deleteMarkers(series); | |
263 | break; |
|
263 | break; | |
264 | } |
|
264 | } | |
265 | default: { |
|
265 | default: { | |
266 | // All other types |
|
266 | // All other types | |
267 | deleteMarkers(series); |
|
267 | deleteMarkers(series); | |
268 | break; |
|
268 | break; | |
269 | } |
|
269 | } | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | updateLayout(); |
|
272 | updateLayout(); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | \internal \a slices Should be called when slices are added to pie chart. |
|
276 | \internal \a slices Should be called when slices are added to pie chart. | |
277 | */ |
|
277 | */ | |
278 | void QLegend::handleAdded(QList<QPieSlice *> slices) |
|
278 | void QLegend::handleAdded(QList<QPieSlice *> slices) | |
279 | { |
|
279 | { | |
280 | QPieSeries* series = static_cast<QPieSeries *> (sender()); |
|
280 | QPieSeries* series = static_cast<QPieSeries *> (sender()); | |
281 | foreach(QPieSlice* slice, slices) { |
|
281 | foreach(QPieSlice* slice, slices) { | |
282 | PieLegendMarker* marker = new PieLegendMarker(series,slice, this); |
|
282 | PieLegendMarker* marker = new PieLegendMarker(series,slice, this); | |
283 | m_markers->addToGroup(marker); |
|
283 | m_markers->addToGroup(marker); | |
284 | } |
|
284 | } | |
285 | updateLayout(); |
|
285 | updateLayout(); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | /*! |
|
288 | /*! | |
289 | \internal \a slices Should be called when slices are removed from pie chart. Currently unused, |
|
289 | \internal \a slices Should be called when slices are removed from pie chart. Currently unused, | |
290 | because removed slices are also deleted and we listen destroyed signal |
|
290 | because removed slices are also deleted and we listen destroyed signal | |
291 | */ |
|
291 | */ | |
292 | void QLegend::handleRemoved(QList<QPieSlice *> slices) |
|
292 | void QLegend::handleRemoved(QList<QPieSlice *> slices) | |
293 | { |
|
293 | { | |
294 | Q_UNUSED(slices) |
|
294 | Q_UNUSED(slices) | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | /*! |
|
297 | /*! | |
298 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
298 | Detaches the legend from chart. Chart won't change layout of the legend. | |
299 | */ |
|
299 | */ | |
300 | void QLegend::detachFromChart() |
|
300 | void QLegend::detachFromChart() | |
301 | { |
|
301 | { | |
302 | m_attachedToChart = false; |
|
302 | m_attachedToChart = false; | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | /*! |
|
305 | /*! | |
306 | Attaches the legend to chart. Chart may change layout of the legend. |
|
306 | Attaches the legend to chart. Chart may change layout of the legend. | |
307 | */ |
|
307 | */ | |
308 | void QLegend::attachToChart() |
|
308 | void QLegend::attachToChart() | |
309 | { |
|
309 | { | |
310 | m_attachedToChart = true; |
|
310 | m_attachedToChart = true; | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | /*! |
|
313 | /*! | |
314 | Returns true, if legend is attached to chart. |
|
314 | Returns true, if legend is attached to chart. | |
315 | */ |
|
315 | */ | |
316 | bool QLegend::isAttachedToChart() |
|
316 | bool QLegend::isAttachedToChart() | |
317 | { |
|
317 | { | |
318 | return m_attachedToChart; |
|
318 | return m_attachedToChart; | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | /*! |
|
321 | /*! | |
322 | \internal Helper function. Appends markers from \a series to legend. |
|
322 | \internal Helper function. Appends markers from \a series to legend. | |
323 | */ |
|
323 | */ | |
324 | void QLegend::appendMarkers(QAreaSeries* series) |
|
324 | void QLegend::appendMarkers(QAreaSeries* series) | |
325 | { |
|
325 | { | |
326 | AreaLegendMarker* marker = new AreaLegendMarker(series,this); |
|
326 | AreaLegendMarker* marker = new AreaLegendMarker(series,this); | |
327 | m_markers->addToGroup(marker); |
|
327 | m_markers->addToGroup(marker); | |
328 | } |
|
328 | } | |
329 |
|
329 | |||
330 | /*! |
|
330 | /*! | |
331 | \internal Helper function. Appends markers from \a series to legend. |
|
331 | \internal Helper function. Appends markers from \a series to legend. | |
332 | */ |
|
332 | */ | |
333 | void QLegend::appendMarkers(QXYSeries* series) |
|
333 | void QLegend::appendMarkers(QXYSeries* series) | |
334 | { |
|
334 | { | |
335 | XYLegendMarker* marker = new XYLegendMarker(series,this); |
|
335 | XYLegendMarker* marker = new XYLegendMarker(series,this); | |
336 | m_markers->addToGroup(marker); |
|
336 | m_markers->addToGroup(marker); | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | /*! |
|
339 | /*! | |
340 | \internal Helper function. Appends markers from \a series to legend. |
|
340 | \internal Helper function. Appends markers from \a series to legend. | |
341 | */ |
|
341 | */ | |
342 | void QLegend::appendMarkers(QBarSeries *series) |
|
342 | void QLegend::appendMarkers(QBarSeries *series) | |
343 | { |
|
343 | { | |
344 | foreach(QBarSet* set, series->barSets()) { |
|
344 | foreach(QBarSet* set, series->barSets()) { | |
345 | BarLegendMarker* marker = new BarLegendMarker(series,set, this); |
|
345 | BarLegendMarker* marker = new BarLegendMarker(series,set, this); | |
346 | m_markers->addToGroup(marker); |
|
346 | m_markers->addToGroup(marker); | |
347 | } |
|
347 | } | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | /*! |
|
350 | /*! | |
351 | \internal Helper function. Appends markers from \a series to legend. |
|
351 | \internal Helper function. Appends markers from \a series to legend. | |
352 | */ |
|
352 | */ | |
353 | void QLegend::appendMarkers(QPieSeries *series) |
|
353 | void QLegend::appendMarkers(QPieSeries *series) | |
354 | { |
|
354 | { | |
355 | foreach(QPieSlice* slice, series->slices()) { |
|
355 | foreach(QPieSlice* slice, series->slices()) { | |
356 | PieLegendMarker* marker = new PieLegendMarker(series,slice, this); |
|
356 | PieLegendMarker* marker = new PieLegendMarker(series,slice, this); | |
357 | m_markers->addToGroup(marker); |
|
357 | m_markers->addToGroup(marker); | |
358 | } |
|
358 | } | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | /*! |
|
361 | /*! | |
362 | \internal Deletes all markers that are created from \a series |
|
362 | \internal Deletes all markers that are created from \a series | |
363 | */ |
|
363 | */ | |
364 | void QLegend::deleteMarkers(QSeries *series) |
|
364 | void QLegend::deleteMarkers(QSeries *series) | |
365 | { |
|
365 | { | |
366 | // Search all markers that belong to given series and delete them. |
|
366 | // Search all markers that belong to given series and delete them. | |
367 |
|
367 | |||
368 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
368 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
369 |
|
369 | |||
370 | foreach (QGraphicsItem *markers, items) { |
|
370 | foreach (QGraphicsItem *markers, items) { | |
371 | LegendMarker *marker = static_cast<LegendMarker*>(markers); |
|
371 | LegendMarker *marker = static_cast<LegendMarker*>(markers); | |
372 | if (marker->series() == series) { |
|
372 | if (marker->series() == series) { | |
373 | delete marker; |
|
373 | delete marker; | |
374 | } |
|
374 | } | |
375 | } |
|
375 | } | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | /*! |
|
378 | /*! | |
379 | \internal Updates layout of legend. Tries to fit as many markers as possible up to the maximum size of legend. |
|
379 | \internal Updates layout of legend. Tries to fit as many markers as possible up to the maximum size of legend. | |
380 | If items don't fit, sets the visibility of scroll buttons accordingly. |
|
380 | If items don't fit, sets the visibility of scroll buttons accordingly. | |
381 | Causes legend to be resized. |
|
381 | Causes legend to be resized. | |
382 | */ |
|
382 | */ | |
383 |
|
383 | |||
384 | void QLegend::setOffset(const QPointF& point) |
|
384 | void QLegend::setOffset(const QPointF& point) | |
385 | { |
|
385 | { | |
386 |
|
386 | |||
387 | switch(m_alignment) { |
|
387 | switch(m_alignment) { | |
388 |
|
388 | |||
389 | case AlignmentTop: |
|
389 | case AlignmentTop: | |
390 | case AlignmentBottom: { |
|
390 | case AlignmentBottom: { | |
391 | if(m_width<=m_rect.width()) return; |
|
391 | if(m_width<=m_rect.width()) return; | |
392 |
|
392 | |||
393 | if (point.x() != m_offsetX) { |
|
393 | if (point.x() != m_offsetX) { | |
394 | m_offsetX = qBound(0.0, point.x(), m_width - m_rect.width()); |
|
394 | m_offsetX = qBound(0.0, point.x(), m_width - m_rect.width()); | |
395 | m_markers->setPos(-m_offsetX,m_rect.top()); |
|
395 | m_markers->setPos(-m_offsetX,m_rect.top()); | |
396 | } |
|
396 | } | |
397 | break; |
|
397 | break; | |
398 | } |
|
398 | } | |
399 | case AlignmentLeft: |
|
399 | case AlignmentLeft: | |
400 | case AlignmentRight: { |
|
400 | case AlignmentRight: { | |
401 |
|
401 | |||
402 | if(m_height<=m_rect.height()) return; |
|
402 | if(m_height<=m_rect.height()) return; | |
403 |
|
403 | |||
404 | if (point.y() != m_offsetY) { |
|
404 | if (point.y() != m_offsetY) { | |
405 | m_offsetY = qBound(0.0, point.y(), m_height - m_rect.height()); |
|
405 | m_offsetY = qBound(0.0, point.y(), m_height - m_rect.height()); | |
406 | m_markers->setPos(m_rect.left(),-m_offsetY); |
|
406 | m_markers->setPos(m_rect.left(),-m_offsetY); | |
407 | } |
|
407 | } | |
408 | break; |
|
408 | break; | |
409 | } |
|
409 | } | |
410 | } |
|
410 | } | |
411 | } |
|
411 | } | |
412 |
|
412 | |||
413 | QPointF QLegend::offset() const |
|
413 | QPointF QLegend::offset() const | |
414 | { |
|
414 | { | |
415 | return QPointF(m_offsetX,m_offsetY); |
|
415 | return QPointF(m_offsetX,m_offsetY); | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | // this function runs first to set min max values |
|
418 | // this function runs first to set min max values | |
419 | void QLegend::updateLayout() |
|
419 | void QLegend::updateLayout() | |
420 | { |
|
420 | { | |
421 | m_offsetX=0; |
|
421 | m_offsetX=0; | |
422 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
422 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
423 |
|
423 | |||
424 | if(items.isEmpty()) return; |
|
424 | if(items.isEmpty()) return; | |
425 |
|
425 | |||
426 | m_minWidth=0; |
|
426 | m_minWidth=0; | |
427 | m_minHeight=0; |
|
427 | m_minHeight=0; | |
428 |
|
428 | |||
429 | switch(m_alignment) { |
|
429 | switch(m_alignment) { | |
430 |
|
430 | |||
431 | case AlignmentTop: |
|
431 | case AlignmentTop: | |
432 | case AlignmentBottom: { |
|
432 | case AlignmentBottom: { | |
433 | QPointF point = m_rect.topLeft(); |
|
433 | QPointF point = m_rect.topLeft(); | |
434 | m_width = 0; |
|
434 | m_width = 0; | |
435 | foreach (QGraphicsItem *item, items) { |
|
435 | foreach (QGraphicsItem *item, items) { | |
436 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); |
|
436 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); | |
437 | const QRectF& rect = item->boundingRect(); |
|
437 | const QRectF& rect = item->boundingRect(); | |
438 | qreal w = rect.width(); |
|
438 | qreal w = rect.width(); | |
439 | m_minWidth=qMax(m_minWidth,w); |
|
439 | m_minWidth=qMax(m_minWidth,w); | |
440 | m_minHeight=qMax(m_minHeight,rect.height()); |
|
440 | m_minHeight=qMax(m_minHeight,rect.height()); | |
441 | m_width+=w; |
|
441 | m_width+=w; | |
442 | point.setX(point.x() + w); |
|
442 | point.setX(point.x() + w); | |
443 | } |
|
443 | } | |
444 | if(m_width<m_rect.width()){ |
|
444 | if(m_width<m_rect.width()){ | |
445 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); |
|
445 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); | |
446 | }else{ |
|
446 | }else{ | |
447 | m_markers->setPos(m_rect.topLeft()); |
|
447 | m_markers->setPos(m_rect.topLeft()); | |
448 | } |
|
448 | } | |
449 | m_height=m_minHeight; |
|
449 | m_height=m_minHeight; | |
450 | } |
|
450 | } | |
451 | break; |
|
451 | break; | |
452 | case AlignmentLeft: |
|
452 | case AlignmentLeft: | |
453 | case AlignmentRight:{ |
|
453 | case AlignmentRight:{ | |
454 | QPointF point = m_rect.topLeft(); |
|
454 | QPointF point = m_rect.topLeft(); | |
455 | m_height = 0; |
|
455 | m_height = 0; | |
456 | foreach (QGraphicsItem *item, items) { |
|
456 | foreach (QGraphicsItem *item, items) { | |
457 | item->setPos(point); |
|
457 | item->setPos(point); | |
458 | const QRectF& rect = item->boundingRect(); |
|
458 | const QRectF& rect = item->boundingRect(); | |
459 | qreal h = rect.height(); |
|
459 | qreal h = rect.height(); | |
460 | m_minWidth=qMax(m_minWidth,rect.width()); |
|
460 | m_minWidth=qMax(m_minWidth,rect.width()); | |
461 | m_minHeight=qMax(m_minHeight,h); |
|
461 | m_minHeight=qMax(m_minHeight,h); | |
462 | m_height+=h; |
|
462 | m_height+=h; | |
463 | point.setY(point.y() + h); |
|
463 | point.setY(point.y() + h); | |
464 | } |
|
464 | } | |
465 | if(m_height<m_rect.height()){ |
|
465 | if(m_height<m_rect.height()){ | |
466 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); |
|
466 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); | |
467 | }else{ |
|
467 | }else{ | |
468 | m_markers->setPos(m_rect.topLeft()); |
|
468 | m_markers->setPos(m_rect.topLeft()); | |
469 | } |
|
469 | } | |
470 | m_width=m_minWidth; |
|
470 | m_width=m_minWidth; | |
471 | } |
|
471 | } | |
472 | break; |
|
472 | break; | |
473 | } |
|
473 | } | |
474 |
|
474 | |||
475 | m_chart->d_ptr->m_presenter->updateLayout(); //TODO fixme; |
|
475 | m_chart->d_ptr->m_presenter->updateLayout(); //TODO fixme; | |
476 | } |
|
476 | } | |
477 |
|
477 | |||
478 | /*! |
|
478 | /*! | |
479 | Sets the visibility of legend background to \a visible |
|
479 | Sets the visibility of legend background to \a visible | |
480 | */ |
|
480 | */ | |
481 | void QLegend::setBackgroundVisible(bool visible) |
|
481 | void QLegend::setBackgroundVisible(bool visible) | |
482 | { |
|
482 | { | |
483 | if(m_backgroundVisible!=visible) |
|
483 | if(m_backgroundVisible!=visible) | |
484 | { |
|
484 | { | |
485 | m_backgroundVisible=visible; |
|
485 | m_backgroundVisible=visible; | |
486 | update(); |
|
486 | update(); | |
487 | } |
|
487 | } | |
488 | } |
|
488 | } | |
489 |
|
489 | |||
490 | /*! |
|
490 | /*! | |
491 | Returns the visibility of legend background |
|
491 | Returns the visibility of legend background | |
492 | */ |
|
492 | */ | |
493 | bool QLegend::isBackgroundVisible() const |
|
493 | bool QLegend::isBackgroundVisible() const | |
494 | { |
|
494 | { | |
495 | return m_backgroundVisible; |
|
495 | return m_backgroundVisible; | |
496 | } |
|
496 | } | |
497 |
|
497 | |||
498 | /*! |
|
498 | /*! | |
499 | \internal \a event see QGraphicsWidget for details |
|
499 | \internal \a event see QGraphicsWidget for details | |
500 | */ |
|
500 | */ | |
501 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
501 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) | |
502 | { |
|
502 | { | |
503 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); |
|
503 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); | |
504 | QGraphicsWidget::resizeEvent(event); |
|
504 | QGraphicsWidget::resizeEvent(event); | |
505 | if(m_rect != rect){ |
|
505 | if(m_rect != rect){ | |
506 | m_rect = rect; |
|
506 | m_rect = rect; | |
507 | updateLayout(); |
|
507 | updateLayout(); | |
508 | } |
|
508 | } | |
509 | } |
|
509 | } | |
510 |
|
510 | |||
511 | /*! |
|
511 | /*! | |
512 | \internal \a event see QGraphicsWidget for details |
|
512 | \internal \a event see QGraphicsWidget for details | |
513 | */ |
|
513 | */ | |
514 | void QLegend::hideEvent(QHideEvent *event) |
|
514 | void QLegend::hideEvent(QHideEvent *event) | |
515 | { |
|
515 | { | |
516 | QGraphicsWidget::hideEvent(event); |
|
516 | QGraphicsWidget::hideEvent(event); | |
517 | setEnabled(false); |
|
517 | setEnabled(false); | |
518 | updateLayout(); |
|
518 | updateLayout(); | |
519 | } |
|
519 | } | |
520 |
|
520 | |||
521 | /*! |
|
521 | /*! | |
522 | \internal \a event see QGraphicsWidget for details |
|
522 | \internal \a event see QGraphicsWidget for details | |
523 | */ |
|
523 | */ | |
524 | void QLegend::showEvent(QShowEvent *event) |
|
524 | void QLegend::showEvent(QShowEvent *event) | |
525 | { |
|
525 | { | |
526 | QGraphicsWidget::showEvent(event); |
|
526 | QGraphicsWidget::showEvent(event); | |
527 | setEnabled(true); |
|
527 | setEnabled(true); | |
528 | updateLayout(); |
|
528 | updateLayout(); | |
529 | } |
|
529 | } | |
530 |
|
530 | |||
531 | #include "moc_qlegend.cpp" |
|
531 | #include "moc_qlegend.cpp" | |
532 |
|
532 | |||
533 | QTCOMMERCIALCHART_END_NAMESPACE |
|
533 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,170 +1,170 | |||||
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 QLEGEND_H |
|
21 | #ifndef QLEGEND_H | |
22 | #define QLEGEND_H |
|
22 | #define QLEGEND_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 | #include "private/scroller_p.h" //TODO fixme |
|
28 | #include "private/scroller_p.h" //TODO fixme | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | class Domain; |
|
32 | class Domain; | |
33 | class LegendMarker; |
|
33 | class LegendMarker; | |
34 | class QPieSlice; |
|
34 | class QPieSlice; | |
35 | class QXYSeries; |
|
35 | class QXYSeries; | |
36 | class QBarSet; |
|
36 | class QBarSet; | |
37 | class QBarSeries; |
|
37 | class QBarSeries; | |
38 | class QPieSeries; |
|
38 | class QPieSeries; | |
39 | class QAreaSeries; |
|
39 | class QAreaSeries; | |
40 | class LegendScrollButton; |
|
40 | class LegendScrollButton; | |
41 | class QSeries; |
|
41 | class QSeries; | |
42 | class QChart; |
|
42 | class QChart; | |
43 |
|
43 | |||
44 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget |
|
44 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | public: |
|
47 | public: | |
48 |
|
48 | |||
49 | // We only support these alignments (for now) |
|
49 | // We only support these alignments (for now) | |
50 | enum Alignment { |
|
50 | enum Alignment { | |
51 | AlignmentTop = Qt::AlignTop, |
|
51 | AlignmentTop = Qt::AlignTop, | |
52 | AlignmentBottom = Qt::AlignBottom, |
|
52 | AlignmentBottom = Qt::AlignBottom, | |
53 | AlignmentLeft = Qt::AlignLeft, |
|
53 | AlignmentLeft = Qt::AlignLeft, | |
54 | AlignmentRight = Qt::AlignRight |
|
54 | AlignmentRight = Qt::AlignRight | |
55 | }; |
|
55 | }; | |
56 |
|
56 | |||
57 | Q_DECLARE_FLAGS(Alignments, Alignment) |
|
57 | Q_DECLARE_FLAGS(Alignments, Alignment) | |
58 |
|
58 | |||
59 | private: |
|
59 | private: | |
60 | explicit QLegend(QChart *chart); |
|
60 | explicit QLegend(QChart *chart); | |
61 |
|
61 | |||
62 | public: |
|
62 | public: | |
63 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
63 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
64 | QRectF boundingRect() const; |
|
64 | QRectF boundingRect() const; | |
65 |
|
65 | |||
66 | void setBrush(const QBrush &brush); |
|
66 | void setBrush(const QBrush &brush); | |
67 | QBrush brush() const; |
|
67 | QBrush brush() const; | |
68 |
|
68 | |||
69 | void setPen(const QPen &pen); |
|
69 | void setPen(const QPen &pen); | |
70 | QPen pen() const; |
|
70 | QPen pen() const; | |
71 |
|
71 | |||
72 |
void setAlignm |
|
72 | void setAlignment(QLegend::Alignments alignment); | |
73 | QLegend::Alignments alignment() const; |
|
73 | QLegend::Alignments alignment() const; | |
74 |
|
74 | |||
75 | void detachFromChart(); |
|
75 | void detachFromChart(); | |
76 | void attachToChart(); |
|
76 | void attachToChart(); | |
77 | bool isAttachedToChart(); |
|
77 | bool isAttachedToChart(); | |
78 |
|
78 | |||
79 | qreal minWidth() const { return m_minWidth;} |
|
79 | qreal minWidth() const { return m_minWidth;} | |
80 | qreal minHeight() const { return m_minHeight;} |
|
80 | qreal minHeight() const { return m_minHeight;} | |
81 |
|
81 | |||
82 | void setBackgroundVisible(bool visible = true); |
|
82 | void setBackgroundVisible(bool visible = true); | |
83 | bool isBackgroundVisible() const; |
|
83 | bool isBackgroundVisible() const; | |
84 |
|
84 | |||
85 | void setOffset(const QPointF& point); |
|
85 | void setOffset(const QPointF& point); | |
86 | QPointF offset() const; |
|
86 | QPointF offset() const; | |
87 |
|
87 | |||
88 | protected: |
|
88 | protected: | |
89 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
89 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
90 | void hideEvent(QHideEvent *event); |
|
90 | void hideEvent(QHideEvent *event); | |
91 | void showEvent(QShowEvent *event); |
|
91 | void showEvent(QShowEvent *event); | |
92 |
|
92 | |||
93 | public Q_SLOTS: |
|
93 | public Q_SLOTS: | |
94 | // PIMPL ---> |
|
94 | // PIMPL ---> | |
95 | void handleSeriesAdded(QSeries *series, Domain *domain); |
|
95 | void handleSeriesAdded(QSeries *series, Domain *domain); | |
96 | void handleSeriesRemoved(QSeries *series); |
|
96 | void handleSeriesRemoved(QSeries *series); | |
97 | void handleAdded(QList<QPieSlice *> slices); |
|
97 | void handleAdded(QList<QPieSlice *> slices); | |
98 | void handleRemoved(QList<QPieSlice *> slices); |
|
98 | void handleRemoved(QList<QPieSlice *> slices); | |
99 | // PIMPL <--- |
|
99 | // PIMPL <--- | |
100 |
|
100 | |||
101 | private: |
|
101 | private: | |
102 | // PIMPL ---> |
|
102 | // PIMPL ---> | |
103 | void appendMarkers(QAreaSeries *series); |
|
103 | void appendMarkers(QAreaSeries *series); | |
104 | void appendMarkers(QXYSeries *series); |
|
104 | void appendMarkers(QXYSeries *series); | |
105 | void appendMarkers(QBarSeries *series); |
|
105 | void appendMarkers(QBarSeries *series); | |
106 | void appendMarkers(QPieSeries *series); |
|
106 | void appendMarkers(QPieSeries *series); | |
107 | void deleteMarkers(QSeries *series); |
|
107 | void deleteMarkers(QSeries *series); | |
108 | void updateLayout(); |
|
108 | void updateLayout(); | |
109 |
|
109 | |||
110 | private: |
|
110 | private: | |
111 | qreal m_margin; |
|
111 | qreal m_margin; | |
112 |
|
112 | |||
113 | QRectF m_rect; |
|
113 | QRectF m_rect; | |
114 | qreal m_offsetX; |
|
114 | qreal m_offsetX; | |
115 | qreal m_offsetY; |
|
115 | qreal m_offsetY; | |
116 |
|
116 | |||
117 | //QList<LegendMarker *> m_markers; |
|
117 | //QList<LegendMarker *> m_markers; | |
118 |
|
118 | |||
119 | QBrush m_brush; |
|
119 | QBrush m_brush; | |
120 | QPen m_pen; |
|
120 | QPen m_pen; | |
121 | QLegend::Alignments m_alignment; |
|
121 | QLegend::Alignments m_alignment; | |
122 | QGraphicsItemGroup* m_markers; |
|
122 | QGraphicsItemGroup* m_markers; | |
123 |
|
123 | |||
124 |
|
124 | |||
125 | bool m_attachedToChart; |
|
125 | bool m_attachedToChart; | |
126 |
|
126 | |||
127 | QChart *m_chart; |
|
127 | QChart *m_chart; | |
128 | qreal m_minWidth; |
|
128 | qreal m_minWidth; | |
129 | qreal m_minHeight; |
|
129 | qreal m_minHeight; | |
130 | qreal m_width; |
|
130 | qreal m_width; | |
131 | qreal m_height; |
|
131 | qreal m_height; | |
132 | bool m_backgroundVisible; |
|
132 | bool m_backgroundVisible; | |
133 | friend class ScrolledQLegend; |
|
133 | friend class ScrolledQLegend; | |
134 | // <--- PIMPL |
|
134 | // <--- PIMPL | |
135 | }; |
|
135 | }; | |
136 |
|
136 | |||
137 | class ScrolledQLegend: public QLegend, public Scroller |
|
137 | class ScrolledQLegend: public QLegend, public Scroller | |
138 | { |
|
138 | { | |
139 |
|
139 | |||
140 | public: |
|
140 | public: | |
141 | ScrolledQLegend(QChart *chart):QLegend(chart) |
|
141 | ScrolledQLegend(QChart *chart):QLegend(chart) | |
142 | { |
|
142 | { | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | void setOffset(const QPointF& point) |
|
145 | void setOffset(const QPointF& point) | |
146 | { |
|
146 | { | |
147 | QLegend::setOffset(point); |
|
147 | QLegend::setOffset(point); | |
148 | } |
|
148 | } | |
149 | QPointF offset() const |
|
149 | QPointF offset() const | |
150 | { |
|
150 | { | |
151 | return QLegend::offset(); |
|
151 | return QLegend::offset(); | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | void mousePressEvent(QGraphicsSceneMouseEvent* event){ |
|
154 | void mousePressEvent(QGraphicsSceneMouseEvent* event){ | |
155 | Scroller::mousePressEvent(event); |
|
155 | Scroller::mousePressEvent(event); | |
156 | //QLegend::mousePressEvent(event); |
|
156 | //QLegend::mousePressEvent(event); | |
157 | } |
|
157 | } | |
158 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event){ |
|
158 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event){ | |
159 | Scroller::mouseMoveEvent(event); |
|
159 | Scroller::mouseMoveEvent(event); | |
160 | //QLegend::mouseMoveEvent(event); |
|
160 | //QLegend::mouseMoveEvent(event); | |
161 | } |
|
161 | } | |
162 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event){ |
|
162 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event){ | |
163 | Scroller::mouseReleaseEvent(event); |
|
163 | Scroller::mouseReleaseEvent(event); | |
164 | //QLegend::mouseReleaseEvent(event); |
|
164 | //QLegend::mouseReleaseEvent(event); | |
165 | } |
|
165 | } | |
166 | }; |
|
166 | }; | |
167 |
|
167 | |||
168 | QTCOMMERCIALCHART_END_NAMESPACE |
|
168 | QTCOMMERCIALCHART_END_NAMESPACE | |
169 |
|
169 | |||
170 | #endif // QLEGEND_H |
|
170 | #endif // QLEGEND_H |
General Comments 0
You need to be logged in to leave comments.
Login now