@@ -0,0 +1,60 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include "charts.h" | |||
|
22 | #include "qchart.h" | |||
|
23 | #include "qlineseries.h" | |||
|
24 | #include "qvalueaxis.h" | |||
|
25 | #include "qcategoryaxis.h" | |||
|
26 | ||||
|
27 | class ValueAxis: public Chart | |||
|
28 | { | |||
|
29 | public: | |||
|
30 | QString name() { return "ValueAxis"; } | |||
|
31 | QString category() { return QObject::tr("Axis"); } | |||
|
32 | QString subCategory() { return QString::null; } | |||
|
33 | ||||
|
34 | QChart* createChart(const DataTable& table) { | |||
|
35 | ||||
|
36 | QChart* chart = new QChart(); | |||
|
37 | chart->setTitle("Value X , Value Y"); | |||
|
38 | ||||
|
39 | QString name("Series "); | |||
|
40 | int nameIndex = 0; | |||
|
41 | foreach (DataList list, table) { | |||
|
42 | QLineSeries *series = new QLineSeries(chart); | |||
|
43 | foreach (Data data, list) | |||
|
44 | series->append(data.first); | |||
|
45 | series->setName(name + QString::number(nameIndex)); | |||
|
46 | nameIndex++; | |||
|
47 | chart->addSeries(series); | |||
|
48 | } | |||
|
49 | ||||
|
50 | chart->createDefaultAxes(); | |||
|
51 | QValueAxis* axis = new QValueAxis(); | |||
|
52 | foreach (QAbstractSeries* series,chart->series()) | |||
|
53 | chart->setAxisX(axis,series); | |||
|
54 | ||||
|
55 | return chart; | |||
|
56 | } | |||
|
57 | ||||
|
58 | }; | |||
|
59 | ||||
|
60 | DECLARE_CHART(ValueAxis); |
@@ -1,93 +1,94 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
|
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 | virtual ~Chart(){}; |
|
38 | virtual ~Chart(){}; | |
39 | virtual QChart* createChart(const DataTable& table) = 0; |
|
39 | virtual QChart* createChart(const DataTable& table) = 0; | |
40 | virtual QString name() = 0; |
|
40 | virtual QString name() = 0; | |
41 | virtual QString category() = 0; |
|
41 | virtual QString category() = 0; | |
42 | virtual QString subCategory() = 0; |
|
42 | virtual QString subCategory() = 0; | |
43 |
|
43 | |||
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
46 | namespace Charts |
|
46 | namespace Charts | |
47 | { |
|
47 | { | |
48 |
|
48 | |||
49 | typedef QList<Chart*> ChartList; |
|
49 | typedef QList<Chart*> ChartList; | |
50 |
|
50 | |||
51 | inline ChartList& chartList() |
|
51 | inline ChartList& chartList() | |
52 | { |
|
52 | { | |
53 | static ChartList list; |
|
53 | static ChartList list; | |
54 | return list; |
|
54 | return list; | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | inline bool findChart(Chart* chart) |
|
57 | inline bool findChart(Chart* chart) | |
58 | { |
|
58 | { | |
59 | ChartList& list = chartList(); |
|
59 | ChartList& list = chartList(); | |
60 | if (list.contains(chart)) { |
|
60 | if (list.contains(chart)) { | |
61 | return true; |
|
61 | return true; | |
62 | } |
|
62 | } | |
63 | foreach (Chart* item, list) { |
|
63 | foreach (Chart* item, list) { | |
64 | 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()) { | |
65 | return true; |
|
65 | return true; | |
66 | } |
|
66 | } | |
67 | } |
|
67 | } | |
68 | return false; |
|
68 | return false; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | inline void addChart(Chart* chart) |
|
71 | inline void addChart(Chart* chart) | |
72 | { |
|
72 | { | |
73 | ChartList& list = chartList(); |
|
73 | ChartList& list = chartList(); | |
74 | if (!findChart(chart)) { |
|
74 | if (!findChart(chart)) { | |
75 | list.append(chart); |
|
75 | list.append(chart); | |
76 | } |
|
76 | } | |
77 | } |
|
77 | } | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | template <class T> |
|
80 | template <class T> | |
81 | class ChartWrapper |
|
81 | class ChartWrapper | |
82 | { |
|
82 | { | |
83 | public: |
|
83 | public: | |
84 | QSharedPointer<T> chart; |
|
84 | QSharedPointer<T> chart; | |
85 | ChartWrapper() : chart(new T) |
|
85 | ChartWrapper() : chart(new T) | |
86 | { |
|
86 | { | |
87 | Charts::addChart(chart.data()); |
|
87 | Charts::addChart(chart.data()); | |
88 | } |
|
88 | } | |
89 | }; |
|
89 | }; | |
90 |
|
90 | |||
91 |
#define DECLARE_CHART(chart |
|
91 | #define DECLARE_CHART(chartType) static ChartWrapper<chartType> chartType; | |
|
92 | #define DECLARE_CHART_TEMPLATE(chartType,chartName) static ChartWrapper<chartType> chartName; | |||
92 |
|
93 | |||
93 | #endif |
|
94 | #endif |
@@ -1,70 +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 "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 | #include <QCategoryAxis> |
|
24 | #include <QCategoryAxis> | |
25 |
|
25 | |||
26 | class CategoryLineChart: public Chart |
|
26 | class CategoryLineChart: public Chart | |
27 | { |
|
27 | { | |
28 | public: |
|
28 | public: | |
29 |
QString name() { return QObject::tr("Category |
|
29 | QString name() { return QObject::tr("CategoryAxis"); } | |
30 |
QString category() { return QObject::tr(" |
|
30 | QString category() { return QObject::tr("Axis"); } | |
31 | QString subCategory() { return QString::null; } |
|
31 | QString subCategory() { return QString::null; } | |
32 |
|
32 | |||
33 | QChart* createChart(const DataTable& table) { |
|
33 | QChart* createChart(const DataTable& table) { | |
34 |
|
34 | |||
35 | QChart* chart = new QChart(); |
|
35 | QChart* chart = new QChart(); | |
36 |
chart->setTitle("Category |
|
36 | chart->setTitle("Category X , Category Y "); | |
37 |
|
37 | |||
38 | QString name("Series "); |
|
38 | QString name("Series "); | |
39 | int nameIndex = 0; |
|
39 | int nameIndex = 0; | |
40 | foreach (DataList list, table) { |
|
40 | foreach (DataList list, table) { | |
41 | QLineSeries *series = new QLineSeries(chart); |
|
41 | QLineSeries *series = new QLineSeries(chart); | |
42 | foreach (Data data, list) |
|
42 | foreach (Data data, list) | |
43 | series->append(data.first); |
|
43 | series->append(data.first); | |
44 | series->setName(name + QString::number(nameIndex)); |
|
44 | series->setName(name + QString::number(nameIndex)); | |
45 | nameIndex++; |
|
45 | nameIndex++; | |
46 | chart->addSeries(series); |
|
46 | chart->addSeries(series); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | // chart->createDefaultAxes(); |
|
|||
50 | QCategoryAxis *axisX = new QCategoryAxis; |
|
49 | QCategoryAxis *axisX = new QCategoryAxis; | |
51 | axisX->append("low", 5); |
|
50 | axisX->append("low", 5); | |
52 | axisX->append("avg.", 12); |
|
51 | axisX->append("avg.", 12); | |
53 | axisX->append("high", 19); |
|
52 | axisX->append("high", 19); | |
54 | axisX->setRange(0, 20); |
|
53 | axisX->setRange(0, 20); | |
55 | chart->setAxisX(axisX, chart->series().at(0)); |
|
54 | chart->setAxisX(axisX, chart->series().at(0)); | |
56 |
|
55 | |||
57 | QCategoryAxis *axisY = new QCategoryAxis; |
|
56 | QCategoryAxis *axisY = new QCategoryAxis; | |
58 | axisY->append("cheap", 5); |
|
57 | axisY->append("cheap", 5); | |
59 | axisY->append("fair", 12); |
|
58 | axisY->append("fair", 12); | |
60 | axisY->append("pricy", 20); |
|
59 | axisY->append("pricy", 20); | |
61 | axisY->setRange(0, 20); |
|
60 | axisY->setRange(0, 20); | |
62 | chart->setAxisY(axisY, chart->series().at(0)); |
|
61 | chart->setAxisY(axisY, chart->series().at(0)); | |
63 |
|
62 | |||
64 | return chart; |
|
63 | return chart; | |
65 | } |
|
64 | } | |
66 |
|
65 | |||
67 | }; |
|
66 | }; | |
68 |
|
67 | |||
69 | DECLARE_CHART(CategoryLineChart) |
|
68 | DECLARE_CHART(CategoryLineChart) | |
70 |
|
69 |
@@ -1,17 +1,18 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 | SOURCES += \ |
|
3 | SOURCES += \ | |
4 | font/font.cpp \ |
|
4 | font/font.cpp \ | |
5 | xyseries/linechart.cpp \ |
|
5 | xyseries/linechart.cpp \ | |
6 | xyseries/scatterchart.cpp \ |
|
6 | xyseries/scatterchart.cpp \ | |
7 | xyseries/splinechart.cpp \ |
|
7 | xyseries/splinechart.cpp \ | |
8 | xyseries/areachart.cpp \ |
|
8 | xyseries/areachart.cpp \ | |
9 | xyseries/categorylinechart.cpp \ |
|
|||
10 | barseries/verticalstackedbarchart.cpp \ |
|
9 | barseries/verticalstackedbarchart.cpp \ | |
11 | barseries/horizontalstackedbarchart.cpp \ |
|
10 | barseries/horizontalstackedbarchart.cpp \ | |
12 | barseries/verticalbarchart.cpp \ |
|
11 | barseries/verticalbarchart.cpp \ | |
13 | barseries/horizontalbarchart.cpp \ |
|
12 | barseries/horizontalbarchart.cpp \ | |
14 | barseries/horizontalpercentbarchart.cpp \ |
|
13 | barseries/horizontalpercentbarchart.cpp \ | |
15 | barseries/verticalpercentbarchart.cpp \ |
|
14 | barseries/verticalpercentbarchart.cpp \ | |
16 | pieseries/piechart.cpp \ |
|
15 | pieseries/piechart.cpp \ | |
17 | pieseries/donutchart.cpp |
|
16 | pieseries/donutchart.cpp \ | |
|
17 | axis/valueaxis.cpp \ | |||
|
18 | axis/categoryaxis.cpp |
General Comments 0
You need to be logged in to leave comments.
Login now