##// END OF EJS Templates
Updated chartthemes demo
Marek Rosa -
r1582:55a73b8deea2
parent child
Show More
@@ -1,382 +1,386
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "themewidget.h"
21 #include "themewidget.h"
22
22
23 #include <QChartView>
23 #include <QChartView>
24 #include <QPieSeries>
24 #include <QPieSeries>
25 #include <QPieSlice>
25 #include <QPieSlice>
26 #include <QBarSeries>
26 #include <QBarSeries>
27 #include <QPercentBarSeries>
27 #include <QPercentBarSeries>
28 #include <QStackedBarSeries>
28 #include <QStackedBarSeries>
29 #include <QBarSet>
29 #include <QBarSet>
30 #include <QLineSeries>
30 #include <QLineSeries>
31 #include <QSplineSeries>
31 #include <QSplineSeries>
32 #include <QScatterSeries>
32 #include <QScatterSeries>
33 #include <QAreaSeries>
33 #include <QAreaSeries>
34 #include <QLegend>
34 #include <QLegend>
35 #include <QGridLayout>
35 #include <QGridLayout>
36 #include <QFormLayout>
36 #include <QFormLayout>
37 #include <QComboBox>
37 #include <QComboBox>
38 #include <QSpinBox>
38 #include <QSpinBox>
39 #include <QCheckBox>
39 #include <QCheckBox>
40 #include <QGroupBox>
40 #include <QGroupBox>
41 #include <QLabel>
41 #include <QLabel>
42 #include <QTime>
42 #include <QTime>
43 #include <QCategoriesAxis>
43 #include <QCategoriesAxis>
44
44
45 ThemeWidget::ThemeWidget(QWidget* parent) :
45 ThemeWidget::ThemeWidget(QWidget* parent) :
46 QWidget(parent),
46 QWidget(parent),
47 m_listCount(3),
47 m_listCount(3),
48 m_valueMax(10),
48 m_valueMax(10),
49 m_valueCount(7),
49 m_valueCount(7),
50 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
50 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
51 m_themeComboBox(createThemeBox()),
51 m_themeComboBox(createThemeBox()),
52 m_antialiasCheckBox(new QCheckBox("Anti-aliasing")),
52 m_antialiasCheckBox(new QCheckBox("Anti-aliasing")),
53 m_animatedComboBox(createAnimationBox()),
53 m_animatedComboBox(createAnimationBox()),
54 m_legendComboBox(createLegendBox())
54 m_legendComboBox(createLegendBox())
55 {
55 {
56 connectSignals();
56 connectSignals();
57 // create layout
57 // create layout
58 QGridLayout* baseLayout = new QGridLayout();
58 QGridLayout* baseLayout = new QGridLayout();
59 QHBoxLayout *settingsLayout = new QHBoxLayout();
59 QHBoxLayout *settingsLayout = new QHBoxLayout();
60 settingsLayout->addWidget(new QLabel("Theme:"));
60 settingsLayout->addWidget(new QLabel("Theme:"));
61 settingsLayout->addWidget(m_themeComboBox);
61 settingsLayout->addWidget(m_themeComboBox);
62 settingsLayout->addWidget(new QLabel("Animation:"));
62 settingsLayout->addWidget(new QLabel("Animation:"));
63 settingsLayout->addWidget(m_animatedComboBox);
63 settingsLayout->addWidget(m_animatedComboBox);
64 settingsLayout->addWidget(new QLabel("Legend:"));
64 settingsLayout->addWidget(new QLabel("Legend:"));
65 settingsLayout->addWidget(m_legendComboBox);
65 settingsLayout->addWidget(m_legendComboBox);
66 settingsLayout->addWidget(m_antialiasCheckBox);
66 settingsLayout->addWidget(m_antialiasCheckBox);
67 settingsLayout->addStretch();
67 settingsLayout->addStretch();
68 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
68 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
69
69
70 //create charts
70 //create charts
71
71
72 QChartView *chartView;
72 QChartView *chartView;
73
73
74 chartView = new QChartView(createAreaChart());
74 chartView = new QChartView(createAreaChart());
75 baseLayout->addWidget(chartView, 1, 0);
75 baseLayout->addWidget(chartView, 1, 0);
76 m_charts << chartView;
76 m_charts << chartView;
77
77
78 chartView = new QChartView(createBarChart(m_valueCount));
78 chartView = new QChartView(createBarChart(m_valueCount));
79 baseLayout->addWidget(chartView, 1, 1);
79 baseLayout->addWidget(chartView, 1, 1);
80 m_charts << chartView;
80 m_charts << chartView;
81
81
82 chartView = new QChartView(createLineChart());
82 chartView = new QChartView(createLineChart());
83 baseLayout->addWidget(chartView, 1, 2);
83 baseLayout->addWidget(chartView, 1, 2);
84 m_charts << chartView;
84 m_charts << chartView;
85
85
86 chartView = new QChartView(createPieChart());
86 chartView = new QChartView(createPieChart());
87 chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen...
87 chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen...
88 baseLayout->addWidget(chartView, 2, 0);
88 baseLayout->addWidget(chartView, 2, 0);
89 m_charts << chartView;
89 m_charts << chartView;
90
90
91 chartView = new QChartView(createSplineChart());
91 chartView = new QChartView(createSplineChart());
92 baseLayout->addWidget(chartView, 2, 1);
92 baseLayout->addWidget(chartView, 2, 1);
93 m_charts << chartView;
93 m_charts << chartView;
94
94
95 chartView = new QChartView(createScatterChart());
95 chartView = new QChartView(createScatterChart());
96 baseLayout->addWidget(chartView, 2, 2);
96 baseLayout->addWidget(chartView, 2, 2);
97 m_charts << chartView;
97 m_charts << chartView;
98
98
99 setLayout(baseLayout);
99 setLayout(baseLayout);
100
100
101 // Set defaults
101 // Set defaults
102 m_antialiasCheckBox->setChecked(true);
102 m_antialiasCheckBox->setChecked(true);
103 updateUI();
103 updateUI();
104 }
104 }
105
105
106 ThemeWidget::~ThemeWidget()
106 ThemeWidget::~ThemeWidget()
107 {
107 {
108 }
108 }
109
109
110 void ThemeWidget::connectSignals()
110 void ThemeWidget::connectSignals()
111 {
111 {
112 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
112 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
113 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
113 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
114 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
114 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
115 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
115 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
116 }
116 }
117
117
118 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
118 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
119 {
119 {
120 DataTable dataTable;
120 DataTable dataTable;
121
121
122 // set seed for random stuff
122 // set seed for random stuff
123 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
123 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
124
124
125 // generate random data
125 // generate random data
126 for (int i(0); i < listCount; i++) {
126 for (int i(0); i < listCount; i++) {
127 DataList dataList;
127 DataList dataList;
128 qreal yValue(0);
128 qreal yValue(0);
129 for (int j(0); j < valueCount; j++) {
129 for (int j(0); j < valueCount; j++) {
130 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
130 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
131 QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount),
131 QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount),
132 yValue);
132 yValue);
133 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
133 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
134 dataList << Data(value, label);
134 dataList << Data(value, label);
135 }
135 }
136 dataTable << dataList;
136 dataTable << dataList;
137 }
137 }
138
138
139 return dataTable;
139 return dataTable;
140 }
140 }
141
141
142 QComboBox* ThemeWidget::createThemeBox() const
142 QComboBox* ThemeWidget::createThemeBox() const
143 {
143 {
144 // settings layout
144 // settings layout
145 QComboBox* themeComboBox = new QComboBox();
145 QComboBox* themeComboBox = new QComboBox();
146 themeComboBox->addItem("Light", QChart::ChartThemeLight);
146 themeComboBox->addItem("Light", QChart::ChartThemeLight);
147 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
147 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
148 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
148 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
149 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
149 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
150 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
150 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
151 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
151 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
152 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
152 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
153 return themeComboBox;
153 return themeComboBox;
154 }
154 }
155
155
156 QComboBox* ThemeWidget::createAnimationBox() const
156 QComboBox* ThemeWidget::createAnimationBox() const
157 {
157 {
158 // settings layout
158 // settings layout
159 QComboBox* animationComboBox = new QComboBox();
159 QComboBox* animationComboBox = new QComboBox();
160 animationComboBox->addItem("No Animations", QChart::NoAnimation);
160 animationComboBox->addItem("No Animations", QChart::NoAnimation);
161 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
161 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
162 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
162 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
163 animationComboBox->addItem("All Animations", QChart::AllAnimations);
163 animationComboBox->addItem("All Animations", QChart::AllAnimations);
164 return animationComboBox;
164 return animationComboBox;
165 }
165 }
166
166
167 QComboBox* ThemeWidget::createLegendBox() const
167 QComboBox* ThemeWidget::createLegendBox() const
168 {
168 {
169 QComboBox* legendComboBox = new QComboBox();
169 QComboBox* legendComboBox = new QComboBox();
170 legendComboBox->addItem("No Legend ", 0);
170 legendComboBox->addItem("No Legend ", 0);
171 legendComboBox->addItem("Legend Top", Qt::AlignTop);
171 legendComboBox->addItem("Legend Top", Qt::AlignTop);
172 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
172 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
173 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
173 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
174 legendComboBox->addItem("Legend Right", Qt::AlignRight);
174 legendComboBox->addItem("Legend Right", Qt::AlignRight);
175 return legendComboBox;
175 return legendComboBox;
176 }
176 }
177
177
178 QChart* ThemeWidget::createAreaChart() const
178 QChart* ThemeWidget::createAreaChart() const
179 {
179 {
180 QChart *chart = new QChart();
180 QChart *chart = new QChart();
181 // chart->axisX()->setNiceNumbersEnabled(true);
181 // chart->axisX()->setNiceNumbersEnabled(true);
182 // chart->axisY()->setNiceNumbersEnabled(true);
182 // chart->axisY()->setNiceNumbersEnabled(true);
183 chart->setTitle("Area chart");
183 chart->setTitle("Area chart");
184
184
185 // The lower series initialized to zero values
185 // The lower series initialized to zero values
186 QLineSeries *lowerSeries = 0;
186 QLineSeries *lowerSeries = 0;
187 QString name("Series ");
187 QString name("Series ");
188 int nameIndex = 0;
188 int nameIndex = 0;
189 for (int i(0); i < m_dataTable.count(); i++) {
189 for (int i(0); i < m_dataTable.count(); i++) {
190 QLineSeries *upperSeries = new QLineSeries(chart);
190 QLineSeries *upperSeries = new QLineSeries(chart);
191 for (int j(0); j < m_dataTable[i].count(); j++) {
191 for (int j(0); j < m_dataTable[i].count(); j++) {
192 Data data = m_dataTable[i].at(j);
192 Data data = m_dataTable[i].at(j);
193 if (lowerSeries){
193 if (lowerSeries){
194 const QList<QPointF>& points = lowerSeries->points();
194 const QList<QPointF>& points = lowerSeries->points();
195 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
195 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
196 }else
196 }else
197 upperSeries->append(QPointF(j, data.first.y()));
197 upperSeries->append(QPointF(j, data.first.y()));
198 }
198 }
199 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
199 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
200 area->setName(name + QString::number(nameIndex));
200 area->setName(name + QString::number(nameIndex));
201 nameIndex++;
201 nameIndex++;
202 chart->addSeries(area);
202 chart->addSeries(area);
203 chart->createDefaultAxes();
203 lowerSeries = upperSeries;
204 lowerSeries = upperSeries;
204 }
205 }
205
206
206 return chart;
207 return chart;
207 }
208 }
208
209
209 QChart* ThemeWidget::createBarChart(int valueCount) const
210 QChart* ThemeWidget::createBarChart(int valueCount) const
210 {
211 {
211 QChart* chart = new QChart();
212 QChart* chart = new QChart();
212 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
213 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
213 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
214 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
214 chart->setTitle("Bar chart");
215 chart->setTitle("Bar chart");
215
216
216 QStringList categories;
217 QStringList categories;
217 for (int i(0); i < valueCount; i++)
218 for (int i(0); i < valueCount; i++)
218 categories << QString::number(i);
219 categories << QString::number(i);
219
220
220 QCategoriesAxis* axis = new QCategoriesAxis();
221 QCategoriesAxis* axis = new QCategoriesAxis();
221 axis->append(categories);
222 axis->append(categories);
222
223
223 QStackedBarSeries* series = new QStackedBarSeries(chart);
224 QStackedBarSeries* series = new QStackedBarSeries(chart);
224 for (int i(0); i < m_dataTable.count(); i++) {
225 for (int i(0); i < m_dataTable.count(); i++) {
225 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
226 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
226 foreach (Data data, m_dataTable[i])
227 foreach (Data data, m_dataTable[i])
227 *set << data.first.y();
228 *set << data.first.y();
228 series->append(set);
229 series->append(set);
229 }
230 }
230 chart->addSeries(series);
231 chart->addSeries(series);
231 chart->createDefaultAxes();
232 chart->createDefaultAxes();
233 chart->setAxisX(axis, series);
232
234
233 return chart;
235 return chart;
234 }
236 }
235
237
236 QChart* ThemeWidget::createLineChart() const
238 QChart* ThemeWidget::createLineChart() const
237 {
239 {
238 QChart* chart = new QChart();
240 QChart* chart = new QChart();
239 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
241 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
240 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
242 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
241 chart->setTitle("Line chart");
243 chart->setTitle("Line chart");
242
244
243 QString name("Series ");
245 QString name("Series ");
244 int nameIndex = 0;
246 int nameIndex = 0;
245 foreach (DataList list, m_dataTable) {
247 foreach (DataList list, m_dataTable) {
246 QLineSeries *series = new QLineSeries(chart);
248 QLineSeries *series = new QLineSeries(chart);
247 foreach (Data data, list)
249 foreach (Data data, list)
248 series->append(data.first);
250 series->append(data.first);
249 series->setName(name + QString::number(nameIndex));
251 series->setName(name + QString::number(nameIndex));
250 nameIndex++;
252 nameIndex++;
251 chart->addSeries(series);
253 chart->addSeries(series);
252 chart->createDefaultAxes();
254 chart->createDefaultAxes();
253
255
254 }
256 }
255
257
256 return chart;
258 return chart;
257 }
259 }
258
260
259 QChart* ThemeWidget::createPieChart() const
261 QChart* ThemeWidget::createPieChart() const
260 {
262 {
261 QChart* chart = new QChart();
263 QChart* chart = new QChart();
262 chart->setTitle("Pie chart");
264 chart->setTitle("Pie chart");
263
265
264 qreal pieSize = 1.0 / m_dataTable.count();
266 qreal pieSize = 1.0 / m_dataTable.count();
265 for (int i = 0; i < m_dataTable.count(); i++) {
267 for (int i = 0; i < m_dataTable.count(); i++) {
266 QPieSeries *series = new QPieSeries(chart);
268 QPieSeries *series = new QPieSeries(chart);
267 foreach (Data data, m_dataTable[i]) {
269 foreach (Data data, m_dataTable[i]) {
268 QPieSlice *slice = series->append(data.second, data.first.y());
270 QPieSlice *slice = series->append(data.second, data.first.y());
269 if (data == m_dataTable[i].first()) {
271 if (data == m_dataTable[i].first()) {
270 slice->setLabelVisible();
272 slice->setLabelVisible();
271 slice->setExploded();
273 slice->setExploded();
272 }
274 }
273 }
275 }
274 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
276 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
275 series->setPieSize(pieSize);
277 series->setPieSize(pieSize);
276 series->setHorizontalPosition(hPos);
278 series->setHorizontalPosition(hPos);
277 series->setVerticalPosition(0.5);
279 series->setVerticalPosition(0.5);
278 chart->addSeries(series);
280 chart->addSeries(series);
279 }
281 }
280
282
281 return chart;
283 return chart;
282 }
284 }
283
285
284 QChart* ThemeWidget::createSplineChart() const
286 QChart* ThemeWidget::createSplineChart() const
285 { // spine chart
287 { // spine chart
286 QChart* chart = new QChart();
288 QChart* chart = new QChart();
287 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
289 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
288 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
290 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
289 chart->setTitle("Spline chart");
291 chart->setTitle("Spline chart");
290 QString name("Series ");
292 QString name("Series ");
291 int nameIndex = 0;
293 int nameIndex = 0;
292 foreach (DataList list, m_dataTable) {
294 foreach (DataList list, m_dataTable) {
293 QSplineSeries *series = new QSplineSeries(chart);
295 QSplineSeries *series = new QSplineSeries(chart);
294 foreach (Data data, list)
296 foreach (Data data, list)
295 series->append(data.first);
297 series->append(data.first);
296 series->setName(name + QString::number(nameIndex));
298 series->setName(name + QString::number(nameIndex));
297 nameIndex++;
299 nameIndex++;
298 chart->addSeries(series);
300 chart->addSeries(series);
301 chart->createDefaultAxes();
299 }
302 }
300 return chart;
303 return chart;
301 }
304 }
302
305
303 QChart* ThemeWidget::createScatterChart() const
306 QChart* ThemeWidget::createScatterChart() const
304 { // scatter chart
307 { // scatter chart
305 QChart* chart = new QChart();
308 QChart* chart = new QChart();
306 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
309 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
307 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
310 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
308 chart->setTitle("Scatter chart");
311 chart->setTitle("Scatter chart");
309 QString name("Series ");
312 QString name("Series ");
310 int nameIndex = 0;
313 int nameIndex = 0;
311 foreach (DataList list, m_dataTable) {
314 foreach (DataList list, m_dataTable) {
312 QScatterSeries *series = new QScatterSeries(chart);
315 QScatterSeries *series = new QScatterSeries(chart);
313 foreach (Data data, list)
316 foreach (Data data, list)
314 series->append(data.first);
317 series->append(data.first);
315 series->setName(name + QString::number(nameIndex));
318 series->setName(name + QString::number(nameIndex));
316 nameIndex++;
319 nameIndex++;
317 chart->addSeries(series);
320 chart->addSeries(series);
321 chart->createDefaultAxes();
318 }
322 }
319 return chart;
323 return chart;
320 }
324 }
321
325
322 void ThemeWidget::updateUI()
326 void ThemeWidget::updateUI()
323 {
327 {
324 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
328 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
325
329
326 if (m_charts.at(0)->chart()->theme() != theme) {
330 if (m_charts.at(0)->chart()->theme() != theme) {
327 foreach (QChartView *chartView, m_charts)
331 foreach (QChartView *chartView, m_charts)
328 chartView->chart()->setTheme(theme);
332 chartView->chart()->setTheme(theme);
329
333
330 QPalette pal = window()->palette();
334 QPalette pal = window()->palette();
331 if (theme == QChart::ChartThemeLight) {
335 if (theme == QChart::ChartThemeLight) {
332 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
336 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
333 pal.setColor(QPalette::WindowText, QRgb(0x404044));
337 pal.setColor(QPalette::WindowText, QRgb(0x404044));
334 } else if (theme == QChart::ChartThemeDark) {
338 } else if (theme == QChart::ChartThemeDark) {
335 pal.setColor(QPalette::Window, QRgb(0x121218));
339 pal.setColor(QPalette::Window, QRgb(0x121218));
336 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
340 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
337 } else if (theme == QChart::ChartThemeBlueCerulean) {
341 } else if (theme == QChart::ChartThemeBlueCerulean) {
338 pal.setColor(QPalette::Window, QRgb(0x40434a));
342 pal.setColor(QPalette::Window, QRgb(0x40434a));
339 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
343 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
340 } else if (theme == QChart::ChartThemeBrownSand) {
344 } else if (theme == QChart::ChartThemeBrownSand) {
341 pal.setColor(QPalette::Window, QRgb(0x9e8965));
345 pal.setColor(QPalette::Window, QRgb(0x9e8965));
342 pal.setColor(QPalette::WindowText, QRgb(0x404044));
346 pal.setColor(QPalette::WindowText, QRgb(0x404044));
343 } else if (theme == QChart::ChartThemeBlueNcs) {
347 } else if (theme == QChart::ChartThemeBlueNcs) {
344 pal.setColor(QPalette::Window, QRgb(0x018bba));
348 pal.setColor(QPalette::Window, QRgb(0x018bba));
345 pal.setColor(QPalette::WindowText, QRgb(0x404044));
349 pal.setColor(QPalette::WindowText, QRgb(0x404044));
346 } else if (theme == QChart::ChartThemeHighContrast) {
350 } else if (theme == QChart::ChartThemeHighContrast) {
347 pal.setColor(QPalette::Window, QRgb(0xffab03));
351 pal.setColor(QPalette::Window, QRgb(0xffab03));
348 pal.setColor(QPalette::WindowText, QRgb(0x181818));
352 pal.setColor(QPalette::WindowText, QRgb(0x181818));
349 } else if (theme == QChart::ChartThemeBlueIcy) {
353 } else if (theme == QChart::ChartThemeBlueIcy) {
350 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
354 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
351 pal.setColor(QPalette::WindowText, QRgb(0x404044));
355 pal.setColor(QPalette::WindowText, QRgb(0x404044));
352 } else {
356 } else {
353 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
357 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
354 pal.setColor(QPalette::WindowText, QRgb(0x404044));
358 pal.setColor(QPalette::WindowText, QRgb(0x404044));
355 }
359 }
356 window()->setPalette(pal);
360 window()->setPalette(pal);
357 }
361 }
358
362
359 bool checked = m_antialiasCheckBox->isChecked();
363 bool checked = m_antialiasCheckBox->isChecked();
360 foreach (QChartView *chart, m_charts)
364 foreach (QChartView *chart, m_charts)
361 chart->setRenderHint(QPainter::Antialiasing, checked);
365 chart->setRenderHint(QPainter::Antialiasing, checked);
362
366
363 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
367 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
364 if (m_charts.at(0)->chart()->animationOptions() != options) {
368 if (m_charts.at(0)->chart()->animationOptions() != options) {
365 foreach (QChartView *chartView, m_charts)
369 foreach (QChartView *chartView, m_charts)
366 chartView->chart()->setAnimationOptions(options);
370 chartView->chart()->setAnimationOptions(options);
367 }
371 }
368
372
369 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
373 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
370
374
371 if (!alignment) {
375 if (!alignment) {
372 foreach (QChartView *chartView, m_charts) {
376 foreach (QChartView *chartView, m_charts) {
373 chartView->chart()->legend()->hide();
377 chartView->chart()->legend()->hide();
374 }
378 }
375 } else {
379 } else {
376 foreach (QChartView *chartView, m_charts) {
380 foreach (QChartView *chartView, m_charts) {
377 chartView->chart()->legend()->setAlignment(alignment);
381 chartView->chart()->legend()->setAlignment(alignment);
378 chartView->chart()->legend()->show();
382 chartView->chart()->legend()->show();
379 }
383 }
380 }
384 }
381 }
385 }
382
386
@@ -1,111 +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 <QGroupedBarSeries>
29 #include <QGroupedBarSeries>
30 #include <QBarSet>
30 #include <QBarSet>
31 #include <QVBarModelMapper>
31 #include <QVBarModelMapper>
32 #include <QHeaderView>
32 #include <QHeaderView>
33 #include <QCategoriesAxis>
33 #include <QCategoriesAxis>
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 QGroupedBarSeries *series = new QGroupedBarSeries;
62 QGroupedBarSeries *series = new QGroupedBarSeries;
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 QCategoriesAxis* axis = new QCategoriesAxis();
91 QCategoriesAxis* axis = new QCategoriesAxis();
92 axis->append(categories);
92 axis->append(categories);
93 chart->createDefaultAxes();
93 chart->createDefaultAxes();
94 chart->setAxisX(axis, series);
94 //! [6]
95 //! [6]
95
96
96 //! [7]
97 //! [7]
97 QChartView *chartView = new QChartView(chart);
98 QChartView *chartView = new QChartView(chart);
98 chartView->setRenderHint(QPainter::Antialiasing);
99 chartView->setRenderHint(QPainter::Antialiasing);
99 chartView->setMinimumSize(640, 480);
100 chartView->setMinimumSize(640, 480);
100 //! [7]
101 //! [7]
101
102
102 //! [8]
103 //! [8]
103 // create main layout
104 // create main layout
104 QGridLayout* mainLayout = new QGridLayout;
105 QGridLayout* mainLayout = new QGridLayout;
105 mainLayout->addWidget(tableView, 1, 0);
106 mainLayout->addWidget(tableView, 1, 0);
106 mainLayout->addWidget(chartView, 1, 1);
107 mainLayout->addWidget(chartView, 1, 1);
107 mainLayout->setColumnStretch(1, 1);
108 mainLayout->setColumnStretch(1, 1);
108 mainLayout->setColumnStretch(0, 0);
109 mainLayout->setColumnStretch(0, 0);
109 setLayout(mainLayout);
110 setLayout(mainLayout);
110 //! [8]
111 //! [8]
111 }
112 }
@@ -1,289 +1,289
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 "qvaluesaxis.h"
21 #include "qvaluesaxis.h"
22 #include "qvaluesaxis_p.h"
22 #include "qvaluesaxis_p.h"
23 #include "chartvaluesaxisx_p.h"
23 #include "chartvaluesaxisx_p.h"
24 #include "chartvaluesaxisy_p.h"
24 #include "chartvaluesaxisy_p.h"
25 #include <QDebug>
25 #include <QDebug>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 /*!
28 /*!
29 \class QValuesAxis
29 \class QValuesAxis
30 \brief The QValuesAxis class is used for manipulating chart's axis.
30 \brief The QValuesAxis class is used for manipulating chart's axis.
31 \mainclass
31 \mainclass
32
32
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 */
34 */
35
35
36 /*!
36 /*!
37 \qmlclass Axis QValuesAxis
37 \qmlclass Axis QValuesAxis
38 \brief The Axis element is used for manipulating chart's axes
38 \brief The Axis element is used for manipulating chart's axes
39
39
40 Axis can be setup to show axis line with tick marks, grid lines and shades.
40 Axis can be setup to show axis line with tick marks, grid lines and shades.
41
41
42 To access Axes you can use ChartView API. For example:
42 To access Axes you can use ChartView API. For example:
43 \code
43 \code
44 ChartView {
44 ChartView {
45 axisX.min: 0
45 axisX.min: 0
46 axisX.max: 3
46 axisX.max: 3
47 axisX.ticksCount: 4
47 axisX.ticksCount: 4
48 axisY.min: 0
48 axisY.min: 0
49 axisY.max: 4
49 axisY.max: 4
50 // Add a few series...
50 // Add a few series...
51 }
51 }
52 \endcode
52 \endcode
53 */
53 */
54
54
55 /*!
55 /*!
56 \property QValuesAxis::min
56 \property QValuesAxis::min
57 Defines the minimum value on the axis.
57 Defines the minimum value on the axis.
58 */
58 */
59 /*!
59 /*!
60 \qmlproperty real Axis::min
60 \qmlproperty real Axis::min
61 Defines the minimum value on the axis.
61 Defines the minimum value on the axis.
62 */
62 */
63
63
64 /*!
64 /*!
65 \property QValuesAxis::max
65 \property QValuesAxis::max
66 Defines the maximum value on the axis.
66 Defines the maximum value on the axis.
67 */
67 */
68 /*!
68 /*!
69 \qmlproperty real Axis::max
69 \qmlproperty real Axis::max
70 Defines the maximum value on the axis.
70 Defines the maximum value on the axis.
71 */
71 */
72
72
73 /*!
73 /*!
74 \fn void QValuesAxis::minChanged(qreal min)
74 \fn void QValuesAxis::minChanged(qreal min)
75 Axis emits signal when \a min of axis has changed.
75 Axis emits signal when \a min of axis has changed.
76 */
76 */
77
77
78 /*!
78 /*!
79 \fn void QValuesAxis::maxChanged(qreal max)
79 \fn void QValuesAxis::maxChanged(qreal max)
80 Axis emits signal when \a max of axis has changed.
80 Axis emits signal when \a max of axis has changed.
81 */
81 */
82
82
83 /*!
83 /*!
84 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
84 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
85 Axis emits signal when \a min or \a max of axis has changed.
85 Axis emits signal when \a min or \a max of axis has changed.
86 */
86 */
87
87
88 /*!
88 /*!
89 \property QValuesAxis::ticksCount
89 \property QValuesAxis::ticksCount
90 The number of tick marks for the axis.
90 The number of tick marks for the axis.
91 */
91 */
92
92
93 /*!
93 /*!
94 \qmlproperty int Axis::ticksCount
94 \qmlproperty int Axis::ticksCount
95 The number of tick marks for the axis.
95 The number of tick marks for the axis.
96 */
96 */
97
97
98 /*!
98 /*!
99 \property QValuesAxis::niceNumbersEnabled
99 \property QValuesAxis::niceNumbersEnabled
100 Whether the nice numbers algorithm is enabled or not for the axis.
100 Whether the nice numbers algorithm is enabled or not for the axis.
101 */
101 */
102
102
103 /*!
103 /*!
104 \qmlproperty bool Axis::niceNumbersEnabled
104 \qmlproperty bool Axis::niceNumbersEnabled
105 Whether the nice numbers algorithm is enabled or not for the axis.
105 Whether the nice numbers algorithm is enabled or not for the axis.
106 */
106 */
107
107
108 QValuesAxis::QValuesAxis(QObject *parent) :
108 QValuesAxis::QValuesAxis(QObject *parent) :
109 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
109 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
110 {
110 {
111
111
112 }
112 }
113
113
114 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
114 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
115 {
115 {
116
116
117 }
117 }
118
118
119 QValuesAxis::~QValuesAxis()
119 QValuesAxis::~QValuesAxis()
120 {
120 {
121
121
122 }
122 }
123
123
124 void QValuesAxis::setMin(qreal min)
124 void QValuesAxis::setMin(qreal min)
125 {
125 {
126 Q_D(QValuesAxis);
126 Q_D(QValuesAxis);
127 setRange(min,d->m_max);
127 setRange(min,d->m_max);
128 }
128 }
129
129
130 qreal QValuesAxis::min() const
130 qreal QValuesAxis::min() const
131 {
131 {
132 Q_D(const QValuesAxis);
132 Q_D(const QValuesAxis);
133 return d->m_min;
133 return d->m_min;
134 }
134 }
135
135
136 void QValuesAxis::setMax(qreal max)
136 void QValuesAxis::setMax(qreal max)
137 {
137 {
138 Q_D(QValuesAxis);
138 Q_D(QValuesAxis);
139 setRange(d->m_min,max);
139 setRange(d->m_min,max);
140 }
140 }
141
141
142 qreal QValuesAxis::max() const
142 qreal QValuesAxis::max() const
143 {
143 {
144 Q_D(const QValuesAxis);
144 Q_D(const QValuesAxis);
145 return d->m_max;
145 return d->m_max;
146 }
146 }
147
147
148 /*!
148 /*!
149 Sets range from \a min to \a max on the axis.
149 Sets range from \a min to \a max on the axis.
150 */
150 */
151 void QValuesAxis::setRange(qreal min, qreal max)
151 void QValuesAxis::setRange(qreal min, qreal max)
152 {
152 {
153 Q_D(QValuesAxis);
153 Q_D(QValuesAxis);
154 bool changed = false;
154 bool changed = false;
155 if (!qFuzzyIsNull(d->m_min - min)) {
155 if (!qFuzzyIsNull(d->m_min - min)) {
156 d->m_min = min;
156 d->m_min = min;
157 changed = true;
157 changed = true;
158 emit minChanged(min);
158 emit minChanged(min);
159 }
159 }
160
160
161 if (!qFuzzyIsNull(d->m_max - max)) {
161 if (!qFuzzyIsNull(d->m_max - max)) {
162 d->m_max = max;
162 d->m_max = max;
163 changed = true;
163 changed = true;
164 emit maxChanged(max);
164 emit maxChanged(max);
165 }
165 }
166
166
167 if (changed) {
167 if (changed) {
168 emit rangeChanged(d->m_min,d->m_max);
168 emit rangeChanged(d->m_min,d->m_max);
169 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
169 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
170 }
170 }
171 d->setRange(min,max);
171 // d->setRange(min,max);
172 }
172 }
173
173
174 /*!
174 /*!
175 Sets \a count for ticks on the axis.
175 Sets \a count for ticks on the axis.
176 */
176 */
177 void QValuesAxis::setTicksCount(int count)
177 void QValuesAxis::setTicksCount(int count)
178 {
178 {
179 Q_D(QValuesAxis);
179 Q_D(QValuesAxis);
180 if (d->m_ticksCount != count) {
180 if (d->m_ticksCount != count) {
181 d->m_ticksCount = count;
181 d->m_ticksCount = count;
182 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
182 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
183 }
183 }
184 }
184 }
185
185
186 /*!
186 /*!
187 \fn int QValuesAxis::ticksCount() const
187 \fn int QValuesAxis::ticksCount() const
188 Return number of ticks on the axis
188 Return number of ticks on the axis
189 */
189 */
190 int QValuesAxis::ticksCount() const
190 int QValuesAxis::ticksCount() const
191 {
191 {
192 Q_D(const QValuesAxis);
192 Q_D(const QValuesAxis);
193 return d->m_ticksCount;
193 return d->m_ticksCount;
194 }
194 }
195
195
196 void QValuesAxis::setNiceNumbersEnabled(bool enable)
196 void QValuesAxis::setNiceNumbersEnabled(bool enable)
197 {
197 {
198 Q_D(QValuesAxis);
198 Q_D(QValuesAxis);
199 if (d->m_niceNumbers != enable){
199 if (d->m_niceNumbers != enable){
200 d->m_niceNumbers = enable;
200 d->m_niceNumbers = enable;
201 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
201 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
202 }
202 }
203 }
203 }
204
204
205 bool QValuesAxis::niceNumbersEnabled() const
205 bool QValuesAxis::niceNumbersEnabled() const
206 {
206 {
207 Q_D(const QValuesAxis);
207 Q_D(const QValuesAxis);
208 return d->m_niceNumbers;
208 return d->m_niceNumbers;
209 }
209 }
210
210
211 QAbstractAxis::AxisType QValuesAxis::type() const
211 QAbstractAxis::AxisType QValuesAxis::type() const
212 {
212 {
213 return AxisTypeValues;
213 return AxisTypeValues;
214 }
214 }
215
215
216 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
216 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
217
217
218 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
218 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
219 QAbstractAxisPrivate(q),
219 QAbstractAxisPrivate(q),
220 m_niceNumbers(false)
220 m_niceNumbers(false)
221 {
221 {
222
222
223 }
223 }
224
224
225 QValuesAxisPrivate::~QValuesAxisPrivate()
225 QValuesAxisPrivate::~QValuesAxisPrivate()
226 {
226 {
227
227
228 }
228 }
229
229
230 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
230 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
231 {
231 {
232 Q_Q(QValuesAxis);
232 Q_Q(QValuesAxis);
233 q->setRange(min,max);
233 q->setRange(min,max);
234 q->setTicksCount(count);
234 q->setTicksCount(count);
235 }
235 }
236
236
237
237
238 void QValuesAxisPrivate::setMin(const QVariant &min)
238 void QValuesAxisPrivate::setMin(const QVariant &min)
239 {
239 {
240 Q_Q(QValuesAxis);
240 Q_Q(QValuesAxis);
241 bool ok;
241 bool ok;
242 qreal value = min.toReal(&ok);
242 qreal value = min.toReal(&ok);
243 if(ok) q->setMin(value);
243 if(ok) q->setMin(value);
244 }
244 }
245
245
246 void QValuesAxisPrivate::setMax(const QVariant &max)
246 void QValuesAxisPrivate::setMax(const QVariant &max)
247 {
247 {
248 Q_Q(QValuesAxis);
248 Q_Q(QValuesAxis);
249 bool ok;
249 bool ok;
250 qreal value = max.toReal(&ok);
250 qreal value = max.toReal(&ok);
251 if(ok) q->setMax(value);
251 if(ok) q->setMax(value);
252 }
252 }
253
253
254 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max, bool force)
254 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max, bool force)
255 {
255 {
256 Q_UNUSED(force); // TODO: use this
256 Q_UNUSED(force); // TODO: use this
257 Q_Q(QValuesAxis);
257 Q_Q(QValuesAxis);
258 bool ok1;
258 bool ok1;
259 bool ok2;
259 bool ok2;
260 qreal value1 = min.toReal(&ok1);
260 qreal value1 = min.toReal(&ok1);
261 qreal value2 = max.toReal(&ok2);
261 qreal value2 = max.toReal(&ok2);
262 if(ok1&&ok2) q->setRange(value1,value2);
262 if(ok1&&ok2) q->setRange(value1,value2);
263 }
263 }
264
264
265 int QValuesAxisPrivate::ticksCount() const
265 int QValuesAxisPrivate::ticksCount() const
266 {
266 {
267 return m_ticksCount;
267 return m_ticksCount;
268 }
268 }
269
269
270 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
270 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
271 {
271 {
272 Q_Q(QValuesAxis);
272 Q_Q(QValuesAxis);
273 if(m_orientation == Qt::Vertical){
273 if(m_orientation == Qt::Vertical){
274 return new ChartValuesAxisY(q,presenter);
274 return new ChartValuesAxisY(q,presenter);
275 }else{
275 }else{
276 return new ChartValuesAxisX(q,presenter);
276 return new ChartValuesAxisX(q,presenter);
277 }
277 }
278
278
279 }
279 }
280
280
281 void QValuesAxisPrivate::updateRange()
281 void QValuesAxisPrivate::updateRange()
282 {
282 {
283 setRange(m_min,m_max,true);
283 setRange(m_min,m_max,true);
284 }
284 }
285
285
286 #include "moc_qvaluesaxis.cpp"
286 #include "moc_qvaluesaxis.cpp"
287 #include "moc_qvaluesaxis_p.cpp"
287 #include "moc_qvaluesaxis_p.cpp"
288
288
289 QTCOMMERCIALCHART_END_NAMESPACE
289 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now