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/Q3DScene>
33#include <QtDataVisualization/Q3DBars>
34
35#include "cpptestutil.h"
36
37using namespace QtDataVisualization;
38
39class tst_scene: public QObject
40{
41 Q_OBJECT
42
43private slots:
44 void initTestCase();
45 void cleanupTestCase();
46 void init();
47 void cleanup();
48
49 void construct();
50
51 void initialProperties();
52 void initializeProperties();
53 void invalidProperties();
54
55 void subViews();
56
57private:
58 Q3DScene *m_scene;
59};
60
61void tst_scene::initTestCase()
62{
63}
64
65void tst_scene::cleanupTestCase()
66{
67}
68
69void tst_scene::init()
70{
71 m_scene = new Q3DScene();
72}
73
74void tst_scene::cleanup()
75{
76 delete m_scene;
77}
78
79void tst_scene::construct()
80{
81 Q3DScene *scene = new Q3DScene();
82 QVERIFY(scene);
83 delete scene;
84}
85
86void tst_scene::initialProperties()
87{
88 QVERIFY(m_scene);
89
90 QVERIFY(m_scene->activeCamera());
91 QVERIFY(m_scene->activeLight());
92 QCOMPARE(m_scene->devicePixelRatio(), 1.0f);
93 QCOMPARE(m_scene->graphPositionQuery(), m_scene->invalidSelectionPoint());
94 QCOMPARE(m_scene->primarySubViewport(), QRect(0, 0, 0, 0));
95 QCOMPARE(m_scene->secondarySubViewport(), QRect(0, 0, 0, 0));
96 QCOMPARE(m_scene->isSecondarySubviewOnTop(), true);
97 QCOMPARE(m_scene->selectionQueryPosition(), m_scene->invalidSelectionPoint());
98 QCOMPARE(m_scene->isSlicingActive(), false);
99 QCOMPARE(m_scene->viewport(), QRect(0, 0, 0, 0));
100}
101
102void tst_scene::initializeProperties()
103{
104 QVERIFY(m_scene);
105
106 Q3DCamera *camera1 = new Q3DCamera();
107 Q3DLight *light1 = new Q3DLight();
108
109 m_scene->setActiveCamera(camera1);
110 m_scene->setActiveLight(light1);
111 m_scene->setDevicePixelRatio(2.0f);
112 m_scene->setGraphPositionQuery(QPoint(0, 0));
113 m_scene->setPrimarySubViewport(QRect(0, 0, 50, 50));
114 m_scene->setSecondarySubViewport(QRect(50, 50, 100, 100));
115 m_scene->setSecondarySubviewOnTop(false);
116 m_scene->setSlicingActive(true);
117 m_scene->setSelectionQueryPosition(QPoint(0, 0));
118
119 QCOMPARE(m_scene->activeCamera(), camera1);
120 QCOMPARE(m_scene->activeLight(), light1);
121 QCOMPARE(m_scene->devicePixelRatio(), 2.0f);
122 QCOMPARE(m_scene->graphPositionQuery(), QPoint(0, 0)); // TODO: When doing signal checks, add tests to check that queries return something (asynchronously)
123 QCOMPARE(m_scene->primarySubViewport(), QRect(0, 0, 50, 50));
124 QCOMPARE(m_scene->secondarySubViewport(), QRect(50, 50, 100, 100));
125 QCOMPARE(m_scene->isSecondarySubviewOnTop(), false);
126 QCOMPARE(m_scene->selectionQueryPosition(), QPoint(0, 0)); // TODO: When doing signal checks, add tests to check that queries return something (asynchronously)
127 QCOMPARE(m_scene->isSlicingActive(), true);
128 QCOMPARE(m_scene->viewport(), QRect(0, 0, 150, 150));
129
130 m_scene->setPrimarySubViewport(QRect());
131 m_scene->setSecondarySubViewport(QRect());
132
133 QCOMPARE(m_scene->primarySubViewport(), QRect(0, 0, 30, 30));
134 QCOMPARE(m_scene->secondarySubViewport(), QRect(0, 0, 150, 150));
135}
136
137void tst_scene::invalidProperties()
138{
139 m_scene->setPrimarySubViewport(QRect(0, 0, -50, -50));
140 m_scene->setSecondarySubViewport(QRect(-50, -50, -100, -100));
141 QCOMPARE(m_scene->primarySubViewport(), QRect(0, 0, 0, 0));
142 QCOMPARE(m_scene->secondarySubViewport(), QRect(0, 0, 0, 0));
143}
144
145void tst_scene::subViews()
146{
147 if (!CpptestUtil::isOpenGLSupported())
148 QSKIP("OpenGL not supported on this platform");
149
150 Q3DBars graph;
151 graph.setPosition(QPoint(0, 0));
152 graph.setWidth(200);
153 graph.setHeight(200);
154
155 Q3DScene *scene = graph.scene();
156
157 QCoreApplication::processEvents();
158
159 QTRY_COMPARE(scene->viewport(), QRect(0, 0, 200, 200));
160 QCOMPARE(scene->primarySubViewport(), QRect(0, 0, 200, 200));
161 QCOMPARE(scene->secondarySubViewport(), QRect(0, 0, 0, 0));
162
163 QCOMPARE(scene->isSecondarySubviewOnTop(), true);
164 QCOMPARE(scene->isPointInPrimarySubView(QPoint(100, 100)), true);
165 QCOMPARE(scene->isPointInPrimarySubView(QPoint(201, 201)), false);
166 QCOMPARE(scene->isPointInSecondarySubView(QPoint(100, 100)), false);
167
168 scene->setSlicingActive(true);
169
170 QCOMPARE(scene->isSecondarySubviewOnTop(), false);
171 QCOMPARE(scene->primarySubViewport(), QRect(0, 0, 40, 40));
172 QCOMPARE(scene->secondarySubViewport(), QRect(0, 0, 200, 200));
173 QCOMPARE(scene->isPointInPrimarySubView(QPoint(100, 100)), false);
174 QCOMPARE(scene->isPointInPrimarySubView(QPoint(30, 30)), true);
175 QCOMPARE(scene->isPointInSecondarySubView(QPoint(100, 100)), true);
176 QCOMPARE(scene->isPointInSecondarySubView(QPoint(30, 30)), false);
177
178 scene->setSecondarySubviewOnTop(true);
179
180 QCOMPARE(scene->isSecondarySubviewOnTop(), true);
181 QCOMPARE(scene->primarySubViewport(), QRect(0, 0, 40, 40));
182 QCOMPARE(scene->secondarySubViewport(), QRect(0, 0, 200, 200));
183 QCOMPARE(scene->isPointInPrimarySubView(QPoint(100, 100)), false);
184 QCOMPARE(scene->isPointInPrimarySubView(QPoint(30, 30)), false);
185 QCOMPARE(scene->isPointInSecondarySubView(QPoint(100, 100)), true);
186 QCOMPARE(scene->isPointInSecondarySubView(QPoint(30, 30)), true);
187}
188
189QTEST_MAIN(tst_scene)
190#include "tst_scene.moc"
191

source code of qtdatavis3d/tests/auto/cpptest/q3dscene/tst_scene.cpp