@@ -1,379 +1,379 | |||||
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 <QAbstractBarSeries> |
|
26 | #include <QAbstractBarSeries> | |
27 | #include <QPercentBarSeries> |
|
27 | #include <QPercentBarSeries> | |
28 | #include <QStackedBarSeries> |
|
28 | #include <QStackedBarSeries> | |
29 | #include <QBarSeries> |
|
29 | #include <QBarSeries> | |
30 | #include <QBarSet> |
|
30 | #include <QBarSet> | |
31 | #include <QLineSeries> |
|
31 | #include <QLineSeries> | |
32 | #include <QSplineSeries> |
|
32 | #include <QSplineSeries> | |
33 | #include <QScatterSeries> |
|
33 | #include <QScatterSeries> | |
34 | #include <QAreaSeries> |
|
34 | #include <QAreaSeries> | |
35 | #include <QLegend> |
|
35 | #include <QLegend> | |
36 | #include <QGridLayout> |
|
36 | #include <QGridLayout> | |
37 | #include <QFormLayout> |
|
37 | #include <QFormLayout> | |
38 | #include <QComboBox> |
|
38 | #include <QComboBox> | |
39 | #include <QSpinBox> |
|
39 | #include <QSpinBox> | |
40 | #include <QCheckBox> |
|
40 | #include <QCheckBox> | |
41 | #include <QGroupBox> |
|
41 | #include <QGroupBox> | |
42 | #include <QLabel> |
|
42 | #include <QLabel> | |
43 | #include <QTime> |
|
43 | #include <QTime> | |
44 |
#include <QBarCategor |
|
44 | #include <QBarCategoryAxis> | |
45 |
|
45 | |||
46 | ThemeWidget::ThemeWidget(QWidget* parent) : |
|
46 | ThemeWidget::ThemeWidget(QWidget* parent) : | |
47 | QWidget(parent), |
|
47 | QWidget(parent), | |
48 | m_listCount(3), |
|
48 | m_listCount(3), | |
49 | m_valueMax(10), |
|
49 | m_valueMax(10), | |
50 | m_valueCount(7), |
|
50 | m_valueCount(7), | |
51 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
51 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), | |
52 | m_themeComboBox(createThemeBox()), |
|
52 | m_themeComboBox(createThemeBox()), | |
53 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), |
|
53 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), | |
54 | m_animatedComboBox(createAnimationBox()), |
|
54 | m_animatedComboBox(createAnimationBox()), | |
55 | m_legendComboBox(createLegendBox()) |
|
55 | m_legendComboBox(createLegendBox()) | |
56 | { |
|
56 | { | |
57 | connectSignals(); |
|
57 | connectSignals(); | |
58 | // create layout |
|
58 | // create layout | |
59 | QGridLayout* baseLayout = new QGridLayout(); |
|
59 | QGridLayout* baseLayout = new QGridLayout(); | |
60 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
60 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
61 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
61 | settingsLayout->addWidget(new QLabel("Theme:")); | |
62 | settingsLayout->addWidget(m_themeComboBox); |
|
62 | settingsLayout->addWidget(m_themeComboBox); | |
63 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
63 | settingsLayout->addWidget(new QLabel("Animation:")); | |
64 | settingsLayout->addWidget(m_animatedComboBox); |
|
64 | settingsLayout->addWidget(m_animatedComboBox); | |
65 | settingsLayout->addWidget(new QLabel("Legend:")); |
|
65 | settingsLayout->addWidget(new QLabel("Legend:")); | |
66 | settingsLayout->addWidget(m_legendComboBox); |
|
66 | settingsLayout->addWidget(m_legendComboBox); | |
67 | settingsLayout->addWidget(m_antialiasCheckBox); |
|
67 | settingsLayout->addWidget(m_antialiasCheckBox); | |
68 | settingsLayout->addStretch(); |
|
68 | settingsLayout->addStretch(); | |
69 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
69 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); | |
70 |
|
70 | |||
71 | //create charts |
|
71 | //create charts | |
72 |
|
72 | |||
73 | QChartView *chartView; |
|
73 | QChartView *chartView; | |
74 |
|
74 | |||
75 | chartView = new QChartView(createAreaChart()); |
|
75 | chartView = new QChartView(createAreaChart()); | |
76 | baseLayout->addWidget(chartView, 1, 0); |
|
76 | baseLayout->addWidget(chartView, 1, 0); | |
77 | m_charts << chartView; |
|
77 | m_charts << chartView; | |
78 |
|
78 | |||
79 | chartView = new QChartView(createBarChart(m_valueCount)); |
|
79 | chartView = new QChartView(createBarChart(m_valueCount)); | |
80 | baseLayout->addWidget(chartView, 1, 1); |
|
80 | baseLayout->addWidget(chartView, 1, 1); | |
81 | m_charts << chartView; |
|
81 | m_charts << chartView; | |
82 |
|
82 | |||
83 | chartView = new QChartView(createLineChart()); |
|
83 | chartView = new QChartView(createLineChart()); | |
84 | baseLayout->addWidget(chartView, 1, 2); |
|
84 | baseLayout->addWidget(chartView, 1, 2); | |
85 | m_charts << chartView; |
|
85 | m_charts << chartView; | |
86 |
|
86 | |||
87 | chartView = new QChartView(createPieChart()); |
|
87 | chartView = new QChartView(createPieChart()); | |
88 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... |
|
88 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... | |
89 | baseLayout->addWidget(chartView, 2, 0); |
|
89 | baseLayout->addWidget(chartView, 2, 0); | |
90 | m_charts << chartView; |
|
90 | m_charts << chartView; | |
91 |
|
91 | |||
92 | chartView = new QChartView(createSplineChart()); |
|
92 | chartView = new QChartView(createSplineChart()); | |
93 | baseLayout->addWidget(chartView, 2, 1); |
|
93 | baseLayout->addWidget(chartView, 2, 1); | |
94 | m_charts << chartView; |
|
94 | m_charts << chartView; | |
95 |
|
95 | |||
96 | chartView = new QChartView(createScatterChart()); |
|
96 | chartView = new QChartView(createScatterChart()); | |
97 | baseLayout->addWidget(chartView, 2, 2); |
|
97 | baseLayout->addWidget(chartView, 2, 2); | |
98 | m_charts << chartView; |
|
98 | m_charts << chartView; | |
99 |
|
99 | |||
100 | setLayout(baseLayout); |
|
100 | setLayout(baseLayout); | |
101 |
|
101 | |||
102 | // Set defaults |
|
102 | // Set defaults | |
103 | m_antialiasCheckBox->setChecked(true); |
|
103 | m_antialiasCheckBox->setChecked(true); | |
104 | updateUI(); |
|
104 | updateUI(); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | ThemeWidget::~ThemeWidget() |
|
107 | ThemeWidget::~ThemeWidget() | |
108 | { |
|
108 | { | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void ThemeWidget::connectSignals() |
|
111 | void ThemeWidget::connectSignals() | |
112 | { |
|
112 | { | |
113 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
113 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
114 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
114 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
115 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
115 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
116 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
116 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
119 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const | |
120 | { |
|
120 | { | |
121 | DataTable dataTable; |
|
121 | DataTable dataTable; | |
122 |
|
122 | |||
123 | // set seed for random stuff |
|
123 | // set seed for random stuff | |
124 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
124 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
125 |
|
125 | |||
126 | // generate random data |
|
126 | // generate random data | |
127 | for (int i(0); i < listCount; i++) { |
|
127 | for (int i(0); i < listCount; i++) { | |
128 | DataList dataList; |
|
128 | DataList dataList; | |
129 | qreal yValue(0); |
|
129 | qreal yValue(0); | |
130 | for (int j(0); j < valueCount; j++) { |
|
130 | for (int j(0); j < valueCount; j++) { | |
131 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; |
|
131 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; | |
132 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), |
|
132 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), | |
133 | yValue); |
|
133 | yValue); | |
134 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); |
|
134 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); | |
135 | dataList << Data(value, label); |
|
135 | dataList << Data(value, label); | |
136 | } |
|
136 | } | |
137 | dataTable << dataList; |
|
137 | dataTable << dataList; | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | return dataTable; |
|
140 | return dataTable; | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | QComboBox* ThemeWidget::createThemeBox() const |
|
143 | QComboBox* ThemeWidget::createThemeBox() const | |
144 | { |
|
144 | { | |
145 | // settings layout |
|
145 | // settings layout | |
146 | QComboBox* themeComboBox = new QComboBox(); |
|
146 | QComboBox* themeComboBox = new QComboBox(); | |
147 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
147 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
148 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
148 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
149 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
149 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
150 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
150 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
151 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
151 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
152 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
152 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
153 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
153 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
154 | return themeComboBox; |
|
154 | return themeComboBox; | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | QComboBox* ThemeWidget::createAnimationBox() const |
|
157 | QComboBox* ThemeWidget::createAnimationBox() const | |
158 | { |
|
158 | { | |
159 | // settings layout |
|
159 | // settings layout | |
160 | QComboBox* animationComboBox = new QComboBox(); |
|
160 | QComboBox* animationComboBox = new QComboBox(); | |
161 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
161 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
162 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
162 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
163 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
163 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
164 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
164 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
165 | return animationComboBox; |
|
165 | return animationComboBox; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | QComboBox* ThemeWidget::createLegendBox() const |
|
168 | QComboBox* ThemeWidget::createLegendBox() const | |
169 | { |
|
169 | { | |
170 | QComboBox* legendComboBox = new QComboBox(); |
|
170 | QComboBox* legendComboBox = new QComboBox(); | |
171 | legendComboBox->addItem("No Legend ", 0); |
|
171 | legendComboBox->addItem("No Legend ", 0); | |
172 | legendComboBox->addItem("Legend Top", Qt::AlignTop); |
|
172 | legendComboBox->addItem("Legend Top", Qt::AlignTop); | |
173 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); |
|
173 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); | |
174 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); |
|
174 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); | |
175 | legendComboBox->addItem("Legend Right", Qt::AlignRight); |
|
175 | legendComboBox->addItem("Legend Right", Qt::AlignRight); | |
176 | return legendComboBox; |
|
176 | return legendComboBox; | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | QChart* ThemeWidget::createAreaChart() const |
|
179 | QChart* ThemeWidget::createAreaChart() const | |
180 | { |
|
180 | { | |
181 | QChart *chart = new QChart(); |
|
181 | QChart *chart = new QChart(); | |
182 | // chart->axisX()->setNiceNumbersEnabled(true); |
|
182 | // chart->axisX()->setNiceNumbersEnabled(true); | |
183 | // chart->axisY()->setNiceNumbersEnabled(true); |
|
183 | // chart->axisY()->setNiceNumbersEnabled(true); | |
184 | chart->setTitle("Area chart"); |
|
184 | chart->setTitle("Area chart"); | |
185 |
|
185 | |||
186 | // The lower series initialized to zero values |
|
186 | // The lower series initialized to zero values | |
187 | QLineSeries *lowerSeries = 0; |
|
187 | QLineSeries *lowerSeries = 0; | |
188 | QString name("Series "); |
|
188 | QString name("Series "); | |
189 | int nameIndex = 0; |
|
189 | int nameIndex = 0; | |
190 | for (int i(0); i < m_dataTable.count(); i++) { |
|
190 | for (int i(0); i < m_dataTable.count(); i++) { | |
191 | QLineSeries *upperSeries = new QLineSeries(chart); |
|
191 | QLineSeries *upperSeries = new QLineSeries(chart); | |
192 | for (int j(0); j < m_dataTable[i].count(); j++) { |
|
192 | for (int j(0); j < m_dataTable[i].count(); j++) { | |
193 | Data data = m_dataTable[i].at(j); |
|
193 | Data data = m_dataTable[i].at(j); | |
194 | if (lowerSeries){ |
|
194 | if (lowerSeries){ | |
195 | const QList<QPointF>& points = lowerSeries->points(); |
|
195 | const QList<QPointF>& points = lowerSeries->points(); | |
196 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); |
|
196 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); | |
197 | }else |
|
197 | }else | |
198 | upperSeries->append(QPointF(j, data.first.y())); |
|
198 | upperSeries->append(QPointF(j, data.first.y())); | |
199 | } |
|
199 | } | |
200 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
200 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); | |
201 | area->setName(name + QString::number(nameIndex)); |
|
201 | area->setName(name + QString::number(nameIndex)); | |
202 | nameIndex++; |
|
202 | nameIndex++; | |
203 | chart->addSeries(area); |
|
203 | chart->addSeries(area); | |
204 | chart->createDefaultAxes(); |
|
204 | chart->createDefaultAxes(); | |
205 | lowerSeries = upperSeries; |
|
205 | lowerSeries = upperSeries; | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | return chart; |
|
208 | return chart; | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
211 | QChart* ThemeWidget::createBarChart(int valueCount) const | |
212 | { |
|
212 | { | |
213 | Q_UNUSED(valueCount); |
|
213 | Q_UNUSED(valueCount); | |
214 | QChart* chart = new QChart(); |
|
214 | QChart* chart = new QChart(); | |
215 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
215 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); | |
216 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
216 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); | |
217 | chart->setTitle("Bar chart"); |
|
217 | chart->setTitle("Bar chart"); | |
218 |
|
218 | |||
219 | QStackedBarSeries* series = new QStackedBarSeries(chart); |
|
219 | QStackedBarSeries* series = new QStackedBarSeries(chart); | |
220 | for (int i(0); i < m_dataTable.count(); i++) { |
|
220 | for (int i(0); i < m_dataTable.count(); i++) { | |
221 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
221 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
222 | foreach (Data data, m_dataTable[i]) |
|
222 | foreach (Data data, m_dataTable[i]) | |
223 | *set << data.first.y(); |
|
223 | *set << data.first.y(); | |
224 | series->append(set); |
|
224 | series->append(set); | |
225 | } |
|
225 | } | |
226 | chart->addSeries(series); |
|
226 | chart->addSeries(series); | |
227 | chart->createDefaultAxes(); |
|
227 | chart->createDefaultAxes(); | |
228 |
|
228 | |||
229 | return chart; |
|
229 | return chart; | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | QChart* ThemeWidget::createLineChart() const |
|
232 | QChart* ThemeWidget::createLineChart() const | |
233 | { |
|
233 | { | |
234 | QChart* chart = new QChart(); |
|
234 | QChart* chart = new QChart(); | |
235 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
235 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); | |
236 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
236 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); | |
237 | chart->setTitle("Line chart"); |
|
237 | chart->setTitle("Line chart"); | |
238 |
|
238 | |||
239 | QString name("Series "); |
|
239 | QString name("Series "); | |
240 | int nameIndex = 0; |
|
240 | int nameIndex = 0; | |
241 | foreach (DataList list, m_dataTable) { |
|
241 | foreach (DataList list, m_dataTable) { | |
242 | QLineSeries *series = new QLineSeries(chart); |
|
242 | QLineSeries *series = new QLineSeries(chart); | |
243 | foreach (Data data, list) |
|
243 | foreach (Data data, list) | |
244 | series->append(data.first); |
|
244 | series->append(data.first); | |
245 | series->setName(name + QString::number(nameIndex)); |
|
245 | series->setName(name + QString::number(nameIndex)); | |
246 | nameIndex++; |
|
246 | nameIndex++; | |
247 | chart->addSeries(series); |
|
247 | chart->addSeries(series); | |
248 | } |
|
248 | } | |
249 | chart->createDefaultAxes(); |
|
249 | chart->createDefaultAxes(); | |
250 |
|
250 | |||
251 | return chart; |
|
251 | return chart; | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | QChart* ThemeWidget::createPieChart() const |
|
254 | QChart* ThemeWidget::createPieChart() const | |
255 | { |
|
255 | { | |
256 | QChart* chart = new QChart(); |
|
256 | QChart* chart = new QChart(); | |
257 | chart->setTitle("Pie chart"); |
|
257 | chart->setTitle("Pie chart"); | |
258 |
|
258 | |||
259 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
259 | qreal pieSize = 1.0 / m_dataTable.count(); | |
260 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
260 | for (int i = 0; i < m_dataTable.count(); i++) { | |
261 | QPieSeries *series = new QPieSeries(chart); |
|
261 | QPieSeries *series = new QPieSeries(chart); | |
262 | foreach (Data data, m_dataTable[i]) { |
|
262 | foreach (Data data, m_dataTable[i]) { | |
263 | QPieSlice *slice = series->append(data.second, data.first.y()); |
|
263 | QPieSlice *slice = series->append(data.second, data.first.y()); | |
264 | if (data == m_dataTable[i].first()) { |
|
264 | if (data == m_dataTable[i].first()) { | |
265 | slice->setLabelVisible(); |
|
265 | slice->setLabelVisible(); | |
266 | slice->setExploded(); |
|
266 | slice->setExploded(); | |
267 | } |
|
267 | } | |
268 | } |
|
268 | } | |
269 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
269 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
270 | series->setPieSize(pieSize); |
|
270 | series->setPieSize(pieSize); | |
271 | series->setHorizontalPosition(hPos); |
|
271 | series->setHorizontalPosition(hPos); | |
272 | series->setVerticalPosition(0.5); |
|
272 | series->setVerticalPosition(0.5); | |
273 | chart->addSeries(series); |
|
273 | chart->addSeries(series); | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | return chart; |
|
276 | return chart; | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | QChart* ThemeWidget::createSplineChart() const |
|
279 | QChart* ThemeWidget::createSplineChart() const | |
280 | { // spine chart |
|
280 | { // spine chart | |
281 | QChart* chart = new QChart(); |
|
281 | QChart* chart = new QChart(); | |
282 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
282 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); | |
283 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
283 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); | |
284 | chart->setTitle("Spline chart"); |
|
284 | chart->setTitle("Spline chart"); | |
285 | QString name("Series "); |
|
285 | QString name("Series "); | |
286 | int nameIndex = 0; |
|
286 | int nameIndex = 0; | |
287 | foreach (DataList list, m_dataTable) { |
|
287 | foreach (DataList list, m_dataTable) { | |
288 | QSplineSeries *series = new QSplineSeries(chart); |
|
288 | QSplineSeries *series = new QSplineSeries(chart); | |
289 | foreach (Data data, list) |
|
289 | foreach (Data data, list) | |
290 | series->append(data.first); |
|
290 | series->append(data.first); | |
291 | series->setName(name + QString::number(nameIndex)); |
|
291 | series->setName(name + QString::number(nameIndex)); | |
292 | nameIndex++; |
|
292 | nameIndex++; | |
293 | chart->addSeries(series); |
|
293 | chart->addSeries(series); | |
294 | } |
|
294 | } | |
295 | chart->createDefaultAxes(); |
|
295 | chart->createDefaultAxes(); | |
296 | return chart; |
|
296 | return chart; | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | QChart* ThemeWidget::createScatterChart() const |
|
299 | QChart* ThemeWidget::createScatterChart() const | |
300 | { // scatter chart |
|
300 | { // scatter chart | |
301 | QChart* chart = new QChart(); |
|
301 | QChart* chart = new QChart(); | |
302 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
302 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); | |
303 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
303 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); | |
304 | chart->setTitle("Scatter chart"); |
|
304 | chart->setTitle("Scatter chart"); | |
305 | QString name("Series "); |
|
305 | QString name("Series "); | |
306 | int nameIndex = 0; |
|
306 | int nameIndex = 0; | |
307 | foreach (DataList list, m_dataTable) { |
|
307 | foreach (DataList list, m_dataTable) { | |
308 | QScatterSeries *series = new QScatterSeries(chart); |
|
308 | QScatterSeries *series = new QScatterSeries(chart); | |
309 | foreach (Data data, list) |
|
309 | foreach (Data data, list) | |
310 | series->append(data.first); |
|
310 | series->append(data.first); | |
311 | series->setName(name + QString::number(nameIndex)); |
|
311 | series->setName(name + QString::number(nameIndex)); | |
312 | nameIndex++; |
|
312 | nameIndex++; | |
313 | chart->addSeries(series); |
|
313 | chart->addSeries(series); | |
314 | } |
|
314 | } | |
315 | chart->createDefaultAxes(); |
|
315 | chart->createDefaultAxes(); | |
316 | return chart; |
|
316 | return chart; | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | void ThemeWidget::updateUI() |
|
319 | void ThemeWidget::updateUI() | |
320 | { |
|
320 | { | |
321 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
321 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
322 |
|
322 | |||
323 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
323 | if (m_charts.at(0)->chart()->theme() != theme) { | |
324 | foreach (QChartView *chartView, m_charts) |
|
324 | foreach (QChartView *chartView, m_charts) | |
325 | chartView->chart()->setTheme(theme); |
|
325 | chartView->chart()->setTheme(theme); | |
326 |
|
326 | |||
327 | QPalette pal = window()->palette(); |
|
327 | QPalette pal = window()->palette(); | |
328 | if (theme == QChart::ChartThemeLight) { |
|
328 | if (theme == QChart::ChartThemeLight) { | |
329 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
329 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
330 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
330 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
331 | } else if (theme == QChart::ChartThemeDark) { |
|
331 | } else if (theme == QChart::ChartThemeDark) { | |
332 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
332 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
333 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
333 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
334 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
334 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
335 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
335 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
336 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
336 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
337 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
337 | } else if (theme == QChart::ChartThemeBrownSand) { | |
338 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
338 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
339 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
339 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
340 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
340 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
341 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
341 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
342 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
342 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
343 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
343 | } else if (theme == QChart::ChartThemeHighContrast) { | |
344 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
344 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
345 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
345 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
346 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
346 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
347 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
347 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
348 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
348 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
349 | } else { |
|
349 | } else { | |
350 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
350 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
351 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
351 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
352 | } |
|
352 | } | |
353 | window()->setPalette(pal); |
|
353 | window()->setPalette(pal); | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | bool checked = m_antialiasCheckBox->isChecked(); |
|
356 | bool checked = m_antialiasCheckBox->isChecked(); | |
357 | foreach (QChartView *chart, m_charts) |
|
357 | foreach (QChartView *chart, m_charts) | |
358 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
358 | chart->setRenderHint(QPainter::Antialiasing, checked); | |
359 |
|
359 | |||
360 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
360 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
361 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
361 | if (m_charts.at(0)->chart()->animationOptions() != options) { | |
362 | foreach (QChartView *chartView, m_charts) |
|
362 | foreach (QChartView *chartView, m_charts) | |
363 | chartView->chart()->setAnimationOptions(options); |
|
363 | chartView->chart()->setAnimationOptions(options); | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
366 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
367 |
|
367 | |||
368 | if (!alignment) { |
|
368 | if (!alignment) { | |
369 | foreach (QChartView *chartView, m_charts) { |
|
369 | foreach (QChartView *chartView, m_charts) { | |
370 | chartView->chart()->legend()->hide(); |
|
370 | chartView->chart()->legend()->hide(); | |
371 | } |
|
371 | } | |
372 | } else { |
|
372 | } else { | |
373 | foreach (QChartView *chartView, m_charts) { |
|
373 | foreach (QChartView *chartView, m_charts) { | |
374 | chartView->chart()->legend()->setAlignment(alignment); |
|
374 | chartView->chart()->legend()->setAlignment(alignment); | |
375 | chartView->chart()->legend()->show(); |
|
375 | chartView->chart()->legend()->show(); | |
376 | } |
|
376 | } | |
377 | } |
|
377 | } | |
378 | } |
|
378 | } | |
379 |
|
379 |
@@ -1,92 +1,92 | |||||
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 |
#include <QBarCategor |
|
27 | #include <QBarCategoryAxis> | |
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 |
|
34 | |||
35 | //![1] |
|
35 | //![1] | |
36 | QBarSet *set0 = new QBarSet("Jane"); |
|
36 | QBarSet *set0 = new QBarSet("Jane"); | |
37 | QBarSet *set1 = new QBarSet("John"); |
|
37 | QBarSet *set1 = new QBarSet("John"); | |
38 | QBarSet *set2 = new QBarSet("Axel"); |
|
38 | QBarSet *set2 = new QBarSet("Axel"); | |
39 | QBarSet *set3 = new QBarSet("Mary"); |
|
39 | QBarSet *set3 = new QBarSet("Mary"); | |
40 | QBarSet *set4 = new QBarSet("Samantha"); |
|
40 | QBarSet *set4 = new QBarSet("Samantha"); | |
41 |
|
41 | |||
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
47 | //![1] |
|
47 | //![1] | |
48 |
|
48 | |||
49 | //![2] |
|
49 | //![2] | |
50 | QBarSeries* series = new QBarSeries(); |
|
50 | QBarSeries* series = new QBarSeries(); | |
51 | series->append(set0); |
|
51 | series->append(set0); | |
52 | series->append(set1); |
|
52 | series->append(set1); | |
53 | series->append(set2); |
|
53 | series->append(set2); | |
54 | series->append(set3); |
|
54 | series->append(set3); | |
55 | series->append(set4); |
|
55 | series->append(set4); | |
56 |
|
56 | |||
57 | //![2] |
|
57 | //![2] | |
58 |
|
58 | |||
59 | //![3] |
|
59 | //![3] | |
60 | QChart* chart = new QChart(); |
|
60 | QChart* chart = new QChart(); | |
61 | chart->addSeries(series); |
|
61 | chart->addSeries(series); | |
62 | chart->setTitle("Simple barchart example"); |
|
62 | chart->setTitle("Simple barchart example"); | |
63 | chart->createDefaultAxes(); |
|
63 | chart->createDefaultAxes(); | |
64 | //![3] |
|
64 | //![3] | |
65 |
|
65 | |||
66 | //![4] |
|
66 | //![4] | |
67 | QStringList categories; |
|
67 | QStringList categories; | |
68 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
68 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
69 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
69 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
70 | axis->append(categories); |
|
70 | axis->append(categories); | |
71 | chart->setAxisX(axis,series); |
|
71 | chart->setAxisX(axis,series); | |
72 | //![4] |
|
72 | //![4] | |
73 |
|
73 | |||
74 | //![5] |
|
74 | //![5] | |
75 | chart->legend()->setVisible(true); |
|
75 | chart->legend()->setVisible(true); | |
76 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
76 | chart->legend()->setAlignment(Qt::AlignBottom); | |
77 | //![5] |
|
77 | //![5] | |
78 |
|
78 | |||
79 | //![6] |
|
79 | //![6] | |
80 | QChartView* chartView = new QChartView(chart); |
|
80 | QChartView* chartView = new QChartView(chart); | |
81 | chartView->setRenderHint(QPainter::Antialiasing); |
|
81 | chartView->setRenderHint(QPainter::Antialiasing); | |
82 | //![6] |
|
82 | //![6] | |
83 |
|
83 | |||
84 | //![7] |
|
84 | //![7] | |
85 | QMainWindow window; |
|
85 | QMainWindow window; | |
86 | window.setCentralWidget(chartView); |
|
86 | window.setCentralWidget(chartView); | |
87 | window.resize(400, 300); |
|
87 | window.resize(400, 300); | |
88 | window.show(); |
|
88 | window.show(); | |
89 | //![7] |
|
89 | //![7] | |
90 |
|
90 | |||
91 | return a.exec(); |
|
91 | return a.exec(); | |
92 | } |
|
92 | } |
@@ -1,112 +1,112 | |||||
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 "tablewidget.h" |
|
21 | #include "tablewidget.h" | |
22 | #include "customtablemodel.h" |
|
22 | #include "customtablemodel.h" | |
23 | #include <QGridLayout> |
|
23 | #include <QGridLayout> | |
24 | #include <QTableView> |
|
24 | #include <QTableView> | |
25 | #include <QChart> |
|
25 | #include <QChart> | |
26 | #include <QChartView> |
|
26 | #include <QChartView> | |
27 | #include <QLineSeries> |
|
27 | #include <QLineSeries> | |
28 | #include <QVXYModelMapper> |
|
28 | #include <QVXYModelMapper> | |
29 | #include <QBarSeries> |
|
29 | #include <QBarSeries> | |
30 | #include <QBarSet> |
|
30 | #include <QBarSet> | |
31 | #include <QVBarModelMapper> |
|
31 | #include <QVBarModelMapper> | |
32 | #include <QHeaderView> |
|
32 | #include <QHeaderView> | |
33 |
#include <QBarCategor |
|
33 | #include <QBarCategoryAxis> | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
35 | QTCOMMERCIALCHART_USE_NAMESPACE | |
36 |
|
36 | |||
37 | TableWidget::TableWidget(QWidget *parent) |
|
37 | TableWidget::TableWidget(QWidget *parent) | |
38 | : QWidget(parent) |
|
38 | : QWidget(parent) | |
39 | { |
|
39 | { | |
40 | // create simple model for storing data |
|
40 | // create simple model for storing data | |
41 | // user's table data model |
|
41 | // user's table data model | |
42 | //! [1] |
|
42 | //! [1] | |
43 | CustomTableModel *model = new CustomTableModel; |
|
43 | CustomTableModel *model = new CustomTableModel; | |
44 | //! [1] |
|
44 | //! [1] | |
45 |
|
45 | |||
46 | //! [2] |
|
46 | //! [2] | |
47 | // create table view and add model to it |
|
47 | // create table view and add model to it | |
48 | QTableView *tableView = new QTableView; |
|
48 | QTableView *tableView = new QTableView; | |
49 | tableView->setModel(model); |
|
49 | tableView->setModel(model); | |
50 | tableView->setMinimumWidth(300); |
|
50 | tableView->setMinimumWidth(300); | |
51 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
51 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |
52 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
52 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |
53 | //! [2] |
|
53 | //! [2] | |
54 |
|
54 | |||
55 | //! [3] |
|
55 | //! [3] | |
56 | QChart *chart = new QChart; |
|
56 | QChart *chart = new QChart; | |
57 | chart->setAnimationOptions(QChart::AllAnimations); |
|
57 | chart->setAnimationOptions(QChart::AllAnimations); | |
58 | //! [3] |
|
58 | //! [3] | |
59 |
|
59 | |||
60 | // series 1 |
|
60 | // series 1 | |
61 | //! [4] |
|
61 | //! [4] | |
62 | QBarSeries *series = new QBarSeries; |
|
62 | QBarSeries *series = new QBarSeries; | |
63 |
|
63 | |||
64 | int first = 3; |
|
64 | int first = 3; | |
65 | int count = 5; |
|
65 | int count = 5; | |
66 | QVBarModelMapper *mapper = new QVBarModelMapper(this); |
|
66 | QVBarModelMapper *mapper = new QVBarModelMapper(this); | |
67 | mapper->setFirstBarSetColumn(1); |
|
67 | mapper->setFirstBarSetColumn(1); | |
68 | mapper->setLastBarSetColumn(4); |
|
68 | mapper->setLastBarSetColumn(4); | |
69 | mapper->setFirstRow(first); |
|
69 | mapper->setFirstRow(first); | |
70 | mapper->setRowCount(count); |
|
70 | mapper->setRowCount(count); | |
71 | mapper->setSeries(series); |
|
71 | mapper->setSeries(series); | |
72 | mapper->setModel(model); |
|
72 | mapper->setModel(model); | |
73 | chart->addSeries(series); |
|
73 | chart->addSeries(series); | |
74 | //! [4] |
|
74 | //! [4] | |
75 |
|
75 | |||
76 | //! [5] |
|
76 | //! [5] | |
77 | // for storing color hex from the series |
|
77 | // for storing color hex from the series | |
78 | QString seriesColorHex = "#000000"; |
|
78 | QString seriesColorHex = "#000000"; | |
79 |
|
79 | |||
80 | // get the color of the series and use it for showing the mapped area |
|
80 | // get the color of the series and use it for showing the mapped area | |
81 | QList<QBarSet*> barsets = series->barSets(); |
|
81 | QList<QBarSet*> barsets = series->barSets(); | |
82 | for (int i = 0; i < barsets.count(); i++) { |
|
82 | for (int i = 0; i < barsets.count(); i++) { | |
83 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
83 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
84 | model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count())); |
|
84 | model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count())); | |
85 | } |
|
85 | } | |
86 | //! [5] |
|
86 | //! [5] | |
87 |
|
87 | |||
88 | //! [6] |
|
88 | //! [6] | |
89 | QStringList categories; |
|
89 | QStringList categories; | |
90 | categories << "April" << "May" << "June" << "July" << "August"; |
|
90 | categories << "April" << "May" << "June" << "July" << "August"; | |
91 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
91 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
92 | axis->append(categories); |
|
92 | axis->append(categories); | |
93 | chart->createDefaultAxes(); |
|
93 | chart->createDefaultAxes(); | |
94 | chart->setAxisX(axis, series); |
|
94 | chart->setAxisX(axis, series); | |
95 | //! [6] |
|
95 | //! [6] | |
96 |
|
96 | |||
97 | //! [7] |
|
97 | //! [7] | |
98 | QChartView *chartView = new QChartView(chart); |
|
98 | QChartView *chartView = new QChartView(chart); | |
99 | chartView->setRenderHint(QPainter::Antialiasing); |
|
99 | chartView->setRenderHint(QPainter::Antialiasing); | |
100 | chartView->setMinimumSize(640, 480); |
|
100 | chartView->setMinimumSize(640, 480); | |
101 | //! [7] |
|
101 | //! [7] | |
102 |
|
102 | |||
103 | //! [8] |
|
103 | //! [8] | |
104 | // create main layout |
|
104 | // create main layout | |
105 | QGridLayout* mainLayout = new QGridLayout; |
|
105 | QGridLayout* mainLayout = new QGridLayout; | |
106 | mainLayout->addWidget(tableView, 1, 0); |
|
106 | mainLayout->addWidget(tableView, 1, 0); | |
107 | mainLayout->addWidget(chartView, 1, 1); |
|
107 | mainLayout->addWidget(chartView, 1, 1); | |
108 | mainLayout->setColumnStretch(1, 1); |
|
108 | mainLayout->setColumnStretch(1, 1); | |
109 | mainLayout->setColumnStretch(0, 0); |
|
109 | mainLayout->setColumnStretch(0, 0); | |
110 | setLayout(mainLayout); |
|
110 | setLayout(mainLayout); | |
111 | //! [8] |
|
111 | //! [8] | |
112 | } |
|
112 | } |
@@ -1,94 +1,94 | |||||
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 |
#include <QBarCategor |
|
27 | #include <QBarCategoryAxis> | |
28 | #include <QHorizontalBarSeries> |
|
28 | #include <QHorizontalBarSeries> | |
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 | //![1] |
|
36 | //![1] | |
37 | QBarSet *set0 = new QBarSet("Jane"); |
|
37 | QBarSet *set0 = new QBarSet("Jane"); | |
38 | QBarSet *set1 = new QBarSet("John"); |
|
38 | QBarSet *set1 = new QBarSet("John"); | |
39 | QBarSet *set2 = new QBarSet("Axel"); |
|
39 | QBarSet *set2 = new QBarSet("Axel"); | |
40 | QBarSet *set3 = new QBarSet("Mary"); |
|
40 | QBarSet *set3 = new QBarSet("Mary"); | |
41 | QBarSet *set4 = new QBarSet("Samantha"); |
|
41 | QBarSet *set4 = new QBarSet("Samantha"); | |
42 |
|
42 | |||
43 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
43 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
44 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
44 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
45 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
45 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
46 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
46 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
47 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
47 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
48 | //![1] |
|
48 | //![1] | |
49 |
|
49 | |||
50 | //![2] |
|
50 | //![2] | |
51 | QHorizontalBarSeries *series = new QHorizontalBarSeries(); |
|
51 | QHorizontalBarSeries *series = new QHorizontalBarSeries(); | |
52 | series->append(set0); |
|
52 | series->append(set0); | |
53 | series->append(set1); |
|
53 | series->append(set1); | |
54 | series->append(set2); |
|
54 | series->append(set2); | |
55 | series->append(set3); |
|
55 | series->append(set3); | |
56 | series->append(set4); |
|
56 | series->append(set4); | |
57 |
|
57 | |||
58 | //![2] |
|
58 | //![2] | |
59 |
|
59 | |||
60 | //![3] |
|
60 | //![3] | |
61 | QChart* chart = new QChart(); |
|
61 | QChart* chart = new QChart(); | |
62 | chart->addSeries(series); |
|
62 | chart->addSeries(series); | |
63 | chart->setTitle("Simple horizontal barchart example"); |
|
63 | chart->setTitle("Simple horizontal barchart example"); | |
64 | chart->createDefaultAxes(); |
|
64 | chart->createDefaultAxes(); | |
65 | chart->setAnimationOptions(QChart::SeriesAnimations); |
|
65 | chart->setAnimationOptions(QChart::SeriesAnimations); | |
66 | //![3] |
|
66 | //![3] | |
67 |
|
67 | |||
68 | //![4] |
|
68 | //![4] | |
69 | QStringList categories; |
|
69 | QStringList categories; | |
70 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
70 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
71 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
71 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
72 | axis->append(categories); |
|
72 | axis->append(categories); | |
73 | chart->setAxisY(axis,series); |
|
73 | chart->setAxisY(axis,series); | |
74 | //![4] |
|
74 | //![4] | |
75 |
|
75 | |||
76 | //![5] |
|
76 | //![5] | |
77 | chart->legend()->setVisible(true); |
|
77 | chart->legend()->setVisible(true); | |
78 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
78 | chart->legend()->setAlignment(Qt::AlignBottom); | |
79 | //![5] |
|
79 | //![5] | |
80 |
|
80 | |||
81 | //![6] |
|
81 | //![6] | |
82 | QChartView* chartView = new QChartView(chart); |
|
82 | QChartView* chartView = new QChartView(chart); | |
83 | chartView->setRenderHint(QPainter::Antialiasing); |
|
83 | chartView->setRenderHint(QPainter::Antialiasing); | |
84 | //![6] |
|
84 | //![6] | |
85 |
|
85 | |||
86 | //![7] |
|
86 | //![7] | |
87 | QMainWindow window; |
|
87 | QMainWindow window; | |
88 | window.setCentralWidget(chartView); |
|
88 | window.setCentralWidget(chartView); | |
89 | window.resize(400, 300); |
|
89 | window.resize(400, 300); | |
90 | window.show(); |
|
90 | window.show(); | |
91 | //![7] |
|
91 | //![7] | |
92 |
|
92 | |||
93 | return a.exec(); |
|
93 | return a.exec(); | |
94 | } |
|
94 | } |
@@ -1,95 +1,95 | |||||
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 |
#include <QBarCategor |
|
27 | #include <QBarCategoryAxis> | |
28 | #include <QHorizontalPercentBarSeries> |
|
28 | #include <QHorizontalPercentBarSeries> | |
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 | //![1] |
|
36 | //![1] | |
37 | QBarSet *set0 = new QBarSet("Jane"); |
|
37 | QBarSet *set0 = new QBarSet("Jane"); | |
38 | QBarSet *set1 = new QBarSet("John"); |
|
38 | QBarSet *set1 = new QBarSet("John"); | |
39 | QBarSet *set2 = new QBarSet("Axel"); |
|
39 | QBarSet *set2 = new QBarSet("Axel"); | |
40 | QBarSet *set3 = new QBarSet("Mary"); |
|
40 | QBarSet *set3 = new QBarSet("Mary"); | |
41 | QBarSet *set4 = new QBarSet("Samantha"); |
|
41 | QBarSet *set4 = new QBarSet("Samantha"); | |
42 |
|
42 | |||
43 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
43 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
44 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
44 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
45 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
45 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
46 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
46 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
47 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
47 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
48 | //![1] |
|
48 | //![1] | |
49 |
|
49 | |||
50 | //![2] |
|
50 | //![2] | |
51 | QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries(); |
|
51 | QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries(); | |
52 | series->append(set0); |
|
52 | series->append(set0); | |
53 | series->append(set1); |
|
53 | series->append(set1); | |
54 | series->append(set2); |
|
54 | series->append(set2); | |
55 | series->append(set3); |
|
55 | series->append(set3); | |
56 | series->append(set4); |
|
56 | series->append(set4); | |
57 |
|
57 | |||
58 | //![2] |
|
58 | //![2] | |
59 |
|
59 | |||
60 | //![3] |
|
60 | //![3] | |
61 | QChart* chart = new QChart(); |
|
61 | QChart* chart = new QChart(); | |
62 | chart->addSeries(series); |
|
62 | chart->addSeries(series); | |
63 | chart->setTitle("Simple horizontal percent barchart example"); |
|
63 | chart->setTitle("Simple horizontal percent barchart example"); | |
64 | chart->createDefaultAxes(); |
|
64 | chart->createDefaultAxes(); | |
65 | chart->setAnimationOptions(QChart::SeriesAnimations); |
|
65 | chart->setAnimationOptions(QChart::SeriesAnimations); | |
66 | //![3] |
|
66 | //![3] | |
67 |
|
67 | |||
68 | //![4] |
|
68 | //![4] | |
69 | QStringList categories; |
|
69 | QStringList categories; | |
70 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
70 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
71 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
71 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
72 | axis->append(categories); |
|
72 | axis->append(categories); | |
73 | chart->createDefaultAxes(); |
|
73 | chart->createDefaultAxes(); | |
74 | chart->setAxisY(axis,series); |
|
74 | chart->setAxisY(axis,series); | |
75 | //![4] |
|
75 | //![4] | |
76 |
|
76 | |||
77 | //![5] |
|
77 | //![5] | |
78 | chart->legend()->setVisible(true); |
|
78 | chart->legend()->setVisible(true); | |
79 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
79 | chart->legend()->setAlignment(Qt::AlignBottom); | |
80 | //![5] |
|
80 | //![5] | |
81 |
|
81 | |||
82 | //![6] |
|
82 | //![6] | |
83 | QChartView* chartView = new QChartView(chart); |
|
83 | QChartView* chartView = new QChartView(chart); | |
84 | chartView->setRenderHint(QPainter::Antialiasing); |
|
84 | chartView->setRenderHint(QPainter::Antialiasing); | |
85 | //![6] |
|
85 | //![6] | |
86 |
|
86 | |||
87 | //![7] |
|
87 | //![7] | |
88 | QMainWindow window; |
|
88 | QMainWindow window; | |
89 | window.setCentralWidget(chartView); |
|
89 | window.setCentralWidget(chartView); | |
90 | window.resize(400, 300); |
|
90 | window.resize(400, 300); | |
91 | window.show(); |
|
91 | window.show(); | |
92 | //![7] |
|
92 | //![7] | |
93 |
|
93 | |||
94 | return a.exec(); |
|
94 | return a.exec(); | |
95 | } |
|
95 | } |
@@ -1,95 +1,95 | |||||
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 |
#include <QBarCategor |
|
27 | #include <QBarCategoryAxis> | |
28 | #include <QHorizontalStackedBarSeries> |
|
28 | #include <QHorizontalStackedBarSeries> | |
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 | //![1] |
|
36 | //![1] | |
37 | QBarSet *set0 = new QBarSet("Jane"); |
|
37 | QBarSet *set0 = new QBarSet("Jane"); | |
38 | QBarSet *set1 = new QBarSet("John"); |
|
38 | QBarSet *set1 = new QBarSet("John"); | |
39 | QBarSet *set2 = new QBarSet("Axel"); |
|
39 | QBarSet *set2 = new QBarSet("Axel"); | |
40 | QBarSet *set3 = new QBarSet("Mary"); |
|
40 | QBarSet *set3 = new QBarSet("Mary"); | |
41 | QBarSet *set4 = new QBarSet("Samantha"); |
|
41 | QBarSet *set4 = new QBarSet("Samantha"); | |
42 |
|
42 | |||
43 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
43 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
44 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
44 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
45 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
45 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
46 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
46 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
47 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
47 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
48 | //![1] |
|
48 | //![1] | |
49 |
|
49 | |||
50 | //![2] |
|
50 | //![2] | |
51 | QHorizontalStackedBarSeries *series = new QHorizontalStackedBarSeries(); |
|
51 | QHorizontalStackedBarSeries *series = new QHorizontalStackedBarSeries(); | |
52 | series->append(set0); |
|
52 | series->append(set0); | |
53 | series->append(set1); |
|
53 | series->append(set1); | |
54 | series->append(set2); |
|
54 | series->append(set2); | |
55 | series->append(set3); |
|
55 | series->append(set3); | |
56 | series->append(set4); |
|
56 | series->append(set4); | |
57 |
|
57 | |||
58 | //![2] |
|
58 | //![2] | |
59 |
|
59 | |||
60 | //![3] |
|
60 | //![3] | |
61 | QChart* chart = new QChart(); |
|
61 | QChart* chart = new QChart(); | |
62 | chart->addSeries(series); |
|
62 | chart->addSeries(series); | |
63 | chart->setTitle("Simple horizontal stacked barchart example"); |
|
63 | chart->setTitle("Simple horizontal stacked barchart example"); | |
64 | chart->createDefaultAxes(); |
|
64 | chart->createDefaultAxes(); | |
65 | chart->setAnimationOptions(QChart::SeriesAnimations); |
|
65 | chart->setAnimationOptions(QChart::SeriesAnimations); | |
66 | //![3] |
|
66 | //![3] | |
67 |
|
67 | |||
68 | //![4] |
|
68 | //![4] | |
69 | QStringList categories; |
|
69 | QStringList categories; | |
70 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
70 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
71 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
71 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
72 | axis->append(categories); |
|
72 | axis->append(categories); | |
73 | chart->createDefaultAxes(); |
|
73 | chart->createDefaultAxes(); | |
74 | chart->setAxisY(axis,series); |
|
74 | chart->setAxisY(axis,series); | |
75 | //![4] |
|
75 | //![4] | |
76 |
|
76 | |||
77 | //![5] |
|
77 | //![5] | |
78 | chart->legend()->setVisible(true); |
|
78 | chart->legend()->setVisible(true); | |
79 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
79 | chart->legend()->setAlignment(Qt::AlignBottom); | |
80 | //![5] |
|
80 | //![5] | |
81 |
|
81 | |||
82 | //![6] |
|
82 | //![6] | |
83 | QChartView* chartView = new QChartView(chart); |
|
83 | QChartView* chartView = new QChartView(chart); | |
84 | chartView->setRenderHint(QPainter::Antialiasing); |
|
84 | chartView->setRenderHint(QPainter::Antialiasing); | |
85 | //![6] |
|
85 | //![6] | |
86 |
|
86 | |||
87 | //![7] |
|
87 | //![7] | |
88 | QMainWindow window; |
|
88 | QMainWindow window; | |
89 | window.setCentralWidget(chartView); |
|
89 | window.setCentralWidget(chartView); | |
90 | window.resize(400, 300); |
|
90 | window.resize(400, 300); | |
91 | window.show(); |
|
91 | window.show(); | |
92 | //![7] |
|
92 | //![7] | |
93 |
|
93 | |||
94 | return a.exec(); |
|
94 | return a.exec(); | |
95 | } |
|
95 | } |
@@ -1,111 +1,111 | |||||
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 <QLineSeries> |
|
26 | #include <QLineSeries> | |
27 | #include <QLegend> |
|
27 | #include <QLegend> | |
28 |
#include <QBarCategor |
|
28 | #include <QBarCategoryAxis> | |
29 | #include <QValueAxis> |
|
29 | #include <QValueAxis> | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
31 | QTCOMMERCIALCHART_USE_NAMESPACE | |
32 |
|
32 | |||
33 | int main(int argc, char *argv[]) |
|
33 | int main(int argc, char *argv[]) | |
34 | { |
|
34 | { | |
35 | QApplication a(argc, argv); |
|
35 | QApplication a(argc, argv); | |
36 |
|
36 | |||
37 | //![1] |
|
37 | //![1] | |
38 | QBarSet *set0 = new QBarSet("Jane"); |
|
38 | QBarSet *set0 = new QBarSet("Jane"); | |
39 | QBarSet *set1 = new QBarSet("John"); |
|
39 | QBarSet *set1 = new QBarSet("John"); | |
40 | QBarSet *set2 = new QBarSet("Axel"); |
|
40 | QBarSet *set2 = new QBarSet("Axel"); | |
41 | QBarSet *set3 = new QBarSet("Mary"); |
|
41 | QBarSet *set3 = new QBarSet("Mary"); | |
42 | QBarSet *set4 = new QBarSet("Samantha"); |
|
42 | QBarSet *set4 = new QBarSet("Samantha"); | |
43 |
|
43 | |||
44 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
44 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
45 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
45 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
46 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
46 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
47 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
47 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
48 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
48 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
49 | //![1] |
|
49 | //![1] | |
50 |
|
50 | |||
51 | //![2] |
|
51 | //![2] | |
52 | QBarSeries* barseries = new QBarSeries(); |
|
52 | QBarSeries* barseries = new QBarSeries(); | |
53 | barseries->append(set0); |
|
53 | barseries->append(set0); | |
54 | barseries->append(set1); |
|
54 | barseries->append(set1); | |
55 | barseries->append(set2); |
|
55 | barseries->append(set2); | |
56 | barseries->append(set3); |
|
56 | barseries->append(set3); | |
57 | barseries->append(set4); |
|
57 | barseries->append(set4); | |
58 | //![2] |
|
58 | //![2] | |
59 |
|
59 | |||
60 | //![8] |
|
60 | //![8] | |
61 | QLineSeries* lineseries = new QLineSeries(); |
|
61 | QLineSeries* lineseries = new QLineSeries(); | |
62 |
|
62 | |||
63 | lineseries->append(QPoint(0,4)); |
|
63 | lineseries->append(QPoint(0,4)); | |
64 | lineseries->append(QPoint(1,15)); |
|
64 | lineseries->append(QPoint(1,15)); | |
65 | lineseries->append(QPoint(2,20)); |
|
65 | lineseries->append(QPoint(2,20)); | |
66 | lineseries->append(QPoint(3,4)); |
|
66 | lineseries->append(QPoint(3,4)); | |
67 | lineseries->append(QPoint(4,12)); |
|
67 | lineseries->append(QPoint(4,12)); | |
68 | lineseries->append(QPoint(5,17)); |
|
68 | lineseries->append(QPoint(5,17)); | |
69 | //![8] |
|
69 | //![8] | |
70 |
|
70 | |||
71 | //![3] |
|
71 | //![3] | |
72 | QChart* chart = new QChart(); |
|
72 | QChart* chart = new QChart(); | |
73 | chart->addSeries(barseries); |
|
73 | chart->addSeries(barseries); | |
74 | chart->addSeries(lineseries); |
|
74 | chart->addSeries(lineseries); | |
75 | chart->setTitle("Line and barchart example"); |
|
75 | chart->setTitle("Line and barchart example"); | |
76 | //![3] |
|
76 | //![3] | |
77 |
|
77 | |||
78 | //![4] |
|
78 | //![4] | |
79 | QStringList categories; |
|
79 | QStringList categories; | |
80 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
80 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
81 | QBarCategoryAxis* axisX = new QBarCategoryAxis(); |
|
81 | QBarCategoryAxis* axisX = new QBarCategoryAxis(); | |
82 | axisX->append(categories); |
|
82 | axisX->append(categories); | |
83 | chart->setAxisX(axisX,lineseries); |
|
83 | chart->setAxisX(axisX,lineseries); | |
84 | chart->setAxisX(axisX,barseries); |
|
84 | chart->setAxisX(axisX,barseries); | |
85 | axisX->setRange(QString("Jan"),QString("Jun")); |
|
85 | axisX->setRange(QString("Jan"),QString("Jun")); | |
86 |
|
86 | |||
87 | QValueAxis* axisY = new QValueAxis(); |
|
87 | QValueAxis* axisY = new QValueAxis(); | |
88 | chart->setAxisY(axisY,lineseries); |
|
88 | chart->setAxisY(axisY,lineseries); | |
89 | chart->setAxisY(axisY,barseries); |
|
89 | chart->setAxisY(axisY,barseries); | |
90 | axisY->setRange(0,20); |
|
90 | axisY->setRange(0,20); | |
91 | //![4] |
|
91 | //![4] | |
92 |
|
92 | |||
93 | //![5] |
|
93 | //![5] | |
94 | chart->legend()->setVisible(true); |
|
94 | chart->legend()->setVisible(true); | |
95 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
95 | chart->legend()->setAlignment(Qt::AlignBottom); | |
96 | //![5] |
|
96 | //![5] | |
97 |
|
97 | |||
98 | //![6] |
|
98 | //![6] | |
99 | QChartView* chartView = new QChartView(chart); |
|
99 | QChartView* chartView = new QChartView(chart); | |
100 | chartView->setRenderHint(QPainter::Antialiasing); |
|
100 | chartView->setRenderHint(QPainter::Antialiasing); | |
101 | //![6] |
|
101 | //![6] | |
102 |
|
102 | |||
103 | //![7] |
|
103 | //![7] | |
104 | QMainWindow window; |
|
104 | QMainWindow window; | |
105 | window.setCentralWidget(chartView); |
|
105 | window.setCentralWidget(chartView); | |
106 | window.resize(400, 300); |
|
106 | window.resize(400, 300); | |
107 | window.show(); |
|
107 | window.show(); | |
108 | //![7] |
|
108 | //![7] | |
109 |
|
109 | |||
110 | return a.exec(); |
|
110 | return a.exec(); | |
111 | } |
|
111 | } |
@@ -1,92 +1,92 | |||||
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 |
#include <QBarCategor |
|
27 | #include <QBarCategoryAxis> | |
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 |
|
34 | |||
35 | //![1] |
|
35 | //![1] | |
36 | QBarSet *set0 = new QBarSet("Jane"); |
|
36 | QBarSet *set0 = new QBarSet("Jane"); | |
37 | QBarSet *set1 = new QBarSet("John"); |
|
37 | QBarSet *set1 = new QBarSet("John"); | |
38 | QBarSet *set2 = new QBarSet("Axel"); |
|
38 | QBarSet *set2 = new QBarSet("Axel"); | |
39 | QBarSet *set3 = new QBarSet("Mary"); |
|
39 | QBarSet *set3 = new QBarSet("Mary"); | |
40 | QBarSet *set4 = new QBarSet("Samantha"); |
|
40 | QBarSet *set4 = new QBarSet("Samantha"); | |
41 |
|
41 | |||
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
47 | //![1] |
|
47 | //![1] | |
48 |
|
48 | |||
49 | //![2] |
|
49 | //![2] | |
50 | QPercentBarSeries* series = new QPercentBarSeries(); |
|
50 | QPercentBarSeries* series = new QPercentBarSeries(); | |
51 | series->append(set0); |
|
51 | series->append(set0); | |
52 | series->append(set1); |
|
52 | series->append(set1); | |
53 | series->append(set2); |
|
53 | series->append(set2); | |
54 | series->append(set3); |
|
54 | series->append(set3); | |
55 | series->append(set4); |
|
55 | series->append(set4); | |
56 | //![2] |
|
56 | //![2] | |
57 |
|
57 | |||
58 | //![3] |
|
58 | //![3] | |
59 | QChart* chart = new QChart(); |
|
59 | QChart* chart = new QChart(); | |
60 | chart->addSeries(series); |
|
60 | chart->addSeries(series); | |
61 | chart->setTitle("Simple percentbarchart example"); |
|
61 | chart->setTitle("Simple percentbarchart example"); | |
62 | //![3] |
|
62 | //![3] | |
63 |
|
63 | |||
64 | //![4] |
|
64 | //![4] | |
65 | QStringList categories; |
|
65 | QStringList categories; | |
66 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
66 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
67 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
67 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
68 | axis->append(categories); |
|
68 | axis->append(categories); | |
69 | chart->createDefaultAxes(); |
|
69 | chart->createDefaultAxes(); | |
70 | chart->setAxisX(axis,series); |
|
70 | chart->setAxisX(axis,series); | |
71 | //![4] |
|
71 | //![4] | |
72 |
|
72 | |||
73 | //![5] |
|
73 | //![5] | |
74 | chart->legend()->setVisible(true); |
|
74 | chart->legend()->setVisible(true); | |
75 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
75 | chart->legend()->setAlignment(Qt::AlignBottom); | |
76 | //![5] |
|
76 | //![5] | |
77 |
|
77 | |||
78 | //![6] |
|
78 | //![6] | |
79 | QChartView* chartView = new QChartView(chart); |
|
79 | QChartView* chartView = new QChartView(chart); | |
80 | chartView->setRenderHint(QPainter::Antialiasing); |
|
80 | chartView->setRenderHint(QPainter::Antialiasing); | |
81 | //![6] |
|
81 | //![6] | |
82 |
|
82 | |||
83 | //![7] |
|
83 | //![7] | |
84 | QMainWindow window; |
|
84 | QMainWindow window; | |
85 | window.setCentralWidget(chartView); |
|
85 | window.setCentralWidget(chartView); | |
86 | window.resize(400, 300); |
|
86 | window.resize(400, 300); | |
87 | window.show(); |
|
87 | window.show(); | |
88 | //![7] |
|
88 | //![7] | |
89 |
|
89 | |||
90 | return a.exec(); |
|
90 | return a.exec(); | |
91 | } |
|
91 | } | |
92 |
|
92 |
@@ -1,93 +1,93 | |||||
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 |
#include <QBarCategor |
|
27 | #include <QBarCategoryAxis> | |
28 | #include <QHorizontalBarSeries> |
|
28 | #include <QHorizontalBarSeries> | |
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 | //![1] |
|
36 | //![1] | |
37 | QBarSet *male = new QBarSet("Male"); |
|
37 | QBarSet *male = new QBarSet("Male"); | |
38 | QBarSet *female = new QBarSet("Female"); |
|
38 | QBarSet *female = new QBarSet("Female"); | |
39 |
|
39 | |||
40 | // From wikipedia |
|
40 | // From wikipedia | |
41 | *male << -145596 << -149894 << -167327 << -164118 << -170710 << -169408 << -158395 << -176975 << -191803 << -191198 << -196815 |
|
41 | *male << -145596 << -149894 << -167327 << -164118 << -170710 << -169408 << -158395 << -176975 << -191803 << -191198 << -196815 | |
42 | << -207826 << -145517 << -113204 << -90986 << -70909 << -40013 << -15887 << -5769; |
|
42 | << -207826 << -145517 << -113204 << -90986 << -70909 << -40013 << -15887 << -5769; | |
43 |
|
43 | |||
44 | *female << 139353 << 143522 << 161212 << 156824 << 163226 << 161766 << 150595 << 170779 << 185979 << 187897 << 196158 |
|
44 | *female << 139353 << 143522 << 161212 << 156824 << 163226 << 161766 << 150595 << 170779 << 185979 << 187897 << 196158 | |
45 | << 209062 << 152460 << 129230 << 114778 << 109611 << 83845 << 44605 << 22328; |
|
45 | << 209062 << 152460 << 129230 << 114778 << 109611 << 83845 << 44605 << 22328; | |
46 |
|
46 | |||
47 | //![1] |
|
47 | //![1] | |
48 |
|
48 | |||
49 | //![2] |
|
49 | //![2] | |
50 | QHorizontalBarSeries *series = new QHorizontalBarSeries(); |
|
50 | QHorizontalBarSeries *series = new QHorizontalBarSeries(); | |
51 | series->append(male); |
|
51 | series->append(male); | |
52 | series->append(female); |
|
52 | series->append(female); | |
53 | series->setBarWidth(0.5); |
|
53 | series->setBarWidth(0.5); | |
54 | series->setGrouping(false); |
|
54 | series->setGrouping(false); | |
55 | //![2] |
|
55 | //![2] | |
56 |
|
56 | |||
57 | //![3] |
|
57 | //![3] | |
58 | QChart* chart = new QChart(); |
|
58 | QChart* chart = new QChart(); | |
59 | chart->addSeries(series); |
|
59 | chart->addSeries(series); | |
60 | chart->setTitle("Population of Finland in 2005 by age group"); |
|
60 | chart->setTitle("Population of Finland in 2005 by age group"); | |
61 | chart->createDefaultAxes(); |
|
61 | chart->createDefaultAxes(); | |
62 | chart->setAnimationOptions(QChart::SeriesAnimations); |
|
62 | chart->setAnimationOptions(QChart::SeriesAnimations); | |
63 | //![3] |
|
63 | //![3] | |
64 |
|
64 | |||
65 | //![4] |
|
65 | //![4] | |
66 | QStringList categories; |
|
66 | QStringList categories; | |
67 | categories << "0-4" << "5-9" << "10-14" << "15-19" << "20-24" << "25-29" << "30-34" << "35-39" << "40-44" << "45-49" |
|
67 | categories << "0-4" << "5-9" << "10-14" << "15-19" << "20-24" << "25-29" << "30-34" << "35-39" << "40-44" << "45-49" | |
68 | << "50-54" << "55-59" << "60-64" << "65-69" << "70-74" << "75-79" << "80-84" << "85-89" << "90-"; |
|
68 | << "50-54" << "55-59" << "60-64" << "65-69" << "70-74" << "75-79" << "80-84" << "85-89" << "90-"; | |
69 |
|
69 | |||
70 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
70 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
71 | axis->append(categories); |
|
71 | axis->append(categories); | |
72 | chart->setAxisY(axis,series); |
|
72 | chart->setAxisY(axis,series); | |
73 | //![4] |
|
73 | //![4] | |
74 |
|
74 | |||
75 | //![5] |
|
75 | //![5] | |
76 | chart->legend()->setVisible(true); |
|
76 | chart->legend()->setVisible(true); | |
77 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
77 | chart->legend()->setAlignment(Qt::AlignBottom); | |
78 | //![5] |
|
78 | //![5] | |
79 |
|
79 | |||
80 | //![6] |
|
80 | //![6] | |
81 | QChartView* chartView = new QChartView(chart); |
|
81 | QChartView* chartView = new QChartView(chart); | |
82 | chartView->setRenderHint(QPainter::Antialiasing); |
|
82 | chartView->setRenderHint(QPainter::Antialiasing); | |
83 | //![6] |
|
83 | //![6] | |
84 |
|
84 | |||
85 | //![7] |
|
85 | //![7] | |
86 | QMainWindow window; |
|
86 | QMainWindow window; | |
87 | window.setCentralWidget(chartView); |
|
87 | window.setCentralWidget(chartView); | |
88 | window.resize(400, 800); |
|
88 | window.resize(400, 800); | |
89 | window.show(); |
|
89 | window.show(); | |
90 | //![7] |
|
90 | //![7] | |
91 |
|
91 | |||
92 | return a.exec(); |
|
92 | return a.exec(); | |
93 | } |
|
93 | } |
@@ -1,89 +1,89 | |||||
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 "chart.h" |
|
21 | #include "chart.h" | |
22 | #include "chartview.h" |
|
22 | #include "chartview.h" | |
23 | #include <QApplication> |
|
23 | #include <QApplication> | |
24 | #include <QMainWindow> |
|
24 | #include <QMainWindow> | |
25 | #include <qmath.h> |
|
25 | #include <qmath.h> | |
26 | #include <QBarSeries> |
|
26 | #include <QBarSeries> | |
27 | #include <QBarSet> |
|
27 | #include <QBarSet> | |
28 |
#include <QBarCategor |
|
28 | #include <QBarCategoryAxis> | |
29 | #include <QLineSeries> |
|
29 | #include <QLineSeries> | |
30 | #include <QHorizontalBarSeries> |
|
30 | #include <QHorizontalBarSeries> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
32 | QTCOMMERCIALCHART_USE_NAMESPACE | |
33 |
|
33 | |||
34 | int main(int argc, char *argv[]) |
|
34 | int main(int argc, char *argv[]) | |
35 | { |
|
35 | { | |
36 | QApplication a(argc, argv); |
|
36 | QApplication a(argc, argv); | |
37 |
|
37 | |||
38 | QLineSeries* series = new QLineSeries(); |
|
38 | QLineSeries* series = new QLineSeries(); | |
39 | for (int i = 0; i < 500; i++) { |
|
39 | for (int i = 0; i < 500; i++) { | |
40 | QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100); |
|
40 | QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100); | |
41 | p.ry() += qrand() % 20; |
|
41 | p.ry() += qrand() % 20; | |
42 | *series << p; |
|
42 | *series << p; | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | QBarSet *set0 = new QBarSet("Jane"); |
|
45 | QBarSet *set0 = new QBarSet("Jane"); | |
46 | QBarSet *set1 = new QBarSet("John"); |
|
46 | QBarSet *set1 = new QBarSet("John"); | |
47 | QBarSet *set2 = new QBarSet("Axel"); |
|
47 | QBarSet *set2 = new QBarSet("Axel"); | |
48 | QBarSet *set3 = new QBarSet("Mary"); |
|
48 | QBarSet *set3 = new QBarSet("Mary"); | |
49 | QBarSet *set4 = new QBarSet("Samantha"); |
|
49 | QBarSet *set4 = new QBarSet("Samantha"); | |
50 |
|
50 | |||
51 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
51 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
52 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
52 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
53 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
53 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
54 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
54 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
55 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
55 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
56 |
|
56 | |||
57 | //QHorizontalBarSeries* series2 = new QHorizontalBarSeries(); |
|
57 | //QHorizontalBarSeries* series2 = new QHorizontalBarSeries(); | |
58 | QBarSeries* series2 = new QBarSeries(); |
|
58 | QBarSeries* series2 = new QBarSeries(); | |
59 | series2->append(set0); |
|
59 | series2->append(set0); | |
60 | series2->append(set1); |
|
60 | series2->append(set1); | |
61 | series2->append(set2); |
|
61 | series2->append(set2); | |
62 | series2->append(set3); |
|
62 | series2->append(set3); | |
63 | series2->append(set4); |
|
63 | series2->append(set4); | |
64 |
|
64 | |||
65 | Chart* chart = new Chart(); |
|
65 | Chart* chart = new Chart(); | |
66 | // chart->addSeries(series); |
|
66 | // chart->addSeries(series); | |
67 | chart->addSeries(series2); |
|
67 | chart->addSeries(series2); | |
68 | chart->setTitle("Scroll in/out example"); |
|
68 | chart->setTitle("Scroll in/out example"); | |
69 | chart->legend()->hide(); |
|
69 | chart->legend()->hide(); | |
70 | chart->createDefaultAxes(); |
|
70 | chart->createDefaultAxes(); | |
71 |
|
71 | |||
72 | QStringList categories; |
|
72 | QStringList categories; | |
73 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
73 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
74 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
74 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
75 | axis->append(categories); |
|
75 | axis->append(categories); | |
76 | chart->setAxisX(axis, series2); |
|
76 | chart->setAxisX(axis, series2); | |
77 |
|
77 | |||
78 | ChartView* chartView = new ChartView(chart); |
|
78 | ChartView* chartView = new ChartView(chart); | |
79 | chartView->setRenderHint(QPainter::Antialiasing); |
|
79 | chartView->setRenderHint(QPainter::Antialiasing); | |
80 |
|
80 | |||
81 | QMainWindow window; |
|
81 | QMainWindow window; | |
82 | window.setCentralWidget(chartView); |
|
82 | window.setCentralWidget(chartView); | |
83 | window.resize(400, 300); |
|
83 | window.resize(400, 300); | |
84 | window.grabGesture(Qt::PanGesture); |
|
84 | window.grabGesture(Qt::PanGesture); | |
85 | window.grabGesture(Qt::PinchGesture); |
|
85 | window.grabGesture(Qt::PinchGesture); | |
86 | window.show(); |
|
86 | window.show(); | |
87 |
|
87 | |||
88 | return a.exec(); |
|
88 | return a.exec(); | |
89 | } |
|
89 | } |
@@ -1,92 +1,92 | |||||
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 |
#include <QBarCategor |
|
27 | #include <QBarCategoryAxis> | |
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 |
|
34 | |||
35 | //![1] |
|
35 | //![1] | |
36 | QBarSet *set0 = new QBarSet("Jane"); |
|
36 | QBarSet *set0 = new QBarSet("Jane"); | |
37 | QBarSet *set1 = new QBarSet("John"); |
|
37 | QBarSet *set1 = new QBarSet("John"); | |
38 | QBarSet *set2 = new QBarSet("Axel"); |
|
38 | QBarSet *set2 = new QBarSet("Axel"); | |
39 | QBarSet *set3 = new QBarSet("Mary"); |
|
39 | QBarSet *set3 = new QBarSet("Mary"); | |
40 | QBarSet *set4 = new QBarSet("Samantha"); |
|
40 | QBarSet *set4 = new QBarSet("Samantha"); | |
41 |
|
41 | |||
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
47 | //![1] |
|
47 | //![1] | |
48 |
|
48 | |||
49 | //![2] |
|
49 | //![2] | |
50 | QStackedBarSeries* series = new QStackedBarSeries(); |
|
50 | QStackedBarSeries* series = new QStackedBarSeries(); | |
51 | series->append(set0); |
|
51 | series->append(set0); | |
52 | series->append(set1); |
|
52 | series->append(set1); | |
53 | series->append(set2); |
|
53 | series->append(set2); | |
54 | series->append(set3); |
|
54 | series->append(set3); | |
55 | series->append(set4); |
|
55 | series->append(set4); | |
56 | //![2] |
|
56 | //![2] | |
57 |
|
57 | |||
58 | //![3] |
|
58 | //![3] | |
59 | QChart* chart = new QChart(); |
|
59 | QChart* chart = new QChart(); | |
60 | chart->addSeries(series); |
|
60 | chart->addSeries(series); | |
61 | chart->setTitle("Simple stackedbarchart example"); |
|
61 | chart->setTitle("Simple stackedbarchart example"); | |
62 | chart->createDefaultAxes(); |
|
62 | chart->createDefaultAxes(); | |
63 | //![3] |
|
63 | //![3] | |
64 |
|
64 | |||
65 | //![4] |
|
65 | //![4] | |
66 | QStringList categories; |
|
66 | QStringList categories; | |
67 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
67 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
68 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
68 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
69 | axis->append(categories); |
|
69 | axis->append(categories); | |
70 | chart->setAxisX(axis,series); |
|
70 | chart->setAxisX(axis,series); | |
71 | //![4] |
|
71 | //![4] | |
72 |
|
72 | |||
73 | //![5] |
|
73 | //![5] | |
74 | chart->legend()->setVisible(true); |
|
74 | chart->legend()->setVisible(true); | |
75 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
75 | chart->legend()->setAlignment(Qt::AlignBottom); | |
76 | //![5] |
|
76 | //![5] | |
77 |
|
77 | |||
78 | //![6] |
|
78 | //![6] | |
79 | QChartView* chartView = new QChartView(chart); |
|
79 | QChartView* chartView = new QChartView(chart); | |
80 | chartView->setRenderHint(QPainter::Antialiasing); |
|
80 | chartView->setRenderHint(QPainter::Antialiasing); | |
81 | //![6] |
|
81 | //![6] | |
82 |
|
82 | |||
83 | //![7] |
|
83 | //![7] | |
84 | QMainWindow window; |
|
84 | QMainWindow window; | |
85 | window.setCentralWidget(chartView); |
|
85 | window.setCentralWidget(chartView); | |
86 | window.resize(400, 300); |
|
86 | window.resize(400, 300); | |
87 | window.show(); |
|
87 | window.show(); | |
88 | //![7] |
|
88 | //![7] | |
89 |
|
89 | |||
90 | return a.exec(); |
|
90 | return a.exec(); | |
91 | } |
|
91 | } | |
92 |
|
92 |
@@ -1,59 +1,59 | |||||
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 <QBarCategor |
|
22 | #include <QBarCategoryAxis> | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
24 | QTCOMMERCIALCHART_USE_NAMESPACE | |
25 |
|
25 | |||
26 | DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
26 | DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
27 | : QChart(parent, wFlags) |
|
27 | : QChart(parent, wFlags) | |
28 | ,m_currentSeries(0) |
|
28 | ,m_currentSeries(0) | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | void DrilldownChart::changeSeries(DrilldownBarSeries *series) |
|
32 | void DrilldownChart::changeSeries(DrilldownBarSeries *series) | |
33 | { |
|
33 | { | |
34 | if (m_currentSeries) { |
|
34 | if (m_currentSeries) { | |
35 | removeSeries(m_currentSeries); |
|
35 | removeSeries(m_currentSeries); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | m_currentSeries = series; |
|
38 | m_currentSeries = series; | |
39 |
|
39 | |||
40 | // Reset axis |
|
40 | // Reset axis | |
41 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
41 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
42 | axis->append(m_currentSeries->categories()); |
|
42 | axis->append(m_currentSeries->categories()); | |
43 |
|
43 | |||
44 | addSeries(series); |
|
44 | addSeries(series); | |
45 |
|
45 | |||
46 | createDefaultAxes(); |
|
46 | createDefaultAxes(); | |
47 | setAxisX(axis,series); |
|
47 | setAxisX(axis,series); | |
48 |
|
48 | |||
49 | setTitle(series->name()); |
|
49 | setTitle(series->name()); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void DrilldownChart::handleClicked(int index, QBarSet *barset) |
|
52 | void DrilldownChart::handleClicked(int index, QBarSet *barset) | |
53 | { |
|
53 | { | |
54 | Q_UNUSED(barset) |
|
54 | Q_UNUSED(barset) | |
55 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); |
|
55 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); | |
56 | changeSeries(series->drilldownSeries(index)); |
|
56 | changeSeries(series->drilldownSeries(index)); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | #include "moc_drilldownchart.cpp" |
|
59 | #include "moc_drilldownchart.cpp" |
@@ -1,471 +1,471 | |||||
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 "qbarcategoriesaxis.h" |
|
21 | #include "qbarcategoriesaxis.h" | |
22 | #include "qbarcategoriesaxis_p.h" |
|
22 | #include "qbarcategoriesaxis_p.h" | |
23 | #include "chartcategoriesaxisx_p.h" |
|
23 | #include "chartcategoriesaxisx_p.h" | |
24 | #include "chartcategoriesaxisy_p.h" |
|
24 | #include "chartcategoriesaxisy_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | /*! |
|
30 | /*! | |
31 |
\class QBarCategor |
|
31 | \class QBarCategoryAxis | |
32 |
\brief The QBarCategor |
|
32 | \brief The QBarCategoryAxis class is used for manipulating chart's axis. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades. | |
36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. | |
37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. |
|
37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 |
\qmlclass BarCategoriesAxis QBarCategor |
|
41 | \qmlclass BarCategoriesAxis QBarCategoryAxis | |
42 | \brief The Axis element is used for manipulating chart's axes. |
|
42 | \brief The Axis element is used for manipulating chart's axes. | |
43 |
|
43 | |||
44 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
44 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
45 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
45 | Categories are drawn between ticks. Note that you can use this also with lineseries too. | |
46 |
|
46 | |||
47 | To access BarCategoriesAxis you can use ChartView API. For example: |
|
47 | To access BarCategoriesAxis you can use ChartView API. For example: | |
48 | \code |
|
48 | \code | |
49 | ChartView { |
|
49 | ChartView { | |
50 | BarCategoriesAxis { |
|
50 | BarCategoriesAxis { | |
51 | id: categoryAxis |
|
51 | id: categoryAxis | |
52 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] |
|
52 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] | |
53 | } |
|
53 | } | |
54 | // Add a few series... |
|
54 | // Add a few series... | |
55 | } |
|
55 | } | |
56 | \endcode |
|
56 | \endcode | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 |
\property QBarCategor |
|
60 | \property QBarCategoryAxis::categories | |
61 | Defines the categories of axis |
|
61 | Defines the categories of axis | |
62 | */ |
|
62 | */ | |
63 | /*! |
|
63 | /*! | |
64 | \qmlproperty QStringList BarCategoriesAxis::categories |
|
64 | \qmlproperty QStringList BarCategoriesAxis::categories | |
65 | Defines the categories of axis |
|
65 | Defines the categories of axis | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 |
\property QBarCategor |
|
69 | \property QBarCategoryAxis::min | |
70 | Defines the minimum value on the axis. |
|
70 | Defines the minimum value on the axis. | |
71 | */ |
|
71 | */ | |
72 | /*! |
|
72 | /*! | |
73 | \qmlproperty QString BarCategoriesAxis::min |
|
73 | \qmlproperty QString BarCategoriesAxis::min | |
74 | Defines the minimum value on the axis. |
|
74 | Defines the minimum value on the axis. | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 |
\property QBarCategor |
|
78 | \property QBarCategoryAxis::max | |
79 | Defines the maximum value on the axis. |
|
79 | Defines the maximum value on the axis. | |
80 | */ |
|
80 | */ | |
81 | /*! |
|
81 | /*! | |
82 | \qmlproperty QString BarCategoriesAxis::max |
|
82 | \qmlproperty QString BarCategoriesAxis::max | |
83 | Defines the maximum value on the axis. |
|
83 | Defines the maximum value on the axis. | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 |
\fn void QBarCategor |
|
88 | \fn void QBarCategoryAxis::categoriesChanged() | |
89 | Axis emits signal when the categories of the axis has changed. |
|
89 | Axis emits signal when the categories of the axis has changed. | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 |
\fn void QBarCategor |
|
92 | \fn void QBarCategoryAxis::minChanged(const QString &min) | |
93 | Axis emits signal when \a min of axis has changed. |
|
93 | Axis emits signal when \a min of axis has changed. | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min) |
|
96 | \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min) | |
97 | Axis emits signal when \a min of axis has changed. |
|
97 | Axis emits signal when \a min of axis has changed. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 |
\fn void QBarCategor |
|
101 | \fn void QBarCategoryAxis::maxChanged(const QString &max) | |
102 | Axis emits signal when \a max of axis has changed. |
|
102 | Axis emits signal when \a max of axis has changed. | |
103 | */ |
|
103 | */ | |
104 | /*! |
|
104 | /*! | |
105 | \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max) |
|
105 | \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max) | |
106 | Axis emits signal when \a max of axis has changed. |
|
106 | Axis emits signal when \a max of axis has changed. | |
107 | */ |
|
107 | */ | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 |
\fn void QBarCategor |
|
110 | \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max) | |
111 | Axis emits signal when \a min or \a max of axis has changed. |
|
111 | Axis emits signal when \a min or \a max of axis has changed. | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | Constructs an axis object which is a child of \a parent. |
|
115 | Constructs an axis object which is a child of \a parent. | |
116 | */ |
|
116 | */ | |
117 | QBarCategoryAxis::QBarCategoryAxis(QObject *parent): |
|
117 | QBarCategoryAxis::QBarCategoryAxis(QObject *parent): | |
118 | QAbstractAxis(*new QBarCategoryAxisPrivate(this),parent) |
|
118 | QAbstractAxis(*new QBarCategoryAxisPrivate(this),parent) | |
119 | { |
|
119 | { | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | Destroys the object |
|
123 | Destroys the object | |
124 | */ |
|
124 | */ | |
125 | QBarCategoryAxis::~QBarCategoryAxis() |
|
125 | QBarCategoryAxis::~QBarCategoryAxis() | |
126 | { |
|
126 | { | |
127 | Q_D(QBarCategoryAxis); |
|
127 | Q_D(QBarCategoryAxis); | |
128 | if(d->m_dataset){ |
|
128 | if(d->m_dataset){ | |
129 | d->m_dataset->removeAxis(this); |
|
129 | d->m_dataset->removeAxis(this); | |
130 | } |
|
130 | } | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \internal |
|
134 | \internal | |
135 | */ |
|
135 | */ | |
136 | QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) |
|
136 | QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) | |
137 | { |
|
137 | { | |
138 |
|
138 | |||
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | /*! |
|
141 | /*! | |
142 | Appends \a categories to axis |
|
142 | Appends \a categories to axis | |
143 | */ |
|
143 | */ | |
144 | void QBarCategoryAxis::append(const QStringList &categories) |
|
144 | void QBarCategoryAxis::append(const QStringList &categories) | |
145 | { |
|
145 | { | |
146 | if(categories.isEmpty()) return; |
|
146 | if(categories.isEmpty()) return; | |
147 |
|
147 | |||
148 | Q_D(QBarCategoryAxis); |
|
148 | Q_D(QBarCategoryAxis); | |
149 | if (d->m_categories.isEmpty()) { |
|
149 | if (d->m_categories.isEmpty()) { | |
150 | d->m_categories.append(categories); |
|
150 | d->m_categories.append(categories); | |
151 | setRange(categories.first(),categories.last()); |
|
151 | setRange(categories.first(),categories.last()); | |
152 | }else{ |
|
152 | }else{ | |
153 | d->m_categories.append(categories); |
|
153 | d->m_categories.append(categories); | |
154 | d->emitUpdated(); |
|
154 | d->emitUpdated(); | |
155 | } |
|
155 | } | |
156 | emit categoriesChanged(); |
|
156 | emit categoriesChanged(); | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | Appends \a category to axis |
|
160 | Appends \a category to axis | |
161 | */ |
|
161 | */ | |
162 | void QBarCategoryAxis::append(const QString &category) |
|
162 | void QBarCategoryAxis::append(const QString &category) | |
163 | { |
|
163 | { | |
164 | Q_D(QBarCategoryAxis); |
|
164 | Q_D(QBarCategoryAxis); | |
165 | if (d->m_categories.isEmpty()) { |
|
165 | if (d->m_categories.isEmpty()) { | |
166 | d->m_categories.append(category); |
|
166 | d->m_categories.append(category); | |
167 | setRange(category,category); |
|
167 | setRange(category,category); | |
168 | }else{ |
|
168 | }else{ | |
169 | d->m_categories.append(category); |
|
169 | d->m_categories.append(category); | |
170 | d->emitUpdated(); |
|
170 | d->emitUpdated(); | |
171 | } |
|
171 | } | |
172 | emit categoriesChanged(); |
|
172 | emit categoriesChanged(); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | /*! |
|
175 | /*! | |
176 | Removes \a category from axis |
|
176 | Removes \a category from axis | |
177 | */ |
|
177 | */ | |
178 | void QBarCategoryAxis::remove(const QString &category) |
|
178 | void QBarCategoryAxis::remove(const QString &category) | |
179 | { |
|
179 | { | |
180 | Q_D(QBarCategoryAxis); |
|
180 | Q_D(QBarCategoryAxis); | |
181 | if (d->m_categories.contains(category)) { |
|
181 | if (d->m_categories.contains(category)) { | |
182 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
182 | d->m_categories.removeAt(d->m_categories.indexOf(category)); | |
183 | if(!d->m_categories.isEmpty()) |
|
183 | if(!d->m_categories.isEmpty()) | |
184 | setRange(d->m_categories.first(),d->m_categories.last()); |
|
184 | setRange(d->m_categories.first(),d->m_categories.last()); | |
185 | else |
|
185 | else | |
186 | setRange(QString::null,QString::null); |
|
186 | setRange(QString::null,QString::null); | |
187 | emit categoriesChanged(); |
|
187 | emit categoriesChanged(); | |
188 | } |
|
188 | } | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | Inserts \a category to axis at \a index |
|
192 | Inserts \a category to axis at \a index | |
193 | */ |
|
193 | */ | |
194 | void QBarCategoryAxis::insert(int index, const QString &category) |
|
194 | void QBarCategoryAxis::insert(int index, const QString &category) | |
195 | { |
|
195 | { | |
196 | Q_D(QBarCategoryAxis); |
|
196 | Q_D(QBarCategoryAxis); | |
197 | if (d->m_categories.isEmpty()) { |
|
197 | if (d->m_categories.isEmpty()) { | |
198 | d->m_categories.insert(index,category); |
|
198 | d->m_categories.insert(index,category); | |
199 | setRange(category,category); |
|
199 | setRange(category,category); | |
200 | }else{ |
|
200 | }else{ | |
201 | d->m_categories.insert(index,category); |
|
201 | d->m_categories.insert(index,category); | |
202 | d->emitUpdated(); |
|
202 | d->emitUpdated(); | |
203 | } |
|
203 | } | |
204 | emit categoriesChanged(); |
|
204 | emit categoriesChanged(); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | /*! |
|
207 | /*! | |
208 | Replaces \a oldCategory with \a newCategory. |
|
208 | Replaces \a oldCategory with \a newCategory. | |
209 | If \a oldCategory does not exits on the axis nothing is done. |
|
209 | If \a oldCategory does not exits on the axis nothing is done. | |
210 | */ |
|
210 | */ | |
211 | void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory) |
|
211 | void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory) | |
212 | { |
|
212 | { | |
213 | Q_D(QBarCategoryAxis); |
|
213 | Q_D(QBarCategoryAxis); | |
214 | int pos = d->m_categories.indexOf(oldCategory); |
|
214 | int pos = d->m_categories.indexOf(oldCategory); | |
215 | if (pos != -1) { |
|
215 | if (pos != -1) { | |
216 | d->m_categories.replace(pos, newCategory); |
|
216 | d->m_categories.replace(pos, newCategory); | |
217 | d->emitUpdated(); |
|
217 | d->emitUpdated(); | |
218 | emit categoriesChanged(); |
|
218 | emit categoriesChanged(); | |
219 | } |
|
219 | } | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | Removes all categories. |
|
223 | Removes all categories. | |
224 | */ |
|
224 | */ | |
225 | void QBarCategoryAxis::clear() |
|
225 | void QBarCategoryAxis::clear() | |
226 | { |
|
226 | { | |
227 | Q_D(QBarCategoryAxis); |
|
227 | Q_D(QBarCategoryAxis); | |
228 | d->m_categories.clear(); |
|
228 | d->m_categories.clear(); | |
229 | setRange(QString::null,QString::null); |
|
229 | setRange(QString::null,QString::null); | |
230 | emit categoriesChanged(); |
|
230 | emit categoriesChanged(); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | void QBarCategoryAxis::setCategories(const QStringList &categories) |
|
233 | void QBarCategoryAxis::setCategories(const QStringList &categories) | |
234 | { |
|
234 | { | |
235 | Q_D(QBarCategoryAxis); |
|
235 | Q_D(QBarCategoryAxis); | |
236 | if(d->m_categories!=categories) { |
|
236 | if(d->m_categories!=categories) { | |
237 | d->m_categories = categories; |
|
237 | d->m_categories = categories; | |
238 | setRange(categories.first(),categories.last()); |
|
238 | setRange(categories.first(),categories.last()); | |
239 | emit categoriesChanged(); |
|
239 | emit categoriesChanged(); | |
240 | } |
|
240 | } | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | QStringList QBarCategoryAxis::categories() |
|
243 | QStringList QBarCategoryAxis::categories() | |
244 | { |
|
244 | { | |
245 | Q_D(QBarCategoryAxis); |
|
245 | Q_D(QBarCategoryAxis); | |
246 | return d->m_categories; |
|
246 | return d->m_categories; | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | /*! |
|
249 | /*! | |
250 | Returns number of categories. |
|
250 | Returns number of categories. | |
251 | */ |
|
251 | */ | |
252 | int QBarCategoryAxis::count() const |
|
252 | int QBarCategoryAxis::count() const | |
253 | { |
|
253 | { | |
254 | Q_D(const QBarCategoryAxis); |
|
254 | Q_D(const QBarCategoryAxis); | |
255 | return d->m_categories.count(); |
|
255 | return d->m_categories.count(); | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | /*! |
|
258 | /*! | |
259 | Returns category at \a index. Index must be valid. |
|
259 | Returns category at \a index. Index must be valid. | |
260 | */ |
|
260 | */ | |
261 | QString QBarCategoryAxis::at(int index) const |
|
261 | QString QBarCategoryAxis::at(int index) const | |
262 | { |
|
262 | { | |
263 | Q_D(const QBarCategoryAxis); |
|
263 | Q_D(const QBarCategoryAxis); | |
264 | return d->m_categories.at(index); |
|
264 | return d->m_categories.at(index); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | /*! |
|
267 | /*! | |
268 | Sets minimum category to \a min. |
|
268 | Sets minimum category to \a min. | |
269 | */ |
|
269 | */ | |
270 | void QBarCategoryAxis::setMin(const QString& min) |
|
270 | void QBarCategoryAxis::setMin(const QString& min) | |
271 | { |
|
271 | { | |
272 | Q_D(QBarCategoryAxis); |
|
272 | Q_D(QBarCategoryAxis); | |
273 | setRange(min,d->m_maxCategory); |
|
273 | setRange(min,d->m_maxCategory); | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | /*! |
|
276 | /*! | |
277 | Returns minimum category. |
|
277 | Returns minimum category. | |
278 | */ |
|
278 | */ | |
279 | QString QBarCategoryAxis::min() const |
|
279 | QString QBarCategoryAxis::min() const | |
280 | { |
|
280 | { | |
281 | Q_D(const QBarCategoryAxis); |
|
281 | Q_D(const QBarCategoryAxis); | |
282 | return d->m_minCategory; |
|
282 | return d->m_minCategory; | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | /*! |
|
285 | /*! | |
286 | Sets maximum category to \a max. |
|
286 | Sets maximum category to \a max. | |
287 | */ |
|
287 | */ | |
288 | void QBarCategoryAxis::setMax(const QString& max) |
|
288 | void QBarCategoryAxis::setMax(const QString& max) | |
289 | { |
|
289 | { | |
290 | Q_D(QBarCategoryAxis); |
|
290 | Q_D(QBarCategoryAxis); | |
291 | setRange(d->m_minCategory,max); |
|
291 | setRange(d->m_minCategory,max); | |
292 | } |
|
292 | } | |
293 |
|
293 | |||
294 | /*! |
|
294 | /*! | |
295 | Returns maximum category |
|
295 | Returns maximum category | |
296 | */ |
|
296 | */ | |
297 | QString QBarCategoryAxis::max() const |
|
297 | QString QBarCategoryAxis::max() const | |
298 | { |
|
298 | { | |
299 | Q_D(const QBarCategoryAxis); |
|
299 | Q_D(const QBarCategoryAxis); | |
300 | return d->m_maxCategory; |
|
300 | return d->m_maxCategory; | |
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | /*! |
|
303 | /*! | |
304 | Sets range from \a minCategory to \a maxCategory |
|
304 | Sets range from \a minCategory to \a maxCategory | |
305 | */ |
|
305 | */ | |
306 | void QBarCategoryAxis::setRange(const QString& minCategory, const QString& maxCategory) |
|
306 | void QBarCategoryAxis::setRange(const QString& minCategory, const QString& maxCategory) | |
307 | { |
|
307 | { | |
308 | Q_D(QBarCategoryAxis); |
|
308 | Q_D(QBarCategoryAxis); | |
309 |
|
309 | |||
310 | bool changed = false; |
|
310 | bool changed = false; | |
311 |
|
311 | |||
312 | //special case |
|
312 | //special case | |
313 | if(minCategory.isNull() && maxCategory.isNull()){ |
|
313 | if(minCategory.isNull() && maxCategory.isNull()){ | |
314 | d->m_minCategory = minCategory; |
|
314 | d->m_minCategory = minCategory; | |
315 | d->m_maxCategory = maxCategory; |
|
315 | d->m_maxCategory = maxCategory; | |
316 | d->m_min = 0; |
|
316 | d->m_min = 0; | |
317 | d->m_max = 0; |
|
317 | d->m_max = 0; | |
318 | emit minChanged(minCategory); |
|
318 | emit minChanged(minCategory); | |
319 | emit maxChanged(maxCategory); |
|
319 | emit maxChanged(maxCategory); | |
320 | d->m_count=0; |
|
320 | d->m_count=0; | |
321 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); |
|
321 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); | |
322 | d->emitUpdated(); |
|
322 | d->emitUpdated(); | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return; |
|
325 | if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return; | |
326 |
|
326 | |||
327 | if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) { |
|
327 | if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) { | |
328 | d->m_minCategory = minCategory; |
|
328 | d->m_minCategory = minCategory; | |
329 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; |
|
329 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; | |
330 | changed = true; |
|
330 | changed = true; | |
331 | emit minChanged(minCategory); |
|
331 | emit minChanged(minCategory); | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) { |
|
334 | if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) { | |
335 | d->m_maxCategory = maxCategory; |
|
335 | d->m_maxCategory = maxCategory; | |
336 | d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5; |
|
336 | d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5; | |
337 | changed = true; |
|
337 | changed = true; | |
338 | emit maxChanged(maxCategory); |
|
338 | emit maxChanged(maxCategory); | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | if (changed) { |
|
341 | if (changed) { | |
342 | d->m_count=d->m_max - d->m_min; |
|
342 | d->m_count=d->m_max - d->m_min; | |
343 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); |
|
343 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); | |
344 | d->emitUpdated(); |
|
344 | d->emitUpdated(); | |
345 | } |
|
345 | } | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | /*! |
|
348 | /*! | |
349 | Returns the type of the axis |
|
349 | Returns the type of the axis | |
350 | */ |
|
350 | */ | |
351 | QAbstractAxis::AxisType QBarCategoryAxis::type() const |
|
351 | QAbstractAxis::AxisType QBarCategoryAxis::type() const | |
352 | { |
|
352 | { | |
353 | return AxisTypeCategories; |
|
353 | return AxisTypeCategories; | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
356 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
357 |
|
357 | |||
358 | QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis* q): |
|
358 | QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis* q): | |
359 | QAbstractAxisPrivate(q), |
|
359 | QAbstractAxisPrivate(q), | |
360 | m_min(0.0), |
|
360 | m_min(0.0), | |
361 | m_max(0.0), |
|
361 | m_max(0.0), | |
362 | m_count(0) |
|
362 | m_count(0) | |
363 | { |
|
363 | { | |
364 |
|
364 | |||
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate() |
|
367 | QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate() | |
368 | { |
|
368 | { | |
369 |
|
369 | |||
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | void QBarCategoryAxisPrivate::setMin(const QVariant &min) |
|
372 | void QBarCategoryAxisPrivate::setMin(const QVariant &min) | |
373 | { |
|
373 | { | |
374 | setRange(min,m_maxCategory); |
|
374 | setRange(min,m_maxCategory); | |
375 | } |
|
375 | } | |
376 |
|
376 | |||
377 | void QBarCategoryAxisPrivate::setMax(const QVariant &max) |
|
377 | void QBarCategoryAxisPrivate::setMax(const QVariant &max) | |
378 | { |
|
378 | { | |
379 | setRange(m_minCategory,max); |
|
379 | setRange(m_minCategory,max); | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
382 | void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
383 | { |
|
383 | { | |
384 | Q_Q(QBarCategoryAxis); |
|
384 | Q_Q(QBarCategoryAxis); | |
385 | QString value1 = min.toString(); |
|
385 | QString value1 = min.toString(); | |
386 | QString value2 = max.toString(); |
|
386 | QString value2 = max.toString(); | |
387 | q->setRange(value1,value2); |
|
387 | q->setRange(value1,value2); | |
388 | } |
|
388 | } | |
389 |
|
389 | |||
390 | void QBarCategoryAxisPrivate::handleDomainUpdated() |
|
390 | void QBarCategoryAxisPrivate::handleDomainUpdated() | |
391 | { |
|
391 | { | |
392 | Q_Q(QBarCategoryAxis); |
|
392 | Q_Q(QBarCategoryAxis); | |
393 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
393 | Domain* domain = qobject_cast<Domain*>(sender()); | |
394 |
|
394 | |||
395 | if(m_orientation==Qt::Horizontal) { |
|
395 | if(m_orientation==Qt::Horizontal) { | |
396 | m_min = domain->minX(); |
|
396 | m_min = domain->minX(); | |
397 | m_max = domain->maxX(); |
|
397 | m_max = domain->maxX(); | |
398 | } |
|
398 | } | |
399 | else if(m_orientation==Qt::Vertical) { |
|
399 | else if(m_orientation==Qt::Vertical) { | |
400 | m_min = domain->minY(); |
|
400 | m_min = domain->minY(); | |
401 | m_max = domain->maxY(); |
|
401 | m_max = domain->maxY(); | |
402 | } |
|
402 | } | |
403 |
|
403 | |||
404 | bool changed = false; |
|
404 | bool changed = false; | |
405 |
|
405 | |||
406 | int min = m_min + 0.5; |
|
406 | int min = m_min + 0.5; | |
407 | if(min>=0 && min<m_categories.count()) { |
|
407 | if(min>=0 && min<m_categories.count()) { | |
408 | QString minCategory = m_categories.at(min); |
|
408 | QString minCategory = m_categories.at(min); | |
409 | if(m_minCategory!=minCategory && !minCategory.isEmpty()) { |
|
409 | if(m_minCategory!=minCategory && !minCategory.isEmpty()) { | |
410 | m_minCategory=minCategory; |
|
410 | m_minCategory=minCategory; | |
411 | changed=true; |
|
411 | changed=true; | |
412 | emit q->minChanged(minCategory); |
|
412 | emit q->minChanged(minCategory); | |
413 | } |
|
413 | } | |
414 | } |
|
414 | } | |
415 | int max = m_max - 0.5; |
|
415 | int max = m_max - 0.5; | |
416 | if(max>=0 && max<m_categories.count()) { |
|
416 | if(max>=0 && max<m_categories.count()) { | |
417 | QString maxCategory = m_categories.at(max); |
|
417 | QString maxCategory = m_categories.at(max); | |
418 | if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) { |
|
418 | if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) { | |
419 | m_maxCategory=maxCategory; |
|
419 | m_maxCategory=maxCategory; | |
420 | emit q->maxChanged(maxCategory); |
|
420 | emit q->maxChanged(maxCategory); | |
421 | } |
|
421 | } | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | if (changed) { |
|
424 | if (changed) { | |
425 | emit q->rangeChanged(m_minCategory,m_maxCategory); |
|
425 | emit q->rangeChanged(m_minCategory,m_maxCategory); | |
426 | } |
|
426 | } | |
427 | } |
|
427 | } | |
428 |
|
428 | |||
429 | ChartAxis* QBarCategoryAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
429 | ChartAxis* QBarCategoryAxisPrivate::createGraphics(ChartPresenter* presenter) | |
430 | { |
|
430 | { | |
431 | Q_Q(QBarCategoryAxis); |
|
431 | Q_Q(QBarCategoryAxis); | |
432 | if(m_orientation == Qt::Vertical){ |
|
432 | if(m_orientation == Qt::Vertical){ | |
433 | return new ChartCategoriesAxisY(q,presenter); |
|
433 | return new ChartCategoriesAxisY(q,presenter); | |
434 | }else{ |
|
434 | }else{ | |
435 | return new ChartCategoriesAxisX(q,presenter); |
|
435 | return new ChartCategoriesAxisX(q,presenter); | |
436 | } |
|
436 | } | |
437 | } |
|
437 | } | |
438 |
|
438 | |||
439 | void QBarCategoryAxisPrivate::intializeDomain(Domain* domain) |
|
439 | void QBarCategoryAxisPrivate::intializeDomain(Domain* domain) | |
440 | { |
|
440 | { | |
441 |
|
441 | |||
442 | Q_Q(QBarCategoryAxis); |
|
442 | Q_Q(QBarCategoryAxis); | |
443 | if(m_max==m_min) { |
|
443 | if(m_max==m_min) { | |
444 | int min; |
|
444 | int min; | |
445 | int max; |
|
445 | int max; | |
446 | if(m_orientation==Qt::Vertical) { |
|
446 | if(m_orientation==Qt::Vertical) { | |
447 | min = domain->minY() + 0.5; |
|
447 | min = domain->minY() + 0.5; | |
448 | max = domain->maxY() - 0.5; |
|
448 | max = domain->maxY() - 0.5; | |
449 | } |
|
449 | } | |
450 | else { |
|
450 | else { | |
451 | min = domain->minX() + 0.5; |
|
451 | min = domain->minX() + 0.5; | |
452 | max = domain->maxX() - 0.5; |
|
452 | max = domain->maxX() - 0.5; | |
453 | } |
|
453 | } | |
454 |
|
454 | |||
455 | if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count()) |
|
455 | if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count()) | |
456 | q->setRange(m_categories.at(min),m_categories.at(max)); |
|
456 | q->setRange(m_categories.at(min),m_categories.at(max)); | |
457 | } |
|
457 | } | |
458 | else { |
|
458 | else { | |
459 | if(m_orientation==Qt::Vertical) { |
|
459 | if(m_orientation==Qt::Vertical) { | |
460 | domain->setRangeY(m_min, m_max); |
|
460 | domain->setRangeY(m_min, m_max); | |
461 | } |
|
461 | } | |
462 | else { |
|
462 | else { | |
463 | domain->setRangeX(m_min, m_max); |
|
463 | domain->setRangeX(m_min, m_max); | |
464 | } |
|
464 | } | |
465 | } |
|
465 | } | |
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | #include "moc_qbarcategoriesaxis.cpp" |
|
468 | #include "moc_qbarcategoriesaxis.cpp" | |
469 | #include "moc_qbarcategoriesaxis_p.cpp" |
|
469 | #include "moc_qbarcategoriesaxis_p.cpp" | |
470 |
|
470 | |||
471 | QTCOMMERCIALCHART_END_NAMESPACE |
|
471 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,504 +1,504 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "legendscroller_p.h" |
|
23 | #include "legendscroller_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
25 | #include "chartbackground_p.h" |
|
25 | #include "chartbackground_p.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include <QGraphicsScene> |
|
27 | #include <QGraphicsScene> | |
28 | #include <QGraphicsSceneResizeEvent> |
|
28 | #include <QGraphicsSceneResizeEvent> | |
29 | #include <QGraphicsLayout> |
|
29 | #include <QGraphicsLayout> | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \enum QChart::ChartTheme |
|
34 | \enum QChart::ChartTheme | |
35 |
|
35 | |||
36 | This enum describes the theme used by the chart. |
|
36 | This enum describes the theme used by the chart. | |
37 |
|
37 | |||
38 | \value ChartThemeLight The default theme |
|
38 | \value ChartThemeLight The default theme | |
39 | \value ChartThemeBlueCerulean |
|
39 | \value ChartThemeBlueCerulean | |
40 | \value ChartThemeDark |
|
40 | \value ChartThemeDark | |
41 | \value ChartThemeBrownSand |
|
41 | \value ChartThemeBrownSand | |
42 | \value ChartThemeBlueNcs |
|
42 | \value ChartThemeBlueNcs | |
43 | \value ChartThemeHighContrast |
|
43 | \value ChartThemeHighContrast | |
44 | \value ChartThemeBlueIcy |
|
44 | \value ChartThemeBlueIcy | |
45 | */ |
|
45 | */ | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | \enum QChart::AnimationOption |
|
48 | \enum QChart::AnimationOption | |
49 |
|
49 | |||
50 | For enabling/disabling animations. Defaults to NoAnimation. |
|
50 | For enabling/disabling animations. Defaults to NoAnimation. | |
51 |
|
51 | |||
52 | \value NoAnimation |
|
52 | \value NoAnimation | |
53 | \value GridAxisAnimations |
|
53 | \value GridAxisAnimations | |
54 | \value SeriesAnimations |
|
54 | \value SeriesAnimations | |
55 | \value AllAnimations |
|
55 | \value AllAnimations | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \class QChart |
|
59 | \class QChart | |
60 | \brief QtCommercial chart API. |
|
60 | \brief QtCommercial chart API. | |
61 |
|
61 | |||
62 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
62 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
63 | representation of different types of series and other chart related objects like |
|
63 | representation of different types of series and other chart related objects like | |
64 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
64 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the | |
65 | convenience class QChartView instead of QChart. |
|
65 | convenience class QChartView instead of QChart. | |
66 | \sa QChartView |
|
66 | \sa QChartView | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | \property QChart::animationOptions |
|
70 | \property QChart::animationOptions | |
71 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
71 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \property QChart::backgroundVisible |
|
75 | \property QChart::backgroundVisible | |
76 | Whether the chart background is visible or not. |
|
76 | Whether the chart background is visible or not. | |
77 | \sa setBackgroundBrush(), setBackgroundPen() |
|
77 | \sa setBackgroundBrush(), setBackgroundPen() | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \property QChart::dropShadowEnabled |
|
81 | \property QChart::dropShadowEnabled | |
82 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
82 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop | |
83 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
83 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | \property QChart::margins |
|
87 | \property QChart::margins | |
88 | Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes. |
|
88 | Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes. | |
89 | */ |
|
89 | */ | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | \property QChart::theme |
|
92 | \property QChart::theme | |
93 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
93 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, | |
94 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
94 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few | |
95 | different themes. |
|
95 | different themes. | |
96 | Note: changing the theme will overwrite all customizations previously applied to the series. |
|
96 | Note: changing the theme will overwrite all customizations previously applied to the series. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \property QChart::title |
|
100 | \property QChart::title | |
101 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
101 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \fn void QChart::marginsChanged(QRectF newMargins) |
|
105 | \fn void QChart::marginsChanged(QRectF newMargins) | |
106 | The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size, |
|
106 | The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size, | |
107 | modify axes or hide/show legend. |
|
107 | modify axes or hide/show legend. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
111 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
112 | */ |
|
112 | */ | |
113 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
113 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
114 | d_ptr(new QChartPrivate()) |
|
114 | d_ptr(new QChartPrivate()) | |
115 | { |
|
115 | { | |
116 | d_ptr->m_dataset = new ChartDataSet(this); |
|
116 | d_ptr->m_dataset = new ChartDataSet(this); | |
117 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
117 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
118 | d_ptr->createConnections(); |
|
118 | d_ptr->createConnections(); | |
119 | d_ptr->m_legend = new LegendScroller(this); |
|
119 | d_ptr->m_legend = new LegendScroller(this); | |
120 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
120 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); | |
121 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); |
|
121 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); | |
122 | setLayout(d_ptr->m_presenter->layout()); |
|
122 | setLayout(d_ptr->m_presenter->layout()); | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | /*! |
|
125 | /*! | |
126 | Destroys the object and it's children, like series and axis objects added to it. |
|
126 | Destroys the object and it's children, like series and axis objects added to it. | |
127 | */ |
|
127 | */ | |
128 | QChart::~QChart() |
|
128 | QChart::~QChart() | |
129 | { |
|
129 | { | |
130 | //delete first presenter , since this is a root of all the graphical items |
|
130 | //delete first presenter , since this is a root of all the graphical items | |
131 | setLayout(0); |
|
131 | setLayout(0); | |
132 | delete d_ptr->m_presenter; |
|
132 | delete d_ptr->m_presenter; | |
133 | d_ptr->m_presenter=0; |
|
133 | d_ptr->m_presenter=0; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Adds the \a series onto the chart and takes the ownership of the object. |
|
137 | Adds the \a series onto the chart and takes the ownership of the object. | |
138 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
138 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
139 | the y axis). |
|
139 | the y axis). | |
140 |
|
140 | |||
141 | \sa removeSeries(), removeAllSeries() |
|
141 | \sa removeSeries(), removeAllSeries() | |
142 | */ |
|
142 | */ | |
143 | void QChart::addSeries(QAbstractSeries *series) |
|
143 | void QChart::addSeries(QAbstractSeries *series) | |
144 | { |
|
144 | { | |
145 | Q_ASSERT(series); |
|
145 | Q_ASSERT(series); | |
146 | d_ptr->m_dataset->addSeries(series); |
|
146 | d_ptr->m_dataset->addSeries(series); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | Removes the \a series specified in a perameter from the QChartView. |
|
150 | Removes the \a series specified in a perameter from the QChartView. | |
151 | It releses its ownership of the specified QChartSeries object. |
|
151 | It releses its ownership of the specified QChartSeries object. | |
152 | It does not delete the pointed QChartSeries data object |
|
152 | It does not delete the pointed QChartSeries data object | |
153 | \sa addSeries(), removeAllSeries() |
|
153 | \sa addSeries(), removeAllSeries() | |
154 | */ |
|
154 | */ | |
155 | void QChart::removeSeries(QAbstractSeries *series) |
|
155 | void QChart::removeSeries(QAbstractSeries *series) | |
156 | { |
|
156 | { | |
157 | Q_ASSERT(series); |
|
157 | Q_ASSERT(series); | |
158 | d_ptr->m_dataset->removeSeries(series); |
|
158 | d_ptr->m_dataset->removeSeries(series); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | Removes all the QChartSeries that have been added to the QChartView |
|
162 | Removes all the QChartSeries that have been added to the QChartView | |
163 | It also deletes the pointed QChartSeries data objects |
|
163 | It also deletes the pointed QChartSeries data objects | |
164 | \sa addSeries(), removeSeries() |
|
164 | \sa addSeries(), removeSeries() | |
165 | */ |
|
165 | */ | |
166 | void QChart::removeAllSeries() |
|
166 | void QChart::removeAllSeries() | |
167 | { |
|
167 | { | |
168 | d_ptr->m_dataset->removeAllSeries(); |
|
168 | d_ptr->m_dataset->removeAllSeries(); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | Sets the \a brush that is used for painting the background of the chart area. |
|
172 | Sets the \a brush that is used for painting the background of the chart area. | |
173 | */ |
|
173 | */ | |
174 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
174 | void QChart::setBackgroundBrush(const QBrush& brush) | |
175 | { |
|
175 | { | |
176 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
176 | d_ptr->m_presenter->setBackgroundBrush(brush); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | Gets the brush that is used for painting the background of the chart area. |
|
180 | Gets the brush that is used for painting the background of the chart area. | |
181 | */ |
|
181 | */ | |
182 | QBrush QChart::backgroundBrush() const |
|
182 | QBrush QChart::backgroundBrush() const | |
183 | { |
|
183 | { | |
184 | return d_ptr->m_presenter->backgroundBrush(); |
|
184 | return d_ptr->m_presenter->backgroundBrush(); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | Sets the \a pen that is used for painting the background of the chart area. |
|
188 | Sets the \a pen that is used for painting the background of the chart area. | |
189 | */ |
|
189 | */ | |
190 | void QChart::setBackgroundPen(const QPen& pen) |
|
190 | void QChart::setBackgroundPen(const QPen& pen) | |
191 | { |
|
191 | { | |
192 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
192 | d_ptr->m_presenter->setBackgroundPen(pen); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | Gets the pen that is used for painting the background of the chart area. |
|
196 | Gets the pen that is used for painting the background of the chart area. | |
197 | */ |
|
197 | */ | |
198 | QPen QChart::backgroundPen() const |
|
198 | QPen QChart::backgroundPen() const | |
199 | { |
|
199 | { | |
200 | return d_ptr->m_presenter->backgroundPen(); |
|
200 | return d_ptr->m_presenter->backgroundPen(); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | Sets the chart \a title. The description text that is drawn above the chart. |
|
204 | Sets the chart \a title. The description text that is drawn above the chart. | |
205 | */ |
|
205 | */ | |
206 | void QChart::setTitle(const QString& title) |
|
206 | void QChart::setTitle(const QString& title) | |
207 | { |
|
207 | { | |
208 | d_ptr->m_presenter->setTitle(title); |
|
208 | d_ptr->m_presenter->setTitle(title); | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | /*! |
|
211 | /*! | |
212 | Returns the chart title. The description text that is drawn above the chart. |
|
212 | Returns the chart title. The description text that is drawn above the chart. | |
213 | */ |
|
213 | */ | |
214 | QString QChart::title() const |
|
214 | QString QChart::title() const | |
215 | { |
|
215 | { | |
216 | return d_ptr->m_presenter->title(); |
|
216 | return d_ptr->m_presenter->title(); | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
220 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | |
221 | */ |
|
221 | */ | |
222 | void QChart::setTitleFont(const QFont& font) |
|
222 | void QChart::setTitleFont(const QFont& font) | |
223 | { |
|
223 | { | |
224 | d_ptr->m_presenter->setTitleFont(font); |
|
224 | d_ptr->m_presenter->setTitleFont(font); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
228 | Gets the font that is used for drawing the chart description text that is rendered above the chart. | |
229 | */ |
|
229 | */ | |
230 | QFont QChart::titleFont() const |
|
230 | QFont QChart::titleFont() const | |
231 | { |
|
231 | { | |
232 | return d_ptr->m_presenter->titleFont(); |
|
232 | return d_ptr->m_presenter->titleFont(); | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | /*! |
|
235 | /*! | |
236 | Sets the \a brush used for rendering the title text. |
|
236 | Sets the \a brush used for rendering the title text. | |
237 | */ |
|
237 | */ | |
238 | void QChart::setTitleBrush(const QBrush &brush) |
|
238 | void QChart::setTitleBrush(const QBrush &brush) | |
239 | { |
|
239 | { | |
240 | d_ptr->m_presenter->setTitleBrush(brush); |
|
240 | d_ptr->m_presenter->setTitleBrush(brush); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Returns the brush used for rendering the title text. |
|
244 | Returns the brush used for rendering the title text. | |
245 | */ |
|
245 | */ | |
246 | QBrush QChart::titleBrush() const |
|
246 | QBrush QChart::titleBrush() const | |
247 | { |
|
247 | { | |
248 | return d_ptr->m_presenter->titleBrush(); |
|
248 | return d_ptr->m_presenter->titleBrush(); | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | void QChart::setTheme(QChart::ChartTheme theme) |
|
251 | void QChart::setTheme(QChart::ChartTheme theme) | |
252 | { |
|
252 | { | |
253 | d_ptr->m_presenter->setTheme(theme); |
|
253 | d_ptr->m_presenter->setTheme(theme); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | QChart::ChartTheme QChart::theme() const |
|
256 | QChart::ChartTheme QChart::theme() const | |
257 | { |
|
257 | { | |
258 | return d_ptr->m_presenter->theme(); |
|
258 | return d_ptr->m_presenter->theme(); | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Zooms in the view by a factor of 2 |
|
262 | Zooms in the view by a factor of 2 | |
263 | */ |
|
263 | */ | |
264 | void QChart::zoomIn() |
|
264 | void QChart::zoomIn() | |
265 | { |
|
265 | { | |
266 | d_ptr->m_presenter->zoomIn(2.0); |
|
266 | d_ptr->m_presenter->zoomIn(2.0); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | /*! |
|
269 | /*! | |
270 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
270 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
271 | */ |
|
271 | */ | |
272 | void QChart::zoomIn(const QRectF& rect) |
|
272 | void QChart::zoomIn(const QRectF& rect) | |
273 | { |
|
273 | { | |
274 | if (!rect.isValid()) return; |
|
274 | if (!rect.isValid()) return; | |
275 | d_ptr->m_presenter->zoomIn(rect); |
|
275 | d_ptr->m_presenter->zoomIn(rect); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | /*! |
|
278 | /*! | |
279 | Restores the view zoom level to the previous one. |
|
279 | Restores the view zoom level to the previous one. | |
280 | */ |
|
280 | */ | |
281 | void QChart::zoomOut() |
|
281 | void QChart::zoomOut() | |
282 | { |
|
282 | { | |
283 | d_ptr->m_presenter->zoomOut(2.0); |
|
283 | d_ptr->m_presenter->zoomOut(2.0); | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 | /*! |
|
286 | /*! | |
287 | Zooms in the view by a \a factor. |
|
287 | Zooms in the view by a \a factor. | |
288 |
|
288 | |||
289 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
289 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | |
290 | */ |
|
290 | */ | |
291 | void QChart::zoom(qreal factor) |
|
291 | void QChart::zoom(qreal factor) | |
292 | { |
|
292 | { | |
293 | if (qFuzzyIsNull(factor)) |
|
293 | if (qFuzzyIsNull(factor)) | |
294 | return; |
|
294 | return; | |
295 |
|
295 | |||
296 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
296 | if (qFuzzyCompare(factor, (qreal)1.0)) | |
297 | return; |
|
297 | return; | |
298 |
|
298 | |||
299 | if (factor < 0) |
|
299 | if (factor < 0) | |
300 | return; |
|
300 | return; | |
301 |
|
301 | |||
302 | if (factor > 1.0) |
|
302 | if (factor > 1.0) | |
303 | d_ptr->m_presenter->zoomIn(factor); |
|
303 | d_ptr->m_presenter->zoomIn(factor); | |
304 | else |
|
304 | else | |
305 | d_ptr->m_presenter->zoomOut(1.0 / factor); |
|
305 | d_ptr->m_presenter->zoomOut(1.0 / factor); | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | /*! |
|
308 | /*! | |
309 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
309 | Returns the pointer to the x axis object of the chart asociated with the specified \a series | |
310 | If no series is provided then pointer to currently visible axis is provided |
|
310 | If no series is provided then pointer to currently visible axis is provided | |
311 | */ |
|
311 | */ | |
312 | QAbstractAxis* QChart::axisX(QAbstractSeries* series) const |
|
312 | QAbstractAxis* QChart::axisX(QAbstractSeries* series) const | |
313 | { |
|
313 | { | |
314 | return d_ptr->m_dataset->axisX(series); |
|
314 | return d_ptr->m_dataset->axisX(series); | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | /*! |
|
317 | /*! | |
318 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
318 | Returns the pointer to the y axis object of the chart asociated with the specified \a series | |
319 | If no series is provided then pointer to currently visible axis is provided |
|
319 | If no series is provided then pointer to currently visible axis is provided | |
320 | */ |
|
320 | */ | |
321 | QAbstractAxis* QChart::axisY(QAbstractSeries *series) const |
|
321 | QAbstractAxis* QChart::axisY(QAbstractSeries *series) const | |
322 | { |
|
322 | { | |
323 | return d_ptr->m_dataset->axisY(series); |
|
323 | return d_ptr->m_dataset->axisY(series); | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | /*! |
|
326 | /*! | |
327 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. |
|
327 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. | |
328 |
|
328 | |||
329 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
329 | Creates the axes for the chart based on the series that has already been added to the chart. | |
330 |
|
330 | |||
331 | \table |
|
331 | \table | |
332 | \header |
|
332 | \header | |
333 | \o Series type |
|
333 | \o Series type | |
334 | \o X-axis |
|
334 | \o X-axis | |
335 | \o Y-axis |
|
335 | \o Y-axis | |
336 | \row |
|
336 | \row | |
337 | \o QXYSeries |
|
337 | \o QXYSeries | |
338 | \o QValueAxis |
|
338 | \o QValueAxis | |
339 | \o QValueAxis |
|
339 | \o QValueAxis | |
340 | \row |
|
340 | \row | |
341 | \o QBarSeries |
|
341 | \o QBarSeries | |
342 |
\o QBarCategor |
|
342 | \o QBarCategoryAxis | |
343 | \o QValueAxis |
|
343 | \o QValueAxis | |
344 | \row |
|
344 | \row | |
345 | \o QPieSeries |
|
345 | \o QPieSeries | |
346 | \o None |
|
346 | \o None | |
347 | \o None |
|
347 | \o None | |
348 | \endtable |
|
348 | \endtable | |
349 |
|
349 | |||
350 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. |
|
350 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. | |
351 | If there are sevaral series added of different types then each series gets its own axes pair. |
|
351 | If there are sevaral series added of different types then each series gets its own axes pair. | |
352 |
|
352 | |||
353 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. |
|
353 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. | |
354 |
|
354 | |||
355 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
355 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. | |
356 | QPieSeries does not create any axes. |
|
356 | QPieSeries does not create any axes. | |
357 |
|
357 | |||
358 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
358 | \sa axisX(), axisY(), setAxisX(), setAxisY() | |
359 | */ |
|
359 | */ | |
360 | void QChart::createDefaultAxes() |
|
360 | void QChart::createDefaultAxes() | |
361 | { |
|
361 | { | |
362 | d_ptr->m_dataset->createDefaultAxes(); |
|
362 | d_ptr->m_dataset->createDefaultAxes(); | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | /*! |
|
365 | /*! | |
366 | Returns the legend object of the chart. Ownership stays in chart. |
|
366 | Returns the legend object of the chart. Ownership stays in chart. | |
367 | */ |
|
367 | */ | |
368 | QLegend* QChart::legend() const |
|
368 | QLegend* QChart::legend() const | |
369 | { |
|
369 | { | |
370 | return d_ptr->m_legend; |
|
370 | return d_ptr->m_legend; | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | /*! |
|
373 | /*! | |
374 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
374 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
375 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
375 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
376 | */ |
|
376 | */ | |
377 | QRectF QChart::margins() const |
|
377 | QRectF QChart::margins() const | |
378 | { |
|
378 | { | |
379 | return d_ptr->m_presenter->margins(); |
|
379 | return d_ptr->m_presenter->margins(); | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | /*! |
|
382 | /*! | |
383 | Returns the the rect within which the drawing of the chart is done. |
|
383 | Returns the the rect within which the drawing of the chart is done. | |
384 | It does not include the area defines by margins. |
|
384 | It does not include the area defines by margins. | |
385 | */ |
|
385 | */ | |
386 | QRectF QChart::plotArea() const |
|
386 | QRectF QChart::plotArea() const | |
387 | { |
|
387 | { | |
388 | return d_ptr->m_presenter->geometry(); |
|
388 | return d_ptr->m_presenter->geometry(); | |
389 | } |
|
389 | } | |
390 |
|
390 | |||
391 | ///*! |
|
391 | ///*! | |
392 | // TODO: Dummy. |
|
392 | // TODO: Dummy. | |
393 | // Adjest the ranges of the axes so that all the data of the specified \a series is visible |
|
393 | // Adjest the ranges of the axes so that all the data of the specified \a series is visible | |
394 | // */ |
|
394 | // */ | |
395 | //void QChart::adjustViewToSeries(QAbstractSeries* series) |
|
395 | //void QChart::adjustViewToSeries(QAbstractSeries* series) | |
396 | //{ |
|
396 | //{ | |
397 | // // |
|
397 | // // | |
398 | //} |
|
398 | //} | |
399 |
|
399 | |||
400 | /*! |
|
400 | /*! | |
401 | Sets animation \a options for the chart |
|
401 | Sets animation \a options for the chart | |
402 | */ |
|
402 | */ | |
403 | void QChart::setAnimationOptions(AnimationOptions options) |
|
403 | void QChart::setAnimationOptions(AnimationOptions options) | |
404 | { |
|
404 | { | |
405 | d_ptr->m_presenter->setAnimationOptions(options); |
|
405 | d_ptr->m_presenter->setAnimationOptions(options); | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | QChart::AnimationOptions QChart::animationOptions() const |
|
408 | QChart::AnimationOptions QChart::animationOptions() const | |
409 | { |
|
409 | { | |
410 | return d_ptr->m_presenter->animationOptions(); |
|
410 | return d_ptr->m_presenter->animationOptions(); | |
411 | } |
|
411 | } | |
412 |
|
412 | |||
413 | /*! |
|
413 | /*! | |
414 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
414 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | |
415 | */ |
|
415 | */ | |
416 | void QChart::scroll(qreal dx, qreal dy) |
|
416 | void QChart::scroll(qreal dx, qreal dy) | |
417 | { |
|
417 | { | |
418 | d_ptr->m_presenter->scroll(dx, dy); |
|
418 | d_ptr->m_presenter->scroll(dx, dy); | |
419 | } |
|
419 | } | |
420 |
|
420 | |||
421 | void QChart::setBackgroundVisible(bool visible) |
|
421 | void QChart::setBackgroundVisible(bool visible) | |
422 | { |
|
422 | { | |
423 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
423 | d_ptr->m_presenter->setBackgroundVisible(visible); | |
424 | } |
|
424 | } | |
425 |
|
425 | |||
426 | bool QChart::isBackgroundVisible() const |
|
426 | bool QChart::isBackgroundVisible() const | |
427 | { |
|
427 | { | |
428 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
428 | return d_ptr->m_presenter->isBackgroundVisible(); | |
429 | } |
|
429 | } | |
430 |
|
430 | |||
431 | void QChart::setDropShadowEnabled(bool enabled) |
|
431 | void QChart::setDropShadowEnabled(bool enabled) | |
432 | { |
|
432 | { | |
433 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
433 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); | |
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 | bool QChart::isDropShadowEnabled() const |
|
436 | bool QChart::isDropShadowEnabled() const | |
437 | { |
|
437 | { | |
438 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
438 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); | |
439 | } |
|
439 | } | |
440 |
|
440 | |||
441 | /*! |
|
441 | /*! | |
442 | Returns all the series that are added to the chart. |
|
442 | Returns all the series that are added to the chart. | |
443 |
|
443 | |||
444 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
444 | \sa addSeries(), removeSeries(), removeAllSeries() | |
445 | */ |
|
445 | */ | |
446 | QList<QAbstractSeries*> QChart::series() const |
|
446 | QList<QAbstractSeries*> QChart::series() const | |
447 | { |
|
447 | { | |
448 | return d_ptr->m_dataset->series(); |
|
448 | return d_ptr->m_dataset->series(); | |
449 | } |
|
449 | } | |
450 | /*! |
|
450 | /*! | |
451 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
451 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
452 | */ |
|
452 | */ | |
453 | void QChart::setMarginsMinimum(const QRectF& margins) |
|
453 | void QChart::setMarginsMinimum(const QRectF& margins) | |
454 | { |
|
454 | { | |
455 | d_ptr->m_presenter->setMarginsMinimum(margins); |
|
455 | d_ptr->m_presenter->setMarginsMinimum(margins); | |
456 | } |
|
456 | } | |
457 |
|
457 | |||
458 | /*! |
|
458 | /*! | |
459 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
459 | Sets \a axis to the chart, which will control the presentation of the \a series | |
460 |
|
460 | |||
461 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
461 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() | |
462 | */ |
|
462 | */ | |
463 | void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series) |
|
463 | void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series) | |
464 | { |
|
464 | { | |
465 | d_ptr->m_dataset->setAxis(series,axis,Qt::Horizontal); |
|
465 | d_ptr->m_dataset->setAxis(series,axis,Qt::Horizontal); | |
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | /*! |
|
468 | /*! | |
469 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
469 | Sets \a axis to the chart, which will control the presentation of the \a series | |
470 |
|
470 | |||
471 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
471 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() | |
472 | */ |
|
472 | */ | |
473 | void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series) |
|
473 | void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series) | |
474 | { |
|
474 | { | |
475 | d_ptr->m_dataset->setAxis(series,axis,Qt::Vertical); |
|
475 | d_ptr->m_dataset->setAxis(series,axis,Qt::Vertical); | |
476 | } |
|
476 | } | |
477 |
|
477 | |||
478 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
478 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
479 |
|
479 | |||
480 | QChartPrivate::QChartPrivate(): |
|
480 | QChartPrivate::QChartPrivate(): | |
481 | m_legend(0), |
|
481 | m_legend(0), | |
482 | m_dataset(0), |
|
482 | m_dataset(0), | |
483 | m_presenter(0) |
|
483 | m_presenter(0) | |
484 | { |
|
484 | { | |
485 |
|
485 | |||
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | QChartPrivate::~QChartPrivate() |
|
488 | QChartPrivate::~QChartPrivate() | |
489 | { |
|
489 | { | |
490 |
|
490 | |||
491 | } |
|
491 | } | |
492 |
|
492 | |||
493 | void QChartPrivate::createConnections() |
|
493 | void QChartPrivate::createConnections() | |
494 | { |
|
494 | { | |
495 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
495 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
496 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
496 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
497 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*))); |
|
497 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*))); | |
498 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
498 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*))); | |
499 | //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF))); |
|
499 | //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF))); | |
500 | } |
|
500 | } | |
501 |
|
501 | |||
502 | #include "moc_qchart.cpp" |
|
502 | #include "moc_qchart.cpp" | |
503 |
|
503 | |||
504 | QTCOMMERCIALCHART_END_NAMESPACE |
|
504 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,376 +1,376 | |||||
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 "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 | #include "dataseriedialog.h" |
|
22 | #include "dataseriedialog.h" | |
23 | #include "qchartview.h" |
|
23 | #include "qchartview.h" | |
24 | #include "qpieseries.h" |
|
24 | #include "qpieseries.h" | |
25 | #include "qscatterseries.h" |
|
25 | #include "qscatterseries.h" | |
26 | #include "qlineseries.h" |
|
26 | #include "qlineseries.h" | |
27 | #include <qareaseries.h> |
|
27 | #include <qareaseries.h> | |
28 | #include <qsplineseries.h> |
|
28 | #include <qsplineseries.h> | |
29 | #include <qbarset.h> |
|
29 | #include <qbarset.h> | |
30 | #include <qbarseries.h> |
|
30 | #include <qbarseries.h> | |
31 | #include <qstackedbarseries.h> |
|
31 | #include <qstackedbarseries.h> | |
32 | #include <qpercentbarseries.h> |
|
32 | #include <qpercentbarseries.h> | |
33 | #include <QPushButton> |
|
33 | #include <QPushButton> | |
34 | #include <QComboBox> |
|
34 | #include <QComboBox> | |
35 | #include <QSpinBox> |
|
35 | #include <QSpinBox> | |
36 | #include <QCheckBox> |
|
36 | #include <QCheckBox> | |
37 | #include <QGridLayout> |
|
37 | #include <QGridLayout> | |
38 | #include <QHBoxLayout> |
|
38 | #include <QHBoxLayout> | |
39 | #include <QLabel> |
|
39 | #include <QLabel> | |
40 | #include <QSpacerItem> |
|
40 | #include <QSpacerItem> | |
41 | #include <QMessageBox> |
|
41 | #include <QMessageBox> | |
42 | #include <cmath> |
|
42 | #include <cmath> | |
43 | #include <QDebug> |
|
43 | #include <QDebug> | |
44 | #include <QStandardItemModel> |
|
44 | #include <QStandardItemModel> | |
45 |
#include <QBarCategor |
|
45 | #include <QBarCategoryAxis> | |
46 | #include <QGLWidget> |
|
46 | #include <QGLWidget> | |
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
48 | QTCOMMERCIALCHART_USE_NAMESPACE | |
49 |
|
49 | |||
50 | MainWidget::MainWidget(QWidget *parent) : |
|
50 | MainWidget::MainWidget(QWidget *parent) : | |
51 | QWidget(parent), |
|
51 | QWidget(parent), | |
52 | m_addSerieDialog(0), |
|
52 | m_addSerieDialog(0), | |
53 | m_chart(0) |
|
53 | m_chart(0) | |
54 | { |
|
54 | { | |
55 | m_chart = new QChart(); |
|
55 | m_chart = new QChart(); | |
56 |
|
56 | |||
57 | // Grid layout for the controls for configuring the chart widget |
|
57 | // Grid layout for the controls for configuring the chart widget | |
58 | QGridLayout *grid = new QGridLayout(); |
|
58 | QGridLayout *grid = new QGridLayout(); | |
59 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
59 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
60 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
60 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
61 | grid->addWidget(addSeriesButton, 0, 1); |
|
61 | grid->addWidget(addSeriesButton, 0, 1); | |
62 | initBackroundCombo(grid); |
|
62 | initBackroundCombo(grid); | |
63 | initScaleControls(grid); |
|
63 | initScaleControls(grid); | |
64 | initThemeCombo(grid); |
|
64 | initThemeCombo(grid); | |
65 | initCheckboxes(grid); |
|
65 | initCheckboxes(grid); | |
66 |
|
66 | |||
67 | // add row with empty label to make all the other rows static |
|
67 | // add row with empty label to make all the other rows static | |
68 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
68 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
69 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
69 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
70 |
|
70 | |||
71 | // Create chart view with the chart |
|
71 | // Create chart view with the chart | |
72 | m_chartView = new QChartView(m_chart, this); |
|
72 | m_chartView = new QChartView(m_chart, this); | |
73 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
73 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); | |
74 |
|
74 | |||
75 | // Another grid layout as a main layout |
|
75 | // Another grid layout as a main layout | |
76 | QGridLayout *mainLayout = new QGridLayout(); |
|
76 | QGridLayout *mainLayout = new QGridLayout(); | |
77 | mainLayout->addLayout(grid, 0, 0); |
|
77 | mainLayout->addLayout(grid, 0, 0); | |
78 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
78 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
79 | setLayout(mainLayout); |
|
79 | setLayout(mainLayout); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | // Combo box for selecting the chart's background |
|
82 | // Combo box for selecting the chart's background | |
83 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
83 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
84 | { |
|
84 | { | |
85 | QComboBox *backgroundCombo = new QComboBox(this); |
|
85 | QComboBox *backgroundCombo = new QComboBox(this); | |
86 | backgroundCombo->addItem("Color"); |
|
86 | backgroundCombo->addItem("Color"); | |
87 | backgroundCombo->addItem("Gradient"); |
|
87 | backgroundCombo->addItem("Gradient"); | |
88 | backgroundCombo->addItem("Image"); |
|
88 | backgroundCombo->addItem("Image"); | |
89 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
89 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
90 | this, SLOT(backgroundChanged(int))); |
|
90 | this, SLOT(backgroundChanged(int))); | |
91 |
|
91 | |||
92 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
92 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
93 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
93 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | // Scale related controls (auto-scale vs. manual min-max values) |
|
96 | // Scale related controls (auto-scale vs. manual min-max values) | |
97 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
97 | void MainWidget::initScaleControls(QGridLayout *grid) | |
98 | { |
|
98 | { | |
99 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
99 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
100 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
100 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
101 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
101 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
102 | m_xMinSpin = new QSpinBox(); |
|
102 | m_xMinSpin = new QSpinBox(); | |
103 | m_xMinSpin->setMinimum(INT_MIN); |
|
103 | m_xMinSpin->setMinimum(INT_MIN); | |
104 | m_xMinSpin->setMaximum(INT_MAX); |
|
104 | m_xMinSpin->setMaximum(INT_MAX); | |
105 | m_xMinSpin->setValue(0); |
|
105 | m_xMinSpin->setValue(0); | |
106 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
106 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
107 | m_xMaxSpin = new QSpinBox(); |
|
107 | m_xMaxSpin = new QSpinBox(); | |
108 | m_xMaxSpin->setMinimum(INT_MIN); |
|
108 | m_xMaxSpin->setMinimum(INT_MIN); | |
109 | m_xMaxSpin->setMaximum(INT_MAX); |
|
109 | m_xMaxSpin->setMaximum(INT_MAX); | |
110 | m_xMaxSpin->setValue(10); |
|
110 | m_xMaxSpin->setValue(10); | |
111 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
111 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
112 | m_yMinSpin = new QSpinBox(); |
|
112 | m_yMinSpin = new QSpinBox(); | |
113 | m_yMinSpin->setMinimum(INT_MIN); |
|
113 | m_yMinSpin->setMinimum(INT_MIN); | |
114 | m_yMinSpin->setMaximum(INT_MAX); |
|
114 | m_yMinSpin->setMaximum(INT_MAX); | |
115 | m_yMinSpin->setValue(0); |
|
115 | m_yMinSpin->setValue(0); | |
116 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
116 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
117 | m_yMaxSpin = new QSpinBox(); |
|
117 | m_yMaxSpin = new QSpinBox(); | |
118 | m_yMaxSpin->setMinimum(INT_MIN); |
|
118 | m_yMaxSpin->setMinimum(INT_MIN); | |
119 | m_yMaxSpin->setMaximum(INT_MAX); |
|
119 | m_yMaxSpin->setMaximum(INT_MAX); | |
120 | m_yMaxSpin->setValue(10); |
|
120 | m_yMaxSpin->setValue(10); | |
121 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
121 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
122 |
|
122 | |||
123 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
123 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
124 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
124 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
125 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
125 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
126 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
126 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
127 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
127 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
128 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
128 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
129 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
129 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
130 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
130 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
131 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
131 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
132 |
|
132 | |||
133 | m_autoScaleCheck->setChecked(true); |
|
133 | m_autoScaleCheck->setChecked(true); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | // Combo box for selecting theme |
|
136 | // Combo box for selecting theme | |
137 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
137 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
138 | { |
|
138 | { | |
139 | QComboBox *chartTheme = new QComboBox(); |
|
139 | QComboBox *chartTheme = new QComboBox(); | |
140 | chartTheme->addItem("Default"); |
|
140 | chartTheme->addItem("Default"); | |
141 | chartTheme->addItem("Light"); |
|
141 | chartTheme->addItem("Light"); | |
142 | chartTheme->addItem("Blue Cerulean"); |
|
142 | chartTheme->addItem("Blue Cerulean"); | |
143 | chartTheme->addItem("Dark"); |
|
143 | chartTheme->addItem("Dark"); | |
144 | chartTheme->addItem("Brown Sand"); |
|
144 | chartTheme->addItem("Brown Sand"); | |
145 | chartTheme->addItem("Blue NCS"); |
|
145 | chartTheme->addItem("Blue NCS"); | |
146 | chartTheme->addItem("High Contrast"); |
|
146 | chartTheme->addItem("High Contrast"); | |
147 | chartTheme->addItem("Blue Icy"); |
|
147 | chartTheme->addItem("Blue Icy"); | |
148 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
148 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
149 | this, SLOT(changeChartTheme(int))); |
|
149 | this, SLOT(changeChartTheme(int))); | |
150 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
150 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
151 | grid->addWidget(chartTheme, 8, 1); |
|
151 | grid->addWidget(chartTheme, 8, 1); | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | // Different check boxes for customizing chart |
|
154 | // Different check boxes for customizing chart | |
155 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
155 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
156 | { |
|
156 | { | |
157 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
157 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off | |
158 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
158 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
159 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
159 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); | |
160 | zoomCheckBox->setChecked(true); |
|
160 | zoomCheckBox->setChecked(true); | |
161 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
161 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
162 |
|
162 | |||
163 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
163 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); | |
164 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
164 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); | |
165 | aliasCheckBox->setChecked(false); |
|
165 | aliasCheckBox->setChecked(false); | |
166 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
166 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); | |
167 |
|
167 | |||
168 | QCheckBox *openGLCheckBox = new QCheckBox("Use QGLWidget"); |
|
168 | QCheckBox *openGLCheckBox = new QCheckBox("Use QGLWidget"); | |
169 | connect(openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(openGLToggled(bool))); |
|
169 | connect(openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(openGLToggled(bool))); | |
170 | openGLCheckBox->setChecked(false); |
|
170 | openGLCheckBox->setChecked(false); | |
171 | grid->addWidget(openGLCheckBox, grid->rowCount(), 0); |
|
171 | grid->addWidget(openGLCheckBox, grid->rowCount(), 0); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | void MainWidget::antiAliasToggled(bool enabled) |
|
174 | void MainWidget::antiAliasToggled(bool enabled) | |
175 | { |
|
175 | { | |
176 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
176 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | void MainWidget::openGLToggled(bool enabled) |
|
179 | void MainWidget::openGLToggled(bool enabled) | |
180 | { |
|
180 | { | |
181 | if (enabled) { |
|
181 | if (enabled) { | |
182 | QGLFormat f = QGLFormat::defaultFormat(); |
|
182 | QGLFormat f = QGLFormat::defaultFormat(); | |
183 | f.setSampleBuffers(true); |
|
183 | f.setSampleBuffers(true); | |
184 | f.setSamples(4); |
|
184 | f.setSamples(4); | |
185 | QGLFormat::setDefaultFormat(f); |
|
185 | QGLFormat::setDefaultFormat(f); | |
186 | QGLWidget *g = new QGLWidget(); |
|
186 | QGLWidget *g = new QGLWidget(); | |
187 | m_chartView->setViewport(g); |
|
187 | m_chartView->setViewport(g); | |
188 | } else { |
|
188 | } else { | |
189 | m_chartView->setViewport(0); |
|
189 | m_chartView->setViewport(0); | |
190 | } |
|
190 | } | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | void MainWidget::addSeries() |
|
193 | void MainWidget::addSeries() | |
194 | { |
|
194 | { | |
195 | if (!m_addSerieDialog) { |
|
195 | if (!m_addSerieDialog) { | |
196 | m_addSerieDialog = new DataSerieDialog(this); |
|
196 | m_addSerieDialog = new DataSerieDialog(this); | |
197 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), |
|
197 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), | |
198 | this, SLOT(addSeries(QString,int,int,QString,bool))); |
|
198 | this, SLOT(addSeries(QString,int,int,QString,bool))); | |
199 | } |
|
199 | } | |
200 | m_addSerieDialog->exec(); |
|
200 | m_addSerieDialog->exec(); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
203 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) | |
204 | { |
|
204 | { | |
205 | // TODO: dataCharacteristics |
|
205 | // TODO: dataCharacteristics | |
206 | QList<RealList> testData; |
|
206 | QList<RealList> testData; | |
207 | for (int j(0); j < columnCount; j++) { |
|
207 | for (int j(0); j < columnCount; j++) { | |
208 | QList <qreal> newColumn; |
|
208 | QList <qreal> newColumn; | |
209 | for (int i(0); i < rowCount; i++) { |
|
209 | for (int i(0); i < rowCount; i++) { | |
210 | if (dataCharacteristics == "Sin") { |
|
210 | if (dataCharacteristics == "Sin") { | |
211 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
211 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
212 | } else if (dataCharacteristics == "Sin + random") { |
|
212 | } else if (dataCharacteristics == "Sin + random") { | |
213 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
213 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
214 | } else if (dataCharacteristics == "Random") { |
|
214 | } else if (dataCharacteristics == "Random") { | |
215 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
215 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); | |
216 | } else if (dataCharacteristics == "Linear") { |
|
216 | } else if (dataCharacteristics == "Linear") { | |
217 | //newColumn.append(i * (j + 1.0)); |
|
217 | //newColumn.append(i * (j + 1.0)); | |
218 | // TODO: temporary hack to make pie work; prevent zero values: |
|
218 | // TODO: temporary hack to make pie work; prevent zero values: | |
219 | newColumn.append(i * (j + 1.0) + 0.1); |
|
219 | newColumn.append(i * (j + 1.0) + 0.1); | |
220 | } else { // "constant" |
|
220 | } else { // "constant" | |
221 | newColumn.append((j + 1.0)); |
|
221 | newColumn.append((j + 1.0)); | |
222 | } |
|
222 | } | |
223 | } |
|
223 | } | |
224 | testData.append(newColumn); |
|
224 | testData.append(newColumn); | |
225 | } |
|
225 | } | |
226 | return testData; |
|
226 | return testData; | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | QStringList MainWidget::generateLabels(int count) |
|
229 | QStringList MainWidget::generateLabels(int count) | |
230 | { |
|
230 | { | |
231 | QStringList result; |
|
231 | QStringList result; | |
232 | for (int i(0); i < count; i++) |
|
232 | for (int i(0); i < count; i++) | |
233 | result.append("label" + QString::number(i)); |
|
233 | result.append("label" + QString::number(i)); | |
234 | return result; |
|
234 | return result; | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
237 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) | |
238 | { |
|
238 | { | |
239 | qDebug() << "addSeries: " << seriesName |
|
239 | qDebug() << "addSeries: " << seriesName | |
240 | << " columnCount: " << columnCount |
|
240 | << " columnCount: " << columnCount | |
241 | << " rowCount: " << rowCount |
|
241 | << " rowCount: " << rowCount | |
242 | << " dataCharacteristics: " << dataCharacteristics |
|
242 | << " dataCharacteristics: " << dataCharacteristics | |
243 | << " labels enabled: " << labelsEnabled; |
|
243 | << " labels enabled: " << labelsEnabled; | |
244 | m_defaultSeriesName = seriesName; |
|
244 | m_defaultSeriesName = seriesName; | |
245 |
|
245 | |||
246 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
246 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); | |
247 |
|
247 | |||
248 | // Line series and scatter series use similar data |
|
248 | // Line series and scatter series use similar data | |
249 | if (seriesName == "Line") { |
|
249 | if (seriesName == "Line") { | |
250 | for (int j(0); j < data.count(); j ++) { |
|
250 | for (int j(0); j < data.count(); j ++) { | |
251 | QList<qreal> column = data.at(j); |
|
251 | QList<qreal> column = data.at(j); | |
252 | QLineSeries *series = new QLineSeries(); |
|
252 | QLineSeries *series = new QLineSeries(); | |
253 | series->setName("line" + QString::number(j)); |
|
253 | series->setName("line" + QString::number(j)); | |
254 | for (int i(0); i < column.count(); i++) |
|
254 | for (int i(0); i < column.count(); i++) | |
255 | series->append(i, column.at(i)); |
|
255 | series->append(i, column.at(i)); | |
256 | m_chart->addSeries(series); |
|
256 | m_chart->addSeries(series); | |
257 | } |
|
257 | } | |
258 | } else if (seriesName == "Area") { |
|
258 | } else if (seriesName == "Area") { | |
259 | // TODO: lower series for the area? |
|
259 | // TODO: lower series for the area? | |
260 | for (int j(0); j < data.count(); j ++) { |
|
260 | for (int j(0); j < data.count(); j ++) { | |
261 | QList<qreal> column = data.at(j); |
|
261 | QList<qreal> column = data.at(j); | |
262 | QLineSeries *lineSeries = new QLineSeries(); |
|
262 | QLineSeries *lineSeries = new QLineSeries(); | |
263 | for (int i(0); i < column.count(); i++) |
|
263 | for (int i(0); i < column.count(); i++) | |
264 | lineSeries->append(i, column.at(i)); |
|
264 | lineSeries->append(i, column.at(i)); | |
265 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
265 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); | |
266 | areaSeries->setName("area" + QString::number(j)); |
|
266 | areaSeries->setName("area" + QString::number(j)); | |
267 | m_chart->addSeries(areaSeries); |
|
267 | m_chart->addSeries(areaSeries); | |
268 | } |
|
268 | } | |
269 | } else if (seriesName == "Scatter") { |
|
269 | } else if (seriesName == "Scatter") { | |
270 | for (int j(0); j < data.count(); j++) { |
|
270 | for (int j(0); j < data.count(); j++) { | |
271 | QList<qreal> column = data.at(j); |
|
271 | QList<qreal> column = data.at(j); | |
272 | QScatterSeries *series = new QScatterSeries(); |
|
272 | QScatterSeries *series = new QScatterSeries(); | |
273 | series->setName("scatter" + QString::number(j)); |
|
273 | series->setName("scatter" + QString::number(j)); | |
274 | for (int i(0); i < column.count(); i++) |
|
274 | for (int i(0); i < column.count(); i++) | |
275 | series->append(i, column.at(i)); |
|
275 | series->append(i, column.at(i)); | |
276 | m_chart->addSeries(series); |
|
276 | m_chart->addSeries(series); | |
277 | } |
|
277 | } | |
278 | } else if (seriesName == "Pie") { |
|
278 | } else if (seriesName == "Pie") { | |
279 | QStringList labels = generateLabels(rowCount); |
|
279 | QStringList labels = generateLabels(rowCount); | |
280 | for (int j(0); j < data.count(); j++) { |
|
280 | for (int j(0); j < data.count(); j++) { | |
281 | QPieSeries *series = new QPieSeries(); |
|
281 | QPieSeries *series = new QPieSeries(); | |
282 | QList<qreal> column = data.at(j); |
|
282 | QList<qreal> column = data.at(j); | |
283 | for (int i(0); i < column.count(); i++) |
|
283 | for (int i(0); i < column.count(); i++) | |
284 | series->append(labels.at(i), column.at(i)); |
|
284 | series->append(labels.at(i), column.at(i)); | |
285 | m_chart->addSeries(series); |
|
285 | m_chart->addSeries(series); | |
286 | } |
|
286 | } | |
287 | } else if (seriesName == "Bar" |
|
287 | } else if (seriesName == "Bar" | |
288 | || seriesName == "Stacked bar" |
|
288 | || seriesName == "Stacked bar" | |
289 | || seriesName == "Percent bar") { |
|
289 | || seriesName == "Percent bar") { | |
290 | QStringList category; |
|
290 | QStringList category; | |
291 | QStringList labels = generateLabels(rowCount); |
|
291 | QStringList labels = generateLabels(rowCount); | |
292 | foreach(QString label, labels) |
|
292 | foreach(QString label, labels) | |
293 | category << label; |
|
293 | category << label; | |
294 | QAbstractBarSeries* series = 0; |
|
294 | QAbstractBarSeries* series = 0; | |
295 | if (seriesName == "Bar") { |
|
295 | if (seriesName == "Bar") { | |
296 | series = new QBarSeries(this); |
|
296 | series = new QBarSeries(this); | |
297 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
297 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
298 | axis->append(category); |
|
298 | axis->append(category); | |
299 | m_chart->setAxisX(axis,series); |
|
299 | m_chart->setAxisX(axis,series); | |
300 | } else if (seriesName == "Stacked bar") { |
|
300 | } else if (seriesName == "Stacked bar") { | |
301 | series = new QStackedBarSeries(this); |
|
301 | series = new QStackedBarSeries(this); | |
302 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
302 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
303 | axis->append(category); |
|
303 | axis->append(category); | |
304 | m_chart->setAxisX(axis,series); |
|
304 | m_chart->setAxisX(axis,series); | |
305 | } else { |
|
305 | } else { | |
306 | series = new QPercentBarSeries(this); |
|
306 | series = new QPercentBarSeries(this); | |
307 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
307 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
308 | axis->append(category); |
|
308 | axis->append(category); | |
309 | m_chart->setAxisX(axis,series); |
|
309 | m_chart->setAxisX(axis,series); | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | for (int j(0); j < data.count(); j++) { |
|
312 | for (int j(0); j < data.count(); j++) { | |
313 | QList<qreal> column = data.at(j); |
|
313 | QList<qreal> column = data.at(j); | |
314 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
314 | QBarSet *set = new QBarSet("set" + QString::number(j)); | |
315 | for (int i(0); i < column.count(); i++) |
|
315 | for (int i(0); i < column.count(); i++) | |
316 | *set << column.at(i); |
|
316 | *set << column.at(i); | |
317 | series->append(set); |
|
317 | series->append(set); | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | m_chart->addSeries(series); |
|
320 | m_chart->addSeries(series); | |
321 | } else if (seriesName == "Spline") { |
|
321 | } else if (seriesName == "Spline") { | |
322 | for (int j(0); j < data.count(); j ++) { |
|
322 | for (int j(0); j < data.count(); j ++) { | |
323 | QList<qreal> column = data.at(j); |
|
323 | QList<qreal> column = data.at(j); | |
324 | QSplineSeries *series = new QSplineSeries(); |
|
324 | QSplineSeries *series = new QSplineSeries(); | |
325 | for (int i(0); i < column.count(); i++) |
|
325 | for (int i(0); i < column.count(); i++) | |
326 | series->append(i, column.at(i)); |
|
326 | series->append(i, column.at(i)); | |
327 | m_chart->addSeries(series); |
|
327 | m_chart->addSeries(series); | |
328 | } |
|
328 | } | |
329 | } |
|
329 | } | |
330 | m_chart->createDefaultAxes(); |
|
330 | m_chart->createDefaultAxes(); | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | void MainWidget::backgroundChanged(int itemIndex) |
|
333 | void MainWidget::backgroundChanged(int itemIndex) | |
334 | { |
|
334 | { | |
335 | qDebug() << "backgroundChanged: " << itemIndex; |
|
335 | qDebug() << "backgroundChanged: " << itemIndex; | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | void MainWidget::autoScaleChanged(int value) |
|
338 | void MainWidget::autoScaleChanged(int value) | |
339 | { |
|
339 | { | |
340 | if (value) { |
|
340 | if (value) { | |
341 | // TODO: enable auto scaling |
|
341 | // TODO: enable auto scaling | |
342 | } else { |
|
342 | } else { | |
343 | // TODO: set scaling manually (and disable auto scaling) |
|
343 | // TODO: set scaling manually (and disable auto scaling) | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | m_xMinSpin->setEnabled(!value); |
|
346 | m_xMinSpin->setEnabled(!value); | |
347 | m_xMaxSpin->setEnabled(!value); |
|
347 | m_xMaxSpin->setEnabled(!value); | |
348 | m_yMinSpin->setEnabled(!value); |
|
348 | m_yMinSpin->setEnabled(!value); | |
349 | m_yMaxSpin->setEnabled(!value); |
|
349 | m_yMaxSpin->setEnabled(!value); | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | void MainWidget::xMinChanged(int value) |
|
352 | void MainWidget::xMinChanged(int value) | |
353 | { |
|
353 | { | |
354 | qDebug() << "xMinChanged: " << value; |
|
354 | qDebug() << "xMinChanged: " << value; | |
355 | } |
|
355 | } | |
356 |
|
356 | |||
357 | void MainWidget::xMaxChanged(int value) |
|
357 | void MainWidget::xMaxChanged(int value) | |
358 | { |
|
358 | { | |
359 | qDebug() << "xMaxChanged: " << value; |
|
359 | qDebug() << "xMaxChanged: " << value; | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | void MainWidget::yMinChanged(int value) |
|
362 | void MainWidget::yMinChanged(int value) | |
363 | { |
|
363 | { | |
364 | qDebug() << "yMinChanged: " << value; |
|
364 | qDebug() << "yMinChanged: " << value; | |
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | void MainWidget::yMaxChanged(int value) |
|
367 | void MainWidget::yMaxChanged(int value) | |
368 | { |
|
368 | { | |
369 | qDebug() << "yMaxChanged: " << value; |
|
369 | qDebug() << "yMaxChanged: " << value; | |
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | void MainWidget::changeChartTheme(int themeIndex) |
|
372 | void MainWidget::changeChartTheme(int themeIndex) | |
373 | { |
|
373 | { | |
374 | qDebug() << "changeChartTheme: " << themeIndex; |
|
374 | qDebug() << "changeChartTheme: " << themeIndex; | |
375 | m_chart->setTheme((QChart::ChartTheme) themeIndex); |
|
375 | m_chart->setTheme((QChart::ChartTheme) themeIndex); | |
376 | } |
|
376 | } |
General Comments 0
You need to be logged in to leave comments.
Login now