##// END OF EJS Templates
Adds templete to chartviewer to simplyfy chart type creation
Michal Klocek -
r1839:16961447933b
parent child
Show More
@@ -1,86 +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
21
22 #ifndef CHARTS_H
22 #ifndef CHARTS_H
23 #define CHARTS_H
23 #define CHARTS_H
24 #include "model.h"
24 #include "model.h"
25 #include <QList>
25 #include <QList>
26 #include <QString>
26 #include <QString>
27 #include <qchartglobal.h>
27 #include <qchartglobal.h>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 class QChart;
30 class QChart;
31 QTCOMMERCIALCHART_END_NAMESPACE
31 QTCOMMERCIALCHART_END_NAMESPACE
32
32
33 QTCOMMERCIALCHART_USE_NAMESPACE
33 QTCOMMERCIALCHART_USE_NAMESPACE
34
34
35 class Chart
35 class Chart
36 {
36 {
37 public:
37 public:
38 Chart();
38 virtual ~Chart(){};
39
40 virtual ~Chart();
41
42 virtual void initialize();
43 virtual QChart* createChart(const DataTable& table) = 0;
39 virtual QChart* createChart(const DataTable& table) = 0;
44 virtual QString name() = 0;
40 virtual QString name() = 0;
45 virtual QString category() = 0;
41 virtual QString category() = 0;
46 virtual QString subCategory() = 0;
42 virtual QString subCategory() = 0;
47
43
48 };
44 };
49
45
50 namespace Charts
46 namespace Charts
51 {
47 {
52
48
53 typedef QList<Chart*> ChartList;
49 typedef QList<Chart*> ChartList;
54
50
55 inline ChartList& chartList()
51 inline ChartList& chartList()
56 {
52 {
57 static ChartList list;
53 static ChartList list;
58 return list;
54 return list;
59 }
55 }
60
56
61 inline bool findChart(Chart* chart)
57 inline bool findChart(Chart* chart)
62 {
58 {
63 ChartList& list = chartList();
59 ChartList& list = chartList();
64 if (list.contains(chart)) {
60 if (list.contains(chart)) {
65 return true;
61 return true;
66 }
62 }
67 foreach (Chart* item, list) {
63 foreach (Chart* item, list) {
68 if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) {
64 if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) {
69 return true;
65 return true;
70 }
66 }
71 }
67 }
72 return false;
68 return false;
73 }
69 }
74
70
75 inline void addChart(Chart* chart)
71 inline void addChart(Chart* chart)
76 {
72 {
77 ChartList& list = chartList();
73 ChartList& list = chartList();
78 if (!findChart(chart)) {
74 if (!findChart(chart)) {
79 list.append(chart);
75 list.append(chart);
80 }
76 }
81 }
77 }
82 }
78 }
83
79
84 #define DECLARE_CHART(chartName) static chartName t;
80 template <class T>
81 class ChartWrapper
82 {
83 public:
84 QSharedPointer<T> chart;
85 ChartWrapper() : chart(new T)
86 {
87 Charts::addChart(chart.data());
88 }
89 };
90
91 #define DECLARE_CHART(chartName) static ChartWrapper<chartName> t;
85
92
86 #endif
93 #endif
@@ -1,74 +1,69
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 "charts.h"
21 #include "charts.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qareaseries.h"
23 #include "qareaseries.h"
24 #include "qlineseries.h"
24 #include "qlineseries.h"
25
25
26 class AreaChart: public Chart
26 class AreaChart: public Chart
27 {
27 {
28 public:
28 public:
29
30 AreaChart(){
31 initialize();
32 }
33
34 QString name() { return QObject::tr("AreaChart"); }
29 QString name() { return QObject::tr("AreaChart"); }
35 QString category() { return QObject::tr("XYSeries"); }
30 QString category() { return QObject::tr("XYSeries"); }
36 QString subCategory() { return QString::null; }
31 QString subCategory() { return QString::null; }
37
32
38 QChart* createChart(const DataTable& table)
33 QChart* createChart(const DataTable& table)
39 {
34 {
40
35
41 QChart *chart = new QChart();
36 QChart *chart = new QChart();
42 chart->setTitle("Area chart");
37 chart->setTitle("Area chart");
43
38
44 // The lower series initialized to zero values
39 // The lower series initialized to zero values
45 QLineSeries *lowerSeries = 0;
40 QLineSeries *lowerSeries = 0;
46 QString name("Series ");
41 QString name("Series ");
47 int nameIndex = 0;
42 int nameIndex = 0;
48 for (int i(0); i < table.count(); i++) {
43 for (int i(0); i < table.count(); i++) {
49 QLineSeries *upperSeries = new QLineSeries(chart);
44 QLineSeries *upperSeries = new QLineSeries(chart);
50 for (int j(0); j < table[i].count(); j++) {
45 for (int j(0); j < table[i].count(); j++) {
51 Data data = table[i].at(j);
46 Data data = table[i].at(j);
52 if (lowerSeries) {
47 if (lowerSeries) {
53 const QList<QPointF>& points = lowerSeries->points();
48 const QList<QPointF>& points = lowerSeries->points();
54 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
49 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
55 }
50 }
56 else
51 else
57 upperSeries->append(QPointF(j, data.first.y()));
52 upperSeries->append(QPointF(j, data.first.y()));
58 }
53 }
59 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
54 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
60 area->setName(name + QString::number(nameIndex));
55 area->setName(name + QString::number(nameIndex));
61 nameIndex++;
56 nameIndex++;
62 chart->addSeries(area);
57 chart->addSeries(area);
63 chart->createDefaultAxes();
58 chart->createDefaultAxes();
64 lowerSeries = upperSeries;
59 lowerSeries = upperSeries;
65 }
60 }
66
61
67 return chart;
62 return chart;
68
63
69 }
64 }
70
65
71 };
66 };
72
67
73 DECLARE_CHART(AreaChart)
68 DECLARE_CHART(AreaChart)
74
69
@@ -1,60 +1,55
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 "charts.h"
21 #include "charts.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qhorizontalbarseries.h"
23 #include "qhorizontalbarseries.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25
25
26 class HorizontalBarChart: public Chart
26 class HorizontalBarChart: public Chart
27 {
27 {
28 public:
28 public:
29
30 HorizontalBarChart(){
31 initialize();
32 }
33
34 QString name() { return QObject::tr("HorizontalBarChart"); }
29 QString name() { return QObject::tr("HorizontalBarChart"); }
35 QString category() { return QObject::tr("BarSeries"); }
30 QString category() { return QObject::tr("BarSeries"); }
36 QString subCategory() { return QObject::tr("Vertical"); }
31 QString subCategory() { return QObject::tr("Vertical"); }
37
32
38 QChart* createChart(const DataTable& table)
33 QChart* createChart(const DataTable& table)
39 {
34 {
40
35
41 QChart* chart = new QChart();
36 QChart* chart = new QChart();
42
37
43 chart->setTitle("Horizontal bar chart");
38 chart->setTitle("Horizontal bar chart");
44
39
45 QHorizontalBarSeries* series = new QHorizontalBarSeries(chart);
40 QHorizontalBarSeries* series = new QHorizontalBarSeries(chart);
46 for (int i(0); i < table.count(); i++) {
41 for (int i(0); i < table.count(); i++) {
47 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
48 foreach (Data data, table[i])
43 foreach (Data data, table[i])
49 *set << data.first.y();
44 *set << data.first.y();
50 series->append(set);
45 series->append(set);
51 }
46 }
52 chart->addSeries(series);
47 chart->addSeries(series);
53 chart->createDefaultAxes();
48 chart->createDefaultAxes();
54 return chart;
49 return chart;
55 }
50 }
56
51
57 };
52 };
58
53
59 DECLARE_CHART(HorizontalBarChart)
54 DECLARE_CHART(HorizontalBarChart)
60
55
@@ -1,60 +1,55
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 "charts.h"
21 #include "charts.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qhorizontalstackedbarseries.h"
23 #include "qhorizontalstackedbarseries.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25
25
26 class HorizontalStackedBarChart: public Chart
26 class HorizontalStackedBarChart: public Chart
27 {
27 {
28 public:
28 public:
29
30 HorizontalStackedBarChart(){
31 initialize();
32 }
33
34 QString name() { return QObject::tr("HorizontalStackedBarChart"); }
29 QString name() { return QObject::tr("HorizontalStackedBarChart"); }
35 QString category() { return QObject::tr("BarSeries"); }
30 QString category() { return QObject::tr("BarSeries"); }
36 QString subCategory() { return QObject::tr("Vertical"); }
31 QString subCategory() { return QObject::tr("Vertical"); }
37
32
38 QChart* createChart(const DataTable& table)
33 QChart* createChart(const DataTable& table)
39 {
34 {
40
35
41 QChart* chart = new QChart();
36 QChart* chart = new QChart();
42
37
43 chart->setTitle("Horizontal stacked chart");
38 chart->setTitle("Horizontal stacked chart");
44
39
45 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries(chart);
40 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries(chart);
46 for (int i(0); i < table.count(); i++) {
41 for (int i(0); i < table.count(); i++) {
47 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
48 foreach (Data data, table[i])
43 foreach (Data data, table[i])
49 *set << data.first.y();
44 *set << data.first.y();
50 series->append(set);
45 series->append(set);
51 }
46 }
52 chart->addSeries(series);
47 chart->addSeries(series);
53 chart->createDefaultAxes();
48 chart->createDefaultAxes();
54 return chart;
49 return chart;
55 }
50 }
56
51
57 };
52 };
58
53
59 DECLARE_CHART(HorizontalStackedBarChart)
54 DECLARE_CHART(HorizontalStackedBarChart)
60
55
@@ -1,61 +1,56
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 "charts.h"
21 #include "charts.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qlineseries.h"
23 #include "qlineseries.h"
24
24
25 class LineChart: public Chart
25 class LineChart: public Chart
26 {
26 {
27 public:
27 public:
28
29 LineChart(){
30 initialize();
31 }
32
33 QString name() { return QObject::tr("LineChart"); }
28 QString name() { return QObject::tr("LineChart"); }
34 QString category() { return QObject::tr("XYSeries"); }
29 QString category() { return QObject::tr("XYSeries"); }
35 QString subCategory() { return QString::null; }
30 QString subCategory() { return QString::null; }
36
31
37 QChart* createChart(const DataTable& table) {
32 QChart* createChart(const DataTable& table) {
38
33
39 QChart* chart = new QChart();
34 QChart* chart = new QChart();
40 chart->setTitle("Line chart");
35 chart->setTitle("Line chart");
41
36
42 QString name("Series ");
37 QString name("Series ");
43 int nameIndex = 0;
38 int nameIndex = 0;
44 foreach (DataList list, table) {
39 foreach (DataList list, table) {
45 QLineSeries *series = new QLineSeries(chart);
40 QLineSeries *series = new QLineSeries(chart);
46 foreach (Data data, list)
41 foreach (Data data, list)
47 series->append(data.first);
42 series->append(data.first);
48 series->setName(name + QString::number(nameIndex));
43 series->setName(name + QString::number(nameIndex));
49 nameIndex++;
44 nameIndex++;
50 chart->addSeries(series);
45 chart->addSeries(series);
51 }
46 }
52
47
53 chart->createDefaultAxes();
48 chart->createDefaultAxes();
54
49
55 return chart;
50 return chart;
56 }
51 }
57
52
58 };
53 };
59
54
60 DECLARE_CHART(LineChart)
55 DECLARE_CHART(LineChart)
61
56
@@ -1,64 +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 "charts.h"
21 #include "charts.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qpieseries.h"
23 #include "qpieseries.h"
24
24
25 class PieChart: public Chart
25 class PieChart: public Chart
26 {
26 {
27 public:
27 public:
28
29 PieChart(){
30 initialize();
31 }
32
33 QString name() { return QObject::tr("PieChart"); }
28 QString name() { return QObject::tr("PieChart"); }
34 QString category() { return QString::null; }
29 QString category() { return QString::null; }
35 QString subCategory() { return QString::null; }
30 QString subCategory() { return QString::null; }
36
31
37 QChart* createChart(const DataTable& table)
32 QChart* createChart(const DataTable& table)
38 {
33 {
39 QChart* chart = new QChart();
34 QChart* chart = new QChart();
40 chart->setTitle("Pie chart");
35 chart->setTitle("Pie chart");
41
36
42 qreal pieSize = 1.0 / table.count();
37 qreal pieSize = 1.0 / table.count();
43 for (int i = 0; i < table.count(); i++) {
38 for (int i = 0; i < table.count(); i++) {
44 QPieSeries *series = new QPieSeries(chart);
39 QPieSeries *series = new QPieSeries(chart);
45 foreach (Data data, table[i]) {
40 foreach (Data data, table[i]) {
46 QPieSlice *slice = series->append(data.second, data.first.y());
41 QPieSlice *slice = series->append(data.second, data.first.y());
47 if (data == table[i].first()) {
42 if (data == table[i].first()) {
48 slice->setLabelVisible();
43 slice->setLabelVisible();
49 slice->setExploded();
44 slice->setExploded();
50 }
45 }
51 }
46 }
52 qreal hPos = (pieSize / 2) + (i / (qreal) table.count());
47 qreal hPos = (pieSize / 2) + (i / (qreal) table.count());
53 series->setPieSize(pieSize);
48 series->setPieSize(pieSize);
54 series->setHorizontalPosition(hPos);
49 series->setHorizontalPosition(hPos);
55 series->setVerticalPosition(0.5);
50 series->setVerticalPosition(0.5);
56 chart->addSeries(series);
51 chart->addSeries(series);
57 }
52 }
58 return chart;
53 return chart;
59 }
54 }
60
55
61 };
56 };
62
57
63 DECLARE_CHART(PieChart)
58 DECLARE_CHART(PieChart)
64
59
@@ -1,59 +1,54
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 "charts.h"
21 #include "charts.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qscatterseries.h"
23 #include "qscatterseries.h"
24
24
25 class ScatterChart: public Chart
25 class ScatterChart: public Chart
26 {
26 {
27 public:
27 public:
28
29 ScatterChart(){
30 initialize();
31 }
32
33 QString name() { return QObject::tr("ScatterChart"); }
28 QString name() { return QObject::tr("ScatterChart"); }
34 QString category() { return QObject::tr("XYSeries"); }
29 QString category() { return QObject::tr("XYSeries"); }
35 QString subCategory() { return QString::null; }
30 QString subCategory() { return QString::null; }
36
31
37 QChart* createChart(const DataTable& table)
32 QChart* createChart(const DataTable& table)
38 {
33 {
39
34
40 QChart* chart = new QChart();
35 QChart* chart = new QChart();
41 chart->setTitle("Scatter chart");
36 chart->setTitle("Scatter chart");
42 QString name("Series ");
37 QString name("Series ");
43 int nameIndex = 0;
38 int nameIndex = 0;
44 foreach (DataList list, table) {
39 foreach (DataList list, table) {
45 QScatterSeries *series = new QScatterSeries(chart);
40 QScatterSeries *series = new QScatterSeries(chart);
46 foreach (Data data, list)
41 foreach (Data data, list)
47 series->append(data.first);
42 series->append(data.first);
48 series->setName(name + QString::number(nameIndex));
43 series->setName(name + QString::number(nameIndex));
49 nameIndex++;
44 nameIndex++;
50 chart->addSeries(series);
45 chart->addSeries(series);
51 }
46 }
52 chart->createDefaultAxes();
47 chart->createDefaultAxes();
53
48
54 return chart;
49 return chart;
55 }
50 }
56
51
57 };
52 };
58
53
59 DECLARE_CHART(ScatterChart)
54 DECLARE_CHART(ScatterChart)
@@ -1,60 +1,55
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 "charts.h"
21 #include "charts.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qsplineseries.h"
23 #include "qsplineseries.h"
24
24
25 class SplineChart: public Chart
25 class SplineChart: public Chart
26 {
26 {
27 public:
27 public:
28
29 SplineChart(){
30 initialize();
31 }
32
33 QString name() { return QObject::tr("SplineChart"); }
28 QString name() { return QObject::tr("SplineChart"); }
34 QString category() { return QObject::tr("XYSeries"); }
29 QString category() { return QObject::tr("XYSeries"); }
35 QString subCategory() { return QString::null; }
30 QString subCategory() { return QString::null; }
36
31
37 QChart* createChart(const DataTable& table)
32 QChart* createChart(const DataTable& table)
38 {
33 {
39
34
40 QChart* chart = new QChart();
35 QChart* chart = new QChart();
41
36
42 chart->setTitle("Spline chart");
37 chart->setTitle("Spline chart");
43 QString name("Series ");
38 QString name("Series ");
44 int nameIndex = 0;
39 int nameIndex = 0;
45 foreach (DataList list, table) {
40 foreach (DataList list, table) {
46 QSplineSeries *series = new QSplineSeries(chart);
41 QSplineSeries *series = new QSplineSeries(chart);
47 foreach (Data data, list)
42 foreach (Data data, list)
48 series->append(data.first);
43 series->append(data.first);
49 series->setName(name + QString::number(nameIndex));
44 series->setName(name + QString::number(nameIndex));
50 nameIndex++;
45 nameIndex++;
51 chart->addSeries(series);
46 chart->addSeries(series);
52 }
47 }
53 chart->createDefaultAxes();
48 chart->createDefaultAxes();
54 return chart;
49 return chart;
55 }
50 }
56
51
57 };
52 };
58
53
59 DECLARE_CHART(SplineChart)
54 DECLARE_CHART(SplineChart)
60
55
@@ -1,60 +1,55
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 "charts.h"
21 #include "charts.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qbarseries.h"
23 #include "qbarseries.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25
25
26 class VerticalBarChart: public Chart
26 class VerticalBarChart: public Chart
27 {
27 {
28 public:
28 public:
29
30 VerticalBarChart(){
31 initialize();
32 }
33
34 QString name() { return QObject::tr("VerticalBarChart"); }
29 QString name() { return QObject::tr("VerticalBarChart"); }
35 QString category() { return QObject::tr("BarSeries"); }
30 QString category() { return QObject::tr("BarSeries"); }
36 QString subCategory() { return QObject::tr("Vertical"); }
31 QString subCategory() { return QObject::tr("Vertical"); }
37
32
38 QChart* createChart(const DataTable& table)
33 QChart* createChart(const DataTable& table)
39 {
34 {
40
35
41 QChart* chart = new QChart();
36 QChart* chart = new QChart();
42
37
43 chart->setTitle("Vertical bar chart");
38 chart->setTitle("Vertical bar chart");
44
39
45 QBarSeries* series = new QBarSeries(chart);
40 QBarSeries* series = new QBarSeries(chart);
46 for (int i(0); i < table.count(); i++) {
41 for (int i(0); i < table.count(); i++) {
47 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
48 foreach (Data data, table[i])
43 foreach (Data data, table[i])
49 *set << data.first.y();
44 *set << data.first.y();
50 series->append(set);
45 series->append(set);
51 }
46 }
52 chart->addSeries(series);
47 chart->addSeries(series);
53 chart->createDefaultAxes();
48 chart->createDefaultAxes();
54 return chart;
49 return chart;
55 }
50 }
56
51
57 };
52 };
58
53
59 DECLARE_CHART(VerticalBarChart)
54 DECLARE_CHART(VerticalBarChart)
60
55
@@ -1,60 +1,55
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 "charts.h"
21 #include "charts.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qstackedbarseries.h"
23 #include "qstackedbarseries.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25
25
26 class VerticalStackedBarChart: public Chart
26 class VerticalStackedBarChart: public Chart
27 {
27 {
28 public:
28 public:
29
30 VerticalStackedBarChart(){
31 initialize();
32 }
33
34 QString name() { return QObject::tr("VerticalStackedBarChart"); }
29 QString name() { return QObject::tr("VerticalStackedBarChart"); }
35 QString category() { return QObject::tr("BarSeries"); }
30 QString category() { return QObject::tr("BarSeries"); }
36 QString subCategory() { return QObject::tr("Vertical"); }
31 QString subCategory() { return QObject::tr("Vertical"); }
37
32
38 QChart* createChart(const DataTable& table)
33 QChart* createChart(const DataTable& table)
39 {
34 {
40
35
41 QChart* chart = new QChart();
36 QChart* chart = new QChart();
42
37
43 chart->setTitle("Stacked bar chart");
38 chart->setTitle("Stacked bar chart");
44
39
45 QStackedBarSeries* series = new QStackedBarSeries(chart);
40 QStackedBarSeries* series = new QStackedBarSeries(chart);
46 for (int i(0); i < table.count(); i++) {
41 for (int i(0); i < table.count(); i++) {
47 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
48 foreach (Data data, table[i])
43 foreach (Data data, table[i])
49 *set << data.first.y();
44 *set << data.first.y();
50 series->append(set);
45 series->append(set);
51 }
46 }
52 chart->addSeries(series);
47 chart->addSeries(series);
53 chart->createDefaultAxes();
48 chart->createDefaultAxes();
54 return chart;
49 return chart;
55 }
50 }
56
51
57 };
52 };
58
53
59 DECLARE_CHART(VerticalStackedBarChart)
54 DECLARE_CHART(VerticalStackedBarChart)
60
55
@@ -1,8 +1,8
1 !include( ../demos.pri ):error( "Couldn't find the demos.pri file!" )
1 !include( ../demos.pri ):error( "Couldn't find the demos.pri file!" )
2 include(charts/charts.pri)
2 include(charts/charts.pri)
3 TARGET = chartviewer
3 TARGET = chartviewer
4 QT += opengl
4 QT += opengl
5 INCLUDEPATH += .
5 INCLUDEPATH += .
6 SOURCES += main.cpp window.cpp view.cpp charts.cpp
6 SOURCES += main.cpp window.cpp view.cpp
7 HEADERS += window.h view.h charts.h model.h
7 HEADERS += window.h view.h charts.h model.h
8
8
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now