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 Data Visualization 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 <QtTest/QtTest>
31
32#include <QtDataVisualization/Q3DScatter>
33
34#include "cpptestutil.h"
35
36using namespace QtDataVisualization;
37
38class tst_scatter: public QObject
39{
40 Q_OBJECT
41
42private slots:
43 void initTestCase();
44 void cleanupTestCase();
45 void init();
46 void cleanup();
47
48 void construct();
49
50 void initialProperties();
51 void initializeProperties();
52 void invalidProperties();
53
54 void addSeries();
55 void addMultipleSeries();
56 void selectSeries();
57 void removeSeries();
58 void removeMultipleSeries();
59
60private:
61 Q3DScatter *m_graph;
62};
63
64QScatter3DSeries *newSeries()
65{
66 QScatter3DSeries *series = new QScatter3DSeries;
67 QScatterDataArray data;
68 data << QVector3D(0.5f, 0.5f, 0.5f) << QVector3D(-0.3f, -0.5f, -0.4f) << QVector3D(0.0f, -0.3f, 0.2f);
69 series->dataProxy()->addItems(items: data);
70 return series;
71}
72
73void tst_scatter::initTestCase()
74{
75 if (!CpptestUtil::isOpenGLSupported())
76 QSKIP("OpenGL not supported on this platform");
77}
78
79void tst_scatter::cleanupTestCase()
80{
81}
82
83void tst_scatter::init()
84{
85 m_graph = new Q3DScatter();
86}
87
88void tst_scatter::cleanup()
89{
90 delete m_graph;
91}
92
93void tst_scatter::construct()
94{
95 Q3DScatter *graph = new Q3DScatter();
96 QVERIFY(graph);
97 delete graph;
98
99 QSurfaceFormat format;
100 graph = new Q3DScatter(&format);
101 QVERIFY(graph);
102 delete graph;
103}
104
105void tst_scatter::initialProperties()
106{
107 QVERIFY(m_graph);
108 QCOMPARE(m_graph->seriesList().length(), 0);
109 QVERIFY(!m_graph->selectedSeries());
110 QCOMPARE(m_graph->axisX()->orientation(), QAbstract3DAxis::AxisOrientationX);
111 QCOMPARE(m_graph->axisY()->orientation(), QAbstract3DAxis::AxisOrientationY);
112 QCOMPARE(m_graph->axisZ()->orientation(), QAbstract3DAxis::AxisOrientationZ);
113
114 // Common properties
115 QCOMPARE(m_graph->activeTheme()->type(), Q3DTheme::ThemeQt);
116 QCOMPARE(m_graph->selectionMode(), QAbstract3DGraph::SelectionItem);
117 QCOMPARE(m_graph->shadowQuality(), QAbstract3DGraph::ShadowQualityMedium);
118 QVERIFY(m_graph->scene());
119 QCOMPARE(m_graph->measureFps(), false);
120 QCOMPARE(m_graph->isOrthoProjection(), false);
121 QCOMPARE(m_graph->selectedElement(), QAbstract3DGraph::ElementNone);
122 QCOMPARE(m_graph->aspectRatio(), 2.0);
123 QCOMPARE(m_graph->optimizationHints(), QAbstract3DGraph::OptimizationDefault);
124 QCOMPARE(m_graph->isPolar(), false);
125 QCOMPARE(m_graph->radialLabelOffset(), 1.0);
126 QCOMPARE(m_graph->horizontalAspectRatio(), 0.0);
127 QCOMPARE(m_graph->isReflection(), false);
128 QCOMPARE(m_graph->reflectivity(), 0.5);
129 QCOMPARE(m_graph->locale(), QLocale("C"));
130 QCOMPARE(m_graph->queriedGraphPosition(), QVector3D(0, 0, 0));
131 QCOMPARE(m_graph->margin(), -1.0);
132}
133
134void tst_scatter::initializeProperties()
135{
136 Q3DTheme *theme = new Q3DTheme(Q3DTheme::ThemeDigia);
137 m_graph->setActiveTheme(theme);
138 m_graph->setSelectionMode(QAbstract3DGraph::SelectionNone);
139 m_graph->setShadowQuality(QAbstract3DGraph::ShadowQualitySoftHigh);
140 QCOMPARE(m_graph->shadowQuality(), QAbstract3DGraph::ShadowQualitySoftHigh);
141 m_graph->setMeasureFps(true);
142 m_graph->setOrthoProjection(true);
143 m_graph->setAspectRatio(1.0);
144 m_graph->setOptimizationHints(QAbstract3DGraph::OptimizationStatic);
145 m_graph->setPolar(true);
146 m_graph->setRadialLabelOffset(0.1f);
147 m_graph->setHorizontalAspectRatio(1.0);
148 m_graph->setReflection(true);
149 m_graph->setReflectivity(0.1);
150 m_graph->setLocale(QLocale("FI"));
151 m_graph->setMargin(1.0);
152
153 QCOMPARE(m_graph->activeTheme()->type(), Q3DTheme::ThemeDigia);
154 QCOMPARE(m_graph->selectionMode(), QAbstract3DGraph::SelectionNone);
155 QCOMPARE(m_graph->shadowQuality(), QAbstract3DGraph::ShadowQualityNone); // Ortho disables shadows
156 QCOMPARE(m_graph->measureFps(), true);
157 QCOMPARE(m_graph->isOrthoProjection(), true);
158 QCOMPARE(m_graph->aspectRatio(), 1.0);
159 QCOMPARE(m_graph->optimizationHints(), QAbstract3DGraph::OptimizationStatic);
160 QCOMPARE(m_graph->isPolar(), true);
161 QCOMPARE(m_graph->radialLabelOffset(), 0.1f);
162 QCOMPARE(m_graph->horizontalAspectRatio(), 1.0);
163 QCOMPARE(m_graph->isReflection(), true);
164 QCOMPARE(m_graph->reflectivity(), 0.1);
165 QCOMPARE(m_graph->locale(), QLocale("FI"));
166 QCOMPARE(m_graph->margin(), 1.0);
167}
168
169void tst_scatter::invalidProperties()
170{
171 m_graph->setSelectionMode(QAbstract3DGraph::SelectionColumn | QAbstract3DGraph::SelectionRow | QAbstract3DGraph::SelectionSlice);
172 m_graph->setAspectRatio(-1.0);
173 m_graph->setHorizontalAspectRatio(-1.0);
174 m_graph->setReflectivity(-1.0);
175 m_graph->setLocale(QLocale("XX"));
176
177 QCOMPARE(m_graph->selectionMode(), QAbstract3DGraph::SelectionItem);
178 QCOMPARE(m_graph->aspectRatio(), -1.0/*2.0*/); // TODO: Fix once QTRD-3367 is done
179 QCOMPARE(m_graph->horizontalAspectRatio(), -1.0/*0.0*/); // TODO: Fix once QTRD-3367 is done
180 QCOMPARE(m_graph->reflectivity(), -1.0/*0.5*/); // TODO: Fix once QTRD-3367 is done
181 QCOMPARE(m_graph->locale(), QLocale("C"));
182}
183
184void tst_scatter::addSeries()
185{
186 m_graph->addSeries(series: newSeries());
187
188 QCOMPARE(m_graph->seriesList().length(), 1);
189 QVERIFY(!m_graph->selectedSeries());
190}
191
192void tst_scatter::addMultipleSeries()
193{
194 QScatter3DSeries *series = newSeries();
195 QScatter3DSeries *series2 = newSeries();
196 QScatter3DSeries *series3 = newSeries();
197
198 m_graph->addSeries(series);
199 m_graph->addSeries(series: series2);
200 m_graph->addSeries(series: series3);
201
202 QCOMPARE(m_graph->seriesList().length(), 3);
203}
204
205void tst_scatter::selectSeries()
206{
207 QScatter3DSeries *series = newSeries();
208
209 m_graph->addSeries(series);
210 m_graph->seriesList()[0]->setSelectedItem(1);
211
212 QCOMPARE(m_graph->seriesList().length(), 1);
213 QCOMPARE(m_graph->selectedSeries(), series);
214
215 m_graph->clearSelection();
216 QVERIFY(!m_graph->selectedSeries());
217}
218
219void tst_scatter::removeSeries()
220{
221 QScatter3DSeries *series = newSeries();
222
223 m_graph->addSeries(series);
224 m_graph->removeSeries(series);
225 QCOMPARE(m_graph->seriesList().length(), 0);
226
227 delete series;
228}
229
230void tst_scatter::removeMultipleSeries()
231{
232 QScatter3DSeries *series = newSeries();
233 QScatter3DSeries *series2 = newSeries();
234 QScatter3DSeries *series3 = newSeries();
235
236 m_graph->addSeries(series);
237 m_graph->addSeries(series: series2);
238 m_graph->addSeries(series: series3);
239
240 m_graph->seriesList()[0]->setSelectedItem(1);
241 QCOMPARE(m_graph->selectedSeries(), series);
242
243 m_graph->removeSeries(series);
244 QCOMPARE(m_graph->seriesList().length(), 2);
245 QVERIFY(!m_graph->selectedSeries());
246
247 m_graph->removeSeries(series: series2);
248 QCOMPARE(m_graph->seriesList().length(), 1);
249
250 m_graph->removeSeries(series: series3);
251 QCOMPARE(m_graph->seriesList().length(), 0);
252
253 delete series;
254 delete series2;
255 delete series3;
256}
257
258QTEST_MAIN(tst_scatter)
259#include "tst_scatter.moc"
260

source code of qtdatavis3d/tests/auto/cpptest/q3dscatter/tst_scatter.cpp