| 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 <QtWidgets/QApplication> | 
| 31 | #include <QtWidgets/QMainWindow> | 
| 32 | #include <QtCharts/QChartView> | 
| 33 | #include <QtCharts/QBoxPlotSeries> | 
| 34 | #include <QtCharts/QBoxSet> | 
| 35 | #include <QtCharts/QLegend> | 
| 36 | #include <QtCharts/QBarCategoryAxis> | 
| 37 | #include <QtCore/QFile> | 
| 38 | |
| 39 | #include "boxdatareader.h" | 
| 40 | |
| 41 | QT_CHARTS_USE_NAMESPACE | 
| 42 | |
| 43 | int main(int argc, char *argv[]) | 
| 44 | { | 
| 45 | QApplication a(argc, argv); | 
| 46 | |
| 47 | //! [1] | 
| 48 | QBoxPlotSeries *acmeSeries = new QBoxPlotSeries(); | 
| 49 |     acmeSeries->setName("Acme Ltd");  | 
| 50 | |
| 51 | QBoxPlotSeries *boxWhiskSeries = new QBoxPlotSeries(); | 
| 52 |     boxWhiskSeries->setName("BoxWhisk Inc");  | 
| 53 | //! [1] | 
| 54 | |
| 55 | //! [2] | 
| 56 |     QFile acmeData(":acme");  | 
| 57 | if (!acmeData.open(flags: QIODevice::ReadOnly | QIODevice::Text)) | 
| 58 | return 1; | 
| 59 | |
| 60 | BoxDataReader dataReader(&acmeData); | 
| 61 | while (!dataReader.atEnd()) { | 
| 62 | QBoxSet *set = dataReader.readBox(); | 
| 63 | if (set) | 
| 64 | acmeSeries->append(box: set); | 
| 65 | } | 
| 66 | //! [2] | 
| 67 | |
| 68 | //! [3] | 
| 69 |     QFile boxwhiskData(":boxwhisk");  | 
| 70 | if (!boxwhiskData.open(flags: QIODevice::ReadOnly | QIODevice::Text)) | 
| 71 | return 1; | 
| 72 | |
| 73 | dataReader.readFile(device: &boxwhiskData); | 
| 74 | while (!dataReader.atEnd()) { | 
| 75 | QBoxSet *set = dataReader.readBox(); | 
| 76 | if (set) | 
| 77 | boxWhiskSeries->append(box: set); | 
| 78 | } | 
| 79 | //! [3] | 
| 80 | |
| 81 | //! [4] | 
| 82 | QChart *chart = new QChart(); | 
| 83 | chart->addSeries(series: acmeSeries); | 
| 84 | chart->addSeries(series: boxWhiskSeries); | 
| 85 |     chart->setTitle("Acme Ltd and BoxWhisk Inc share deviation in 2012");  | 
| 86 | chart->setAnimationOptions(QChart::SeriesAnimations); | 
| 87 | //! [4] | 
| 88 | |
| 89 | //! [5] | 
| 90 | chart->createDefaultAxes(); | 
| 91 | chart->axes(orientation: Qt::Vertical).first()->setMin(15.0); | 
| 92 | chart->axes(orientation: Qt::Horizontal).first()->setMax(34.0); | 
| 93 | //! [5] | 
| 94 | |
| 95 | //! [6] | 
| 96 | chart->legend()->setVisible(true); | 
| 97 | chart->legend()->setAlignment(Qt::AlignBottom); | 
| 98 | //! [6] | 
| 99 | |
| 100 | //! [7] | 
| 101 | QChartView *chartView = new QChartView(chart); | 
| 102 | chartView->setRenderHint(hint: QPainter::Antialiasing); | 
| 103 | //! [7] | 
| 104 | |
| 105 | //! [8] | 
| 106 | QMainWindow window; | 
| 107 | window.setCentralWidget(chartView); | 
| 108 | window.resize(w: 800, h: 600); | 
| 109 | window.show(); | 
| 110 | //! [8] | 
| 111 | |
| 112 | return a.exec(); | 
| 113 | } | 
| 114 | |
| 115 | 
