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