1/****************************************************************************
2**
3** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
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 Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "quick3dlevelofdetailloader_p_p.h"
41#include <Qt3DRender/qlevelofdetailboundingsphere.h>
42#include <Qt3DRender/qcamera.h>
43#include <Qt3DQuick/private/quick3dentityloader_p.h>
44
45QT_BEGIN_NAMESPACE
46
47namespace Qt3DExtras {
48namespace Extras {
49namespace Quick {
50
51Quick3DLevelOfDetailLoaderPrivate::Quick3DLevelOfDetailLoaderPrivate()
52 : QEntityPrivate()
53 , m_loader(new Qt3DCore::Quick::Quick3DEntityLoader)
54 , m_lod(new Qt3DRender::QLevelOfDetail)
55{
56}
57
58Quick3DLevelOfDetailLoader::Quick3DLevelOfDetailLoader(QNode *parent)
59 : QEntity(*new Quick3DLevelOfDetailLoaderPrivate, parent)
60{
61 Q_D(Quick3DLevelOfDetailLoader);
62 d->m_loader->setParent(this);
63 d->m_loader->addComponent(comp: d->m_lod);
64
65 connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::cameraChanged,
66 receiver: this, slot: &Quick3DLevelOfDetailLoader::cameraChanged);
67 connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::currentIndexChanged,
68 receiver: this, slot: &Quick3DLevelOfDetailLoader::currentIndexChanged);
69 connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::thresholdTypeChanged,
70 receiver: this, slot: &Quick3DLevelOfDetailLoader::thresholdTypeChanged);
71 connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::thresholdsChanged,
72 receiver: this, slot: &Quick3DLevelOfDetailLoader::thresholdsChanged);
73 connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::volumeOverrideChanged,
74 receiver: this, slot: &Quick3DLevelOfDetailLoader::volumeOverrideChanged);
75 connect(sender: d->m_loader, signal: &Qt3DCore::Quick::Quick3DEntityLoader::entityChanged,
76 receiver: this, slot: &Quick3DLevelOfDetailLoader::entityChanged);
77 connect(sender: d->m_loader, signal: &Qt3DCore::Quick::Quick3DEntityLoader::sourceChanged,
78 receiver: this, slot: &Quick3DLevelOfDetailLoader::sourceChanged);
79
80 connect(sender: this, signal: &Quick3DLevelOfDetailLoader::enabledChanged,
81 receiver: d->m_lod, slot: &Qt3DRender::QLevelOfDetail::setEnabled);
82
83 auto applyCurrentSource = [this] {
84 Q_D(Quick3DLevelOfDetailLoader);
85 const auto index = currentIndex();
86 if (index >= 0 && index < d->m_sources.size())
87 d->m_loader->setSource(d->m_sources.at(i: index).toUrl());
88 };
89
90 connect(sender: this, signal: &Quick3DLevelOfDetailLoader::sourcesChanged,
91 context: this, slot: applyCurrentSource);
92 connect(sender: this, signal: &Quick3DLevelOfDetailLoader::currentIndexChanged,
93 context: this, slot: applyCurrentSource);
94}
95
96QVariantList Quick3DLevelOfDetailLoader::sources() const
97{
98 Q_D(const Quick3DLevelOfDetailLoader);
99 return d->m_sources;
100}
101
102void Quick3DLevelOfDetailLoader::setSources(const QVariantList &sources)
103{
104 Q_D(Quick3DLevelOfDetailLoader);
105 if (d->m_sources != sources) {
106 d->m_sources = sources;
107 emit sourcesChanged();
108 }
109}
110
111Qt3DRender::QCamera *Quick3DLevelOfDetailLoader::camera() const
112{
113 Q_D(const Quick3DLevelOfDetailLoader);
114 return d->m_lod->camera();
115}
116
117void Quick3DLevelOfDetailLoader::setCamera(Qt3DRender::QCamera *camera)
118{
119 Q_D(Quick3DLevelOfDetailLoader);
120 d->m_lod->setCamera(camera);
121}
122
123int Quick3DLevelOfDetailLoader::currentIndex() const
124{
125 Q_D(const Quick3DLevelOfDetailLoader);
126 return d->m_lod->currentIndex();
127}
128
129void Quick3DLevelOfDetailLoader::setCurrentIndex(int currentIndex)
130{
131 Q_D(Quick3DLevelOfDetailLoader);
132 d->m_lod->setCurrentIndex(currentIndex);
133}
134
135Qt3DRender::QLevelOfDetail::ThresholdType Quick3DLevelOfDetailLoader::thresholdType() const
136{
137 Q_D(const Quick3DLevelOfDetailLoader);
138 return d->m_lod->thresholdType();
139}
140
141void Quick3DLevelOfDetailLoader::setThresholdType(Qt3DRender::QLevelOfDetail::ThresholdType thresholdType)
142{
143 Q_D(Quick3DLevelOfDetailLoader);
144 d->m_lod->setThresholdType(thresholdType);
145}
146
147QVector<qreal> Quick3DLevelOfDetailLoader::thresholds() const
148{
149 Q_D(const Quick3DLevelOfDetailLoader);
150 return d->m_lod->thresholds();
151}
152
153void Quick3DLevelOfDetailLoader::setThresholds(const QVector<qreal> &thresholds)
154{
155 Q_D(Quick3DLevelOfDetailLoader);
156 d->m_lod->setThresholds(thresholds);
157}
158
159Qt3DRender::QLevelOfDetailBoundingSphere Quick3DLevelOfDetailLoader::createBoundingSphere(const QVector3D &center, float radius)
160{
161 return Qt3DRender::QLevelOfDetailBoundingSphere(center, radius);
162}
163
164Qt3DRender::QLevelOfDetailBoundingSphere Quick3DLevelOfDetailLoader::volumeOverride() const
165{
166 Q_D(const Quick3DLevelOfDetailLoader);
167 return d->m_lod->volumeOverride();
168}
169
170void Quick3DLevelOfDetailLoader::setVolumeOverride(const Qt3DRender::QLevelOfDetailBoundingSphere &volumeOverride)
171{
172 Q_D(Quick3DLevelOfDetailLoader);
173 d->m_lod->setVolumeOverride(volumeOverride);
174}
175
176QObject *Quick3DLevelOfDetailLoader::entity() const
177{
178 Q_D(const Quick3DLevelOfDetailLoader);
179 return d->m_loader->entity();
180}
181
182QUrl Quick3DLevelOfDetailLoader::source() const
183{
184 Q_D(const Quick3DLevelOfDetailLoader);
185 return d->m_loader->source();
186}
187
188} // namespace Quick
189} // namespace Extras
190} // namespace Qt3DExtras
191
192QT_END_NAMESPACE
193
194
195

source code of qt3d/src/quick3d/quick3dextras/items/quick3dlevelofdetailloader.cpp