1// Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "quick3dlevelofdetailloader_p_p.h"
5#include <Qt3DRender/qlevelofdetailboundingsphere.h>
6#include <Qt3DRender/qcamera.h>
7#include <Qt3DQuick/private/quick3dentityloader_p.h>
8
9QT_BEGIN_NAMESPACE
10
11namespace Qt3DExtras {
12namespace Extras {
13namespace Quick {
14
15Quick3DLevelOfDetailLoaderPrivate::Quick3DLevelOfDetailLoaderPrivate()
16 : QEntityPrivate()
17 , m_loader(new Qt3DCore::Quick::Quick3DEntityLoader)
18 , m_lod(new Qt3DRender::QLevelOfDetail)
19{
20}
21
22Quick3DLevelOfDetailLoader::Quick3DLevelOfDetailLoader(QNode *parent)
23 : QEntity(*new Quick3DLevelOfDetailLoaderPrivate, parent)
24{
25 Q_D(Quick3DLevelOfDetailLoader);
26 d->m_loader->setParent(this);
27 d->m_loader->addComponent(comp: d->m_lod);
28
29 connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::cameraChanged,
30 context: this, slot: &Quick3DLevelOfDetailLoader::cameraChanged);
31 connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::currentIndexChanged,
32 context: this, slot: &Quick3DLevelOfDetailLoader::currentIndexChanged);
33 connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::thresholdTypeChanged,
34 context: this, slot: &Quick3DLevelOfDetailLoader::thresholdTypeChanged);
35 connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::thresholdsChanged,
36 context: this, slot: &Quick3DLevelOfDetailLoader::thresholdsChanged);
37 connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::volumeOverrideChanged,
38 context: this, slot: &Quick3DLevelOfDetailLoader::volumeOverrideChanged);
39 connect(sender: d->m_loader, signal: &Qt3DCore::Quick::Quick3DEntityLoader::entityChanged,
40 context: this, slot: &Quick3DLevelOfDetailLoader::entityChanged);
41 connect(sender: d->m_loader, signal: &Qt3DCore::Quick::Quick3DEntityLoader::sourceChanged,
42 context: this, slot: &Quick3DLevelOfDetailLoader::sourceChanged);
43
44 connect(sender: this, signal: &Quick3DLevelOfDetailLoader::enabledChanged,
45 context: d->m_lod, slot: &Qt3DRender::QLevelOfDetail::setEnabled);
46
47 auto applyCurrentSource = [this] {
48 Q_D(Quick3DLevelOfDetailLoader);
49 const auto index = currentIndex();
50 if (index >= 0 && index < d->m_sources.size())
51 d->m_loader->setSource(d->m_sources.at(i: index).toUrl());
52 };
53
54 connect(sender: this, signal: &Quick3DLevelOfDetailLoader::sourcesChanged,
55 context: this, slot&: applyCurrentSource);
56 connect(sender: this, signal: &Quick3DLevelOfDetailLoader::currentIndexChanged,
57 context: this, slot&: applyCurrentSource);
58}
59
60QVariantList Quick3DLevelOfDetailLoader::sources() const
61{
62 Q_D(const Quick3DLevelOfDetailLoader);
63 return d->m_sources;
64}
65
66void Quick3DLevelOfDetailLoader::setSources(const QVariantList &sources)
67{
68 Q_D(Quick3DLevelOfDetailLoader);
69 if (d->m_sources != sources) {
70 d->m_sources = sources;
71 emit sourcesChanged();
72 }
73}
74
75Qt3DRender::QCamera *Quick3DLevelOfDetailLoader::camera() const
76{
77 Q_D(const Quick3DLevelOfDetailLoader);
78 return d->m_lod->camera();
79}
80
81void Quick3DLevelOfDetailLoader::setCamera(Qt3DRender::QCamera *camera)
82{
83 Q_D(Quick3DLevelOfDetailLoader);
84 d->m_lod->setCamera(camera);
85}
86
87int Quick3DLevelOfDetailLoader::currentIndex() const
88{
89 Q_D(const Quick3DLevelOfDetailLoader);
90 return d->m_lod->currentIndex();
91}
92
93void Quick3DLevelOfDetailLoader::setCurrentIndex(int currentIndex)
94{
95 Q_D(Quick3DLevelOfDetailLoader);
96 d->m_lod->setCurrentIndex(currentIndex);
97}
98
99Qt3DRender::QLevelOfDetail::ThresholdType Quick3DLevelOfDetailLoader::thresholdType() const
100{
101 Q_D(const Quick3DLevelOfDetailLoader);
102 return d->m_lod->thresholdType();
103}
104
105void Quick3DLevelOfDetailLoader::setThresholdType(Qt3DRender::QLevelOfDetail::ThresholdType thresholdType)
106{
107 Q_D(Quick3DLevelOfDetailLoader);
108 d->m_lod->setThresholdType(thresholdType);
109}
110
111QList<qreal> Quick3DLevelOfDetailLoader::thresholds() const
112{
113 Q_D(const Quick3DLevelOfDetailLoader);
114 return d->m_lod->thresholds();
115}
116
117void Quick3DLevelOfDetailLoader::setThresholds(const QList<qreal> &thresholds)
118{
119 Q_D(Quick3DLevelOfDetailLoader);
120 d->m_lod->setThresholds(thresholds);
121}
122
123Qt3DRender::QLevelOfDetailBoundingSphere Quick3DLevelOfDetailLoader::createBoundingSphere(const QVector3D &center, float radius)
124{
125 return Qt3DRender::QLevelOfDetailBoundingSphere(center, radius);
126}
127
128Qt3DRender::QLevelOfDetailBoundingSphere Quick3DLevelOfDetailLoader::volumeOverride() const
129{
130 Q_D(const Quick3DLevelOfDetailLoader);
131 return d->m_lod->volumeOverride();
132}
133
134void Quick3DLevelOfDetailLoader::setVolumeOverride(const Qt3DRender::QLevelOfDetailBoundingSphere &volumeOverride)
135{
136 Q_D(Quick3DLevelOfDetailLoader);
137 d->m_lod->setVolumeOverride(volumeOverride);
138}
139
140QObject *Quick3DLevelOfDetailLoader::entity() const
141{
142 Q_D(const Quick3DLevelOfDetailLoader);
143 return d->m_loader->entity();
144}
145
146QUrl Quick3DLevelOfDetailLoader::source() const
147{
148 Q_D(const Quick3DLevelOfDetailLoader);
149 return d->m_loader->source();
150}
151
152} // namespace Quick
153} // namespace Extras
154} // namespace Qt3DExtras
155
156QT_END_NAMESPACE
157
158#include "moc_quick3dlevelofdetailloader_p.cpp"
159
160
161

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