Debian Codegraph @

tests/manual/chartviewer/charts/axis/valueaxis.cpp

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
5
6 #include "charts.h"
7 #include <QtCharts/QChart>
8 #include <QtCharts/QLineSeries>
9 #include <QtCharts/QValueAxis>
10 #include <QtCharts/QCategoryAxis>
11
12 class ValueAxis: public Chart
13 {
14 public:
15 QString name() { return "ValueAxis"; }
16 QString category() { return QObject::tr("Axis"); }
17 QString subCategory() { return QString(); }
18
19 QChart *createChart(const DataTable &table)
20 {
21 QChart *chart = new QChart();
22 chart->setTitle("Value X , Value Y");
23
24 QString name("Series ");
25 int nameIndex = 0;
26 foreach (DataList list, table) {
27 QLineSeries *series = new QLineSeries(chart);
28 foreach (Data data, list)
29 series->append(data.first);
30 series->setName(name + QString::number(nameIndex));
31 nameIndex++;
32 chart->addSeries(series);
33 }
34
35 chart->createDefaultAxes();
36 QValueAxis *axis = new QValueAxis();
37 foreach (QAbstractSeries *series, chart->series())
38 chart->setAxisX(axis, series);
39
40 return chart;
41 }
42 };
43
44 class ValueAxisTitle: public ValueAxis
45 {
46 public:
47 QString name() { return "ValueAxis Title"; }
48
49 QChart *createChart(const DataTable &table)
50 {
51 QChart *chart = ValueAxis::createChart(table);
52 chart->axisX()->setTitleText("Axis X");
53 chart->axisY()->setTitleText("Axis Y");
54 chart->setTitle("Value X , Value Y, title");
55 return chart;
56 }
57 };
58
59 DECLARE_CHART(ValueAxis);
60 DECLARE_CHART(ValueAxisTitle);