1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | #include "charts.h" |
31 | #include <QtCharts/QChart> |
32 | #include <QtCharts/QLineSeries> |
33 | #include <QtCharts/QValueAxis> |
34 | |
35 | class SizeChart: public Chart |
36 | { |
37 | public: |
38 | QString name() { return QObject::tr(s: "PlotArea" ); } |
39 | QString category() { return QObject::tr(s: "Size" ); } |
40 | QString subCategory() { return QString(); } |
41 | |
42 | QChart *createChart(const DataTable &table) |
43 | { |
44 | |
45 | QChart *chart = new QChart(); |
46 | QString name("Series" ); |
47 | int nameIndex = 0; |
48 | foreach (DataList list, table) { |
49 | QLineSeries *series = new QLineSeries(chart); |
50 | foreach (Data data, list) |
51 | series->append(point: data.first); |
52 | series->setName(name + QString::number(nameIndex)); |
53 | nameIndex++; |
54 | chart->addSeries(series); |
55 | } |
56 | chart->setContentsMargins(left: 0,top: 0,right: 0,bottom: 0); |
57 | chart->setMargins(QMargins(0,0,0,0)); |
58 | return chart; |
59 | } |
60 | }; |
61 | |
62 | class SizeChart2: public SizeChart |
63 | { |
64 | public: |
65 | QString name() { return QObject::tr(s: "PA + T" ); } |
66 | |
67 | QChart *createChart(const DataTable &table) |
68 | { |
69 | QChart *chart = SizeChart::createChart(table); |
70 | chart->setTitle(name()); |
71 | return chart; |
72 | } |
73 | }; |
74 | |
75 | class SizeChart3: public SizeChart2 |
76 | { |
77 | public: |
78 | QString name() { return QObject::tr(s: "PA+T+CM10" ); } |
79 | |
80 | QChart *createChart(const DataTable &table) |
81 | { |
82 | QChart *chart = SizeChart2::createChart(table); |
83 | chart->setContentsMargins(left: 10,top: 10,right: 10,bottom: 10); |
84 | |
85 | return chart; |
86 | } |
87 | }; |
88 | |
89 | class SizeChart4: public SizeChart3 |
90 | { |
91 | public: |
92 | QString name() { return QObject::tr(s: "PA+T+CM10+M25" ); } |
93 | |
94 | QChart *createChart(const DataTable &table) |
95 | { |
96 | QChart *chart = SizeChart3::createChart(table); |
97 | chart->setMargins(QMargins(30,30,30,30)); |
98 | return chart; |
99 | } |
100 | }; |
101 | |
102 | class SizeChart5: public SizeChart4 |
103 | { |
104 | public: |
105 | QString name() { return QObject::tr(s: "PA+T+CM10+M25+AX" ); } |
106 | |
107 | QChart *createChart(const DataTable &table) |
108 | { |
109 | QChart *chart = SizeChart4::createChart(table); |
110 | chart->createDefaultAxes(); |
111 | chart->axisY()->hide(); |
112 | return chart; |
113 | } |
114 | }; |
115 | |
116 | class SizeChart6: public SizeChart4 |
117 | { |
118 | public: |
119 | QString name() { return QObject::tr(s: "PA+T+CM10+M25+AY" ); } |
120 | |
121 | QChart *createChart(const DataTable &table) |
122 | { |
123 | QChart *chart = SizeChart4::createChart(table); |
124 | chart->createDefaultAxes(); |
125 | chart->axisX()->hide(); |
126 | return chart; |
127 | } |
128 | }; |
129 | |
130 | class SizeChart7: public SizeChart4 |
131 | { |
132 | public: |
133 | QString name() { return QObject::tr(s: "PA+T+CM10+M25+AX+AY" ); } |
134 | |
135 | QChart *createChart(const DataTable &table) |
136 | { |
137 | QChart *chart = SizeChart4::createChart(table); |
138 | chart->createDefaultAxes(); |
139 | return chart; |
140 | } |
141 | }; |
142 | |
143 | DECLARE_CHART(SizeChart) |
144 | DECLARE_CHART(SizeChart2) |
145 | DECLARE_CHART(SizeChart3) |
146 | DECLARE_CHART(SizeChart4) |
147 | DECLARE_CHART(SizeChart5) |
148 | DECLARE_CHART(SizeChart6) |
149 | DECLARE_CHART(SizeChart7) |
150 | |