@@ -0,0 +1,16 | |||||
|
1 | !include( ../tests.pri ) { | |||
|
2 | error( "Couldn't find the test.pri file!" ) | |||
|
3 | } | |||
|
4 | ||||
|
5 | TEMPLATE = app | |||
|
6 | ||||
|
7 | QT += core gui opengl | |||
|
8 | contains(QT_MAJOR_VERSION, 5) { | |||
|
9 | QT += widgets | |||
|
10 | } | |||
|
11 | ||||
|
12 | SOURCES += main.cpp \ | |||
|
13 | mainwidget.cpp | |||
|
14 | ||||
|
15 | HEADERS += \ | |||
|
16 | mainwidget.h |
@@ -0,0 +1,38 | |||||
|
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 <QtCore/QtGlobal> | |||
|
22 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) | |||
|
23 | #include <QApplication> | |||
|
24 | #else | |||
|
25 | #include <QtWidgets/QApplication> | |||
|
26 | #endif | |||
|
27 | #include "mainwidget.h" | |||
|
28 | ||||
|
29 | int main(int argc, char *argv[]) | |||
|
30 | { | |||
|
31 | QApplication a(argc, argv); | |||
|
32 | ||||
|
33 | MainWidget w; | |||
|
34 | w.resize(1000,600); | |||
|
35 | w.show(); | |||
|
36 | ||||
|
37 | return a.exec(); | |||
|
38 | } |
@@ -0,0 +1,227 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 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 "mainwidget.h" | |||
|
22 | #include <QChartView> | |||
|
23 | #include <QBoxPlotSeries> | |||
|
24 | #include <QBarSet> | |||
|
25 | #include <QLegend> | |||
|
26 | #include <QBarCategoryAxis> | |||
|
27 | #include <QBrush> | |||
|
28 | #include <QColor> | |||
|
29 | #include <QPushButton> | |||
|
30 | #include <QComboBox> | |||
|
31 | #include <QSpinBox> | |||
|
32 | #include <QCheckBox> | |||
|
33 | #include <QGridLayout> | |||
|
34 | #include <QHBoxLayout> | |||
|
35 | #include <QLabel> | |||
|
36 | #include <QSpacerItem> | |||
|
37 | #include <QMessageBox> | |||
|
38 | #include <cmath> | |||
|
39 | #include <QDebug> | |||
|
40 | #include <QStandardItemModel> | |||
|
41 | #include <QBarCategoryAxis> | |||
|
42 | ||||
|
43 | ||||
|
44 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
45 | ||||
|
46 | MainWidget::MainWidget(QWidget *parent) : | |||
|
47 | QWidget(parent), | |||
|
48 | m_chart(0), | |||
|
49 | rowPos(0), | |||
|
50 | nSeries(0) | |||
|
51 | { | |||
|
52 | m_chart = new QChart(); | |||
|
53 | ||||
|
54 | // Grid layout for the controls for configuring the chart widget | |||
|
55 | QGridLayout *grid = new QGridLayout(); | |||
|
56 | ||||
|
57 | // Create add a series button | |||
|
58 | QPushButton *addSeriesButton = new QPushButton("Add a series"); | |||
|
59 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |||
|
60 | grid->addWidget(addSeriesButton, rowPos++, 1); | |||
|
61 | ||||
|
62 | // Create remove a series button | |||
|
63 | QPushButton *removeSeriesButton = new QPushButton("Remove a series"); | |||
|
64 | connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries())); | |||
|
65 | grid->addWidget(removeSeriesButton, rowPos++, 1); | |||
|
66 | ||||
|
67 | ||||
|
68 | // Create add a single box button | |||
|
69 | QPushButton *addBoxButton = new QPushButton("Add a box"); | |||
|
70 | connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox())); | |||
|
71 | grid->addWidget(addBoxButton, rowPos++, 1); | |||
|
72 | ||||
|
73 | initThemeCombo(grid); | |||
|
74 | initCheckboxes(grid); | |||
|
75 | ||||
|
76 | // add row with empty label to make all the other rows static | |||
|
77 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |||
|
78 | grid->setRowStretch(grid->rowCount() - 1, 1); | |||
|
79 | ||||
|
80 | // Create chart view with the chart | |||
|
81 | m_chartView = new QChartView(m_chart, this); | |||
|
82 | //m_chartView->setRubberBand(QChartView::HorizonalRubberBand); | |||
|
83 | ||||
|
84 | // Another grid layout as a main layout | |||
|
85 | QGridLayout *mainLayout = new QGridLayout(); | |||
|
86 | mainLayout->addLayout(grid, 0, 0); | |||
|
87 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |||
|
88 | setLayout(mainLayout); | |||
|
89 | ||||
|
90 | legendToggled(false); | |||
|
91 | animationToggled(false); | |||
|
92 | } | |||
|
93 | ||||
|
94 | // Combo box for selecting theme | |||
|
95 | void MainWidget::initThemeCombo(QGridLayout *grid) | |||
|
96 | { | |||
|
97 | QComboBox *chartTheme = new QComboBox(); | |||
|
98 | chartTheme->addItem("Default"); | |||
|
99 | chartTheme->addItem("Light"); | |||
|
100 | chartTheme->addItem("Blue Cerulean"); | |||
|
101 | chartTheme->addItem("Dark"); | |||
|
102 | chartTheme->addItem("Brown Sand"); | |||
|
103 | chartTheme->addItem("Blue NCS"); | |||
|
104 | chartTheme->addItem("High Contrast"); | |||
|
105 | chartTheme->addItem("Blue Icy"); | |||
|
106 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |||
|
107 | this, SLOT(changeChartTheme(int))); | |||
|
108 | grid->addWidget(new QLabel("Chart theme:"), rowPos, 0); | |||
|
109 | grid->addWidget(chartTheme, rowPos++, 1); | |||
|
110 | } | |||
|
111 | ||||
|
112 | // Different check boxes for customizing chart | |||
|
113 | void MainWidget::initCheckboxes(QGridLayout *grid) | |||
|
114 | { | |||
|
115 | QCheckBox *animationCheckBox = new QCheckBox("Animation"); | |||
|
116 | connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); | |||
|
117 | animationCheckBox->setChecked(false); | |||
|
118 | grid->addWidget(animationCheckBox, rowPos++, 0); | |||
|
119 | ||||
|
120 | QCheckBox *legendCheckBox = new QCheckBox("Legend"); | |||
|
121 | connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); | |||
|
122 | legendCheckBox->setChecked(false); | |||
|
123 | grid->addWidget(legendCheckBox, rowPos++, 0); | |||
|
124 | ||||
|
125 | QCheckBox *titleCheckBox = new QCheckBox("Title"); | |||
|
126 | connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); | |||
|
127 | titleCheckBox->setChecked(false); | |||
|
128 | grid->addWidget(titleCheckBox, rowPos++, 0); | |||
|
129 | } | |||
|
130 | ||||
|
131 | void MainWidget::addSeries() | |||
|
132 | { | |||
|
133 | qDebug() << "BoxPlotTester::MainWidget::addSeries()"; | |||
|
134 | ||||
|
135 | if (nSeries > 9) | |||
|
136 | return; | |||
|
137 | ||||
|
138 | // Initial data | |||
|
139 | //![1] | |||
|
140 | QBarSet *set0 = new QBarSet("Jan"); | |||
|
141 | QBarSet *set1 = new QBarSet("Feb"); | |||
|
142 | QBarSet *set2 = new QBarSet("Mar"); | |||
|
143 | QBarSet *set3 = new QBarSet("Apr"); | |||
|
144 | QBarSet *set4 = new QBarSet("May"); | |||
|
145 | QBarSet *set5 = new QBarSet("Jun"); | |||
|
146 | ||||
|
147 | // low bot med top upp | |||
|
148 | *set0 << 3 << 4 << 4.4 << 6 << 7; | |||
|
149 | *set1 << 5 << 6 << 7.5 << 8 << 12; | |||
|
150 | *set2 << 3 << 5 << 5.7 << 8 << 9; | |||
|
151 | *set3 << 5 << 6 << 6.8 << 7 << 8; | |||
|
152 | *set4 << 4 << 5 << 5.2 << 6 << 7; | |||
|
153 | *set5 << 4 << 7 << 8.2 << 9 << 10; | |||
|
154 | ||||
|
155 | m_series[nSeries] = new QBoxPlotSeries(); | |||
|
156 | m_series[nSeries]->append(set0); | |||
|
157 | m_series[nSeries]->append(set1); | |||
|
158 | m_series[nSeries]->append(set2); | |||
|
159 | m_series[nSeries]->append(set3); | |||
|
160 | m_series[nSeries]->append(set4); | |||
|
161 | m_series[nSeries]->append(set5); | |||
|
162 | m_series[nSeries]->type(); | |||
|
163 | m_series[nSeries]->setName("Box & Whiskers"); | |||
|
164 | ||||
|
165 | m_chart->addSeries(m_series[nSeries]); | |||
|
166 | ||||
|
167 | QStringList categories; | |||
|
168 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |||
|
169 | QBarCategoryAxis *axis = new QBarCategoryAxis(); | |||
|
170 | axis->append(categories); | |||
|
171 | m_chart->createDefaultAxes(); | |||
|
172 | m_chart->setAxisX(axis, m_series[nSeries]); | |||
|
173 | ||||
|
174 | nSeries++; | |||
|
175 | } | |||
|
176 | ||||
|
177 | void MainWidget::removeSeries() | |||
|
178 | { | |||
|
179 | if (nSeries > 0) { | |||
|
180 | nSeries--; | |||
|
181 | m_chart->removeSeries(m_series[nSeries]); | |||
|
182 | delete m_series[nSeries]; | |||
|
183 | } | |||
|
184 | } | |||
|
185 | ||||
|
186 | void MainWidget::addBox() | |||
|
187 | { | |||
|
188 | qDebug() << "BoxPlotTester::MainWidget::addBox()"; | |||
|
189 | ||||
|
190 | QBarSet *newSet = new QBarSet("New"); | |||
|
191 | *newSet << 5 << 6 << 6.8 << 7 << 8; | |||
|
192 | ||||
|
193 | m_series[0]->append(newSet); | |||
|
194 | } | |||
|
195 | ||||
|
196 | void MainWidget::animationToggled(bool enabled) | |||
|
197 | { | |||
|
198 | qDebug() << "BoxPlotTester::Animation toggled to " << enabled; | |||
|
199 | if (enabled) | |||
|
200 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |||
|
201 | else | |||
|
202 | m_chart->setAnimationOptions(QChart::NoAnimation); | |||
|
203 | } | |||
|
204 | ||||
|
205 | void MainWidget::legendToggled(bool enabled) | |||
|
206 | { | |||
|
207 | qDebug() << "BoxPlotTester::Legend toggled to " << enabled; | |||
|
208 | m_chart->legend()->setVisible(enabled); | |||
|
209 | if (enabled) | |||
|
210 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |||
|
211 | } | |||
|
212 | ||||
|
213 | void MainWidget::titleToggled(bool enabled) | |||
|
214 | { | |||
|
215 | qDebug() << "BoxPlotTester::Title toggled to " << enabled; | |||
|
216 | if (enabled) | |||
|
217 | m_chart->setTitle("Simple boxplotchart example"); | |||
|
218 | else | |||
|
219 | m_chart->setTitle(""); | |||
|
220 | } | |||
|
221 | ||||
|
222 | ||||
|
223 | void MainWidget::changeChartTheme(int themeIndex) | |||
|
224 | { | |||
|
225 | qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; | |||
|
226 | m_chart->setTheme((QChart::ChartTheme) themeIndex); | |||
|
227 | } |
@@ -0,0 +1,64 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 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 | #ifndef MAINWIDGET_H | |||
|
22 | #define MAINWIDGET_H | |||
|
23 | ||||
|
24 | #include "qchartglobal.h" | |||
|
25 | #include "qchart.h" | |||
|
26 | #include "qchartview.h" | |||
|
27 | #include <QWidget> | |||
|
28 | #include <QBoxPlotSeries> | |||
|
29 | ||||
|
30 | class QGridLayout; | |||
|
31 | ||||
|
32 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
33 | ||||
|
34 | class MainWidget : public QWidget | |||
|
35 | { | |||
|
36 | Q_OBJECT | |||
|
37 | public: | |||
|
38 | explicit MainWidget(QWidget *parent = 0); | |||
|
39 | ||||
|
40 | signals: | |||
|
41 | ||||
|
42 | private: | |||
|
43 | void initThemeCombo(QGridLayout *grid); | |||
|
44 | void initCheckboxes(QGridLayout *grid); | |||
|
45 | ||||
|
46 | private slots: | |||
|
47 | void addSeries(); | |||
|
48 | void removeSeries(); | |||
|
49 | void addBox(); | |||
|
50 | void animationToggled(bool enabled); | |||
|
51 | void legendToggled(bool enabled); | |||
|
52 | void titleToggled(bool enabled); | |||
|
53 | void changeChartTheme(int themeIndex); | |||
|
54 | ||||
|
55 | private: | |||
|
56 | QChart *m_chart; | |||
|
57 | QChartView *m_chartView; | |||
|
58 | QGridLayout *m_scatterLayout; | |||
|
59 | int rowPos; | |||
|
60 | int nSeries; | |||
|
61 | QBoxPlotSeries *m_series[10]; | |||
|
62 | }; | |||
|
63 | ||||
|
64 | #endif // MAINWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now